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 | ||
faba1457 | 13 | public function setUp(): void { |
632196ea | 14 | $this->useTransaction(TRUE); |
15 | parent::setUp(); | |
16 | } | |
17 | ||
18 | /** | |
19 | * Initial test of submit function. | |
632196ea | 20 | */ |
82e5b7ad | 21 | public function testSubmit(): void { |
632196ea | 22 | $event = $this->eventCreate(); |
e579af79 | 23 | $mut = new CiviMailUtils($this, TRUE); |
d026b890 EM |
24 | $this->submitForm($event['id'], [ |
25 | 'first_name' => 'k', | |
26 | 'last_name' => 'p', | |
27 | 'email-Primary' => 'demo@example.com', | |
28 | 'hidden_processor' => '1', | |
29 | 'credit_card_number' => '4111111111111111', | |
30 | 'cvv2' => '123', | |
31 | 'credit_card_exp_date' => [ | |
32 | 'M' => '1', | |
33 | 'Y' => '2019', | |
34 | ], | |
35 | 'credit_card_type' => 'Visa', | |
36 | 'billing_first_name' => 'p', | |
37 | 'billing_middle_name' => '', | |
38 | 'billing_last_name' => 'p', | |
39 | 'billing_street_address-5' => 'p', | |
40 | 'billing_city-5' => 'p', | |
41 | 'billing_state_province_id-5' => '1061', | |
42 | 'billing_postal_code-5' => '7', | |
43 | 'billing_country_id-5' => '1228', | |
44 | 'priceSetId' => '6', | |
45 | 'price_7' => [ | |
46 | 13 => 1, | |
9099cab3 | 47 | ], |
d026b890 EM |
48 | 'payment_processor_id' => '1', |
49 | 'bypass_payment' => '', | |
50 | 'is_primary' => 1, | |
51 | 'is_pay_later' => 0, | |
52 | 'campaign_id' => NULL, | |
53 | 'defaultRole' => 1, | |
54 | 'participant_role_id' => '1', | |
55 | 'currencyID' => 'USD', | |
56 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
57 | 'amount' => '800.00', | |
58 | 'tax_amount' => NULL, | |
59 | 'year' => '2019', | |
60 | 'month' => '1', | |
61 | 'ip_address' => '127.0.0.1', | |
62 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
63 | 'button' => '_qf_Register_upload', | |
64 | 'billing_state_province-5' => 'AP', | |
65 | 'billing_country-5' => 'US', | |
9099cab3 | 66 | ]); |
bf302610 | 67 | |
e579af79 | 68 | $mut->checkMailLog([ |
12ff7379 | 69 | 'Dear Logged In, Thank you for your registration. This is a confirmation that your registration has been received and your status has been updated to Registered.', |
e579af79 | 70 | ]); |
71 | $mut->stop(); | |
72 | $mut->clearMessages(); | |
632196ea | 73 | } |
74 | ||
5e40de84 | 75 | /** |
76 | * Initial test of submit function for paid event. | |
77 | * | |
3ae1b2f4 | 78 | * @param string $thousandSeparator |
79 | * | |
f816b68f | 80 | * @throws \CRM_Core_Exception |
81 | * @throws \CiviCRM_API3_Exception | |
3ae1b2f4 | 82 | * |
f816b68f | 83 | * @dataProvider getThousandSeparators |
5e40de84 | 84 | */ |
3ae1b2f4 | 85 | public function testPaidSubmit($thousandSeparator) { |
db92bcb9 EM |
86 | // @todo - figure out why this doesn't pass validate financials |
87 | $this->isValidateFinancialsOnPostAssert = FALSE; | |
3ae1b2f4 | 88 | $this->setCurrencySeparators($thousandSeparator); |
220bfdc3 | 89 | $mut = new CiviMailUtils($this); |
5e40de84 | 90 | $paymentProcessorID = $this->processorCreate(); |
c1797e86 | 91 | /* @var \CRM_Core_Payment_Dummy $processor */ |
92 | $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); | |
93 | $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]); | |
9099cab3 | 94 | $params = ['is_monetary' => 1, 'financial_type_id' => 1]; |
5e40de84 | 95 | $event = $this->eventCreate($params); |
96 | $individualID = $this->individualCreate(); | |
9099cab3 | 97 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
5e40de84 | 98 | 'id' => $event['id'], |
99 | 'contributeMode' => 'direct', | |
100 | 'registerByID' => $individualID, | |
101 | 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), | |
b2dc39fc | 102 | 'totalAmount' => 8000.67, |
9099cab3 CW |
103 | 'params' => [ |
104 | [ | |
5e40de84 | 105 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
106 | 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', | |
107 | 'first_name' => 'k', | |
108 | 'last_name' => 'p', | |
109 | 'email-Primary' => 'demo@example.com', | |
110 | 'hidden_processor' => '1', | |
111 | 'credit_card_number' => '4111111111111111', | |
112 | 'cvv2' => '123', | |
9099cab3 | 113 | 'credit_card_exp_date' => [ |
5e40de84 | 114 | 'M' => '1', |
90530b87 | 115 | 'Y' => date('Y') + 1, |
9099cab3 | 116 | ], |
5e40de84 | 117 | 'credit_card_type' => 'Visa', |
118 | 'billing_first_name' => 'p', | |
119 | 'billing_middle_name' => '', | |
120 | 'billing_last_name' => 'p', | |
121 | 'billing_street_address-5' => 'p', | |
122 | 'billing_city-5' => 'p', | |
123 | 'billing_state_province_id-5' => '1061', | |
124 | 'billing_postal_code-5' => '7', | |
125 | 'billing_country_id-5' => '1228', | |
5e40de84 | 126 | 'priceSetId' => '6', |
9099cab3 | 127 | 'price_7' => [ |
5e40de84 | 128 | 13 => 1, |
9099cab3 | 129 | ], |
5e40de84 | 130 | 'payment_processor_id' => $paymentProcessorID, |
131 | 'bypass_payment' => '', | |
5e40de84 | 132 | 'is_primary' => 1, |
133 | 'is_pay_later' => 0, | |
134 | 'campaign_id' => NULL, | |
135 | 'defaultRole' => 1, | |
136 | 'participant_role_id' => '1', | |
137 | 'currencyID' => 'USD', | |
138 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
3ae1b2f4 | 139 | 'amount' => $this->formatMoneyInput(8000.67), |
5e40de84 | 140 | 'tax_amount' => NULL, |
141 | 'year' => '2019', | |
142 | 'month' => '1', | |
143 | 'ip_address' => '127.0.0.1', | |
144 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
145 | 'button' => '_qf_Register_upload', | |
146 | 'billing_state_province-5' => 'AP', | |
147 | 'billing_country-5' => 'US', | |
9099cab3 CW |
148 | ], |
149 | ], | |
150 | ]); | |
151 | $this->callAPISuccessGetCount('Participant', [], 1); | |
152 | $contribution = $this->callAPISuccessGetSingle('Contribution', []); | |
3ae1b2f4 | 153 | $this->assertEquals(8000.67, $contribution['total_amount']); |
c1797e86 | 154 | $this->assertEquals(1.67, $contribution['fee_amount']); |
155 | $this->assertEquals(7999, $contribution['net_amount']); | |
f816b68f | 156 | $this->assertNotEmpty($contribution['receipt_date']); |
a91b8131 | 157 | $this->assertNotContains(' (multiple participants)', $contribution['amount_level']); |
5e40de84 | 158 | $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); |
159 | $financialTrxn = $this->callAPISuccessGetSingle( | |
160 | 'FinancialTrxn', | |
9099cab3 | 161 | [ |
5e40de84 | 162 | 'id' => $lastFinancialTrxnId['financialTrxnId'], |
9099cab3 CW |
163 | 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'], |
164 | ] | |
5e40de84 | 165 | ); |
166 | $this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID); | |
167 | $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); | |
168 | $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 1111); | |
c1797e86 | 169 | |
170 | // This looks like it's missing an item for the main contribution - but just locking in current behaviour. | |
171 | $financialItems = $this->callAPISuccess('FinancialItem', 'get', [ | |
172 | 'return' => ['description', 'financial_account_id', 'amount', 'contact_id', 'currency', 'status_id', 'entity_table', 'entity_id'], | |
173 | 'sequential' => 1, | |
174 | ])['values']; | |
175 | ||
176 | $entityFinancialTrxns = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['sequential' => 1])['values']; | |
177 | ||
178 | $this->assertAPIArrayComparison([ | |
179 | 'entity_table' => 'civicrm_contribution', | |
180 | 'entity_id' => $contribution['id'], | |
181 | 'financial_trxn_id' => $financialTrxn['id'], | |
182 | 'amount' => '8000.67', | |
183 | ], $entityFinancialTrxns[0], ['id']); | |
184 | ||
185 | $this->assertAPIArrayComparison([ | |
186 | 'entity_table' => 'civicrm_contribution', | |
187 | 'entity_id' => $contribution['id'], | |
188 | 'financial_trxn_id' => $financialTrxn['id'] + 1, | |
189 | 'amount' => '1.67', | |
190 | ], $entityFinancialTrxns[1], ['id']); | |
191 | ||
192 | $this->assertAPIArrayComparison([ | |
193 | 'entity_table' => 'civicrm_financial_item', | |
194 | 'entity_id' => $financialItems[0]['id'], | |
195 | 'financial_trxn_id' => $financialTrxn['id'] + 1, | |
196 | 'amount' => '1.67', | |
197 | ], $entityFinancialTrxns[2], ['id', 'entity_id']); | |
220bfdc3 | 198 | $mut->checkMailLog([ |
d026b890 EM |
199 | 'Event Information and Location', |
200 | 'Registration Confirmation - Annual CiviCRM meet', | |
90530b87 | 201 | 'Expires: January ' . (date('Y') + 1), |
ea93110b | 202 | 'Visa', |
203 | '************1111', | |
12ff7379 | 204 | 'This is a confirmation that your registration has been received and your status has been updated to <strong> Registered</strong>', |
220bfdc3 | 205 | ]); |
206 | $mut->clearMessages(); | |
5e40de84 | 207 | } |
208 | ||
9e142397 DS |
209 | /** |
210 | * Tests missing contactID when registering for paid event from waitlist | |
211 | * https://github.com/civicrm/civicrm-core/pull/23358, https://lab.civicrm.org/extensions/stripe/-/issues/347 | |
212 | * | |
213 | * @throws \CiviCRM_API3_Exception | |
214 | */ | |
215 | public function testWaitlistRegistrationContactIdParam() { | |
216 | // @todo - figure out why this doesn't pass validate financials | |
217 | $this->isValidateFinancialsOnPostAssert = FALSE; | |
218 | $paymentProcessorID = $this->processorCreate(); | |
219 | /* @var \CRM_Core_Payment_Dummy $processor */ | |
220 | $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); | |
221 | $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]); | |
222 | $params = ['is_monetary' => 1, 'financial_type_id' => 1]; | |
223 | $event = $this->eventCreatePaid($params, [['name' => 'test', 'amount' => 8000.67]]); | |
224 | $individualID = $this->individualCreate(); | |
225 | //$this->submitForm($event['id'], [ | |
226 | $form = CRM_Event_Form_Registration_Confirm::testSubmit([ | |
227 | 'id' => $event['id'], | |
228 | 'contributeMode' => 'direct', | |
229 | 'registerByID' => $individualID, | |
230 | 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), | |
231 | 'amount' => 8000.67, | |
232 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
233 | 'params' => [ | |
234 | [ | |
235 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', | |
236 | 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', | |
237 | 'first_name' => 'k', | |
238 | 'last_name' => 'p', | |
239 | 'email-Primary' => 'demo@example.com', | |
240 | 'hidden_processor' => '1', | |
241 | 'credit_card_number' => '4111111111111111', | |
242 | 'cvv2' => '123', | |
243 | 'credit_card_exp_date' => [ | |
244 | 'M' => '1', | |
245 | 'Y' => date('Y') + 1, | |
246 | ], | |
247 | 'credit_card_type' => 'Visa', | |
248 | 'billing_first_name' => 'p', | |
249 | 'billing_middle_name' => '', | |
250 | 'billing_last_name' => 'p', | |
251 | 'billing_street_address-5' => 'p', | |
252 | 'billing_city-5' => 'p', | |
253 | 'billing_state_province_id-5' => '1061', | |
254 | 'billing_postal_code-5' => '7', | |
255 | 'billing_country_id-5' => '1228', | |
256 | 'priceSetId' => '6', | |
257 | 'price_7' => [ | |
258 | 13 => 1, | |
259 | ], | |
260 | 'payment_processor_id' => $paymentProcessorID, | |
261 | 'bypass_payment' => '', | |
262 | 'is_primary' => 1, | |
263 | 'is_pay_later' => 0, | |
264 | 'contact_id' => $individualID, | |
265 | 'campaign_id' => NULL, | |
266 | 'defaultRole' => 1, | |
267 | 'participant_role_id' => '1', | |
268 | 'currencyID' => 'USD', | |
269 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
270 | 'amount' => $this->formatMoneyInput(8000.67), | |
271 | 'tax_amount' => NULL, | |
272 | 'year' => '2019', | |
273 | 'month' => '1', | |
274 | 'ip_address' => '127.0.0.1', | |
275 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
276 | 'button' => '_qf_Register_upload', | |
277 | 'billing_state_province-5' => 'AP', | |
278 | 'billing_country-5' => 'US', | |
279 | ], | |
280 | ], | |
281 | ]); | |
282 | $this->callAPISuccessGetCount('Participant', [], 1); | |
283 | ||
284 | $value = $form->get('value'); | |
285 | $this->assertArrayHasKey('contact_id', $value, 'contact_id missing in $value array'); | |
286 | $this->assertEquals($value['contact_id'], $individualID, 'Invalid contact_id in $value array.'); | |
287 | ||
288 | // Add someone to the waitlist. | |
289 | $waitlistContactId = $this->individualCreate(); | |
290 | $waitlistContact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $waitlistContactId]); | |
291 | $waitlistParticipantId = $this->participantCreate(['event_id' => $event['id'], 'contact_id' => $waitlistContactId, 'status_id' => 'On waitlist']); | |
292 | ||
293 | $waitlistParticipant = $this->callAPISuccess('Participant', 'getsingle', ['id' => $waitlistParticipantId, 'return' => ["participant_status"]]); | |
294 | $this->assertEquals($waitlistParticipant['participant_status'], 'On waitlist', 'Invalid participant status. Expecting: On waitlist'); | |
295 | ||
296 | $form = CRM_Event_Form_Registration_Confirm::testSubmit([ | |
297 | 'id' => $event['id'], | |
298 | 'contributeMode' => 'direct', | |
299 | 'registerByID' => $waitlistContactId, | |
300 | 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), | |
301 | 'amount' => 8000.67, | |
302 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
303 | 'params' => [ | |
304 | [ | |
305 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', | |
306 | 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', | |
307 | 'first_name' => $waitlistContact['first_name'], | |
308 | 'last_name' => $waitlistContact['last_name'], | |
309 | 'email-Primary' => $waitlistContact['email'], | |
310 | 'hidden_processor' => '1', | |
311 | 'credit_card_number' => '4111111111111111', | |
312 | 'cvv2' => '123', | |
313 | 'credit_card_exp_date' => [ | |
314 | 'M' => '1', | |
315 | 'Y' => date('Y') + 1, | |
316 | ], | |
317 | 'credit_card_type' => 'Visa', | |
318 | 'billing_first_name' => $waitlistContact['first_name'], | |
319 | 'billing_middle_name' => '', | |
320 | 'billing_last_name' => $waitlistContact['last_name'], | |
321 | 'billing_street_address-5' => 'p', | |
322 | 'billing_city-5' => 'p', | |
323 | 'billing_state_province_id-5' => '1061', | |
324 | 'billing_postal_code-5' => '7', | |
325 | 'billing_country_id-5' => '1228', | |
326 | 'priceSetId' => '6', | |
327 | 'price_7' => [ | |
328 | 13 => 1, | |
329 | ], | |
330 | 'payment_processor_id' => $paymentProcessorID, | |
331 | 'bypass_payment' => '', | |
332 | 'is_primary' => 1, | |
333 | 'is_pay_later' => 0, | |
334 | 'participant_id' => $waitlistParticipantId, | |
335 | 'campaign_id' => NULL, | |
336 | 'defaultRole' => 1, | |
337 | 'participant_role_id' => '1', | |
338 | 'currencyID' => 'USD', | |
339 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
340 | 'amount' => $this->formatMoneyInput(8000.67), | |
341 | 'tax_amount' => NULL, | |
342 | 'year' => '2019', | |
343 | 'month' => '1', | |
344 | 'ip_address' => '127.0.0.1', | |
345 | 'invoiceID' => '68adc34957a29171948e8643ce906332', | |
346 | 'button' => '_qf_Register_upload', | |
347 | 'billing_state_province-5' => 'AP', | |
348 | 'billing_country-5' => 'US', | |
349 | ], | |
350 | ], | |
351 | ]); | |
352 | $this->callAPISuccessGetCount('Participant', [], 2); | |
353 | ||
354 | $waitlistParticipant = $this->callAPISuccess('Participant', 'getsingle', ['id' => $waitlistParticipantId, 'return' => ["participant_status"]]); | |
355 | $this->assertEquals($waitlistParticipant['participant_status'], 'Registered', 'Invalid participant status. Expecting: Registered'); | |
356 | ||
357 | $value = $form->get('value'); | |
358 | $this->assertArrayHasKey('contactID', $value, 'contactID missing in waitlist registration $value array'); | |
359 | $this->assertEquals($value['contactID'], $waitlistParticipant['contact_id'], 'Invalid contactID in waitlist $value array.'); | |
360 | } | |
361 | ||
6704d983 PN |
362 | /** |
363 | * Test for Tax amount for multiple participant. | |
364 | * | |
d7ade6fe | 365 | * @throws \CRM_Core_Exception |
7a2ee417 | 366 | * @throws \Exception |
6704d983 | 367 | */ |
f740d864 | 368 | public function testTaxMultipleParticipant(): void { |
db92bcb9 EM |
369 | // @todo - figure out why this doesn't pass validate financials |
370 | $this->isValidateFinancialsOnPostAssert = FALSE; | |
d7ade6fe | 371 | $mut = new CiviMailUtils($this); |
9099cab3 | 372 | $params = ['is_monetary' => 1, 'financial_type_id' => 1]; |
6704d983 | 373 | $event = $this->eventCreate($params); |
7a2ee417 | 374 | $this->swapMessageTemplateForTestTemplate('event_online_receipt', 'text'); |
9099cab3 | 375 | CRM_Event_Form_Registration_Confirm::testSubmit([ |
6704d983 PN |
376 | 'id' => $event['id'], |
377 | 'contributeMode' => 'direct', | |
378 | 'registerByID' => $this->createLoggedInUser(), | |
379 | 'totalAmount' => 440, | |
f740d864 | 380 | 'event' => $event, |
9099cab3 CW |
381 | 'params' => [ |
382 | [ | |
6704d983 PN |
383 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
384 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
385 | 'first_name' => 'Participant1', | |
386 | 'last_name' => 'LastName', | |
387 | 'email-Primary' => 'participant1@example.com', | |
6704d983 PN |
388 | 'additional_participants' => 2, |
389 | 'payment_processor_id' => 0, | |
390 | 'bypass_payment' => '', | |
6704d983 PN |
391 | 'is_primary' => 1, |
392 | 'is_pay_later' => 1, | |
393 | 'campaign_id' => NULL, | |
394 | 'defaultRole' => 1, | |
395 | 'participant_role_id' => '1', | |
396 | 'currencyID' => 'USD', | |
397 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
398 | 'amount' => '100.00', | |
399 | 'tax_amount' => 10, | |
400 | 'ip_address' => '127.0.0.1', | |
401 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
402 | 'trxn_id' => '123456789', | |
403 | 'button' => '_qf_Register_upload', | |
9099cab3 CW |
404 | ], |
405 | [ | |
6704d983 PN |
406 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
407 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
408 | 'first_name' => 'Participant2', | |
409 | 'last_name' => 'LastName', | |
410 | 'email-Primary' => 'participant2@example.com', | |
6704d983 PN |
411 | 'campaign_id' => NULL, |
412 | 'is_pay_later' => 1, | |
413 | 'participant_role_id' => '1', | |
414 | 'currencyID' => 'USD', | |
415 | 'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1', | |
416 | 'amount' => '200.00', | |
417 | 'tax_amount' => 20, | |
9099cab3 CW |
418 | ], |
419 | [ | |
6704d983 PN |
420 | 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', |
421 | 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", | |
422 | 'first_name' => 'Participant3', | |
423 | 'last_name' => 'LastName', | |
424 | 'email-Primary' => 'participant3@example.com', | |
6704d983 PN |
425 | 'campaign_id' => NULL, |
426 | 'is_pay_later' => 1, | |
427 | 'participant_role_id' => '1', | |
428 | 'currencyID' => 'USD', | |
429 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
430 | 'amount' => '100.00', | |
431 | 'tax_amount' => 10, | |
9099cab3 CW |
432 | ], |
433 | ], | |
434 | ]); | |
d7ade6fe | 435 | $participants = $this->callAPISuccess('Participant', 'get', [])['values']; |
436 | $this->assertCount(3, $participants); | |
6704d983 PN |
437 | $contribution = $this->callAPISuccessGetSingle( |
438 | 'Contribution', | |
9099cab3 | 439 | [ |
a91b8131 | 440 | 'return' => ['tax_amount', 'total_amount', 'amount_level'], |
9099cab3 | 441 | ] |
6704d983 | 442 | ); |
a91b8131 | 443 | $this->assertContains(' (multiple participants)', $contribution['amount_level']); |
f740d864 EM |
444 | $this->assertEquals(40, $contribution['tax_amount'], 'Invalid Tax amount.'); |
445 | $this->assertEquals(440, $contribution['total_amount'], 'Invalid Tax amount.'); | |
d7ade6fe | 446 | $mailSent = $mut->getAllMessages(); |
447 | $this->assertCount(3, $mailSent, 'Three mails should have been sent to the 3 participants.'); | |
275686a3 SL |
448 | $this->assertStringContainsString('contactID:::' . $contribution['contact_id'], $mailSent[0]); |
449 | $this->assertStringContainsString('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[1]); | |
7a2ee417 | 450 | |
451 | $this->callAPISuccess('Payment', 'create', ['total_amount' => 100, 'payment_type_id' => 'Cash', 'contribution_id' => $contribution['id']]); | |
452 | $mailSent = $mut->getAllMessages(); | |
453 | $this->assertCount(6, $mailSent); | |
454 | ||
275686a3 SL |
455 | $this->assertStringContainsString('participant_status:::Registered', $mailSent[3]); |
456 | $this->assertStringContainsString('Dear Participant2', $mailSent[3]); | |
7a2ee417 | 457 | |
275686a3 SL |
458 | $this->assertStringContainsString('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[3]); |
459 | $this->assertStringContainsString('contactID:::' . ($contribution['contact_id'] + 2), $mailSent[4]); | |
460 | $this->assertStringContainsString('contactID:::' . $contribution['contact_id'], $mailSent[5]); | |
7a2ee417 | 461 | $this->revertTemplateToReservedTemplate('event_online_receipt', 'text'); |
6704d983 PN |
462 | } |
463 | ||
c91b1cc3 E |
464 | /** |
465 | * Test online registration for event with no price options selected as per CRM-19964. | |
466 | */ | |
d026b890 | 467 | public function testOnlineRegNoPrice(): void { |
7a2ee417 | 468 | $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]); |
9099cab3 CW |
469 | $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]); |
470 | $params = [ | |
c91b1cc3 E |
471 | 'start_date' => date('YmdHis', strtotime('+ 1 week')), |
472 | 'end_date' => date('YmdHis', strtotime('+ 1 year')), | |
473 | 'registration_start_date' => date('YmdHis', strtotime('- 1 day')), | |
474 | 'registration_end_date' => date('YmdHis', strtotime('+ 1 year')), | |
475 | 'payment_processor_id' => $paymentProcessorID, | |
476 | 'is_monetary' => TRUE, | |
477 | 'financial_type_id' => 'Event Fee', | |
9099cab3 | 478 | ]; |
c91b1cc3 | 479 | $event = $this->eventCreate($params); |
9099cab3 | 480 | $priceFieldOptions = [ |
c91b1cc3 E |
481 | 'option_label' => 'Price Field', |
482 | 'option_value' => 100, | |
483 | 'is_required' => FALSE, | |
484 | 'html_type' => 'Text', | |
9099cab3 | 485 | ]; |
c91b1cc3 E |
486 | $this->createPriceSet('event', $event['id'], $priceFieldOptions); |
487 | ||
488 | $priceField = $this->callAPISuccess('PriceField', 'get', | |
9099cab3 | 489 | [ |
c91b1cc3 | 490 | 'label' => 'Price Field', |
9099cab3 | 491 | ] |
c91b1cc3 E |
492 | ); |
493 | // Create online event registration. | |
d026b890 | 494 | $this->submitForm( |
f740d864 EM |
495 | $event['id'], [ |
496 | [ | |
497 | 'first_name' => 'Bruce', | |
498 | 'last_name' => 'Wayne', | |
499 | 'email-Primary' => 'bruce@gotham.com', | |
500 | 'price_' . $priceField['id'] => '', | |
501 | 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'], | |
502 | 'payment_processor_id' => $paymentProcessorID, | |
503 | 'amount' => 0, | |
504 | 'amount_level' => '', | |
505 | 'bypass_payment' => '', | |
506 | 'is_primary' => 1, | |
507 | 'is_pay_later' => 0, | |
508 | 'campaign_id' => NULL, | |
509 | 'defaultRole' => 1, | |
510 | 'participant_role_id' => '1', | |
511 | 'tax_amount' => NULL, | |
512 | 'ip_address' => '127.0.0.1', | |
513 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
514 | 'button' => '_qf_Register_upload', | |
515 | ], | |
d026b890 EM |
516 | ] |
517 | ); | |
9099cab3 | 518 | $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']); |
f740d864 | 519 | $this->assertEquals('0', $contribution['count'], 'Contribution should not be created for zero fee event registration when no price field selected.'); |
c91b1cc3 E |
520 | } |
521 | ||
6d2e7dc0 | 522 | /** |
523 | * Test form profile assignment. | |
524 | * | |
525 | * @throws \CRM_Core_Exception | |
526 | * @throws \Exception | |
527 | */ | |
f740d864 | 528 | public function testAssignProfiles(): void { |
6d2e7dc0 | 529 | $event = $this->eventCreate(); |
530 | $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]); | |
531 | ||
d026b890 | 532 | $_REQUEST['id'] = $event['id']; |
6d2e7dc0 | 533 | /* @var \CRM_Event_Form_Registration_Confirm $form */ |
534 | $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); | |
535 | $form->set('params', [[]]); | |
6d2e7dc0 | 536 | $form->set('values', [ |
f740d864 | 537 | 'event' => $event, |
6d2e7dc0 | 538 | 'location' => [], |
539 | 'custom_pre_id' => $this->ids['UFGroup']['our profile'], | |
540 | ]); | |
541 | $form->preProcess(); | |
542 | ||
543 | CRM_Event_Form_Registration_Confirm::assignProfiles($form); | |
544 | ||
545 | $smarty = CRM_Core_Smarty::singleton(); | |
546 | $tplVar = $smarty->get_template_vars(); | |
547 | $this->assertEquals([ | |
548 | 'CustomPre' => ['First Name' => NULL], | |
549 | 'CustomPreGroupTitle' => 'Public title', | |
550 | ], $tplVar['primaryParticipantProfile']); | |
551 | } | |
552 | ||
eba56939 BS |
553 | /** |
554 | * Submit event registration with a note field | |
555 | * | |
bf302610 | 556 | * @param array $event |
f740d864 | 557 | * @param int|null $contact_id |
eba56939 | 558 | * |
bf302610 | 559 | * @return array |
eba56939 BS |
560 | * @throws \Exception |
561 | */ | |
f740d864 EM |
562 | private function submitWithNote(array $event, ?int $contact_id): array { |
563 | if ($contact_id === NULL) { | |
eba56939 BS |
564 | $contact_id = $this->createLoggedInUser(); |
565 | } | |
566 | $mut = new CiviMailUtils($this, TRUE); | |
d026b890 | 567 | $this->submitForm($event['id'], [ |
f740d864 EM |
568 | [ |
569 | 'first_name' => 'k', | |
570 | 'last_name' => 'p', | |
571 | 'email-Primary' => 'demo@example.com', | |
572 | 'hidden_processor' => '1', | |
573 | 'credit_card_number' => '4111111111111111', | |
574 | 'cvv2' => '123', | |
575 | 'credit_card_exp_date' => [ | |
576 | 'M' => '1', | |
577 | 'Y' => '2019', | |
578 | ], | |
579 | 'credit_card_type' => 'Visa', | |
580 | 'billing_first_name' => 'p', | |
581 | 'billing_middle_name' => '', | |
582 | 'billing_last_name' => 'p', | |
583 | 'billing_street_address-5' => 'p', | |
584 | 'billing_city-5' => 'p', | |
585 | 'billing_state_province_id-5' => '1061', | |
586 | 'billing_postal_code-5' => '7', | |
587 | 'billing_country_id-5' => '1228', | |
588 | 'priceSetId' => '6', | |
589 | 'price_7' => [ | |
590 | 13 => 1, | |
591 | ], | |
592 | 'payment_processor_id' => '1', | |
593 | 'bypass_payment' => '', | |
594 | 'is_primary' => 1, | |
595 | 'is_pay_later' => 0, | |
596 | 'campaign_id' => NULL, | |
597 | 'defaultRole' => 1, | |
598 | 'participant_role_id' => '1', | |
599 | 'currencyID' => 'USD', | |
600 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
601 | 'amount' => '800.00', | |
602 | 'tax_amount' => NULL, | |
603 | 'year' => '2019', | |
604 | 'month' => '1', | |
605 | 'ip_address' => '127.0.0.1', | |
606 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
607 | 'button' => '_qf_Register_upload', | |
608 | 'billing_state_province-5' => 'AP', | |
609 | 'billing_country-5' => 'US', | |
610 | 'note' => $event['note'], | |
d026b890 | 611 | ], |
eba56939 BS |
612 | ]); |
613 | $participant = $this->callAPISuccessGetSingle('Participant', []); | |
614 | $mut->checkMailLog(['Comment: ' . $event['note'] . chr(0x0A)]); | |
615 | $mut->stop(); | |
616 | $mut->clearMessages(); | |
eba56939 BS |
617 | //return ['contact_id' => $contact_id, 'participant_id' => $participant['id']]; |
618 | return [$contact_id, $participant['id']]; | |
619 | } | |
620 | ||
621 | /** | |
622 | * Create an event with a "pre" profile | |
623 | * | |
624 | * @throws \CRM_Core_Exception | |
eba56939 | 625 | */ |
f740d864 | 626 | private function creatEventWithProfile($event): array { |
eba56939 BS |
627 | if (empty($event)) { |
628 | $event = $this->eventCreate(); | |
629 | $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]); | |
f740d864 | 630 | $this->uf_field_add($this->ids['UFGroup']['our profile'], 'note', 'Contact', 'Comment'); |
eba56939 BS |
631 | } |
632 | ||
d026b890 | 633 | $_REQUEST['id'] = $event['id']; |
eba56939 BS |
634 | /* @var \CRM_Event_Form_Registration_Confirm $form */ |
635 | $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); | |
636 | $form->set('params', [[]]); | |
eba56939 | 637 | $form->set('values', [ |
f740d864 | 638 | 'event' => $event, |
eba56939 BS |
639 | 'location' => [], |
640 | 'custom_pre_id' => $this->ids['UFGroup']['our profile'], | |
641 | ]); | |
642 | $form->preProcess(); | |
643 | ||
644 | CRM_Event_Form_Registration_Confirm::assignProfiles($form); | |
645 | ||
646 | $smarty = CRM_Core_Smarty::singleton(); | |
647 | $tplVar = $smarty->get_template_vars(); | |
648 | $this->assertEquals([ | |
649 | 'CustomPre' => ['First Name' => NULL, 'Comment' => NULL], | |
650 | 'CustomPreGroupTitle' => 'Public title', | |
651 | ], $tplVar['primaryParticipantProfile']); | |
652 | return $event; | |
653 | } | |
654 | ||
655 | /** | |
656 | * Add a field to the specified profile | |
657 | * | |
658 | * @param int $uf_group_id | |
659 | * @param string $field_name | |
660 | * @param string $field_type | |
661 | * @param string $field_label | |
bf302610 | 662 | * |
eba56939 BS |
663 | * @return array |
664 | * API result array | |
bf302610 | 665 | * @throws \CRM_Core_Exception |
eba56939 BS |
666 | */ |
667 | private function uf_field_add($uf_group_id, $field_name, $field_type, $field_label) { | |
668 | $params = [ | |
669 | 'field_name' => $field_name, | |
670 | 'field_type' => $field_type, | |
671 | 'visibility' => 'Public Pages and Listings', | |
672 | 'weight' => 1, | |
673 | 'label' => $field_label, | |
674 | 'is_searchable' => 1, | |
675 | 'is_active' => 1, | |
676 | 'uf_group_id' => $uf_group_id, | |
677 | ]; | |
bf302610 | 678 | return $this->callAPISuccess('UFField', 'create', $params); |
eba56939 BS |
679 | } |
680 | ||
681 | /** | |
682 | * /dev/event#10 | |
683 | * Test submission with a note in the profile, ensuring the confirmation | |
684 | * email reflects the submitted value | |
82e5b7ad | 685 | * |
686 | * @throws \CRM_Core_Exception | |
687 | * @throws \CiviCRM_API3_Exception | |
688 | * @throws \Exception | |
eba56939 | 689 | */ |
82e5b7ad | 690 | public function testNoteSubmission(): void { |
eba56939 BS |
691 | //create an event with an attached profile containing a note |
692 | $event = $this->creatEventWithProfile(NULL); | |
82e5b7ad | 693 | $event['custom_pre_id'] = $this->ids['UFGroup']['our profile']; |
bf302610 | 694 | $event['note'] = 'This is note 1'; |
82e5b7ad | 695 | [$contact_id, $participant_id] = $this->submitWithNote($event, NULL); |
eba56939 BS |
696 | civicrm_api3('Participant', 'delete', ['id' => $participant_id]); |
697 | ||
698 | //now that the contact has one note, register this contact again with a different note | |
699 | //and confirm that the note shown in the email is the current one | |
700 | $event = $this->creatEventWithProfile($event); | |
f740d864 | 701 | $event['custom_pre_id'] = $this->ids['UFGroup']['our profile']; |
bf302610 | 702 | $event['note'] = 'This is note 2'; |
82e5b7ad | 703 | [$contact_id, $participant_id] = $this->submitWithNote($event, $contact_id); |
eba56939 BS |
704 | civicrm_api3('Participant', 'delete', ['id' => $participant_id]); |
705 | ||
706 | //finally, submit a blank note and confirm that the note shown in the email is blank | |
707 | $event = $this->creatEventWithProfile($event); | |
f740d864 | 708 | $event['custom_pre_id'] = $this->ids['UFGroup']['our profile']; |
bf302610 | 709 | $event['note'] = ''; |
710 | $this->submitWithNote($event, $contact_id); | |
eba56939 BS |
711 | } |
712 | ||
2ba7b9e8 | 713 | /** |
819a6429 | 714 | * Ensure we send to the submitted email, not the primary email, if different. |
2ba7b9e8 | 715 | * |
819a6429 | 716 | * event#64. |
2ba7b9e8 JG |
717 | */ |
718 | public function testSubmitNonPrimaryEmail(): void { | |
719 | $event = $this->eventCreate(); | |
720 | $mut = new CiviMailUtils($this, TRUE); | |
819a6429 | 721 | $this->submitForm($event['id'], [ |
f740d864 EM |
722 | [ |
723 | 'first_name' => 'k', | |
724 | 'last_name' => 'p', | |
725 | 'email-Other' => 'nonprimaryemail@example.com', | |
726 | 'hidden_processor' => '1', | |
727 | 'credit_card_number' => '4111111111111111', | |
728 | 'cvv2' => '123', | |
729 | 'credit_card_exp_date' => [ | |
730 | 'M' => '1', | |
731 | 'Y' => '2019', | |
732 | ], | |
733 | 'credit_card_type' => 'Visa', | |
734 | 'billing_first_name' => 'p', | |
735 | 'billing_middle_name' => '', | |
736 | 'billing_last_name' => 'p', | |
737 | 'billing_street_address-5' => 'p', | |
738 | 'billing_city-5' => 'p', | |
739 | 'billing_state_province_id-5' => '1061', | |
740 | 'billing_postal_code-5' => '7', | |
741 | 'billing_country_id-5' => '1228', | |
742 | 'priceSetId' => '6', | |
743 | 'price_7' => [ | |
744 | 13 => 1, | |
745 | ], | |
746 | 'payment_processor_id' => '1', | |
747 | 'bypass_payment' => '', | |
748 | 'is_primary' => 1, | |
749 | 'is_pay_later' => 0, | |
750 | 'campaign_id' => NULL, | |
751 | 'defaultRole' => 1, | |
752 | 'participant_role_id' => '1', | |
753 | 'currencyID' => 'USD', | |
754 | 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1', | |
755 | 'amount' => '800.00', | |
756 | 'tax_amount' => NULL, | |
757 | 'year' => '2019', | |
758 | 'month' => '1', | |
759 | 'invoiceID' => '57adc34957a29171948e8643ce906332', | |
760 | 'button' => '_qf_Register_upload', | |
761 | 'billing_state_province-5' => 'AP', | |
762 | 'billing_country-5' => 'US', | |
819a6429 | 763 | ], |
2ba7b9e8 | 764 | ]); |
2ba7b9e8 JG |
765 | $mut->checkMailLog(['nonprimaryemail@example.com']); |
766 | $mut->stop(); | |
767 | $mut->clearMessages(); | |
768 | } | |
769 | ||
d026b890 EM |
770 | /** |
771 | * Submit the confirm form. | |
772 | * | |
773 | * @param int $eventID | |
774 | * @param array $params | |
775 | * Array that would be stored in the form as params at this point. | |
776 | * (ideally we will move to submitted rather than processed values | |
777 | * in time). | |
778 | */ | |
779 | protected function submitForm(int $eventID, array $params): void { | |
780 | $_REQUEST['id'] = $eventID; | |
f740d864 EM |
781 | $form = $this->getFormObject('CRM_Event_Form_Registration_Register', $params); |
782 | $form->buildForm(); | |
783 | $form->postProcess(); | |
d026b890 | 784 | $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm', []); |
f740d864 EM |
785 | if (!isset($params[0])) { |
786 | $params = [$params]; | |
787 | } | |
788 | $form->set('params', $params); | |
d026b890 EM |
789 | $form->set('registerByID', $this->createLoggedInUser()); |
790 | $form->buildForm(); | |
791 | $form->postProcess(); | |
792 | } | |
793 | ||
632196ea | 794 | } |