Update 'Thank You' & other corrections in message templates
[civicrm-core.git] / tests / phpunit / CRM / Event / Form / Registration / ConfirmTest.php
CommitLineData
632196ea 1<?php
2
3/**
4 * Test CRM_Event_Form_Registration functions.
5 *
6 * @package CiviCRM
7 * @group headless
8 */
9class 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&amp;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([
12ff7379 83 '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 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);
220bfdc3 103 $mut = new CiviMailUtils($this);
5e40de84 104 $paymentProcessorID = $this->processorCreate();
c1797e86 105 /* @var \CRM_Core_Payment_Dummy $processor */
106 $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID);
107 $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]);
9099cab3 108 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
5e40de84 109 $event = $this->eventCreate($params);
110 $individualID = $this->individualCreate();
9099cab3 111 CRM_Event_Form_Registration_Confirm::testSubmit([
5e40de84 112 'id' => $event['id'],
113 'contributeMode' => 'direct',
114 'registerByID' => $individualID,
115 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID),
3ae1b2f4 116 'totalAmount' => $this->formatMoneyInput(8000.67),
9099cab3
CW
117 'params' => [
118 [
5e40de84 119 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
120 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&amp;id=3',
121 'first_name' => 'k',
122 'last_name' => 'p',
123 'email-Primary' => 'demo@example.com',
124 'hidden_processor' => '1',
125 'credit_card_number' => '4111111111111111',
126 'cvv2' => '123',
9099cab3 127 'credit_card_exp_date' => [
5e40de84 128 'M' => '1',
129 'Y' => '2019',
9099cab3 130 ],
5e40de84 131 'credit_card_type' => 'Visa',
132 'billing_first_name' => 'p',
133 'billing_middle_name' => '',
134 'billing_last_name' => 'p',
135 'billing_street_address-5' => 'p',
136 'billing_city-5' => 'p',
137 'billing_state_province_id-5' => '1061',
138 'billing_postal_code-5' => '7',
139 'billing_country_id-5' => '1228',
5e40de84 140 'priceSetId' => '6',
9099cab3 141 'price_7' => [
5e40de84 142 13 => 1,
9099cab3 143 ],
5e40de84 144 'payment_processor_id' => $paymentProcessorID,
145 'bypass_payment' => '',
5e40de84 146 'is_primary' => 1,
147 'is_pay_later' => 0,
148 'campaign_id' => NULL,
149 'defaultRole' => 1,
150 'participant_role_id' => '1',
151 'currencyID' => 'USD',
152 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
3ae1b2f4 153 'amount' => $this->formatMoneyInput(8000.67),
5e40de84 154 'tax_amount' => NULL,
155 'year' => '2019',
156 'month' => '1',
157 'ip_address' => '127.0.0.1',
158 'invoiceID' => '57adc34957a29171948e8643ce906332',
159 'button' => '_qf_Register_upload',
160 'billing_state_province-5' => 'AP',
161 'billing_country-5' => 'US',
9099cab3
CW
162 ],
163 ],
164 ]);
165 $this->callAPISuccessGetCount('Participant', [], 1);
166 $contribution = $this->callAPISuccessGetSingle('Contribution', []);
3ae1b2f4 167 $this->assertEquals(8000.67, $contribution['total_amount']);
c1797e86 168 $this->assertEquals(1.67, $contribution['fee_amount']);
169 $this->assertEquals(7999, $contribution['net_amount']);
5e40de84 170 $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
171 $financialTrxn = $this->callAPISuccessGetSingle(
172 'FinancialTrxn',
9099cab3 173 [
5e40de84 174 'id' => $lastFinancialTrxnId['financialTrxnId'],
9099cab3
CW
175 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'],
176 ]
5e40de84 177 );
178 $this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID);
179 $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa');
180 $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 1111);
c1797e86 181
182 // This looks like it's missing an item for the main contribution - but just locking in current behaviour.
183 $financialItems = $this->callAPISuccess('FinancialItem', 'get', [
184 'return' => ['description', 'financial_account_id', 'amount', 'contact_id', 'currency', 'status_id', 'entity_table', 'entity_id'],
185 'sequential' => 1,
186 ])['values'];
187
188 $entityFinancialTrxns = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['sequential' => 1])['values'];
189
190 $this->assertAPIArrayComparison([
191 'entity_table' => 'civicrm_contribution',
192 'entity_id' => $contribution['id'],
193 'financial_trxn_id' => $financialTrxn['id'],
194 'amount' => '8000.67',
195 ], $entityFinancialTrxns[0], ['id']);
196
197 $this->assertAPIArrayComparison([
198 'entity_table' => 'civicrm_contribution',
199 'entity_id' => $contribution['id'],
200 'financial_trxn_id' => $financialTrxn['id'] + 1,
201 'amount' => '1.67',
202 ], $entityFinancialTrxns[1], ['id']);
203
204 $this->assertAPIArrayComparison([
205 'entity_table' => 'civicrm_financial_item',
206 'entity_id' => $financialItems[0]['id'],
207 'financial_trxn_id' => $financialTrxn['id'] + 1,
208 'amount' => '1.67',
209 ], $entityFinancialTrxns[2], ['id', 'entity_id']);
220bfdc3 210 $mut->checkMailLog([
211 'Event Information and Location', 'Registration Confirmation - Annual CiviCRM meet',
ea93110b 212 'Expires: January 2019',
213 'Visa',
214 '************1111',
12ff7379 215 'This is a confirmation that your registration has been received and your status has been updated to <strong> Registered</strong>',
220bfdc3 216 ]);
217 $mut->clearMessages();
5e40de84 218 }
219
6704d983
PN
220 /**
221 * Test for Tax amount for multiple participant.
222 *
d7ade6fe 223 * @throws \CRM_Core_Exception
7a2ee417 224 * @throws \Exception
6704d983
PN
225 */
226 public function testTaxMultipleParticipant() {
d7ade6fe 227 $mut = new CiviMailUtils($this);
9099cab3 228 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
6704d983 229 $event = $this->eventCreate($params);
7a2ee417 230 $this->swapMessageTemplateForTestTemplate('event_online_receipt', 'text');
9099cab3 231 CRM_Event_Form_Registration_Confirm::testSubmit([
6704d983
PN
232 'id' => $event['id'],
233 'contributeMode' => 'direct',
234 'registerByID' => $this->createLoggedInUser(),
235 'totalAmount' => 440,
236 'event' => reset($event['values']),
9099cab3
CW
237 'params' => [
238 [
6704d983
PN
239 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
240 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&amp;id={$event['id']}",
241 'first_name' => 'Participant1',
242 'last_name' => 'LastName',
243 'email-Primary' => 'participant1@example.com',
6704d983
PN
244 'additional_participants' => 2,
245 'payment_processor_id' => 0,
246 'bypass_payment' => '',
6704d983
PN
247 'is_primary' => 1,
248 'is_pay_later' => 1,
249 'campaign_id' => NULL,
250 'defaultRole' => 1,
251 'participant_role_id' => '1',
252 'currencyID' => 'USD',
253 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
254 'amount' => '100.00',
255 'tax_amount' => 10,
256 'ip_address' => '127.0.0.1',
257 'invoiceID' => '57adc34957a29171948e8643ce906332',
258 'trxn_id' => '123456789',
259 'button' => '_qf_Register_upload',
9099cab3
CW
260 ],
261 [
6704d983
PN
262 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
263 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&amp;id={$event['id']}",
264 'first_name' => 'Participant2',
265 'last_name' => 'LastName',
266 'email-Primary' => 'participant2@example.com',
267 'scriptFee' => '',
268 'scriptArray' => '',
269 'campaign_id' => NULL,
270 'is_pay_later' => 1,
271 'participant_role_id' => '1',
272 'currencyID' => 'USD',
273 'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1',
274 'amount' => '200.00',
275 'tax_amount' => 20,
9099cab3
CW
276 ],
277 [
6704d983
PN
278 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
279 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&amp;id={$event['id']}",
280 'first_name' => 'Participant3',
281 'last_name' => 'LastName',
282 'email-Primary' => 'participant3@example.com',
283 'scriptFee' => '',
284 'scriptArray' => '',
285 'campaign_id' => NULL,
286 'is_pay_later' => 1,
287 'participant_role_id' => '1',
288 'currencyID' => 'USD',
289 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
290 'amount' => '100.00',
291 'tax_amount' => 10,
9099cab3
CW
292 ],
293 ],
294 ]);
d7ade6fe 295 $participants = $this->callAPISuccess('Participant', 'get', [])['values'];
296 $this->assertCount(3, $participants);
6704d983
PN
297 $contribution = $this->callAPISuccessGetSingle(
298 'Contribution',
9099cab3
CW
299 [
300 'return' => ['tax_amount', 'total_amount'],
301 ]
6704d983
PN
302 );
303 $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
304 $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
d7ade6fe 305 $mailSent = $mut->getAllMessages();
306 $this->assertCount(3, $mailSent, 'Three mails should have been sent to the 3 participants.');
7a2ee417 307 $this->assertContains('contactID:::' . $contribution['contact_id'], $mailSent[0]);
308 $this->assertContains('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[1]);
309
310 $this->callAPISuccess('Payment', 'create', ['total_amount' => 100, 'payment_type_id' => 'Cash', 'contribution_id' => $contribution['id']]);
311 $mailSent = $mut->getAllMessages();
312 $this->assertCount(6, $mailSent);
313
314 $this->assertContains('participant_status:::Registered', $mailSent[3]);
315 $this->assertContains('Dear Participant2', $mailSent[3]);
316
317 $this->assertContains('contactID:::' . ($contribution['contact_id'] + 1), $mailSent[3]);
318 $this->assertContains('contactID:::' . ($contribution['contact_id'] + 2), $mailSent[4]);
319 $this->assertContains('contactID:::' . $contribution['contact_id'], $mailSent[5]);
320 $this->revertTemplateToReservedTemplate('event_online_receipt', 'text');
6704d983
PN
321 }
322
c91b1cc3
E
323 /**
324 * Test online registration for event with no price options selected as per CRM-19964.
325 */
326 public function testOnlineRegNoPrice() {
7a2ee417 327 $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]);
9099cab3
CW
328 $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]);
329 $params = [
c91b1cc3
E
330 'start_date' => date('YmdHis', strtotime('+ 1 week')),
331 'end_date' => date('YmdHis', strtotime('+ 1 year')),
332 'registration_start_date' => date('YmdHis', strtotime('- 1 day')),
333 'registration_end_date' => date('YmdHis', strtotime('+ 1 year')),
334 'payment_processor_id' => $paymentProcessorID,
335 'is_monetary' => TRUE,
336 'financial_type_id' => 'Event Fee',
9099cab3 337 ];
c91b1cc3 338 $event = $this->eventCreate($params);
9099cab3 339 $priceFieldOptions = [
c91b1cc3
E
340 'option_label' => 'Price Field',
341 'option_value' => 100,
342 'is_required' => FALSE,
343 'html_type' => 'Text',
9099cab3 344 ];
c91b1cc3
E
345 $this->createPriceSet('event', $event['id'], $priceFieldOptions);
346
347 $priceField = $this->callAPISuccess('PriceField', 'get',
9099cab3 348 [
c91b1cc3 349 'label' => 'Price Field',
9099cab3 350 ]
c91b1cc3
E
351 );
352 // Create online event registration.
9099cab3 353 CRM_Event_Form_Registration_Confirm::testSubmit([
c91b1cc3
E
354 'id' => $event['id'],
355 'contributeMode' => 'direct',
356 'registerByID' => $this->createLoggedInUser(),
9099cab3
CW
357 'params' => [
358 [
c91b1cc3
E
359 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
360 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&amp;id={$event['id']}",
361 'first_name' => 'Bruce',
362 'last_name' => 'Wayne',
363 'email-Primary' => 'bruce@gotham.com',
364 'price_' . $priceField['id'] => '',
365 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'],
366 'payment_processor_id' => $paymentProcessorID,
367 'amount' => 0,
368 'bypass_payment' => '',
369 'MAX_FILE_SIZE' => '33554432',
370 'is_primary' => 1,
371 'is_pay_later' => 0,
372 'campaign_id' => NULL,
373 'defaultRole' => 1,
374 'participant_role_id' => '1',
375 'tax_amount' => NULL,
376 'ip_address' => '127.0.0.1',
377 'invoiceID' => '57adc34957a29171948e8643ce906332',
378 'button' => '_qf_Register_upload',
379 'scriptFee' => '',
380 'scriptArray' => '',
9099cab3
CW
381 ],
382 ],
383 ]);
384 $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']);
37479886 385 $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
c91b1cc3
E
386 }
387
6d2e7dc0 388 /**
389 * Test form profile assignment.
390 *
391 * @throws \CRM_Core_Exception
392 * @throws \Exception
393 */
394 public function testAssignProfiles() {
395 $event = $this->eventCreate();
396 $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
397
398 /* @var \CRM_Event_Form_Registration_Confirm $form */
399 $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
400 $form->set('params', [[]]);
401 $form->set('id', $event['id']);
402 $form->set('values', [
403 'event' => $event['values'][$event['id']],
404 'location' => [],
405 'custom_pre_id' => $this->ids['UFGroup']['our profile'],
406 ]);
407 $form->preProcess();
408
409 CRM_Event_Form_Registration_Confirm::assignProfiles($form);
410
411 $smarty = CRM_Core_Smarty::singleton();
412 $tplVar = $smarty->get_template_vars();
413 $this->assertEquals([
414 'CustomPre' => ['First Name' => NULL],
415 'CustomPreGroupTitle' => 'Public title',
416 ], $tplVar['primaryParticipantProfile']);
417 }
418
eba56939
BS
419 /**
420 * Submit event registration with a note field
421 *
422 * @param array $event
423 * @param int $contact_id
424 *
425 * @throws \Exception
426 */
427 private function submitWithNote($event, $contact_id) {
428 if (empty($contact_id)) {
429 $contact_id = $this->createLoggedInUser();
430 }
431 $mut = new CiviMailUtils($this, TRUE);
432 CRM_Event_Form_Registration_Confirm::testSubmit([
433 'id' => $event['id'],
434 'contributeMode' => 'direct',
435 'registerByID' => $contact_id,
436 'custom_pre_id' => $event['custom_pre_id'],
437 'params' => [
438 [
439 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
440 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&amp;id=3',
441 'first_name' => 'k',
442 'last_name' => 'p',
443 'email-Primary' => 'demo@example.com',
444 'hidden_processor' => '1',
445 'credit_card_number' => '4111111111111111',
446 'cvv2' => '123',
447 'credit_card_exp_date' => [
448 'M' => '1',
449 'Y' => '2019',
450 ],
451 'credit_card_type' => 'Visa',
452 'billing_first_name' => 'p',
453 'billing_middle_name' => '',
454 'billing_last_name' => 'p',
455 'billing_street_address-5' => 'p',
456 'billing_city-5' => 'p',
457 'billing_state_province_id-5' => '1061',
458 'billing_postal_code-5' => '7',
459 'billing_country_id-5' => '1228',
460 'scriptFee' => '',
461 'scriptArray' => '',
462 'priceSetId' => '6',
463 'price_7' => [
464 13 => 1,
465 ],
466 'payment_processor_id' => '1',
467 'bypass_payment' => '',
468 'MAX_FILE_SIZE' => '33554432',
469 'is_primary' => 1,
470 'is_pay_later' => 0,
471 'campaign_id' => NULL,
472 'defaultRole' => 1,
473 'participant_role_id' => '1',
474 'currencyID' => 'USD',
475 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
476 'amount' => '800.00',
477 'tax_amount' => NULL,
478 'year' => '2019',
479 'month' => '1',
480 'ip_address' => '127.0.0.1',
481 'invoiceID' => '57adc34957a29171948e8643ce906332',
482 'button' => '_qf_Register_upload',
483 'billing_state_province-5' => 'AP',
484 'billing_country-5' => 'US',
485 'note' => $event['note'],
486 ],
487 ],
488 ]);
489 $participant = $this->callAPISuccessGetSingle('Participant', []);
490 $mut->checkMailLog(['Comment: ' . $event['note'] . chr(0x0A)]);
491 $mut->stop();
492 $mut->clearMessages();
493 $tplVars = CRM_Core_Smarty::singleton()->get_template_vars();
494 $this->assertEquals($participant['id'], $tplVars['participantID']);
495 //return ['contact_id' => $contact_id, 'participant_id' => $participant['id']];
496 return [$contact_id, $participant['id']];
497 }
498
499 /**
500 * Create an event with a "pre" profile
501 *
502 * @throws \CRM_Core_Exception
503 * @throws \Exception
504 */
505 private function creatEventWithProfile($event) {
506 if (empty($event)) {
507 $event = $this->eventCreate();
508 $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
509 $this->uf_field_add($this->ids["UFGroup"]["our profile"], 'note', 'Contact', 'Comment');
510 }
511
512 /* @var \CRM_Event_Form_Registration_Confirm $form */
513 $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
514 $form->set('params', [[]]);
515 $form->set('id', $event['id']);
516 $form->set('values', [
517 'event' => $event['values'][$event['id']],
518 'location' => [],
519 'custom_pre_id' => $this->ids['UFGroup']['our profile'],
520 ]);
521 $form->preProcess();
522
523 CRM_Event_Form_Registration_Confirm::assignProfiles($form);
524
525 $smarty = CRM_Core_Smarty::singleton();
526 $tplVar = $smarty->get_template_vars();
527 $this->assertEquals([
528 'CustomPre' => ['First Name' => NULL, 'Comment' => NULL],
529 'CustomPreGroupTitle' => 'Public title',
530 ], $tplVar['primaryParticipantProfile']);
531 return $event;
532 }
533
534 /**
535 * Add a field to the specified profile
536 *
537 * @param int $uf_group_id
538 * @param string $field_name
539 * @param string $field_type
540 * @param string $field_label
541 * @return array
542 * API result array
543 */
544 private function uf_field_add($uf_group_id, $field_name, $field_type, $field_label) {
545 $params = [
546 'field_name' => $field_name,
547 'field_type' => $field_type,
548 'visibility' => 'Public Pages and Listings',
549 'weight' => 1,
550 'label' => $field_label,
551 'is_searchable' => 1,
552 'is_active' => 1,
553 'uf_group_id' => $uf_group_id,
554 ];
555 $result = civicrm_api3('UFField', 'create', $params);
556 return $result;
557 }
558
559 /**
560 * /dev/event#10
561 * Test submission with a note in the profile, ensuring the confirmation
562 * email reflects the submitted value
563 */
564 public function testNoteSubmission() {
565 //create an event with an attached profile containing a note
566 $event = $this->creatEventWithProfile(NULL);
567 $event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
568 $event['note'] = "This is note 1";
5b6ea055 569 list($contact_id, $participant_id) = $this->submitWithNote($event, NULL);
eba56939
BS
570 civicrm_api3('Participant', 'delete', ['id' => $participant_id]);
571
572 //now that the contact has one note, register this contact again with a different note
573 //and confirm that the note shown in the email is the current one
574 $event = $this->creatEventWithProfile($event);
575 $event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
576 $event['note'] = "This is note 2";
5b6ea055 577 list($contact_id, $participant_id) = $this->submitWithNote($event, $contact_id);
eba56939
BS
578 civicrm_api3('Participant', 'delete', ['id' => $participant_id]);
579
580 //finally, submit a blank note and confirm that the note shown in the email is blank
581 $event = $this->creatEventWithProfile($event);
582 $event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
583 $event['note'] = "";
5b6ea055 584 list($contact_id, $participant_id) = $this->submitWithNote($event, $contact_id);
eba56939
BS
585 }
586
632196ea 587}