4 * Test CRM_Event_Form_Registration functions.
9 class CRM_Event_Form_Registration_ConfirmTest
extends CiviUnitTestCase
{
11 public function setUp() {
12 $this->useTransaction(TRUE);
17 * Initial test of submit function.
21 public function testSubmit() {
22 $event = $this->eventCreate();
23 CRM_Event_Form_Registration_Confirm
::testSubmit([
25 'contributeMode' => 'direct',
26 'registerByID' => $this->createLoggedInUser(),
29 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
30 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
33 'email-Primary' => 'demo@example.com',
34 'hidden_processor' => '1',
35 'credit_card_number' => '4111111111111111',
37 'credit_card_exp_date' => [
41 'credit_card_type' => 'Visa',
42 'billing_first_name' => 'p',
43 'billing_middle_name' => '',
44 'billing_last_name' => 'p',
45 'billing_street_address-5' => 'p',
46 'billing_city-5' => 'p',
47 'billing_state_province_id-5' => '1061',
48 'billing_postal_code-5' => '7',
49 'billing_country_id-5' => '1228',
56 'payment_processor_id' => '1',
57 'bypass_payment' => '',
58 'MAX_FILE_SIZE' => '33554432',
61 'campaign_id' => NULL,
63 'participant_role_id' => '1',
64 'currencyID' => 'USD',
65 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
70 'ip_address' => '127.0.0.1',
71 'invoiceID' => '57adc34957a29171948e8643ce906332',
72 'button' => '_qf_Register_upload',
73 'billing_state_province-5' => 'AP',
74 'billing_country-5' => 'US',
78 $this->callAPISuccessGetSingle('Participant', []);
82 * Initial test of submit function for paid event.
84 * @param string $thousandSeparator
86 * @dataProvider getThousandSeparators
90 public function testPaidSubmit($thousandSeparator) {
91 $this->setCurrencySeparators($thousandSeparator);
92 $paymentProcessorID = $this->processorCreate();
93 /* @var \CRM_Core_Payment_Dummy $processor */
94 $processor = Civi\Payment\System
::singleton()->getById($paymentProcessorID);
95 $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]);
96 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
97 $event = $this->eventCreate($params);
98 $individualID = $this->individualCreate();
99 CRM_Event_Form_Registration_Confirm
::testSubmit([
100 'id' => $event['id'],
101 'contributeMode' => 'direct',
102 'registerByID' => $individualID,
103 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor
::getPayment($paymentProcessorID),
104 'totalAmount' => $this->formatMoneyInput(8000.67),
107 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
108 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3',
111 'email-Primary' => 'demo@example.com',
112 'hidden_processor' => '1',
113 'credit_card_number' => '4111111111111111',
115 'credit_card_exp_date' => [
119 'credit_card_type' => 'Visa',
120 'billing_first_name' => 'p',
121 'billing_middle_name' => '',
122 'billing_last_name' => 'p',
123 'billing_street_address-5' => 'p',
124 'billing_city-5' => 'p',
125 'billing_state_province_id-5' => '1061',
126 'billing_postal_code-5' => '7',
127 'billing_country_id-5' => '1228',
134 'payment_processor_id' => $paymentProcessorID,
135 'bypass_payment' => '',
136 'MAX_FILE_SIZE' => '33554432',
139 'campaign_id' => NULL,
141 'participant_role_id' => '1',
142 'currencyID' => 'USD',
143 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
144 'amount' => $this->formatMoneyInput(8000.67),
145 'tax_amount' => NULL,
148 'ip_address' => '127.0.0.1',
149 'invoiceID' => '57adc34957a29171948e8643ce906332',
150 'button' => '_qf_Register_upload',
151 'billing_state_province-5' => 'AP',
152 'billing_country-5' => 'US',
156 $this->callAPISuccessGetCount('Participant', [], 1);
157 $contribution = $this->callAPISuccessGetSingle('Contribution', []);
158 $this->assertEquals(8000.67, $contribution['total_amount']);
159 $this->assertEquals(1.67, $contribution['fee_amount']);
160 $this->assertEquals(7999, $contribution['net_amount']);
161 $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($contribution['id'], 'DESC');
162 $financialTrxn = $this->callAPISuccessGetSingle(
165 'id' => $lastFinancialTrxnId['financialTrxnId'],
166 'return' => ['payment_processor_id', 'card_type_id.label', 'pan_truncation'],
169 $this->assertEquals(CRM_Utils_Array
::value('payment_processor_id', $financialTrxn), $paymentProcessorID);
170 $this->assertEquals(CRM_Utils_Array
::value('card_type_id.label', $financialTrxn), 'Visa');
171 $this->assertEquals(CRM_Utils_Array
::value('pan_truncation', $financialTrxn), 1111);
173 // This looks like it's missing an item for the main contribution - but just locking in current behaviour.
174 $financialItems = $this->callAPISuccess('FinancialItem', 'get', [
175 'return' => ['description', 'financial_account_id', 'amount', 'contact_id', 'currency', 'status_id', 'entity_table', 'entity_id'],
179 $entityFinancialTrxns = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['sequential' => 1])['values'];
181 $this->assertAPIArrayComparison([
182 'entity_table' => 'civicrm_contribution',
183 'entity_id' => $contribution['id'],
184 'financial_trxn_id' => $financialTrxn['id'],
185 'amount' => '8000.67',
186 ], $entityFinancialTrxns[0], ['id']);
188 $this->assertAPIArrayComparison([
189 'entity_table' => 'civicrm_contribution',
190 'entity_id' => $contribution['id'],
191 'financial_trxn_id' => $financialTrxn['id'] +
1,
193 ], $entityFinancialTrxns[1], ['id']);
195 $this->assertAPIArrayComparison([
196 'entity_table' => 'civicrm_financial_item',
197 'entity_id' => $financialItems[0]['id'],
198 'financial_trxn_id' => $financialTrxn['id'] +
1,
200 ], $entityFinancialTrxns[2], ['id', 'entity_id']);
204 * Test for Tax amount for multiple participant.
208 public function testTaxMultipleParticipant() {
209 $params = ['is_monetary' => 1, 'financial_type_id' => 1];
210 $event = $this->eventCreate($params);
211 CRM_Event_Form_Registration_Confirm
::testSubmit([
212 'id' => $event['id'],
213 'contributeMode' => 'direct',
214 'registerByID' => $this->createLoggedInUser(),
215 'totalAmount' => 440,
216 'event' => reset($event['values']),
219 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
220 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
221 'first_name' => 'Participant1',
222 'last_name' => 'LastName',
223 'email-Primary' => 'participant1@example.com',
226 'additional_participants' => 2,
227 'payment_processor_id' => 0,
228 'bypass_payment' => '',
229 'MAX_FILE_SIZE' => '33554432',
232 'campaign_id' => NULL,
234 'participant_role_id' => '1',
235 'currencyID' => 'USD',
236 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
237 'amount' => '100.00',
239 'ip_address' => '127.0.0.1',
240 'invoiceID' => '57adc34957a29171948e8643ce906332',
241 'trxn_id' => '123456789',
242 'button' => '_qf_Register_upload',
245 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
246 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
247 'first_name' => 'Participant2',
248 'last_name' => 'LastName',
249 'email-Primary' => 'participant2@example.com',
252 'campaign_id' => NULL,
254 'participant_role_id' => '1',
255 'currencyID' => 'USD',
256 'amount_level' => '\ 1Tiny-tots (ages 9-18) - 1\ 1',
257 'amount' => '200.00',
261 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
262 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
263 'first_name' => 'Participant3',
264 'last_name' => 'LastName',
265 'email-Primary' => 'participant3@example.com',
268 'campaign_id' => NULL,
270 'participant_role_id' => '1',
271 'currencyID' => 'USD',
272 'amount_level' => '\ 1Tiny-tots (ages 5-8) - 1\ 1',
273 'amount' => '100.00',
278 $this->callAPISuccessGetCount('Participant', [], 3);
279 $contribution = $this->callAPISuccessGetSingle(
282 'return' => ['tax_amount', 'total_amount'],
285 $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
286 $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
290 * Test online registration for event with no price options selected as per CRM-19964.
292 public function testOnlineRegNoPrice() {
293 $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]);
294 $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]);
296 'start_date' => date('YmdHis', strtotime('+ 1 week')),
297 'end_date' => date('YmdHis', strtotime('+ 1 year')),
298 'registration_start_date' => date('YmdHis', strtotime('- 1 day')),
299 'registration_end_date' => date('YmdHis', strtotime('+ 1 year')),
300 'payment_processor_id' => $paymentProcessorID,
301 'is_monetary' => TRUE,
302 'financial_type_id' => 'Event Fee',
304 $event = $this->eventCreate($params);
305 $priceFieldOptions = [
306 'option_label' => 'Price Field',
307 'option_value' => 100,
308 'is_required' => FALSE,
309 'html_type' => 'Text',
311 $this->createPriceSet('event', $event['id'], $priceFieldOptions);
313 $priceField = $this->callAPISuccess('PriceField', 'get',
315 'label' => 'Price Field',
318 // Create online event registration.
319 CRM_Event_Form_Registration_Confirm
::testSubmit([
320 'id' => $event['id'],
321 'contributeMode' => 'direct',
322 'registerByID' => $this->createLoggedInUser(),
325 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
326 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}",
327 'first_name' => 'Bruce',
328 'last_name' => 'Wayne',
329 'email-Primary' => 'bruce@gotham.com',
330 'price_' . $priceField['id'] => '',
331 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'],
332 'payment_processor_id' => $paymentProcessorID,
334 'bypass_payment' => '',
335 'MAX_FILE_SIZE' => '33554432',
338 'campaign_id' => NULL,
340 'participant_role_id' => '1',
341 'tax_amount' => NULL,
342 'ip_address' => '127.0.0.1',
343 'invoiceID' => '57adc34957a29171948e8643ce906332',
344 'button' => '_qf_Register_upload',
350 $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']);
351 $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");