Commit | Line | Data |
---|---|---|
632196ea | 1 | <?php |
2 | ||
3 | /** | |
4 | * Test CRM_Event_Form_Registration functions. | |
5 | * | |
6 | * @package CiviCRM | |
7 | * @group headless | |
8 | */ | |
9 | class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { | |
10 | ||
6d2e7dc0 | 11 | use CRMTraits_Profile_ProfileTrait; |
12 | ||
632196ea | 13 | public function setUp() { |
14 | $this->useTransaction(TRUE); | |
15 | parent::setUp(); | |
16 | } | |
17 | ||
18 | /** | |
19 | * Initial test of submit function. | |
20 | * | |
21 | * @throws \Exception | |
22 | */ | |
23 | public function testSubmit() { | |
24 | $event = $this->eventCreate(); | |
e579af79 | 25 | $mut = new CiviMailUtils($this, TRUE); |
9099cab3 | 26 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
632196ea | 27 | 'id' => $event['id'], |
28 | 'contributeMode' => 'direct', | |
29 | 'registerByID' => $this->createLoggedInUser(), | |
9099cab3 CW |
30 | 'params' => [ |
31 | [ | |
632196ea | 32 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
33 | 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', | |
34 | 'first_name' => 'k', | |
35 | 'last_name' => 'p', | |
36 | 'email-Primary' => 'demo@example.com', | |
37 | 'hidden_processor' => '1', | |
38 | 'credit_card_number' => '4111111111111111', | |
39 | 'cvv2' => '123', | |
9099cab3 | 40 | 'credit_card_exp_date' => [ |
632196ea | 41 | 'M' => '1', |
42 | 'Y' => '2019', | |
9099cab3 | 43 | ], |
632196ea | 44 | 'credit_card_type' => 'Visa', |
45 | 'billing_first_name' => 'p', | |
46 | 'billing_middle_name' => '', | |
47 | 'billing_last_name' => 'p', | |
48 | 'billing_street_address-5' => 'p', | |
49 | 'billing_city-5' => 'p', | |
50 | 'billing_state_province_id-5' => '1061', | |
51 | 'billing_postal_code-5' => '7', | |
52 | 'billing_country_id-5' => '1228', | |
53 | 'scriptFee' => '', | |
54 | 'scriptArray' => '', | |
55 | 'priceSetId' => '6', | |
9099cab3 | 56 | 'price_7' => [ |
29541621 | 57 | 13 => 1, |
9099cab3 | 58 | ], |
632196ea | 59 | 'payment_processor_id' => '1', |
60 | 'bypass_payment' => '', | |
61 | 'MAX_FILE_SIZE' => '33554432', | |
62 | 'is_primary' => 1, | |
63 | 'is_pay_later' => 0, | |
64 | 'campaign_id' => NULL, | |
65 | 'defaultRole' => 1, | |
66 | 'participant_role_id' => '1', | |
67 | 'currencyID' => 'USD', | |
68 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
69 | 'amount' => '800.00', | |
70 | 'tax_amount' => NULL, | |
71 | 'year' => '2019', | |
72 | 'month' => '1', | |
73 | 'ip_address' => '127.0.0.1', | |
74 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
75 | 'button' => '_qf_Register_upload', | |
76 | 'billing_state_province-5' => 'AP', | |
77 | 'billing_country-5' => 'US', | |
9099cab3 CW |
78 | ], |
79 | ], | |
80 | ]); | |
e579af79 | 81 | $participant = $this->callAPISuccessGetSingle('Participant', []); |
82 | $mut->checkMailLog([ | |
83 | 'Dear Logged In, Thank you for your participation. This letter is a confirmation that your registration has been received and your status has been updated to Registered.', | |
84 | ]); | |
85 | $mut->stop(); | |
86 | $mut->clearMessages(); | |
87 | $tplVars = CRM_Core_Smarty::singleton()->get_template_vars(); | |
88 | $this->assertEquals($participant['id'], $tplVars['participantID']); | |
89 | ||
632196ea | 90 | } |
91 | ||
5e40de84 | 92 | /** |
93 | * Initial test of submit function for paid event. | |
94 | * | |
3ae1b2f4 | 95 | * @param string $thousandSeparator |
96 | * | |
97 | * @dataProvider getThousandSeparators | |
98 | * | |
5e40de84 | 99 | * @throws \Exception |
100 | */ | |
3ae1b2f4 | 101 | public function testPaidSubmit($thousandSeparator) { |
102 | $this->setCurrencySeparators($thousandSeparator); | |
5e40de84 | 103 | $paymentProcessorID = $this->processorCreate(); |
c1797e86 | 104 | /* @var \CRM_Core_Payment_Dummy $processor */ |
105 | $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); | |
106 | $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]); | |
9099cab3 | 107 | $params = ['is_monetary' => 1, 'financial_type_id' => 1]; |
5e40de84 | 108 | $event = $this->eventCreate($params); |
109 | $individualID = $this->individualCreate(); | |
9099cab3 | 110 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
5e40de84 | 111 | 'id' => $event['id'], |
112 | 'contributeMode' => 'direct', | |
113 | 'registerByID' => $individualID, | |
114 | 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), | |
3ae1b2f4 | 115 | 'totalAmount' => $this->formatMoneyInput(8000.67), |
9099cab3 CW |
116 | 'params' => [ |
117 | [ | |
5e40de84 | 118 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
119 | 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', | |
120 | 'first_name' => 'k', | |
121 | 'last_name' => 'p', | |
122 | 'email-Primary' => 'demo@example.com', | |
123 | 'hidden_processor' => '1', | |
124 | 'credit_card_number' => '4111111111111111', | |
125 | 'cvv2' => '123', | |
9099cab3 | 126 | 'credit_card_exp_date' => [ |
5e40de84 | 127 | 'M' => '1', |
128 | 'Y' => '2019', | |
9099cab3 | 129 | ], |
5e40de84 | 130 | 'credit_card_type' => 'Visa', |
131 | 'billing_first_name' => 'p', | |
132 | 'billing_middle_name' => '', | |
133 | 'billing_last_name' => 'p', | |
134 | 'billing_street_address-5' => 'p', | |
135 | 'billing_city-5' => 'p', | |
136 | 'billing_state_province_id-5' => '1061', | |
137 | 'billing_postal_code-5' => '7', | |
138 | 'billing_country_id-5' => '1228', | |
139 | 'scriptFee' => '', | |
140 | 'scriptArray' => '', | |
141 | 'priceSetId' => '6', | |
9099cab3 | 142 | 'price_7' => [ |
5e40de84 | 143 | 13 => 1, |
9099cab3 | 144 | ], |
5e40de84 | 145 | 'payment_processor_id' => $paymentProcessorID, |
146 | 'bypass_payment' => '', | |
147 | 'MAX_FILE_SIZE' => '33554432', | |
148 | 'is_primary' => 1, | |
149 | 'is_pay_later' => 0, | |
150 | 'campaign_id' => NULL, | |
151 | 'defaultRole' => 1, | |
152 | 'participant_role_id' => '1', | |
153 | 'currencyID' => 'USD', | |
154 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
3ae1b2f4 | 155 | 'amount' => $this->formatMoneyInput(8000.67), |
5e40de84 | 156 | 'tax_amount' => NULL, |
157 | 'year' => '2019', | |
158 | 'month' => '1', | |
159 | 'ip_address' => '127.0.0.1', | |
160 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
161 | 'button' => '_qf_Register_upload', | |
162 | 'billing_state_province-5' => 'AP', | |
163 | 'billing_country-5' => 'US', | |
9099cab3 CW |
164 | ], |
165 | ], | |
166 | ]); | |
167 | $this->callAPISuccessGetCount('Participant', [], 1); | |
168 | $contribution = $this->callAPISuccessGetSingle('Contribution', []); | |
3ae1b2f4 | 169 | $this->assertEquals(8000.67, $contribution['total_amount']); |
c1797e86 | 170 | $this->assertEquals(1.67, $contribution['fee_amount']); |
171 | $this->assertEquals(7999, $contribution['net_amount']); | |
5e40de84 | 172 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); |
173 | $financialTrxn = $this->callAPISuccessGetSingle( | |
174 | 'FinancialTrxn', | |
9099cab3 | 175 | [ |
5e40de84 | 176 | 'id' => $lastFinancialTrxnId['financialTrxnId'], |
9099cab3 CW |
177 | 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'], |
178 | ] | |
5e40de84 | 179 | ); |
180 | $this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID); | |
181 | $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); | |
182 | $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 1111); | |
c1797e86 | 183 | |
184 | // This looks like it's missing an item for the main contribution - but just locking in current behaviour. | |
185 | $financialItems = $this->callAPISuccess('FinancialItem', 'get', [ | |
186 | 'return' => ['description', 'financial_account_id', 'amount', 'contact_id', 'currency', 'status_id', 'entity_table', 'entity_id'], | |
187 | 'sequential' => 1, | |
188 | ])['values']; | |
189 | ||
190 | $entityFinancialTrxns = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['sequential' => 1])['values']; | |
191 | ||
192 | $this->assertAPIArrayComparison([ | |
193 | 'entity_table' => 'civicrm_contribution', | |
194 | 'entity_id' => $contribution['id'], | |
195 | 'financial_trxn_id' => $financialTrxn['id'], | |
196 | 'amount' => '8000.67', | |
197 | ], $entityFinancialTrxns[0], ['id']); | |
198 | ||
199 | $this->assertAPIArrayComparison([ | |
200 | 'entity_table' => 'civicrm_contribution', | |
201 | 'entity_id' => $contribution['id'], | |
202 | 'financial_trxn_id' => $financialTrxn['id'] + 1, | |
203 | 'amount' => '1.67', | |
204 | ], $entityFinancialTrxns[1], ['id']); | |
205 | ||
206 | $this->assertAPIArrayComparison([ | |
207 | 'entity_table' => 'civicrm_financial_item', | |
208 | 'entity_id' => $financialItems[0]['id'], | |
209 | 'financial_trxn_id' => $financialTrxn['id'] + 1, | |
210 | 'amount' => '1.67', | |
211 | ], $entityFinancialTrxns[2], ['id', 'entity_id']); | |
5e40de84 | 212 | } |
213 | ||
6704d983 PN |
214 | /** |
215 | * Test for Tax amount for multiple participant. | |
216 | * | |
217 | * @throws \Exception | |
218 | */ | |
219 | public function testTaxMultipleParticipant() { | |
9099cab3 | 220 | $params = ['is_monetary' => 1, 'financial_type_id' => 1]; |
6704d983 | 221 | $event = $this->eventCreate($params); |
9099cab3 | 222 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
6704d983 PN |
223 | 'id' => $event['id'], |
224 | 'contributeMode' => 'direct', | |
225 | 'registerByID' => $this->createLoggedInUser(), | |
226 | 'totalAmount' => 440, | |
227 | 'event' => reset($event['values']), | |
9099cab3 CW |
228 | 'params' => [ |
229 | [ | |
6704d983 PN |
230 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
231 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
232 | 'first_name' => 'Participant1', | |
233 | 'last_name' => 'LastName', | |
234 | 'email-Primary' => 'participant1@example.com', | |
235 | 'scriptFee' => '', | |
236 | 'scriptArray' => '', | |
237 | 'additional_participants' => 2, | |
238 | 'payment_processor_id' => 0, | |
239 | 'bypass_payment' => '', | |
240 | 'MAX_FILE_SIZE' => '33554432', | |
241 | 'is_primary' => 1, | |
242 | 'is_pay_later' => 1, | |
243 | 'campaign_id' => NULL, | |
244 | 'defaultRole' => 1, | |
245 | 'participant_role_id' => '1', | |
246 | 'currencyID' => 'USD', | |
247 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
248 | 'amount' => '100.00', | |
249 | 'tax_amount' => 10, | |
250 | 'ip_address' => '127.0.0.1', | |
251 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
252 | 'trxn_id' => '123456789', | |
253 | 'button' => '_qf_Register_upload', | |
9099cab3 CW |
254 | ], |
255 | [ | |
6704d983 PN |
256 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
257 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
258 | 'first_name' => 'Participant2', | |
259 | 'last_name' => 'LastName', | |
260 | 'email-Primary' => 'participant2@example.com', | |
261 | 'scriptFee' => '', | |
262 | 'scriptArray' => '', | |
263 | 'campaign_id' => NULL, | |
264 | 'is_pay_later' => 1, | |
265 | 'participant_role_id' => '1', | |
266 | 'currencyID' => 'USD', | |
267 | 'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1', | |
268 | 'amount' => '200.00', | |
269 | 'tax_amount' => 20, | |
9099cab3 CW |
270 | ], |
271 | [ | |
6704d983 PN |
272 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
273 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
274 | 'first_name' => 'Participant3', | |
275 | 'last_name' => 'LastName', | |
276 | 'email-Primary' => 'participant3@example.com', | |
277 | 'scriptFee' => '', | |
278 | 'scriptArray' => '', | |
279 | 'campaign_id' => NULL, | |
280 | 'is_pay_later' => 1, | |
281 | 'participant_role_id' => '1', | |
282 | 'currencyID' => 'USD', | |
283 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
284 | 'amount' => '100.00', | |
285 | 'tax_amount' => 10, | |
9099cab3 CW |
286 | ], |
287 | ], | |
288 | ]); | |
289 | $this->callAPISuccessGetCount('Participant', [], 3); | |
6704d983 PN |
290 | $contribution = $this->callAPISuccessGetSingle( |
291 | 'Contribution', | |
9099cab3 CW |
292 | [ |
293 | 'return' => ['tax_amount', 'total_amount'], | |
294 | ] | |
6704d983 PN |
295 | ); |
296 | $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.'); | |
297 | $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.'); | |
298 | } | |
299 | ||
c91b1cc3 E |
300 | /** |
301 | * Test online registration for event with no price options selected as per CRM-19964. | |
302 | */ | |
303 | public function testOnlineRegNoPrice() { | |
9099cab3 CW |
304 | $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]); |
305 | $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]); | |
306 | $params = [ | |
c91b1cc3 E |
307 | 'start_date' => date('YmdHis', strtotime('+ 1 week')), |
308 | 'end_date' => date('YmdHis', strtotime('+ 1 year')), | |
309 | 'registration_start_date' => date('YmdHis', strtotime('- 1 day')), | |
310 | 'registration_end_date' => date('YmdHis', strtotime('+ 1 year')), | |
311 | 'payment_processor_id' => $paymentProcessorID, | |
312 | 'is_monetary' => TRUE, | |
313 | 'financial_type_id' => 'Event Fee', | |
9099cab3 | 314 | ]; |
c91b1cc3 | 315 | $event = $this->eventCreate($params); |
9099cab3 | 316 | $priceFieldOptions = [ |
c91b1cc3 E |
317 | 'option_label' => 'Price Field', |
318 | 'option_value' => 100, | |
319 | 'is_required' => FALSE, | |
320 | 'html_type' => 'Text', | |
9099cab3 | 321 | ]; |
c91b1cc3 E |
322 | $this->createPriceSet('event', $event['id'], $priceFieldOptions); |
323 | ||
324 | $priceField = $this->callAPISuccess('PriceField', 'get', | |
9099cab3 | 325 | [ |
c91b1cc3 | 326 | 'label' => 'Price Field', |
9099cab3 | 327 | ] |
c91b1cc3 E |
328 | ); |
329 | // Create online event registration. | |
9099cab3 | 330 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
c91b1cc3 E |
331 | 'id' => $event['id'], |
332 | 'contributeMode' => 'direct', | |
333 | 'registerByID' => $this->createLoggedInUser(), | |
9099cab3 CW |
334 | 'params' => [ |
335 | [ | |
c91b1cc3 E |
336 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
337 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
338 | 'first_name' => 'Bruce', | |
339 | 'last_name' => 'Wayne', | |
340 | 'email-Primary' => 'bruce@gotham.com', | |
341 | 'price_' . $priceField['id'] => '', | |
342 | 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'], | |
343 | 'payment_processor_id' => $paymentProcessorID, | |
344 | 'amount' => 0, | |
345 | 'bypass_payment' => '', | |
346 | 'MAX_FILE_SIZE' => '33554432', | |
347 | 'is_primary' => 1, | |
348 | 'is_pay_later' => 0, | |
349 | 'campaign_id' => NULL, | |
350 | 'defaultRole' => 1, | |
351 | 'participant_role_id' => '1', | |
352 | 'tax_amount' => NULL, | |
353 | 'ip_address' => '127.0.0.1', | |
354 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
355 | 'button' => '_qf_Register_upload', | |
356 | 'scriptFee' => '', | |
357 | 'scriptArray' => '', | |
9099cab3 CW |
358 | ], |
359 | ], | |
360 | ]); | |
361 | $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']); | |
37479886 | 362 | $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected."); |
c91b1cc3 E |
363 | } |
364 | ||
6d2e7dc0 | 365 | /** |
366 | * Test form profile assignment. | |
367 | * | |
368 | * @throws \CRM_Core_Exception | |
369 | * @throws \Exception | |
370 | */ | |
371 | public function testAssignProfiles() { | |
372 | $event = $this->eventCreate(); | |
373 | $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]); | |
374 | ||
375 | /* @var \CRM_Event_Form_Registration_Confirm $form */ | |
376 | $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); | |
377 | $form->set('params', [[]]); | |
378 | $form->set('id', $event['id']); | |
379 | $form->set('values', [ | |
380 | 'event' => $event['values'][$event['id']], | |
381 | 'location' => [], | |
382 | 'custom_pre_id' => $this->ids['UFGroup']['our profile'], | |
383 | ]); | |
384 | $form->preProcess(); | |
385 | ||
386 | CRM_Event_Form_Registration_Confirm::assignProfiles($form); | |
387 | ||
388 | $smarty = CRM_Core_Smarty::singleton(); | |
389 | $tplVar = $smarty->get_template_vars(); | |
390 | $this->assertEquals([ | |
391 | 'CustomPre' => ['First Name' => NULL], | |
392 | 'CustomPreGroupTitle' => 'Public title', | |
393 | ], $tplVar['primaryParticipantProfile']); | |
394 | } | |
395 | ||
632196ea | 396 | } |