From 5e40de8466ce038d8bb8df4892908d87a24a4d8c Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Wed, 26 Apr 2017 23:44:42 +0530 Subject: [PATCH] added unit test --- CRM/Event/Form/Registration/Confirm.php | 3 + .../Event/Form/Registration/ConfirmTest.php | 82 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 22486236c9..ff9f4258fd 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -1305,6 +1305,9 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { $eventParams = array('id' => $params['id']); CRM_Event_BAO_Event::retrieve($eventParams, $form->_values['event']); $form->set('registerByID', $params['registerByID']); + if (!empty($params['paymentProcessorObj'])) { + $form->_paymentProcessor = $params['paymentProcessorObj']; + } $form->postProcess(); } diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index d57e1eb6bd..41e4f1c1c5 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -78,6 +78,88 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $this->callAPISuccessGetSingle('Participant', array()); } + /** + * Initial test of submit function for paid event. + * + * @throws \Exception + */ + public function testPaidSubmit() { + $paymentProcessorID = $this->processorCreate(); + $params = array('is_monetary' => 1, 'financial_type_id' => 1); + $event = $this->eventCreate($params); + $individualID = $this->individualCreate(); + CRM_Event_Form_Registration_Confirm::testSubmit(array( + 'id' => $event['id'], + 'contributeMode' => 'direct', + 'registerByID' => $individualID, + 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), + 'totalAmount' => 800, + 'params' => array( + array( + 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', + 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', + 'first_name' => 'k', + 'last_name' => 'p', + 'email-Primary' => 'demo@example.com', + 'hidden_processor' => '1', + 'credit_card_number' => '4111111111111111', + 'cvv2' => '123', + 'credit_card_exp_date' => array( + 'M' => '1', + 'Y' => '2019', + ), + 'credit_card_type' => 'Visa', + 'billing_first_name' => 'p', + 'billing_middle_name' => '', + 'billing_last_name' => 'p', + 'billing_street_address-5' => 'p', + 'billing_city-5' => 'p', + 'billing_state_province_id-5' => '1061', + 'billing_postal_code-5' => '7', + 'billing_country_id-5' => '1228', + 'scriptFee' => '', + 'scriptArray' => '', + 'priceSetId' => '6', + 'price_7' => array( + 13 => 1, + ), + 'payment_processor_id' => $paymentProcessorID, + 'bypass_payment' => '', + 'MAX_FILE_SIZE' => '33554432', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'currencyID' => 'USD', + 'amount_level' => 'Tiny-tots (ages 5-8) - 1', + 'amount' => '800.00', + 'tax_amount' => NULL, + 'year' => '2019', + 'month' => '1', + 'ip_address' => '127.0.0.1', + 'invoiceID' => '57adc34957a29171948e8643ce906332', + 'button' => '_qf_Register_upload', + 'billing_state_province-5' => 'AP', + 'billing_country-5' => 'US', + ), + ), + )); + $this->callAPISuccessGetCount('Participant', array(), 1); + $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC'); + $financialTrxn = $this->callAPISuccessGetSingle( + 'FinancialTrxn', + array( + 'id' => $lastFinancialTrxnId['financialTrxnId'], + 'return' => array('payment_processor_id', 'card_type_id.label', 'pan_truncation'), + ) + ); + $this->assertEquals(CRM_Utils_Array::value('payment_processor_id', $financialTrxn), $paymentProcessorID); + $this->assertEquals(CRM_Utils_Array::value('card_type_id.label', $financialTrxn), 'Visa'); + $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 1111); + } + /** * Test for Tax amount for multiple participant. * -- 2.25.1