From 80c9b98c60dde5c5bdd059e52f04dc6c7c8915e6 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 19 Apr 2017 19:03:30 +1200 Subject: [PATCH] CRM-20392 enable remaining unit tests added by Pradeep I did alter the fix side on this a little more - notably to use the shared functions beginPostProcess and assignPaymentRelatedVariables so this will require independent review --- CRM/Contribute/BAO/Contribution.php | 3 ++ CRM/Contribute/Form/AdditionalPayment.php | 32 +++++-------------- .../Contribute/Form/AdditionalPaymentTest.php | 16 ++++------ 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 23b2f9d317..e527ad5d95 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3223,6 +3223,9 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac if (!empty($financialTrxnValues)) { $trxnParams = array_merge($trxnParams, $financialTrxnValues); } + if (empty($trxnParams['payment_processor_id'])) { + unset($trxnParams['payment_processor_id']); + } $params['trxnParams'] = $trxnParams; diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 799948d995..0fc8076afb 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -330,6 +330,8 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract * */ public function submit($submittedValues) { + $this->_params = $submittedValues; + $this->beginPostProcess(); $participantId = NULL; if ($this->_component == 'event') { $participantId = $this->_id; @@ -403,12 +405,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } // Get the required fields value only. - $params = $this->_params = $submittedValues; - - //get the payment processor id as per mode. - //@todo unclear relevance of mode - seems like a lot of duplicated params here! - $this->_params['payment_processor'] = $params['payment_processor_id'] - = $this->_params['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor['id']; + $params = $submittedValues; $now = date('YmdHis'); $fields = array(); @@ -462,11 +459,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]); $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]); - if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD) { - $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); - $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); - } - $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $this->_params['total_amount']; // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel // function to get correct amount level consistently. Remove setting of the amount level in @@ -495,14 +487,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_bltID )); - $date = CRM_Utils_Date::format($params['credit_card_exp_date']); - $date = CRM_Utils_Date::mysqlToIso($date); - $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params)); - $this->assign('credit_card_exp_date', $date); - $this->assign('credit_card_number', - CRM_Utils_System::mungeCreditCard($params['credit_card_number']) - ); - //Add common data to formatted params CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this); // at this point we've created a contact and stored its address etc @@ -656,7 +640,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract /** * Wrapper for unit testing the post process submit function. * - * * @param array $params * @param string|null $creditCardMode * @param string $enitityType @@ -665,6 +648,11 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract */ public function testSubmit($params, $creditCardMode = NULL, $enitityType = 'contribute') { $this->_bltID = 5; + // Required because processCreditCard calls set method on this. + $_SERVER['REQUEST_METHOD'] = 'GET'; + $this->controller = new CRM_Core_Controller(); + + $this->assignPaymentRelatedVariables(); if (!empty($params['contribution_id'])) { $this->_contributionId = $params['contribution_id']; @@ -692,10 +680,6 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_mode = $creditCardMode; } - // Required because processCreditCard calls set method on this. - $_SERVER['REQUEST_METHOD'] = 'GET'; - $this->controller = new CRM_Core_Controller(); - $this->_fields = array(); $this->submit($params); } diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index 50ec1fdf86..544f8ab1ad 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -127,7 +127,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { /** * Test the submit function that completes the partially paid Contribution using Credit Card. - + */ public function testAddPaymentUsingCreditCardForPartialyPaidContribution() { $this->createContribution('Partially paid'); @@ -135,7 +135,6 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->submitPayment(70, 'live'); $this->checkResults(array(30, 70), 2); } - */ /** * Test the submit function that completes the partially paid Contribution. @@ -163,10 +162,11 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->submitPayment(20); $this->checkResults(array(30, 50, 20), 3); } + /** * Test the submit function that completes the partially paid Contribution with multiple payments. - * - public function testMultiplePaymentForPartialyPaidContributionWithOneCreditCardPayment() { + */ + public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCardPayment() { $this->createContribution('Partially paid'); // pay additional amount @@ -179,10 +179,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->checkResults(array(30, 50, 20), 3); } - /** * Test the submit function that completes the pending pay later Contribution using Credit Card. - * + */ public function testAddPaymentUsingCreditCardForPendingPayLaterContribution() { $this->createContribution('Pending'); @@ -190,7 +189,6 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->submitPayment(100, 'live'); $this->checkResults(array(100), 1); } - */ /** * Test the submit function that completes the pending pay later Contribution. @@ -233,7 +231,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { /** * Test the submit function that completes the pending pay later Contribution with multiple payments. - * + */ public function testMultiplePaymentForPendingPayLaterContributionWithOneCreditCardPayment() { $this->createContribution('Pending'); @@ -253,7 +251,6 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $this->submitPayment(10, 'live'); $this->checkResults(array(50, 20, 20, 10), 4); } - */ /** * Function to create pending pay later or partially paid conntribution. @@ -303,6 +300,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { 'receive_date' => '04/21/2015', 'receive_date_time' => '11:27PM', 'trxn_date' => '2017-04-11 13:05:11', + 'payment_processor_id' => 0, ); if ($mode) { $submitParams += array( -- 2.25.1