3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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.
45 protected function setUp() {
47 $this->_contributionPageId
= ContributionPage
::create();
51 * Tears down the fixture, for example, closes a network connection.
52 * This method is called after a test is executed.
56 protected function tearDown() {}
63 'name' => 'PledgeBlock BAOs',
64 'description' => 'Test all Pledge_BAO_PledgeBlock methods.',
65 'group' => 'CiviCRM BAO Tests',
70 * create() and deletepledgeblock() method
72 function testCreateAndDeletePledgeBlock() {
74 $pledgeFrequencyUnit = array(
81 'entity_id' => $this->_contributionPageId
,
82 'entity_table' => 'civicrm_contribution_page',
83 'pledge_frequency_unit' => $pledgeFrequencyUnit,
85 'initial_reminder_day' => 2,
86 'additional_reminder_day' => 1,
89 //Checking for pledgeBlock id in the Pledge_block table.
90 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::create($params);
91 $pledgeBlockId = $this->assertDBNotNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id
, 'id',
92 'id', 'Check DB for Pledge block id'
95 //Checking for pledgeBlock id after delete.
96 CRM_Pledge_BAO_PledgeBlock
::deletePledgeBlock($pledgeBlock->id
);
97 $pledgeBlockId = $this->assertDBNull('CRM_Pledge_DAO_PledgeBlock', $pledgeBlock->id
, 'id',
98 'id', 'Check DB for Pledge block id'
103 * Add() method (add and edit modes of pledge block)
105 function testAddPledgeBlock() {
107 $pledgeFrequencyUnit = array(
114 'entity_id' => $this->_contributionPageId
,
115 'entity_table' => 'civicrm_contribution_page',
116 'pledge_frequency_unit' => $pledgeFrequencyUnit,
117 'max_reminders' => 2,
118 'initial_reminder_day' => 2,
119 'additional_reminder_day' => 1,
122 // check for add pledge block
123 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::add($params);
124 foreach ($params as $param => $value) {
125 $this->assertEquals($value, $pledgeBlock->$param);
129 'id' => $pledgeBlock->id
,
130 'entity_id' => $this->_contributionPageId
,
131 'entity_table' => 'civicrm_contribution_page',
132 'pledge_frequency_unit' => $pledgeFrequencyUnit,
133 'max_reminders' => 3,
134 'initial_reminder_day' => 3,
135 'additional_reminder_day' => 2,
136 'is_pledge_interval' => 1,
139 // also check for edit pledge block
140 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::add($params);
141 foreach ($params as $param => $value) {
142 $this->assertEquals($value, $pledgeBlock->$param);
147 * Retrieve() and getPledgeBlock() method of pledge block
149 function testRetrieveAndGetPledgeBlock() {
151 $pledgeFrequencyUnit = array(
158 'entity_id' => $this->_contributionPageId
,
159 'entity_table' => 'civicrm_contribution_page',
160 'pledge_frequency_unit' => $pledgeFrequencyUnit,
161 'max_reminders' => 2,
162 'initial_reminder_day' => 2,
163 'additional_reminder_day' => 1,
166 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock
::create($params);
168 // use retrieve() method
169 $retrieveParams = array(
170 'entity_id' => $this->_contributionPageId
,
171 'entity_table' => 'civicrm_contribution_page',
174 $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock
::retrieve($retrieveParams, $default);
176 // use getPledgeBlock() method
177 $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock
::getPledgeBlock($this->_contributionPageId
);
179 // check on both retrieve and getPledgeBlock values
180 foreach ($params as $param => $value) {
181 $this->assertEquals($value, $retrievePledgeBlock->$param);
182 $this->assertEquals($value, $getPledgeBlock[$param]);
185 // Also check for pledgeBlock id.
186 $this->assertEquals($pledgeBlock->id
, $retrievePledgeBlock->id
);
187 $this->assertEquals($pledgeBlock->id
, $getPledgeBlock['id']);