CRM-20392 enable remaining unit tests added by Pradeep
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 19 Apr 2017 07:03:30 +0000 (19:03 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 19 Apr 2017 07:33:42 +0000 (19:33 +1200)
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
CRM/Contribute/Form/AdditionalPayment.php
tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php

index 23b2f9d317f999e0702f551a30decfebe638b533..e527ad5d950ab9930a4288d5aa949b79ea62af05 100644 (file)
@@ -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;
 
index 799948d995750f3c17924f5779854b5db480951b..0fc8076afb05100c7a063af83725efed121dde81 100644 (file)
@@ -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);
   }
index 50ec1fdf862c2eb5785035d4da8104ebf1bd57bd..544f8ab1adb2e88a605a8797c18a75b01b2590b1 100644 (file)
@@ -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(