From 632196ea963620d71d5750d580f33a9f1bd45787 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 16 Nov 2016 22:28:02 +1300 Subject: [PATCH] CRM-19213 fix payment_instrument_id on event & add first test (shell really) --- CRM/Event/Form/Registration/Confirm.php | 31 ++++++- .../CRM/Contribute/Form/ContributionTest.php | 3 +- .../Event/Form/Registration/ConfirmTest.php | 82 +++++++++++++++++++ 3 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index 28cfda5d45..e08c82d135 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -608,7 +608,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } //passing contribution id is already registered. - $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount); + $contribution = self::processContribution($this, $value, $result, $contactID, $pending, $isAdditionalAmount, $this->_paymentProcessor); $value['contributionID'] = $contribution->id; $value['contributionTypeID'] = $contribution->financial_type_id; $value['receive_date'] = $contribution->receive_date; @@ -943,7 +943,8 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { */ public static function processContribution( &$form, $params, $result, $contactID, - $pending = FALSE, $isAdditionalAmount = FALSE + $pending = FALSE, $isAdditionalAmount = FALSE, + $paymentProcessor = NULL ) { $transaction = new CRM_Core_Transaction(); @@ -972,8 +973,8 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params), ); - if (empty($params['is_pay_later'])) { - $contribParams['payment_instrument_id'] = 1; + if ($paymentProcessor) { + $contribParams['payment_instrument_id'] = $paymentProcessor['payment_instrument_id']; } if (!$pending && $result) { @@ -1277,4 +1278,26 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { } } + /** + * Submit in test mode. + * + * @param $params + */ + public static function testSubmit($params) { + $form = new CRM_Event_Form_Registration_Confirm(); + // This way the mocked up controller ignores the session stuff. + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_REQUEST['id'] = $form->_eventId = $params['id']; + $form->controller = new CRM_Event_Controller_Registration(); + $form->_params = $params['params']; + $form->set('params', $params['params']); + $form->_values['custom_pre_id'] = array(); + $form->_values['custom_post_id'] = array(); + $form->_contributeMode = $params['contributeMode']; + $eventParams = array('id' => $params['id']); + CRM_Event_BAO_Event::retrieve($eventParams, $form->_values['event']); + $form->set('registerByID', $params['registerByID']); + $form->postProcess(); + } + } diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 1b9733d5e7..0612e33e10 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -228,10 +228,11 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { catch (Civi\Payment\Exception\PaymentProcessorException $e) { $error = TRUE; } + $this->assertTrue($error); $this->callAPISuccessGetCount('Contribution', array( 'contact_id' => $this->_individualId, - 'contribution_status_id' => 'Pending', + 'contribution_status_id' => $error ? 'Pending' : 'Completed', 'payment_instrument_id' => $this->callAPISuccessGetValue('PaymentProcessor', array( 'return' => 'payment_instrument_id', 'id' => $paymentProcessorID, diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php new file mode 100644 index 0000000000..bd6cf5b2df --- /dev/null +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -0,0 +1,82 @@ +useTransaction(TRUE); + parent::setUp(); + } + + /** + * Initial test of submit function. + * + * @throws \Exception + */ + public function testSubmit() { + $event = $this->eventCreate(); + CRM_Event_Form_Registration_Confirm::testSubmit(array( + 'id' => $event['id'], + 'contributeMode' => 'direct', + 'registerByID' => $this->createLoggedInUser(), + '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' => '1', + '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->callAPISuccessGetSingle('Participant', array()); + } + +} -- 2.25.1