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