INFRA-132 - Fix misc oddball syntax
[civicrm-core.git] / tests / phpunit / CRM / Batch / Form / EntryTest.php
1 <?php
2
3 /**
4 * File for the EntryTest class
5 *
6 * (PHP 5)
7 *
8 * @package CiviCRM
9 *
10 * This file is part of CiviCRM
11 *
12 * CiviCRM is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
16 *
17 * CiviCRM is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public
23 * License along with this program. If not, see
24 * <http://www.gnu.org/licenses/>.
25 */
26
27 require_once 'CiviTest/CiviUnitTestCase.php';
28
29
30 /**
31 * Test CRM/Member/BAO Membership Log add , delete functions
32 *
33 * @package CiviCRM
34 */
35 class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
36
37 /**
38 * Membership type name used in test function
39 * @var String
40 */
41 protected $_membershipTypeName = NULL;
42
43 /**
44 * Membership type id used in test function
45 * @var String
46 */
47 protected $_membershipTypeID = NULL;
48
49 /**
50 * Contact id used in test function
51 * @var String
52 */
53 protected $_contactID = NULL;
54 /**
55 * Contact id used in test function
56 * @var String
57 */
58 protected $_contactID2 = NULL;
59
60 /**
61 * Contact id used in test function
62 * @var String
63 */
64 protected $_contactID3 = NULL;
65
66 /**
67 * Contact id used in test function
68 * @var String
69 */
70 protected $_contactID4 = NULL;
71
72 public function setUp() {
73 parent::setUp();
74
75 $params = array(
76 'contact_type_a' => 'Individual',
77 'contact_type_b' => 'Organization',
78 'name_a_b' => 'Test Employee of',
79 'name_b_a' => 'Test Employer of',
80 );
81 $this->_relationshipTypeId = $this->relationshipTypeCreate($params);
82 $this->_orgContactID = $this->organizationCreate();
83 $this->_financialTypeId = 1;
84 $this->_membershipTypeName = 'Mickey Mouse Club Member';
85 $params = array(
86 'name' => $this->_membershipTypeName,
87 'description' => NULL,
88 'minimum_fee' => 10,
89 'duration_unit' => 'year',
90 'member_of_contact_id' => $this->_orgContactID,
91 'period_type' => 'fixed',
92 'duration_interval' => 1,
93 'financial_type_id' => $this->_financialTypeId,
94 'relationship_type_id' => $this->_relationshipTypeId,
95 'visibility' => 'Public',
96 'is_active' => 1,
97 'fixed_period_start_day' => 101,
98 'fixed_period_rollover_day' => 1231,
99 'domain_id' => CRM_Core_Config::domainID(),
100 );
101 $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
102 $this->_membershipTypeID = $membershipType['id'];
103
104 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
105 $this->_contactID = $this->individualCreate();
106 $contact2Params = array(
107 'first_name' => 'Anthonita',
108 'middle_name' => 'J.',
109 'last_name' => 'Anderson',
110 'prefix_id' => 3,
111 'suffix_id' => 3,
112 'email' => 'b@c.com',
113 'contact_type' => 'Individual',
114 );
115 $this->_contactID2 = $this->individualCreate($contact2Params);
116 $this->_contactID3 = $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
117 $this->_contactID4 = $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
118
119 $session = CRM_Core_Session::singleton();
120 $session->set('dateTypes', 1);
121 $this->_sethtmlGlobals();
122
123 }
124
125 /**
126 * Tears down the fixture, for example, closes a network connection.
127 * This method is called after a test is executed.
128 *
129 */
130 public function tearDown()
131 {
132 $this->quickCleanUpFinancialEntities();
133 $this->relationshipTypeDelete($this->_relationshipTypeId);
134 if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID))) {
135 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
136 }
137 $this->membershipStatusDelete($this->_membershipStatusID);
138 $this->contactDelete($this->_contactID);
139 $this->contactDelete($this->_contactID2);
140 $this->contactDelete($this->_orgContactID);
141 }
142
143 /**
144 * Test Import
145 */
146 public function testProcessMembership() {
147 $form = new CRM_Batch_Form_Entry();
148 $params = $this->getMembershipData();
149 $this->assertTrue($form->testProcessMembership($params));
150 $result = $this->callAPISuccess('membership', 'get', array());
151 $this->assertEquals(3, $result['count']);
152 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
153 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
154 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
155
156 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
157 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
158 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
159 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
160
161 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
162 $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
163 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
164 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
165 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
166 $this->assertEquals(3, $result['count']);
167 foreach ($result['values'] as $contribution) {
168 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
169 'contribution_id' => $contribution['id'],
170 'return' => 'line_total',
171
172 )), $contribution['total_amount']);
173 }
174 }
175
176 /**
177 * Test Contribution Import
178 */
179 public function testProcessContribution() {
180 $this->offsetDefaultPriceSet();
181 $form = new CRM_Batch_Form_Entry();
182 $params = $this->getContributionData();
183 $this->assertTrue($form->testProcessContribution($params));
184 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
185 $this->assertEquals(2, $result['count']);
186 foreach ($result['values'] as $contribution) {
187 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
188 'contribution_id' => $contribution['id'],
189 'return' => 'line_total',
190
191 )), $contribution['total_amount']);
192 }
193 }
194 /**
195 * Data provider for test process membership
196 * @return array
197 */
198 public function getMembershipData() {
199
200 return array(
201 'batch_id' => 4,
202 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
203 'primary_contact_id' => array(
204 1 => $this->_contactID,
205 2 => $this->_contactID2,
206 3 => $this->_contactID3,
207 ),
208 'field' => array(
209 1 => array(
210 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
211 'join_date' => '07/22/2013',
212 'membership_start_date' => NULL,
213 'membership_end_date' => NULL,
214 'membership_source' => NULL,
215 'financial_type' => 2,
216 'total_amount' => 1,
217 'receive_date' => '07/24/2013',
218 'receive_date_time' => NULL,
219 'payment_instrument' => 1,
220 'check_number' => NULL,
221 'contribution_status_id' => 1,
222 ),
223 2 => array(
224 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
225 'join_date' => '07/03/2013',
226 'membership_start_date' => '02/03/2013',
227 'membership_end_date' => NULL,
228 'membership_source' => NULL,
229 'financial_type' => 2,
230 'total_amount' => 1,
231 'receive_date' => '07/17/2013',
232 'receive_date_time' => NULL,
233 'payment_instrument' => NULL,
234 'check_number' => NULL,
235 'contribution_status_id' => 1,
236 ),
237 // no join date, coded end date
238 3 => array(
239 'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
240 'join_date' => NULL,
241 'membership_start_date' => NULL,
242 'membership_end_date' => '2013-12-01',
243 'membership_source' => NULL,
244 'financial_type' => 2,
245 'total_amount' => 1,
246 'receive_date' => '07/17/2013',
247 'receive_date_time' => NULL,
248 'payment_instrument' => NULL,
249 'check_number' => NULL,
250 'contribution_status_id' => 1,
251 ),
252
253 ),
254 'actualBatchTotal' => 0,
255
256 );
257 }
258
259 /**
260 * @return array
261 */
262 public function getContributionData() {
263 return array(
264 //'batch_id' => 4,
265 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
266 'primary_contact_id' => array(
267 1 => $this->_contactID,
268 2 => $this->_contactID2,
269 3 => $this->_contactID3,
270 ),
271 'field' => array(
272 1 => array(
273 'financial_type' => 1,
274 'total_amount' => 15,
275 'receive_date' => '07/24/2013',
276 'receive_date_time' => NULL,
277 'payment_instrument' => 1,
278 'check_number' => NULL,
279 'contribution_status_id' => 1,
280 ),
281 2 => array(
282 'financial_type' => 1,
283 'total_amount' => 15,
284 'receive_date' => '07/24/2013',
285 'receive_date_time' => NULL,
286 'payment_instrument' => 1,
287 'check_number' => NULL,
288 'contribution_status_id' => 1,
289 ),
290 ),
291 'actualBatchTotal' => 30,
292
293 );
294 }
295 }