Commit | Line | Data |
---|---|---|
4187b12f EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
4187b12f | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
4187b12f EM |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
4187b12f EM |
12 | /** |
13 | * Test CRM_Member_Form_Membership functions. | |
14 | * | |
15 | * @package CiviCRM | |
acb109b7 | 16 | * @group headless |
4187b12f | 17 | */ |
bce3b15b | 18 | class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { |
4187b12f | 19 | |
4187b12f EM |
20 | protected $_individualId; |
21 | protected $_contribution; | |
22 | protected $_financialTypeId = 1; | |
4187b12f EM |
23 | protected $_entity = 'Membership'; |
24 | protected $_params; | |
4187b12f EM |
25 | protected $_paymentProcessorID; |
26 | ||
27 | /** | |
28 | * Membership type ID for annual fixed membership. | |
29 | * | |
30 | * @var int | |
31 | */ | |
32 | protected $membershipTypeAnnualFixedID; | |
33 | ||
34 | /** | |
35 | * Parameters to create payment processor. | |
36 | * | |
37 | * @var array | |
38 | */ | |
08d620bc | 39 | protected $_processorParams = []; |
4187b12f EM |
40 | |
41 | /** | |
42 | * ID of created membership. | |
43 | * | |
44 | * @var int | |
45 | */ | |
46 | protected $_membershipID; | |
47 | ||
48 | /** | |
49 | * Payment instrument mapping. | |
50 | * | |
51 | * @var array | |
52 | */ | |
08d620bc | 53 | protected $paymentInstruments = []; |
4187b12f | 54 | |
1f31bbc4 | 55 | |
56 | /** | |
57 | * @var CiviMailUtils | |
58 | */ | |
59 | protected $mut; | |
60 | ||
e5c0aee0 | 61 | /** |
62 | * @var int | |
63 | */ | |
64 | private $financialTypeID; | |
65 | ||
4187b12f EM |
66 | /** |
67 | * Test setup for every test. | |
68 | * | |
69 | * Connect to the database, truncate the tables that will be used | |
70 | * and redirect stdin to a temporary file. | |
e5c0aee0 | 71 | * |
72 | * @throws \CRM_Core_Exception | |
4187b12f EM |
73 | */ |
74 | public function setUp() { | |
4187b12f EM |
75 | parent::setUp(); |
76 | ||
77 | $this->_individualId = $this->individualCreate(); | |
8950ecdc | 78 | $this->_paymentProcessorID = $this->processorCreate(); |
e5c0aee0 | 79 | $this->financialTypeID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Member Dues'); |
08d620bc | 80 | |
81 | $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml'); | |
e5c0aee0 | 82 | $this->membershipTypeAnnualFixedID = $this->callAPISuccess('membership_type', 'create', [ |
4187b12f | 83 | 'domain_id' => 1, |
e5c0aee0 | 84 | 'name' => 'AnnualFixed', |
4187b12f | 85 | 'member_of_contact_id' => 23, |
e5c0aee0 | 86 | 'duration_unit' => 'year', |
4187b12f | 87 | 'duration_interval' => 1, |
e5c0aee0 | 88 | 'period_type' => 'fixed', |
89 | 'fixed_period_start_day' => '101', | |
90 | 'fixed_period_rollover_day' => '1231', | |
4187b12f | 91 | 'relationship_type_id' => 20, |
e5c0aee0 | 92 | 'financial_type_id' => $this->financialTypeID, |
93 | ])['id']; | |
94 | ||
95 | $this->_membershipID = $this->callAPISuccess('Membership', 'create', [ | |
4187b12f EM |
96 | 'contact_id' => $this->_individualId, |
97 | 'membership_type_id' => $this->membershipTypeAnnualFixedID, | |
e5c0aee0 | 98 | ])['id']; |
4187b12f | 99 | |
e5c0aee0 | 100 | $this->paymentInstruments = $this->callAPISuccess('Contribution', 'getoptions', ['field' => 'payment_instrument_id'])['values']; |
4187b12f EM |
101 | } |
102 | ||
103 | /** | |
104 | * Clean up after each test. | |
e5c0aee0 | 105 | * |
106 | * @throws \CRM_Core_Exception | |
4187b12f EM |
107 | */ |
108 | public function tearDown() { | |
3fc37a30 | 109 | $this->validateAllPayments(); |
110 | $this->validateAllContributions(); | |
4187b12f EM |
111 | $this->quickCleanUpFinancialEntities(); |
112 | $this->quickCleanup( | |
9099cab3 | 113 | [ |
4187b12f EM |
114 | 'civicrm_relationship', |
115 | 'civicrm_membership_type', | |
116 | 'civicrm_membership', | |
117 | 'civicrm_uf_match', | |
0816949d | 118 | 'civicrm_address', |
9099cab3 | 119 | ] |
4187b12f | 120 | ); |
9099cab3 CW |
121 | foreach ([17, 18, 23, 32] as $contactID) { |
122 | $this->callAPISuccess('contact', 'delete', ['id' => $contactID, 'skip_undelete' => TRUE]); | |
e2ce0d88 | 123 | } |
9099cab3 | 124 | $this->callAPISuccess('relationship_type', 'delete', ['id' => 20]); |
4187b12f EM |
125 | } |
126 | ||
4187b12f EM |
127 | /** |
128 | * Test the submit function of the membership form. | |
e5c0aee0 | 129 | * |
130 | * @throws \CRM_Core_Exception | |
131 | * @throws \CiviCRM_API3_Exception | |
4187b12f EM |
132 | */ |
133 | public function testSubmit() { | |
134 | $form = $this->getForm(); | |
135 | $this->createLoggedInUser(); | |
08d620bc | 136 | $params = [ |
4187b12f EM |
137 | 'cid' => $this->_individualId, |
138 | 'join_date' => date('m/d/Y', time()), | |
139 | 'start_date' => '', | |
140 | 'end_date' => '', | |
141 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 142 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
4187b12f EM |
143 | 'auto_renew' => '0', |
144 | 'max_related' => '', | |
145 | 'num_terms' => '1', | |
146 | 'source' => '', | |
147 | 'total_amount' => '50.00', | |
1a00ea3c EM |
148 | //Member dues, see data.xml |
149 | 'financial_type_id' => '2', | |
4187b12f EM |
150 | 'soft_credit_type_id' => '', |
151 | 'soft_credit_contact_id' => '', | |
152 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
153 | 'receipt_text_signup' => 'Thank you text', | |
154 | 'payment_processor_id' => $this->_paymentProcessorID, | |
155 | 'credit_card_number' => '4111111111111111', | |
156 | 'cvv2' => '123', | |
9099cab3 | 157 | 'credit_card_exp_date' => [ |
4187b12f | 158 | 'M' => '9', |
39b959db SL |
159 | // TODO: Future proof |
160 | 'Y' => '2024', | |
9099cab3 | 161 | ], |
4187b12f EM |
162 | 'credit_card_type' => 'Visa', |
163 | 'billing_first_name' => 'Test', | |
164 | 'billing_middlename' => 'Last', | |
165 | 'billing_street_address-5' => '10 Test St', | |
166 | 'billing_city-5' => 'Test', | |
167 | 'billing_state_province_id-5' => '1003', | |
168 | 'billing_postal_code-5' => '90210', | |
169 | 'billing_country_id-5' => '1228', | |
08d620bc | 170 | ]; |
4187b12f EM |
171 | $form->_contactID = $this->_individualId; |
172 | ||
173 | $form->testSubmit($params); | |
24d9c528 | 174 | $form->setRenewalMessage(); |
9099cab3 CW |
175 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
176 | $this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 0); | |
177 | $contribution = $this->callAPISuccess('Contribution', 'get', [ | |
4187b12f EM |
178 | 'contact_id' => $this->_individualId, |
179 | 'is_test' => TRUE, | |
9099cab3 | 180 | ]); |
4187b12f | 181 | |
9099cab3 | 182 | $this->callAPISuccessGetCount('LineItem', [ |
4187b12f EM |
183 | 'entity_id' => $membership['id'], |
184 | 'entity_table' => 'civicrm_membership', | |
185 | 'contribution_id' => $contribution['id'], | |
9099cab3 CW |
186 | ], 1); |
187 | $this->_checkFinancialRecords([ | |
16f3bd02 | 188 | 'id' => $contribution['id'], |
189 | 'total_amount' => 50, | |
190 | 'financial_account_id' => 2, | |
9099cab3 | 191 | 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', [ |
16f3bd02 | 192 | 'id' => $this->_paymentProcessorID, |
193 | 'return' => 'payment_instrument_id', | |
9099cab3 CW |
194 | ]), |
195 | ], 'online'); | |
24d9c528 JG |
196 | $this->assertEquals([ |
197 | [ | |
198 | 'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been renewed.', | |
199 | 'title' => 'Complete', | |
200 | 'type' => 'success', | |
201 | 'options' => NULL, | |
202 | ], | |
203 | ], CRM_Core_Session::singleton()->getStatus()); | |
4187b12f EM |
204 | } |
205 | ||
206 | /** | |
207 | * Test the submit function of the membership form. | |
91786f44 | 208 | * |
209 | * @throws \CRM_Core_Exception | |
e5c0aee0 | 210 | * @throws \CiviCRM_API3_Exception |
4187b12f EM |
211 | */ |
212 | public function testSubmitRecur() { | |
213 | $form = $this->getForm(); | |
214 | ||
9099cab3 | 215 | $this->callAPISuccess('MembershipType', 'create', [ |
4187b12f EM |
216 | 'id' => $this->membershipTypeAnnualFixedID, |
217 | 'duration_unit' => 'month', | |
218 | 'duration_interval' => 1, | |
219 | 'auto_renew' => TRUE, | |
9099cab3 | 220 | ]); |
4187b12f EM |
221 | $form->preProcess(); |
222 | $this->createLoggedInUser(); | |
9099cab3 | 223 | $params = [ |
4187b12f EM |
224 | 'cid' => $this->_individualId, |
225 | 'price_set_id' => 0, | |
226 | 'join_date' => date('m/d/Y', time()), | |
227 | 'start_date' => '', | |
228 | 'end_date' => '', | |
229 | 'campaign_id' => '', | |
230 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 231 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
4187b12f EM |
232 | 'auto_renew' => '1', |
233 | 'is_recur' => 1, | |
234 | 'max_related' => 0, | |
235 | 'num_terms' => '1', | |
236 | 'source' => '', | |
237 | 'total_amount' => '77.00', | |
bb069c16 | 238 | //Member dues, see data.xml |
239 | 'financial_type_id' => '2', | |
4187b12f EM |
240 | 'soft_credit_type_id' => 11, |
241 | 'soft_credit_contact_id' => '', | |
242 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
243 | 'receipt_text' => 'Thank you text', | |
244 | 'payment_processor_id' => $this->_paymentProcessorID, | |
245 | 'credit_card_number' => '4111111111111111', | |
246 | 'cvv2' => '123', | |
9099cab3 | 247 | 'credit_card_exp_date' => [ |
4187b12f | 248 | 'M' => '9', |
90530b87 | 249 | 'Y' => date('Y') + 1, |
9099cab3 | 250 | ], |
4187b12f EM |
251 | 'credit_card_type' => 'Visa', |
252 | 'billing_first_name' => 'Test', | |
253 | 'billing_middlename' => 'Last', | |
254 | 'billing_street_address-5' => '10 Test St', | |
255 | 'billing_city-5' => 'Test', | |
256 | 'billing_state_province_id-5' => '1003', | |
257 | 'billing_postal_code-5' => '90210', | |
258 | 'billing_country_id-5' => '1228', | |
bb069c16 | 259 | 'send_receipt' => 1, |
9099cab3 | 260 | ]; |
4187b12f EM |
261 | $form->_mode = 'test'; |
262 | $form->_contactID = $this->_individualId; | |
263 | ||
264 | $form->testSubmit($params); | |
9099cab3 CW |
265 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
266 | $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); | |
bb069c16 | 267 | $this->assertEquals(1, $contributionRecur['is_email_receipt']); |
268 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); | |
269 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); | |
270 | $this->assertNotEmpty($contributionRecur['invoice_id']); | |
271 | $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', | |
272 | 'Pending'), $contributionRecur['contribution_status_id']); | |
9099cab3 | 273 | $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [ |
16f3bd02 | 274 | 'id' => $this->_paymentProcessorID, |
275 | 'return' => 'payment_instrument_id', | |
9099cab3 | 276 | ]), $contributionRecur['payment_instrument_id']); |
bb069c16 | 277 | |
9099cab3 | 278 | $contribution = $this->callAPISuccess('Contribution', 'getsingle', [ |
4187b12f EM |
279 | 'contact_id' => $this->_individualId, |
280 | 'is_test' => TRUE, | |
9099cab3 | 281 | ]); |
4187b12f | 282 | |
9099cab3 | 283 | $this->assertEquals($this->callAPISuccessGetValue('PaymentProcessor', [ |
16f3bd02 | 284 | 'id' => $this->_paymentProcessorID, |
285 | 'return' => 'payment_instrument_id', | |
9099cab3 | 286 | ]), $contribution['payment_instrument_id']); |
e136edcf | 287 | $this->assertEquals($contributionRecur['id'], $contribution['contribution_recur_id']); |
bb069c16 | 288 | |
9099cab3 | 289 | $this->callAPISuccessGetCount('LineItem', [ |
4187b12f EM |
290 | 'entity_id' => $membership['id'], |
291 | 'entity_table' => 'civicrm_membership', | |
292 | 'contribution_id' => $contribution['id'], | |
9099cab3 | 293 | ], 1); |
4187b12f | 294 | |
9099cab3 | 295 | $this->callAPISuccessGetSingle('address', [ |
0816949d EM |
296 | 'contact_id' => $this->_individualId, |
297 | 'street_address' => '10 Test St', | |
39b959db | 298 | 'postal_code' => 90210, |
9099cab3 | 299 | ]); |
0816949d EM |
300 | } |
301 | ||
b3f6108a | 302 | /** |
303 | * Test the submit function of the membership form. | |
e5c0aee0 | 304 | * |
305 | * @throws \CRM_Core_Exception | |
306 | * @throws \CiviCRM_API3_Exception | |
b3f6108a | 307 | */ |
308 | public function testSubmitRecurCompleteInstant() { | |
309 | $form = $this->getForm(); | |
1f31bbc4 | 310 | /** @var \CRM_Core_Payment_Dummy $processor */ |
b3f6108a | 311 | $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); |
9099cab3 | 312 | $processor->setDoDirectPaymentResult([ |
b3f6108a | 313 | 'payment_status_id' => 1, |
314 | 'trxn_id' => 'kettles boil water', | |
315 | 'fee_amount' => .29, | |
9099cab3 | 316 | ]); |
b3f6108a | 317 | |
9099cab3 | 318 | $this->callAPISuccess('MembershipType', 'create', [ |
b3f6108a | 319 | 'id' => $this->membershipTypeAnnualFixedID, |
320 | 'duration_unit' => 'month', | |
321 | 'duration_interval' => 1, | |
322 | 'auto_renew' => TRUE, | |
9099cab3 | 323 | ]); |
b3f6108a | 324 | $this->createLoggedInUser(); |
325 | $form->preProcess(); | |
326 | ||
327 | $form->_contactID = $this->_individualId; | |
328 | $params = $this->getBaseSubmitParams(); | |
329 | $form->_mode = 'test'; | |
330 | ||
331 | $form->testSubmit($params); | |
9099cab3 CW |
332 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
333 | $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); | |
3a1f9fd3 | 334 | $this->assertEquals($contributionRecur['id'], $membership['contribution_recur_id']); |
bb069c16 | 335 | $this->assertEquals(0, $contributionRecur['is_email_receipt']); |
336 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contributionRecur['modified_date']))); | |
337 | $this->assertNotEmpty($contributionRecur['invoice_id']); | |
bb069c16 | 338 | // @todo fix this part! |
339 | /* | |
340 | $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', | |
b1b2796c | 341 | 'In Progress'), $contributionRecur['contribution_status_id']); |
bb069c16 | 342 | $this->assertNotEmpty($contributionRecur['next_sched_contribution_date']); |
b1b2796c | 343 | */ |
9099cab3 | 344 | $paymentInstrumentID = $this->callAPISuccessGetValue('PaymentProcessor', [ |
16f3bd02 | 345 | 'id' => $this->_paymentProcessorID, |
346 | 'return' => 'payment_instrument_id', | |
9099cab3 | 347 | ]); |
16f3bd02 | 348 | $this->assertEquals($paymentInstrumentID, $contributionRecur['payment_instrument_id']); |
bb069c16 | 349 | |
9099cab3 | 350 | $contribution = $this->callAPISuccess('Contribution', 'getsingle', [ |
b3f6108a | 351 | 'contact_id' => $this->_individualId, |
352 | 'is_test' => TRUE, | |
9099cab3 | 353 | ]); |
16f3bd02 | 354 | $this->assertEquals($paymentInstrumentID, $contribution['payment_instrument_id']); |
b3f6108a | 355 | |
356 | $this->assertEquals('kettles boil water', $contribution['trxn_id']); | |
357 | $this->assertEquals(.29, $contribution['fee_amount']); | |
1f31bbc4 | 358 | $this->assertEquals(7800.90, $contribution['total_amount']); |
359 | $this->assertEquals(7800.61, $contribution['net_amount']); | |
b3f6108a | 360 | |
9099cab3 | 361 | $this->callAPISuccessGetCount('LineItem', [ |
b3f6108a | 362 | 'entity_id' => $membership['id'], |
363 | 'entity_table' => 'civicrm_membership', | |
364 | 'contribution_id' => $contribution['id'], | |
9099cab3 | 365 | ], 1); |
1f31bbc4 | 366 | } |
367 | ||
368 | /** | |
369 | * Test the submit function of the membership form. | |
370 | * | |
371 | * @param string $thousandSeparator | |
372 | * | |
373 | * @dataProvider getThousandSeparators | |
90530b87 | 374 | * |
375 | * @throws \CiviCRM_API3_Exception | |
376 | * @throws \CRM_Core_Exception | |
1f31bbc4 | 377 | */ |
378 | public function testSubmitRecurCompleteInstantWithMail($thousandSeparator) { | |
379 | $this->setCurrencySeparators($thousandSeparator); | |
380 | $form = $this->getForm(); | |
381 | $this->mut = new CiviMailUtils($this, TRUE); | |
382 | /** @var \CRM_Core_Payment_Dummy $processor */ | |
383 | $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID); | |
9099cab3 | 384 | $processor->setDoDirectPaymentResult([ |
1f31bbc4 | 385 | 'payment_status_id' => 1, |
386 | 'trxn_id' => 'kettles boil water', | |
387 | 'fee_amount' => .29, | |
9099cab3 | 388 | ]); |
1f31bbc4 | 389 | |
9099cab3 | 390 | $this->callAPISuccess('MembershipType', 'create', [ |
1f31bbc4 | 391 | 'id' => $this->membershipTypeAnnualFixedID, |
392 | 'duration_unit' => 'month', | |
393 | 'duration_interval' => 1, | |
394 | 'auto_renew' => TRUE, | |
9099cab3 | 395 | ]); |
1f31bbc4 | 396 | $this->createLoggedInUser(); |
397 | $form->preProcess(); | |
398 | ||
399 | $form->_contactID = $this->_individualId; | |
400 | $params = $this->getBaseSubmitParams(); | |
401 | $params['send_receipt'] = 1; | |
402 | $form->_mode = 'test'; | |
b3f6108a | 403 | |
1f31bbc4 | 404 | $form->testSubmit($params); |
9099cab3 | 405 | $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]); |
1f31bbc4 | 406 | $this->assertEquals(1, $contributionRecur['is_email_receipt']); |
407 | $this->mut->checkMailLog([ | |
39b959db | 408 | '$ ' . $this->formatMoneyInput(7800.90), |
1f31bbc4 | 409 | ]); |
410 | $this->mut->stop(); | |
411 | $this->setCurrencySeparators(','); | |
b3f6108a | 412 | } |
3a1f9fd3 | 413 | |
0816949d EM |
414 | /** |
415 | * Test the submit function of the membership form. | |
91786f44 | 416 | * |
417 | * @throws \CRM_Core_Exception | |
e5c0aee0 | 418 | * @throws \CiviCRM_API3_Exception |
0816949d EM |
419 | */ |
420 | public function testSubmitPayLater() { | |
421 | $form = $this->getForm(NULL); | |
422 | $this->createLoggedInUser(); | |
9099cab3 CW |
423 | $originalMembership = $this->callAPISuccessGetSingle('membership', []); |
424 | $params = [ | |
0816949d EM |
425 | 'cid' => $this->_individualId, |
426 | 'join_date' => date('m/d/Y', time()), | |
427 | 'start_date' => '', | |
428 | 'end_date' => '', | |
429 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 430 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
0816949d EM |
431 | 'auto_renew' => '0', |
432 | 'max_related' => '', | |
433 | 'num_terms' => '2', | |
434 | 'source' => '', | |
435 | 'total_amount' => '50.00', | |
436 | //Member dues, see data.xml | |
437 | 'financial_type_id' => '2', | |
438 | 'soft_credit_type_id' => '', | |
439 | 'soft_credit_contact_id' => '', | |
440 | 'payment_instrument_id' => 4, | |
441 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
442 | 'receipt_text_signup' => 'Thank you text', | |
443 | 'payment_processor_id' => $this->_paymentProcessorID, | |
444 | 'record_contribution' => TRUE, | |
445 | 'trxn_id' => 777, | |
446 | 'contribution_status_id' => 2, | |
9099cab3 | 447 | ]; |
0816949d EM |
448 | $form->_contactID = $this->_individualId; |
449 | ||
450 | $form->testSubmit($params); | |
9099cab3 | 451 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
0816949d | 452 | $this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date'])); |
9099cab3 | 453 | $contribution = $this->callAPISuccessGetSingle('Contribution', [ |
0816949d EM |
454 | 'contact_id' => $this->_individualId, |
455 | 'contribution_status_id' => 2, | |
e5c0aee0 | 456 | 'return' => ['tax_amount', 'trxn_id'], |
9099cab3 | 457 | ]); |
0816949d | 458 | $this->assertEquals($contribution['trxn_id'], 777); |
85ade0ae | 459 | $this->assertEquals($contribution['tax_amount'], NULL); |
0816949d | 460 | |
9099cab3 | 461 | $this->callAPISuccessGetCount('LineItem', [ |
0816949d EM |
462 | 'entity_id' => $membership['id'], |
463 | 'entity_table' => 'civicrm_membership', | |
464 | 'contribution_id' => $contribution['id'], | |
9099cab3 | 465 | ], 1); |
0816949d EM |
466 | } |
467 | ||
468 | /** | |
469 | * Test the submit function of the membership form. | |
91786f44 | 470 | * |
471 | * @throws \CRM_Core_Exception | |
e5c0aee0 | 472 | * @throws \CiviCRM_API3_Exception |
0816949d EM |
473 | */ |
474 | public function testSubmitPayLaterWithBilling() { | |
475 | $form = $this->getForm(NULL); | |
476 | $this->createLoggedInUser(); | |
9099cab3 CW |
477 | $originalMembership = $this->callAPISuccessGetSingle('membership', []); |
478 | $params = [ | |
0816949d EM |
479 | 'cid' => $this->_individualId, |
480 | 'join_date' => date('m/d/Y', time()), | |
481 | 'start_date' => '', | |
482 | 'end_date' => '', | |
483 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 484 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
0816949d EM |
485 | 'auto_renew' => '0', |
486 | 'max_related' => '', | |
487 | 'num_terms' => '2', | |
488 | 'source' => '', | |
489 | 'total_amount' => '50.00', | |
490 | //Member dues, see data.xml | |
491 | 'financial_type_id' => '2', | |
492 | 'soft_credit_type_id' => '', | |
493 | 'soft_credit_contact_id' => '', | |
494 | 'payment_instrument_id' => 4, | |
495 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
496 | 'receipt_text_signup' => 'Thank you text', | |
497 | 'payment_processor_id' => $this->_paymentProcessorID, | |
498 | 'record_contribution' => TRUE, | |
499 | 'trxn_id' => 777, | |
500 | 'contribution_status_id' => 2, | |
501 | 'billing_first_name' => 'Test', | |
502 | 'billing_middlename' => 'Last', | |
503 | 'billing_street_address-5' => '10 Test St', | |
504 | 'billing_city-5' => 'Test', | |
505 | 'billing_state_province_id-5' => '1003', | |
506 | 'billing_postal_code-5' => '90210', | |
507 | 'billing_country_id-5' => '1228', | |
9099cab3 | 508 | ]; |
0816949d EM |
509 | $form->_contactID = $this->_individualId; |
510 | ||
511 | $form->testSubmit($params); | |
9099cab3 | 512 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
0816949d | 513 | $this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date'])); |
9099cab3 | 514 | $contribution = $this->callAPISuccessGetSingle('Contribution', [ |
0816949d EM |
515 | 'contact_id' => $this->_individualId, |
516 | 'contribution_status_id' => 2, | |
9099cab3 | 517 | ]); |
0816949d EM |
518 | $this->assertEquals($contribution['trxn_id'], 777); |
519 | ||
9099cab3 | 520 | $this->callAPISuccessGetCount('LineItem', [ |
0816949d EM |
521 | 'entity_id' => $membership['id'], |
522 | 'entity_table' => 'civicrm_membership', | |
523 | 'contribution_id' => $contribution['id'], | |
9099cab3 CW |
524 | ], 1); |
525 | $this->callAPISuccessGetSingle('address', [ | |
0816949d EM |
526 | 'contact_id' => $this->_individualId, |
527 | 'street_address' => '10 Test St', | |
528 | 'postal_code' => 90210, | |
9099cab3 | 529 | ]); |
0816949d EM |
530 | } |
531 | ||
532 | /** | |
533 | * Test the submit function of the membership form. | |
e5c0aee0 | 534 | * |
535 | * @throws \CRM_Core_Exception | |
536 | * @throws \CiviCRM_API3_Exception | |
0816949d EM |
537 | */ |
538 | public function testSubmitComplete() { | |
539 | $form = $this->getForm(NULL); | |
540 | $this->createLoggedInUser(); | |
9099cab3 CW |
541 | $originalMembership = $this->callAPISuccessGetSingle('membership', []); |
542 | $params = [ | |
0816949d EM |
543 | 'cid' => $this->_individualId, |
544 | 'join_date' => date('m/d/Y', time()), | |
545 | 'start_date' => '', | |
546 | 'end_date' => '', | |
547 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 548 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
0816949d EM |
549 | 'auto_renew' => '0', |
550 | 'max_related' => '', | |
551 | 'num_terms' => '2', | |
552 | 'source' => '', | |
553 | 'total_amount' => '50.00', | |
554 | //Member dues, see data.xml | |
555 | 'financial_type_id' => '2', | |
556 | 'soft_credit_type_id' => '', | |
557 | 'soft_credit_contact_id' => '', | |
558 | 'payment_instrument_id' => 4, | |
559 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
560 | 'receipt_text_signup' => 'Thank you text', | |
561 | 'payment_processor_id' => $this->_paymentProcessorID, | |
562 | 'record_contribution' => TRUE, | |
563 | 'trxn_id' => 777, | |
564 | 'contribution_status_id' => 1, | |
77623a96 | 565 | 'fee_amount' => .5, |
9099cab3 | 566 | ]; |
0816949d EM |
567 | $form->_contactID = $this->_individualId; |
568 | ||
569 | $form->testSubmit($params); | |
9099cab3 | 570 | $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); |
0816949d EM |
571 | $this->assertEquals(strtotime($membership['end_date']), strtotime('+ 2 years', |
572 | strtotime($originalMembership['end_date']))); | |
9099cab3 | 573 | $contribution = $this->callAPISuccessGetSingle('Contribution', [ |
0816949d EM |
574 | 'contact_id' => $this->_individualId, |
575 | 'contribution_status_id' => 1, | |
9099cab3 | 576 | ]); |
0816949d EM |
577 | |
578 | $this->assertEquals($contribution['trxn_id'], 777); | |
77623a96 | 579 | $this->assertEquals(.5, $contribution['fee_amount']); |
9099cab3 | 580 | $this->callAPISuccessGetCount('LineItem', [ |
0816949d EM |
581 | 'entity_id' => $membership['id'], |
582 | 'entity_table' => 'civicrm_membership', | |
583 | 'contribution_id' => $contribution['id'], | |
9099cab3 | 584 | ], 1); |
4187b12f EM |
585 | } |
586 | ||
587 | /** | |
588 | * Get a membership form object. | |
589 | * | |
590 | * We need to instantiate the form to run preprocess, which means we have to trick it about the request method. | |
591 | * | |
0816949d EM |
592 | * @param string $mode |
593 | * | |
4187b12f | 594 | * @return \CRM_Member_Form_MembershipRenewal |
e5c0aee0 | 595 | * |
596 | * @throws \CRM_Core_Exception | |
597 | * @throws \CiviCRM_API3_Exception | |
4187b12f | 598 | */ |
0816949d | 599 | protected function getForm($mode = 'test') { |
4187b12f EM |
600 | $form = new CRM_Member_Form_MembershipRenewal(); |
601 | $_SERVER['REQUEST_METHOD'] = 'GET'; | |
602 | $form->controller = new CRM_Core_Controller(); | |
603 | $form->_bltID = 5; | |
0816949d | 604 | $form->_mode = $mode; |
4187b12f EM |
605 | $form->_id = $this->_membershipID; |
606 | $form->preProcess(); | |
607 | return $form; | |
608 | } | |
609 | ||
b3f6108a | 610 | /** |
611 | * Get some re-usable parameters for the submit function. | |
612 | * | |
613 | * @return array | |
614 | */ | |
615 | protected function getBaseSubmitParams() { | |
e5c0aee0 | 616 | return [ |
b3f6108a | 617 | 'cid' => $this->_individualId, |
618 | 'price_set_id' => 0, | |
619 | 'join_date' => date('m/d/Y', time()), | |
620 | 'start_date' => '', | |
621 | 'end_date' => '', | |
622 | 'campaign_id' => '', | |
623 | // This format reflects the 23 being the organisation & the 25 being the type. | |
9099cab3 | 624 | 'membership_type_id' => [23, $this->membershipTypeAnnualFixedID], |
b3f6108a | 625 | 'auto_renew' => '1', |
626 | 'is_recur' => 1, | |
627 | 'max_related' => 0, | |
628 | 'num_terms' => '1', | |
629 | 'source' => '', | |
1f31bbc4 | 630 | 'total_amount' => $this->formatMoneyInput('7800.90'), |
39b959db SL |
631 | //Member dues, see data.xml |
632 | 'financial_type_id' => '2', | |
b3f6108a | 633 | 'soft_credit_type_id' => 11, |
634 | 'soft_credit_contact_id' => '', | |
635 | 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>', | |
636 | 'receipt_text' => 'Thank you text', | |
637 | 'payment_processor_id' => $this->_paymentProcessorID, | |
638 | 'credit_card_number' => '4111111111111111', | |
639 | 'cvv2' => '123', | |
9099cab3 | 640 | 'credit_card_exp_date' => [ |
b3f6108a | 641 | 'M' => '9', |
90530b87 | 642 | 'Y' => date('Y') + 1, |
9099cab3 | 643 | ], |
b3f6108a | 644 | 'credit_card_type' => 'Visa', |
645 | 'billing_first_name' => 'Test', | |
646 | 'billing_middlename' => 'Last', | |
647 | 'billing_street_address-5' => '10 Test St', | |
648 | 'billing_city-5' => 'Test', | |
649 | 'billing_state_province_id-5' => '1003', | |
650 | 'billing_postal_code-5' => '90210', | |
651 | 'billing_country_id-5' => '1228', | |
9099cab3 | 652 | ]; |
b3f6108a | 653 | } |
654 | ||
4187b12f | 655 | } |