3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 require_once 'CiviTest/ContributionPage.php';
33 * Test class for CRM_Pledge_BAO_PledgeBlock BAO
37 class CRM_Pledge_BAO_PledgeBlockTest
extends CiviUnitTestCase
{
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
43 protected function setUp() {
45 $this->_contributionPageId
= ContributionPage
::create();
49 * Tears down the fixture, for example, closes a network connection.
50 * This method is called after a test is executed.
52 protected function tearDown() {
56 * create() and deletepledgeblock() method
58 public function testCreateAndDeletePledgeBlock() {
60 $pledgeFrequencyUnit = array(
67 'entity_id' => $this->_contributionPageId
,
68 'entity_table' => 'civicrm_contribution_page',
69 'pledge_frequency_unit' => $pledgeFrequencyUnit,
71 'initial_reminder_day' => 2,
72 'additional_reminder_day' => 1,
75 //Checking for pledgeBlock id in the Pledge_block table.
76 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::create($params);
77 $pledgeBlockId = $this->assertDBNotNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id
, 'id',
78 'id', 'Check DB for Pledge block id'
81 //Checking for pledgeBlock id after delete.
82 CRM_Pledge_BAO_PledgeBlock
::deletePledgeBlock($pledgeBlock->id
);
83 $pledgeBlockId = $this->assertDBNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id
, 'id',
84 'id', 'Check DB for Pledge block id'
89 * Add() method (add and edit modes of pledge block)
91 public function testAddPledgeBlock() {
93 $pledgeFrequencyUnit = array(
100 'entity_id' => $this->_contributionPageId
,
101 'entity_table' => 'civicrm_contribution_page',
102 'pledge_frequency_unit' => $pledgeFrequencyUnit,
103 'max_reminders' => 2,
104 'initial_reminder_day' => 2,
105 'additional_reminder_day' => 1,
108 // check for add pledge block
109 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::add($params);
110 foreach ($params as $param => $value) {
111 $this->assertEquals($value, $pledgeBlock->$param);
115 'id' => $pledgeBlock->id
,
116 'entity_id' => $this->_contributionPageId
,
117 'entity_table' => 'civicrm_contribution_page',
118 'pledge_frequency_unit' => $pledgeFrequencyUnit,
119 'max_reminders' => 3,
120 'initial_reminder_day' => 3,
121 'additional_reminder_day' => 2,
122 'is_pledge_interval' => 1,
125 // also check for edit pledge block
126 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::add($params);
127 foreach ($params as $param => $value) {
128 $this->assertEquals($value, $pledgeBlock->$param);
133 * Retrieve() and getPledgeBlock() method of pledge block
135 public function testRetrieveAndGetPledgeBlock() {
137 $pledgeFrequencyUnit = array(
144 'entity_id' => $this->_contributionPageId
,
145 'entity_table' => 'civicrm_contribution_page',
146 'pledge_frequency_unit' => $pledgeFrequencyUnit,
147 'max_reminders' => 2,
148 'initial_reminder_day' => 2,
149 'additional_reminder_day' => 1,
152 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::create($params);
154 // use retrieve() method
155 $retrieveParams = array(
156 'entity_id' => $this->_contributionPageId
,
157 'entity_table' => 'civicrm_contribution_page',
160 $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock
::retrieve($retrieveParams, $default);
162 // use getPledgeBlock() method
163 $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock
::getPledgeBlock($this->_contributionPageId
);
165 // check on both retrieve and getPledgeBlock values
166 foreach ($params as $param => $value) {
167 $this->assertEquals($value, $retrievePledgeBlock->$param);
168 $this->assertEquals($value, $getPledgeBlock[$param]);
171 // Also check for pledgeBlock id.
172 $this->assertEquals($pledgeBlock->id
, $retrievePledgeBlock->id
);
173 $this->assertEquals($pledgeBlock->id
, $getPledgeBlock['id']);