Merge remote-tracking branch 'upstream/4.5' into 4.5-4.6-2015-03-23-18-42-19
[civicrm-core.git] / tests / phpunit / CRM / Pledge / BAO / PledgeBlockTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 protected function setUp() {
44 parent::setUp();
45 $this->_contributionPageId = ContributionPage::create();
46 }
47
48 /**
49 * Tears down the fixture, for example, closes a network connection.
50 * This method is called after a test is executed.
51 */
52 protected function tearDown() {
53 }
54
55 /**
56 * create() and deletepledgeblock() method
57 */
58 public function testCreateAndDeletePledgeBlock() {
59
60 $pledgeFrequencyUnit = array(
61 'week' => 1,
62 'month' => 1,
63 'year' => 1,
64 );
65
66 $params = array(
67 'entity_id' => $this->_contributionPageId,
68 'entity_table' => 'civicrm_contribution_page',
69 'pledge_frequency_unit' => $pledgeFrequencyUnit,
70 'max_reminders' => 2,
71 'initial_reminder_day' => 2,
72 'additional_reminder_day' => 1,
73 );
74
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'
79 );
80
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'
85 );
86 }
87
88 /**
89 * Add() method (add and edit modes of pledge block)
90 */
91 public function testAddPledgeBlock() {
92
93 $pledgeFrequencyUnit = array(
94 'week' => 1,
95 'month' => 1,
96 'year' => 1,
97 );
98
99 $params = 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,
106 );
107
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);
112 }
113
114 $params = array(
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,
123 );
124
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);
129 }
130 }
131
132 /**
133 * Retrieve() and getPledgeBlock() method of pledge block
134 */
135 public function testRetrieveAndGetPledgeBlock() {
136
137 $pledgeFrequencyUnit = array(
138 'week' => 1,
139 'month' => 1,
140 'year' => 1,
141 );
142
143 $params = 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,
150 );
151
152 $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params);
153
154 // use retrieve() method
155 $retrieveParams = array(
156 'entity_id' => $this->_contributionPageId,
157 'entity_table' => 'civicrm_contribution_page',
158 );
159 $default = array();
160 $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default);
161
162 // use getPledgeBlock() method
163 $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_contributionPageId);
164
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]);
169 }
170
171 // Also check for pledgeBlock id.
172 $this->assertEquals($pledgeBlock->id, $retrievePledgeBlock->id);
173 $this->assertEquals($pledgeBlock->id, $getPledgeBlock['id']);
174 }
175
176 }