Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-12-09-14-48-51
[civicrm-core.git] / tests / phpunit / CRM / Pledge / BAO / PledgeBlockTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 require_once 'CiviTest/ContributionPage.php';
31
32 /**
33 * Test class for CRM_Pledge_BAO_PledgeBlock BAO
34 *
35 * @package CiviCRM
36 */
37 class CRM_Pledge_BAO_PledgeBlockTest extends CiviUnitTestCase {
38
39 /**
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
42 *
43 * @access protected
44 */
45 protected function setUp() {
46 parent::setUp();
47 $this->_contributionPageId = ContributionPage::create();
48 }
49
50 /**
51 * Tears down the fixture, for example, closes a network connection.
52 * This method is called after a test is executed.
53 *
54 * @access protected
55 */
56 protected function tearDown() {}
57
58 /**
59 * test info
60 */
61 function get_info() {
62 return array(
63 'name' => 'PledgeBlock BAOs',
64 'description' => 'Test all Pledge_BAO_PledgeBlock methods.',
65 'group' => 'CiviCRM BAO Tests',
66 );
67 }
68
69 /**
70 * create() and deletepledgeblock() method
71 */
72 function testCreateAndDeletePledgeBlock() {
73
74 $pledgeFrequencyUnit = array(
75 'week' => 1,
76 'month' => 1,
77 'year' => 1,
78 );
79
80 $params = array(
81 'entity_id' => $this->_contributionPageId,
82 'entity_table' => 'civicrm_contribution_page',
83 'pledge_frequency_unit' => $pledgeFrequencyUnit,
84 'max_reminders' => 2,
85 'initial_reminder_day' => 2,
86 'additional_reminder_day' => 1,
87 );
88
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'
93 );
94
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'
99 );
100 }
101
102 /**
103 * Add() method (add and edit modes of pledge block)
104 */
105 function testAddPledgeBlock() {
106
107 $pledgeFrequencyUnit = array(
108 'week' => 1,
109 'month' => 1,
110 'year' => 1,
111 );
112
113 $params = 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,
120 );
121
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);
126 }
127
128 $params = array(
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,
137 );
138
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);
143 }
144 }
145
146 /**
147 * Retrieve() and getPledgeBlock() method of pledge block
148 */
149 function testRetrieveAndGetPledgeBlock() {
150
151 $pledgeFrequencyUnit = array(
152 'week' => 1,
153 'month' => 1,
154 'year' => 1,
155 );
156
157 $params = 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,
164 );
165
166 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
167
168 // use retrieve() method
169 $retrieveParams = array(
170 'entity_id' => $this->_contributionPageId,
171 'entity_table' => 'civicrm_contribution_page',
172 );
173 $default = array();
174 $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default);
175
176 // use getPledgeBlock() method
177 $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_contributionPageId);
178
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]);
183 }
184
185 // Also check for pledgeBlock id.
186 $this->assertEquals($pledgeBlock->id, $retrievePledgeBlock->id);
187 $this->assertEquals($pledgeBlock->id, $getPledgeBlock['id']);
188 }
189 }
190