Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
7865d848 EM |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
7865d848 EM |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
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 | */ | |
6a488035 TO |
27 | |
28 | /** | |
29 | * File for the MembershipTest class | |
30 | * | |
31 | * (PHP 5) | |
32 | * | |
6c6e6187 | 33 | * @author Walt Haas <walt@dharmatech.org> (801) 534-1262 |
6a488035 TO |
34 | */ |
35 | ||
6a488035 | 36 | /** |
7865d848 | 37 | * Test CRM_Member_Form_Membership functions. |
6a488035 | 38 | * |
6c6e6187 | 39 | * @package CiviCRM |
acb109b7 | 40 | * @group headless |
6a488035 TO |
41 | */ |
42 | class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { | |
43 | ||
7865d848 EM |
44 | /** |
45 | * Assume empty database with just civicrm_data. | |
46 | */ | |
47 | protected $_individualId; | |
48 | protected $_contribution; | |
49 | protected $_financialTypeId = 1; | |
50 | protected $_apiversion; | |
51 | protected $_entity = 'Membership'; | |
52 | protected $_params; | |
53 | protected $_ids = array(); | |
54 | protected $_paymentProcessorID; | |
55 | ||
08fd4b45 EM |
56 | /** |
57 | * Membership type ID for annual fixed membership. | |
58 | * | |
59 | * @var int | |
60 | */ | |
61 | protected $membershipTypeAnnualFixedID; | |
62 | ||
7865d848 EM |
63 | /** |
64 | * Parameters to create payment processor. | |
65 | * | |
66 | * @var array | |
67 | */ | |
68 | protected $_processorParams = array(); | |
69 | ||
70 | /** | |
71 | * ID of created membership. | |
72 | * | |
73 | * @var int | |
74 | */ | |
75 | protected $_membershipID; | |
76 | ||
77 | /** | |
78 | * Payment instrument mapping. | |
79 | * | |
80 | * @var array | |
81 | */ | |
82 | protected $paymentInstruments = array(); | |
83 | ||
6a488035 | 84 | /** |
41709813 | 85 | * Test setup for every test. |
6a488035 | 86 | * |
41709813 EM |
87 | * Connect to the database, truncate the tables that will be used |
88 | * and redirect stdin to a temporary file. | |
6a488035 TO |
89 | */ |
90 | public function setUp() { | |
cb447e7a | 91 | $this->_apiversion = 3; |
6a488035 TO |
92 | parent::setUp(); |
93 | ||
cb447e7a | 94 | $this->_individualId = $this->individualCreate(); |
8950ecdc | 95 | $this->_paymentProcessorID = $this->processorCreate(); |
41709813 | 96 | // Insert test data. |
6a488035 TO |
97 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); |
98 | $op->execute($this->_dbconn, | |
bbfd46a5 | 99 | $this->createFlatXMLDataSet( |
6a488035 TO |
100 | dirname(__FILE__) . '/dataset/data.xml' |
101 | ) | |
102 | ); | |
08fd4b45 EM |
103 | $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array( |
104 | 'domain_id' => 1, | |
105 | 'name' => "AnnualFixed", | |
106 | 'member_of_contact_id' => 23, | |
107 | 'duration_unit' => "year", | |
108 | 'duration_interval' => 1, | |
109 | 'period_type' => "fixed", | |
110 | 'fixed_period_start_day' => "101", | |
111 | 'fixed_period_rollover_day' => "1231", | |
112 | 'relationship_type_id' => 20, | |
113 | 'financial_type_id' => 2, | |
114 | )); | |
115 | $this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id']; | |
7865d848 | 116 | |
7865d848 EM |
117 | $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id')); |
118 | $this->paymentInstruments = $instruments['values']; | |
119 | } | |
120 | ||
cb447e7a EM |
121 | /** |
122 | * Clean up after each test. | |
123 | */ | |
124 | public function tearDown() { | |
125 | $this->quickCleanUpFinancialEntities(); | |
126 | $this->quickCleanup( | |
127 | array( | |
128 | 'civicrm_relationship', | |
129 | 'civicrm_membership_type', | |
130 | 'civicrm_membership', | |
a8215a8d | 131 | 'civicrm_uf_match', |
cb447e7a EM |
132 | ) |
133 | ); | |
134 | $this->callAPISuccess('contact', 'delete', array('id' => 17, 'skip_undelete' => TRUE)); | |
135 | $this->callAPISuccess('contact', 'delete', array('id' => 23, 'skip_undelete' => TRUE)); | |
136 | $this->callAPISuccess('relationship_type', 'delete', array('id' => 20)); | |
137 | } | |
138 | ||
6a488035 TO |
139 | /** |
140 | * Test CRM_Member_Form_Membership::buildQuickForm() | |
141 | */ | |
142 | //function testCRMMemberFormMembershipBuildQuickForm() | |
143 | //{ | |
144 | // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" ); | |
145 | //} | |
146 | ||
147 | /** | |
148 | * Test CRM_Member_Form_Membership::formRule() with a parameter | |
149 | * that has an empty contact_select_id value | |
150 | */ | |
00be9182 | 151 | public function testFormRuleEmptyContact() { |
6a488035 TO |
152 | $params = array( |
153 | 'contact_select_id' => 0, | |
9e8b2bb1 | 154 | 'membership_type_id' => array(1 => NULL), |
6a488035 TO |
155 | ); |
156 | $files = array(); | |
a130e045 | 157 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 158 | $rc = $obj->formRule($params, $files, $obj); |
cb447e7a EM |
159 | $this->assertType('array', $rc); |
160 | $this->assertTrue(array_key_exists('membership_type_id', $rc)); | |
6a488035 TO |
161 | |
162 | $params['membership_type_id'] = array(1 => 3); | |
163 | $rc = $obj->formRule($params, $files, $obj); | |
cb447e7a EM |
164 | $this->assertType('array', $rc); |
165 | $this->assertTrue(array_key_exists('join_date', $rc)); | |
6a488035 TO |
166 | } |
167 | ||
168 | /** | |
cb447e7a EM |
169 | * Test that form rule fails if start date is before join date. |
170 | * | |
171 | * Test CRM_Member_Form_Membership::formRule() with a parameter | |
172 | * that has an start date before the join date and a rolling | |
173 | * membership type. | |
6a488035 | 174 | */ |
00be9182 | 175 | public function testFormRuleRollingEarlyStart() { |
92915c55 TO |
176 | $unixNow = time(); |
177 | $ymdNow = date('m/d/Y', $unixNow); | |
6a488035 | 178 | $unixYesterday = $unixNow - (24 * 60 * 60); |
92915c55 TO |
179 | $ymdYesterday = date('m/d/Y', $unixYesterday); |
180 | $params = array( | |
6a488035 TO |
181 | 'join_date' => $ymdNow, |
182 | 'start_date' => $ymdYesterday, | |
183 | 'end_date' => '', | |
cb447e7a | 184 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
185 | ); |
186 | $files = array(); | |
a130e045 | 187 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 188 | $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'), |
6a488035 TO |
189 | $params, $files, $obj |
190 | ); | |
cb447e7a EM |
191 | $this->assertType('array', $rc); |
192 | $this->assertTrue(array_key_exists('start_date', $rc)); | |
6a488035 TO |
193 | } |
194 | ||
195 | /** | |
196 | * Test CRM_Member_Form_Membership::formRule() with a parameter | |
197 | * that has an end date before the start date and a rolling | |
198 | * membership type | |
199 | */ | |
00be9182 | 200 | public function testFormRuleRollingEarlyEnd() { |
92915c55 TO |
201 | $unixNow = time(); |
202 | $ymdNow = date('m/d/Y', $unixNow); | |
6a488035 | 203 | $unixYesterday = $unixNow - (24 * 60 * 60); |
92915c55 TO |
204 | $ymdYesterday = date('m/d/Y', $unixYesterday); |
205 | $params = array( | |
6a488035 TO |
206 | 'join_date' => $ymdNow, |
207 | 'start_date' => $ymdNow, | |
208 | 'end_date' => $ymdYesterday, | |
cb447e7a | 209 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
210 | ); |
211 | $files = array(); | |
a130e045 | 212 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 213 | $rc = $obj->formRule($params, $files, $obj); |
08fd4b45 EM |
214 | $this->assertType('array', $rc); |
215 | $this->assertTrue(array_key_exists('end_date', $rc)); | |
6a488035 TO |
216 | } |
217 | ||
218 | /** | |
41709813 | 219 | * Test CRM_Member_Form_Membership::formRule() with end date but no start date and a rolling membership type. |
6a488035 | 220 | */ |
00be9182 | 221 | public function testFormRuleRollingEndNoStart() { |
92915c55 TO |
222 | $unixNow = time(); |
223 | $ymdNow = date('m/d/Y', $unixNow); | |
6a488035 | 224 | $unixYearFromNow = $unixNow + (365 * 24 * 60 * 60); |
92915c55 TO |
225 | $ymdYearFromNow = date('m/d/Y', $unixYearFromNow); |
226 | $params = array( | |
6a488035 TO |
227 | 'join_date' => $ymdNow, |
228 | 'start_date' => '', | |
229 | 'end_date' => $ymdYearFromNow, | |
cb447e7a | 230 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
231 | ); |
232 | $files = array(); | |
a130e045 | 233 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 234 | $rc = $obj->formRule($params, $files, $obj); |
08fd4b45 EM |
235 | $this->assertType('array', $rc); |
236 | $this->assertTrue(array_key_exists('start_date', $rc)); | |
6a488035 TO |
237 | } |
238 | ||
239 | /** | |
240 | * Test CRM_Member_Form_Membership::formRule() with a parameter | |
241 | * that has an end date and a lifetime membership type | |
242 | */ | |
00be9182 | 243 | public function testFormRuleRollingLifetimeEnd() { |
92915c55 | 244 | $unixNow = time(); |
6a488035 | 245 | $unixYearFromNow = $unixNow + (365 * 24 * 60 * 60); |
92915c55 | 246 | $params = array( |
fada2199 | 247 | 'join_date' => date('m/d/Y', $unixNow), |
6a488035 TO |
248 | 'start_date' => date('m/d/Y', $unixNow), |
249 | 'end_date' => date('m/d/Y', | |
250 | $unixYearFromNow | |
251 | ), | |
cb447e7a | 252 | 'membership_type_id' => array('23', '25'), |
6a488035 TO |
253 | ); |
254 | $files = array(); | |
a130e045 | 255 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 256 | $rc = $obj->formRule($params, $files, $obj); |
fada2199 EM |
257 | $this->assertType('array', $rc); |
258 | $this->assertTrue(array_key_exists('status_id', $rc)); | |
6a488035 TO |
259 | } |
260 | ||
261 | /** | |
262 | * Test CRM_Member_Form_Membership::formRule() with a parameter | |
263 | * that has an override and no status | |
264 | */ | |
00be9182 | 265 | public function testFormRuleOverrideNoStatus() { |
92915c55 | 266 | $unixNow = time(); |
92915c55 TO |
267 | $params = array( |
268 | 'join_date' => date('m/d/Y', $unixNow), | |
cb447e7a | 269 | 'membership_type_id' => array('23', '25'), |
6a488035 TO |
270 | 'is_override' => TRUE, |
271 | ); | |
272 | $files = array(); | |
a130e045 | 273 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 274 | $rc = $obj->formRule($params, $files, $obj); |
41709813 EM |
275 | $this->assertType('array', $rc); |
276 | $this->assertTrue(array_key_exists('status_id', $rc)); | |
6a488035 TO |
277 | } |
278 | ||
279 | /** | |
280 | * Test CRM_Member_Form_Membership::formRule() with a join date | |
281 | * of one month from now and a rolling membership type | |
282 | */ | |
00be9182 | 283 | public function testFormRuleRollingJoin1MonthFromNow() { |
92915c55 | 284 | $unixNow = time(); |
6a488035 | 285 | $unix1MFmNow = $unixNow + (31 * 24 * 60 * 60); |
92915c55 TO |
286 | $params = array( |
287 | 'join_date' => date('m/d/Y', $unix1MFmNow), | |
6a488035 TO |
288 | 'start_date' => '', |
289 | 'end_date' => '', | |
cb447e7a | 290 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
291 | ); |
292 | $files = array(); | |
a130e045 | 293 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 294 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 | 295 | |
41709813 EM |
296 | // Should have found no valid membership status. |
297 | $this->assertType('array', $rc); | |
298 | $this->assertTrue(array_key_exists('_qf_default', $rc)); | |
6a488035 TO |
299 | } |
300 | ||
301 | /** | |
41709813 | 302 | * Test CRM_Member_Form_Membership::formRule() with a join date of today and a rolling membership type. |
6a488035 | 303 | */ |
00be9182 | 304 | public function testFormRuleRollingJoinToday() { |
6a488035 | 305 | $unixNow = time(); |
6c6e6187 | 306 | $params = array( |
92915c55 | 307 | 'join_date' => date('m/d/Y', $unixNow), |
6a488035 TO |
308 | 'start_date' => '', |
309 | 'end_date' => '', | |
cb447e7a | 310 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
311 | ); |
312 | $files = array(); | |
a130e045 | 313 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 314 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 TO |
315 | |
316 | // Should have found New membership status | |
a15773db | 317 | $this->assertTrue($rc); |
6a488035 TO |
318 | } |
319 | ||
320 | /** | |
321 | * Test CRM_Member_Form_Membership::formRule() with a join date | |
322 | * of one month ago and a rolling membership type | |
323 | */ | |
00be9182 | 324 | public function testFormRuleRollingJoin1MonthAgo() { |
92915c55 | 325 | $unixNow = time(); |
6a488035 | 326 | $unix1MAgo = $unixNow - (31 * 24 * 60 * 60); |
92915c55 TO |
327 | $params = array( |
328 | 'join_date' => date('m/d/Y', $unix1MAgo), | |
6a488035 TO |
329 | 'start_date' => '', |
330 | 'end_date' => '', | |
cb447e7a | 331 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
332 | ); |
333 | $files = array(); | |
a130e045 | 334 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 335 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 | 336 | |
41709813 EM |
337 | // Should have found New membership status. |
338 | $this->assertTrue($rc); | |
6a488035 TO |
339 | } |
340 | ||
341 | /** | |
41709813 | 342 | * Test CRM_Member_Form_Membership::formRule() with a join date of six months ago and a rolling membership type. |
6a488035 | 343 | */ |
00be9182 | 344 | public function testFormRuleRollingJoin6MonthsAgo() { |
92915c55 | 345 | $unixNow = time(); |
6a488035 | 346 | $unix6MAgo = $unixNow - (180 * 24 * 60 * 60); |
92915c55 TO |
347 | $params = array( |
348 | 'join_date' => date('m/d/Y', $unix6MAgo), | |
6a488035 TO |
349 | 'start_date' => '', |
350 | 'end_date' => '', | |
cb447e7a | 351 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
352 | ); |
353 | $files = array(); | |
a130e045 | 354 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 355 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 | 356 | |
41709813 EM |
357 | // Should have found Current membership status. |
358 | $this->assertTrue($rc); | |
6a488035 TO |
359 | } |
360 | ||
361 | /** | |
362 | * Test CRM_Member_Form_Membership::formRule() with a join date | |
363 | * of one year+ ago and a rolling membership type | |
364 | */ | |
00be9182 | 365 | public function testFormRuleRollingJoin1YearAgo() { |
92915c55 | 366 | $unixNow = time(); |
6a488035 | 367 | $unix1YAgo = $unixNow - (370 * 24 * 60 * 60); |
92915c55 TO |
368 | $params = array( |
369 | 'join_date' => date('m/d/Y', $unix1YAgo), | |
6a488035 TO |
370 | 'start_date' => '', |
371 | 'end_date' => '', | |
cb447e7a | 372 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
373 | ); |
374 | $files = array(); | |
a130e045 | 375 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 376 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 TO |
377 | |
378 | // Should have found Grace membership status | |
a15773db | 379 | $this->assertTrue($rc); |
6a488035 TO |
380 | } |
381 | ||
382 | /** | |
383 | * Test CRM_Member_Form_Membership::formRule() with a join date | |
384 | * of two years ago and a rolling membership type | |
385 | */ | |
00be9182 | 386 | public function testFormRuleRollingJoin2YearsAgo() { |
92915c55 | 387 | $unixNow = time(); |
6a488035 | 388 | $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60); |
92915c55 TO |
389 | $params = array( |
390 | 'join_date' => date('m/d/Y', $unix2YAgo), | |
6a488035 TO |
391 | 'start_date' => '', |
392 | 'end_date' => '', | |
cb447e7a | 393 | 'membership_type_id' => array('23', '15'), |
6a488035 TO |
394 | ); |
395 | $files = array(); | |
a130e045 | 396 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 397 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 TO |
398 | |
399 | // Should have found Expired membership status | |
a15773db | 400 | $this->assertTrue($rc); |
6a488035 TO |
401 | } |
402 | ||
403 | /** | |
404 | * Test CRM_Member_Form_Membership::formRule() with a join date | |
405 | * of six months ago and a fixed membership type | |
406 | */ | |
00be9182 | 407 | public function testFormRuleFixedJoin6MonthsAgo() { |
92915c55 | 408 | $unixNow = time(); |
6a488035 | 409 | $unix6MAgo = $unixNow - (180 * 24 * 60 * 60); |
92915c55 TO |
410 | $params = array( |
411 | 'join_date' => date('m/d/Y', $unix6MAgo), | |
6a488035 TO |
412 | 'start_date' => '', |
413 | 'end_date' => '', | |
414 | 'membership_type_id' => array('23', '7'), | |
415 | ); | |
416 | $files = array(); | |
a130e045 | 417 | $obj = new CRM_Member_Form_Membership(); |
92915c55 | 418 | $rc = $obj->formRule($params, $files, $obj); |
6a488035 TO |
419 | |
420 | // Should have found Current membership status | |
cb447e7a | 421 | $this->assertTrue($rc); |
6a488035 | 422 | } |
96025800 | 423 | |
7865d848 EM |
424 | /** |
425 | * Test the submit function of the membership form. | |
426 | */ | |
427 | public function testSubmit() { | |
08fd4b45 EM |
428 | $form = $this->getForm(); |
429 | $form->_mode = 'test'; | |
c41bfe2b | 430 | $this->createLoggedInUser(); |
7865d848 EM |
431 | $params = array( |
432 | 'cid' => $this->_individualId, | |
433 | 'join_date' => date('m/d/Y', time()), | |
434 | 'start_date' => '', | |
435 | 'end_date' => '', | |
08fd4b45 EM |
436 | // This format reflects the 23 being the organisation & the 25 being the type. |
437 | 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), | |
7865d848 EM |
438 | 'auto_renew' => '0', |
439 | 'max_related' => '', | |
440 | 'num_terms' => '1', | |
441 | 'source' => '', | |
442 | 'total_amount' => '50.00', | |
059103da | 443 | 'financial_type_id' => '2', //Member dues, see data.xml |
7865d848 EM |
444 | 'soft_credit_type_id' => '', |
445 | 'soft_credit_contact_id' => '', | |
446 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
447 | 'receipt_text_signup' => 'Thank you text', | |
448 | 'payment_processor_id' => $this->_paymentProcessorID, | |
449 | 'credit_card_number' => '4111111111111111', | |
450 | 'cvv2' => '123', | |
451 | 'credit_card_exp_date' => array( | |
452 | 'M' => '9', | |
08fd4b45 | 453 | 'Y' => '2024', // TODO: Future proof |
41709813 EM |
454 | ), |
455 | 'credit_card_type' => 'Visa', | |
456 | 'billing_first_name' => 'Test', | |
457 | 'billing_middlename' => 'Last', | |
458 | 'billing_street_address-5' => '10 Test St', | |
459 | 'billing_city-5' => 'Test', | |
460 | 'billing_state_province_id-5' => '1003', | |
461 | 'billing_postal_code-5' => '90210', | |
462 | 'billing_country_id-5' => '1228', | |
7865d848 | 463 | ); |
09108d7d | 464 | $form->_contactID = $this->_individualId; |
465 | $form->testSubmit($params); | |
08fd4b45 EM |
466 | $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); |
467 | $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0); | |
468 | $contribution = $this->callAPISuccess('Contribution', 'get', array( | |
469 | 'contact_id' => $this->_individualId, | |
470 | 'is_test' => TRUE, | |
471 | )); | |
472 | ||
473 | $this->callAPISuccessGetCount('LineItem', array( | |
474 | 'entity_id' => $membership['id'], | |
475 | 'entity_table' => 'civicrm_membership', | |
476 | 'contribution_id' => $contribution['id'], | |
477 | ), 1); | |
7865d848 EM |
478 | } |
479 | ||
a8215a8d EM |
480 | /** |
481 | * Test the submit function of the membership form. | |
482 | */ | |
483 | public function testSubmitRecur() { | |
484 | $form = $this->getForm(); | |
485 | ||
486 | $this->callAPISuccess('MembershipType', 'create', array( | |
08fd4b45 | 487 | 'id' => $this->membershipTypeAnnualFixedID, |
a8215a8d EM |
488 | 'duration_unit' => 'month', |
489 | 'duration_interval' => 1, | |
490 | 'auto_renew' => TRUE, | |
491 | )); | |
492 | $form->preProcess(); | |
493 | $this->createLoggedInUser(); | |
3cc61729 | 494 | $params = $this->getBaseSubmitParams(); |
495 | $form->_mode = 'test'; | |
09108d7d | 496 | $form->_contactID = $this->_individualId; |
497 | $form->testSubmit($params); | |
3cc61729 | 498 | $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); |
499 | $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); | |
500 | ||
501 | $contribution = $this->callAPISuccess('Contribution', 'get', array( | |
502 | 'contact_id' => $this->_individualId, | |
503 | 'is_test' => TRUE, | |
504 | )); | |
505 | ||
506 | // CRM-16992. | |
507 | $this->callAPISuccessGetCount('LineItem', array( | |
508 | 'entity_id' => $membership['id'], | |
509 | 'entity_table' => 'civicrm_membership', | |
510 | 'contribution_id' => $contribution['id'], | |
511 | ), 1); | |
512 | } | |
513 | ||
09108d7d | 514 | /** |
515 | * Test the submit function of the membership form. | |
516 | */ | |
517 | public function testSubmitPayLaterWithBilling() { | |
518 | $form = $this->getForm(NULL); | |
519 | $this->createLoggedInUser(); | |
520 | $params = array( | |
521 | 'cid' => $this->_individualId, | |
522 | 'join_date' => date('m/d/Y', time()), | |
523 | 'start_date' => '', | |
524 | 'end_date' => '', | |
525 | // This format reflects the 23 being the organisation & the 25 being the type. | |
526 | 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), | |
527 | 'auto_renew' => '0', | |
528 | 'max_related' => '', | |
529 | 'num_terms' => '2', | |
530 | 'source' => '', | |
531 | 'total_amount' => '50.00', | |
532 | //Member dues, see data.xml | |
533 | 'financial_type_id' => '2', | |
534 | 'soft_credit_type_id' => '', | |
535 | 'soft_credit_contact_id' => '', | |
536 | 'payment_instrument_id' => 4, | |
537 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
538 | 'receipt_text_signup' => 'Thank you text', | |
539 | 'payment_processor_id' => $this->_paymentProcessorID, | |
540 | 'record_contribution' => TRUE, | |
541 | 'trxn_id' => 777, | |
542 | 'contribution_status_id' => 2, | |
543 | 'billing_first_name' => 'Test', | |
544 | 'billing_middlename' => 'Last', | |
545 | 'billing_street_address-5' => '10 Test St', | |
546 | 'billing_city-5' => 'Test', | |
547 | 'billing_state_province_id-5' => '1003', | |
548 | 'billing_postal_code-5' => '90210', | |
549 | 'billing_country_id-5' => '1228', | |
550 | ); | |
551 | $form->_contactID = $this->_individualId; | |
552 | ||
553 | $form->testSubmit($params); | |
554 | $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); | |
555 | $contribution = $this->callAPISuccessGetSingle('Contribution', array( | |
556 | 'contact_id' => $this->_individualId, | |
557 | 'contribution_status_id' => 2, | |
558 | )); | |
559 | $this->assertEquals($contribution['trxn_id'], 777); | |
560 | ||
561 | $this->callAPISuccessGetCount('LineItem', array( | |
562 | 'entity_id' => $membership['id'], | |
563 | 'entity_table' => 'civicrm_membership', | |
564 | 'contribution_id' => $contribution['id'], | |
565 | ), 1); | |
566 | $this->callAPISuccessGetSingle('address', array( | |
567 | 'contact_id' => $this->_individualId, | |
568 | 'street_address' => '10 Test St', | |
569 | 'postal_code' => 90210, | |
570 | )); | |
571 | } | |
572 | ||
bf6ba9fc | 573 | /** |
574 | * Test the submit function of the membership form. | |
575 | */ | |
576 | public function testSubmitRecurCompleteInstant() { | |
577 | $form = $this->getForm(); | |
e9dfe40a | 578 | $mut = new CiviMailUtils($this, TRUE); |
bf6ba9fc | 579 | $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); |
77623a96 | 580 | $processor->setDoDirectPaymentResult(array( |
581 | 'payment_status_id' => 1, | |
582 | 'trxn_id' => 'kettles boil water', | |
583 | 'fee_amount' => .14, | |
584 | )); | |
bf6ba9fc | 585 | $this->callAPISuccess('MembershipType', 'create', array( |
586 | 'id' => $this->membershipTypeAnnualFixedID, | |
587 | 'duration_unit' => 'month', | |
588 | 'duration_interval' => 1, | |
589 | 'auto_renew' => TRUE, | |
590 | )); | |
591 | $form->preProcess(); | |
592 | $this->createLoggedInUser(); | |
593 | $params = $this->getBaseSubmitParams(); | |
594 | $form->_mode = 'test'; | |
09108d7d | 595 | $form->_contactID = $this->_individualId; |
596 | $form->testSubmit($params); | |
bf6ba9fc | 597 | $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); |
598 | $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1); | |
599 | ||
77623a96 | 600 | $contribution = $this->callAPISuccess('Contribution', 'getsingle', array( |
bf6ba9fc | 601 | 'contact_id' => $this->_individualId, |
602 | 'is_test' => TRUE, | |
603 | )); | |
604 | ||
77623a96 | 605 | $this->assertEquals(.14, $contribution['fee_amount']); |
606 | $this->assertEquals('kettles boil water', $contribution['trxn_id']); | |
607 | ||
bf6ba9fc | 608 | $this->callAPISuccessGetCount('LineItem', array( |
609 | 'entity_id' => $membership['id'], | |
610 | 'entity_table' => 'civicrm_membership', | |
611 | 'contribution_id' => $contribution['id'], | |
612 | ), 1); | |
e9dfe40a | 613 | $mut->checkMailLog(array( |
614 | '=========================================================== | |
615 | Billing Name and Address | |
616 | =========================================================== | |
617 | Test | |
618 | 10 Test St | |
619 | Test, AR 90210 | |
620 | US', | |
621 | '=========================================================== | |
622 | Membership Information | |
623 | =========================================================== | |
624 | Membership Type: AnnualFixed | |
625 | Membership Start Date: ', | |
626 | '=========================================================== | |
627 | Credit Card Information | |
628 | =========================================================== | |
629 | Visa | |
630 | ************1111 | |
631 | Expires: ', | |
632 | ) | |
633 | ); | |
634 | $mut->stop(); | |
bf6ba9fc | 635 | |
636 | } | |
637 | ||
3cc61729 | 638 | /** |
639 | * Get a membership form object. | |
640 | * | |
641 | * We need to instantiate the form to run preprocess, which means we have to trick it about the request method. | |
642 | * | |
643 | * @return \CRM_Member_Form_Membership | |
644 | */ | |
645 | protected function getForm() { | |
646 | $form = new CRM_Member_Form_Membership(); | |
647 | $_SERVER['REQUEST_METHOD'] = 'GET'; | |
648 | $form->controller = new CRM_Core_Controller(); | |
649 | $form->_bltID = 5; | |
650 | return $form; | |
651 | } | |
652 | ||
653 | /** | |
654 | * @return array | |
655 | */ | |
656 | protected function getBaseSubmitParams() { | |
a8215a8d EM |
657 | $params = array( |
658 | 'cid' => $this->_individualId, | |
659 | 'price_set_id' => 0, | |
660 | 'join_date' => date('m/d/Y', time()), | |
661 | 'start_date' => '', | |
662 | 'end_date' => '', | |
663 | 'campaign_id' => '', | |
08fd4b45 EM |
664 | // This format reflects the 23 being the organisation & the 25 being the type. |
665 | 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID), | |
a8215a8d EM |
666 | 'auto_renew' => '1', |
667 | 'is_recur' => 1, | |
668 | 'max_related' => 0, | |
669 | 'num_terms' => '1', | |
670 | 'source' => '', | |
671 | 'total_amount' => '77.00', | |
672 | 'financial_type_id' => '2', //Member dues, see data.xml | |
673 | 'soft_credit_type_id' => 11, | |
674 | 'soft_credit_contact_id' => '', | |
675 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
676 | 'receipt_text' => 'Thank you text', | |
677 | 'payment_processor_id' => $this->_paymentProcessorID, | |
678 | 'credit_card_number' => '4111111111111111', | |
679 | 'cvv2' => '123', | |
680 | 'credit_card_exp_date' => array( | |
681 | 'M' => '9', | |
682 | 'Y' => '2019', // TODO: Future proof | |
683 | ), | |
684 | 'credit_card_type' => 'Visa', | |
685 | 'billing_first_name' => 'Test', | |
686 | 'billing_middlename' => 'Last', | |
687 | 'billing_street_address-5' => '10 Test St', | |
688 | 'billing_city-5' => 'Test', | |
689 | 'billing_state_province_id-5' => '1003', | |
690 | 'billing_postal_code-5' => '90210', | |
691 | 'billing_country_id-5' => '1228', | |
e9dfe40a | 692 | 'send_receipt' => 1, |
a8215a8d | 693 | ); |
3cc61729 | 694 | return $params; |
a8215a8d | 695 | } |
a271822c | 696 | |
6a488035 | 697 | } |