4 * Test CRM_Event_Form_Registration functions.
9 class CRM_Event_Form_Registration_ConfirmTest
extends CiviUnitTestCase
{
11 use CRMTraits_Profile_ProfileTrait
;
13 public function setUp() {
14 $this->useTransaction(TRUE);
19 * Initial test of submit function.
23 public function testSubmit() {
24 $event = $this->eventCreate();
25 $mut = new CiviMailUtils($this, TRUE);
26 CRM_Event_Form_Registration_Confirm
::testSubmit([
28 'contributeMode' => 'direct',
29 'registerByID' => $this->createLoggedInUser(),
32 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
33 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
36 'email-Primary' => 'demo@example.com',
37 'hidden_processor' => '1',
38 'credit_card_number' => '4111111111111111',
40 'credit_card_exp_date' => [
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',
59 'payment_processor_id' => '1',
60 'bypass_payment' => '',
61 'MAX_FILE_SIZE' => '33554432',
64 'campaign_id' => NULL,
66 'participant_role_id' => '1',
67 'currencyID' => 'USD',
68 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 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',
81 $participant = $this->callAPISuccessGetSingle('Participant', []);
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.',
86 $mut->clearMessages();
87 $tplVars = CRM_Core_Smarty
::singleton()->get_template_vars();
88 $this->assertEquals($participant['id'], $tplVars['participantID']);
93 * Initial test of submit function for paid event.
95 * @param string $thousandSeparator
97 * @dataProvider getThousandSeparators
101 public function testPaidSubmit($thousandSeparator) {
102 $this->setCurrencySeparators($thousandSeparator);
103 $paymentProcessorID = $this->processorCreate();
104 /* @var \CRM_Core_Payment_Dummy $processor */
105 $processor = Civi\Payment\System
::singleton()->getById($paymentProcessorID);
106 $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]);
107 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
108 $event = $this->eventCreate($params);
109 $individualID = $this->individualCreate();
110 CRM_Event_Form_Registration_Confirm
::testSubmit([
111 'id' => $event['id'],
112 'contributeMode' => 'direct',
113 'registerByID' => $individualID,
114 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor
::getPayment($paymentProcessorID),
115 'totalAmount' => $this->formatMoneyInput(8000.67),
118 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
119 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
122 'email-Primary' => 'demo@example.com',
123 'hidden_processor' => '1',
124 'credit_card_number' => '4111111111111111',
126 'credit_card_exp_date' => [
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',
145 'payment_processor_id' => $paymentProcessorID,
146 'bypass_payment' => '',
147 'MAX_FILE_SIZE' => '33554432',
150 'campaign_id' => NULL,
152 'participant_role_id' => '1',
153 'currencyID' => 'USD',
154 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
155 'amount' => $this->formatMoneyInput(8000.67),
156 'tax_amount' => NULL,
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',
167 $this->callAPISuccessGetCount('Participant', [], 1);
168 $contribution = $this->callAPISuccessGetSingle('Contribution', []);
169 $this->assertEquals(8000.67, $contribution['total_amount']);
170 $this->assertEquals(1.67, $contribution['fee_amount']);
171 $this->assertEquals(7999, $contribution['net_amount']);
172 $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($contribution['id'], 'DESC');
173 $financialTrxn = $this->callAPISuccessGetSingle(
176 'id' => $lastFinancialTrxnId['financialTrxnId'],
177 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'],
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);
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'],
190 $entityFinancialTrxns = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['sequential' => 1])['values'];
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']);
199 $this->assertAPIArrayComparison([
200 'entity_table' => 'civicrm_contribution',
201 'entity_id' => $contribution['id'],
202 'financial_trxn_id' => $financialTrxn['id'] +
1,
204 ], $entityFinancialTrxns[1], ['id']);
206 $this->assertAPIArrayComparison([
207 'entity_table' => 'civicrm_financial_item',
208 'entity_id' => $financialItems[0]['id'],
209 'financial_trxn_id' => $financialTrxn['id'] +
1,
211 ], $entityFinancialTrxns[2], ['id', 'entity_id']);
215 * Test for Tax amount for multiple participant.
219 public function testTaxMultipleParticipant() {
220 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
221 $event = $this->eventCreate($params);
222 CRM_Event_Form_Registration_Confirm
::testSubmit([
223 'id' => $event['id'],
224 'contributeMode' => 'direct',
225 'registerByID' => $this->createLoggedInUser(),
226 'totalAmount' => 440,
227 'event' => reset($event['values']),
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',
237 'additional_participants' => 2,
238 'payment_processor_id' => 0,
239 'bypass_payment' => '',
240 'MAX_FILE_SIZE' => '33554432',
243 'campaign_id' => NULL,
245 'participant_role_id' => '1',
246 'currencyID' => 'USD',
247 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
248 'amount' => '100.00',
250 'ip_address' => '127.0.0.1',
251 'invoiceID' => '57adc34957a29171948e8643ce906332',
252 'trxn_id' => '123456789',
253 'button' => '_qf_Register_upload',
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',
263 'campaign_id' => NULL,
265 'participant_role_id' => '1',
266 'currencyID' => 'USD',
267 'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1',
268 'amount' => '200.00',
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',
279 'campaign_id' => NULL,
281 'participant_role_id' => '1',
282 'currencyID' => 'USD',
283 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
284 'amount' => '100.00',
289 $this->callAPISuccessGetCount('Participant', [], 3);
290 $contribution = $this->callAPISuccessGetSingle(
293 'return' => ['tax_amount', 'total_amount'],
296 $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
297 $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
301 * Test online registration for event with no price options selected as per CRM-19964.
303 public function testOnlineRegNoPrice() {
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]);
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',
315 $event = $this->eventCreate($params);
316 $priceFieldOptions = [
317 'option_label' => 'Price Field',
318 'option_value' => 100,
319 'is_required' => FALSE,
320 'html_type' => 'Text',
322 $this->createPriceSet('event', $event['id'], $priceFieldOptions);
324 $priceField = $this->callAPISuccess('PriceField', 'get',
326 'label' => 'Price Field',
329 // Create online event registration.
330 CRM_Event_Form_Registration_Confirm
::testSubmit([
331 'id' => $event['id'],
332 'contributeMode' => 'direct',
333 'registerByID' => $this->createLoggedInUser(),
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,
345 'bypass_payment' => '',
346 'MAX_FILE_SIZE' => '33554432',
349 'campaign_id' => NULL,
351 'participant_role_id' => '1',
352 'tax_amount' => NULL,
353 'ip_address' => '127.0.0.1',
354 'invoiceID' => '57adc34957a29171948e8643ce906332',
355 'button' => '_qf_Register_upload',
361 $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']);
362 $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
366 * Test form profile assignment.
368 * @throws \CRM_Core_Exception
371 public function testAssignProfiles() {
372 $event = $this->eventCreate();
373 $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
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']],
382 'custom_pre_id' => $this->ids
['UFGroup']['our profile'],
386 CRM_Event_Form_Registration_Confirm
::assignProfiles($form);
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']);