test fixes
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 12 Jul 2015 15:00:24 +0000 (03:00 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 12 Jul 2015 15:00:24 +0000 (03:00 +1200)
CRM/Contribute/BAO/Contribution.php
CRM/Core/Payment/AuthorizeNetIPN.php
CRM/Core/PseudoConstant.php
CRM/Financial/BAO/PaymentProcessor.php
Civi/Payment/System.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php
tests/phpunit/CRM/Core/Payment/AuthorizeNetTest.php
tests/phpunit/CiviTest/AuthorizeNet.php [deleted file]
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 36d37426b65ad2bb126f4f6404f42f6e63a0388b..40dff6d26ef729a5a84e3779edcc1195c687f44f 100644 (file)
@@ -2203,7 +2203,7 @@ WHERE  contribution_id = %1 ";
         $this->is_test ? 'test' : 'live'
       );
       $ids['paymentProcessor'] = $paymentProcessorID;
-      $this->_relatedObjects['paymentProcessor'] = &$paymentProcessor;
+      $this->_relatedObjects['paymentProcessor'] = $paymentProcessor;
     }
     elseif ($required) {
       throw new Exception("Could not find payment processor for contribution record: " . $this->id);
index c479e6d298a19d8e0680fcce8ff47fd13afce2f3..ea9540f851731c0f291dfb55382e246442d929de 100644 (file)
@@ -101,6 +101,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
   public function recur(&$input, &$ids, &$objects, $first) {
     $this->_isRecurring = TRUE;
     $recur = &$objects['contributionRecur'];
+    $paymentProcessorObject = $objects['contribution']->_relatedObjects['paymentProcessor']['object'];
 
     // do a subscription check
     if ($recur->processor_id != $input['subscription_id']) {
@@ -152,9 +153,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
     $objects['contribution']->total_amount = $input['amount'];
     $objects['contribution']->trxn_id = $input['trxn_id'];
 
-    // since we have processor loaded for sure at this point,
-    // check and validate gateway MD5 response if present
-    $this->checkMD5($ids, $input);
+    $this->checkMD5($paymentProcessorObject, $input);
 
     if ($input['response_code'] == 1) {
       // Approved
@@ -330,17 +329,14 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr
   }
 
   /**
-   * @param $ids
-   * @param $input
+   * Check and validate gateway MD5 response if present.
+   *
+   * @param CRM_Core_Payment_AuthorizeNet $paymentObject
+   * @param array $input
    *
    * @return bool
    */
-  public function checkMD5($ids, $input) {
-    $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ids['paymentProcessor'],
-      $input['is_test'] ? 'test' : 'live'
-    );
-    $paymentObject = $paymentProcessor['object'];
-
+  public function checkMD5($paymentObject, $input) {
     if (!$paymentObject->checkMD5($input['MD5_Hash'], $input['trxn_id'], $input['amount'], TRUE)) {
       CRM_Core_Error::debug_log_message("MD5 Verification failed.");
       echo "Failure: Security verification failed<p>";
index 352e9e89e465bb99c6bf8540c4deff4ce0c44752..079fdb73fbee0a2c49ff2300fa0788d865619224 100644 (file)
@@ -1425,7 +1425,7 @@ WHERE  id = %1";
    * @return array
    *   array of all payment processors
    */
-  public static function &paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
+  public static function paymentProcessor($all = FALSE, $test = FALSE, $additionalCond = NULL) {
     $condition = "is_test = ";
     $condition .= ($test) ? '1' : '0';
 
index 34e761b481806f9b58c76a81d2a88ee681a24f85..83550bdb59c9558e50c8095121137717171feba7 100644 (file)
@@ -29,8 +29,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
  */
 
 /**
@@ -81,6 +79,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
       );
       CRM_Financial_BAO_FinancialTypeAccount::add($values);
     }
+    Civi\Payment\System::singleton()->flushProcessors();
     return $processor;
   }
 
@@ -170,6 +169,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
     $testDAO->delete();
 
     $dao->delete();
+    Civi\Payment\System::singleton()->flushProcessors();
   }
 
   /**
index 42b1152806c84d35f109a5864cbfcfca94d1f80b..c9ba4bc9514809804264823e9dd26779417d48bd 100644 (file)
@@ -103,6 +103,8 @@ class System {
    */
   public function flushProcessors() {
     $this->cache = array();
+    \CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors(NULL, TRUE);
+    \CRM_Financial_BAO_PaymentProcessor::getAllPaymentProcessors('test', TRUE);
   }
 
 }
index 20997d1628fc9b9be1323a32fb49a15fc849f5e2..0661a7604e8da75635806b09746d740c86b30f50 100644 (file)
@@ -16,9 +16,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
 
   public function setUp() {
     parent::setUp();
-    $this->_paymentProcessorID = $this->paymentProcessorCreate(array(
-      'payment_processor_type_id' => 'AuthNet',
-    ));
+    $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate();
     $this->_contactID = $this->individualCreate();
     $contributionPage = $this->callAPISuccess('contribution_page', 'create', array(
       'title' => "Test Contribution Page",
index 55759d15f507166e3660ddd6ac5d995022571a77..5f671dbee07363d224da04ccf66ec22081cf0eab 100644 (file)
@@ -36,17 +36,9 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
 
   public function setUp() {
     parent::setUp();
-    $this->paymentProcessor = new AuthorizeNet();
-    $this->processorParams = $this->paymentProcessor->create();
+    $this->_paymentProcessorID = $this->paymentProcessorAuthorizeNetCreate();
 
-    $paymentProcessor = array(
-      'user_name' => $this->processorParams->user_name,
-      'password' => $this->processorParams->password,
-      'url_recur' => $this->processorParams->url_recur,
-      'signature' => '',
-    );
-
-    $this->processor = new CRM_Core_Payment_AuthorizeNet('Contribute', $paymentProcessor);
+    $this->processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
     $this->_financialTypeId = 1;
 
     // for some strange unknown reason, in batch mode this value gets set to null
@@ -85,7 +77,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
       'invoice_id' => $invoiceID,
       'contribution_status_id' => 2,
       'is_test' => 1,
-      'payment_processor_id' => $this->processorParams->id,
+      'payment_processor_id' => $this->_paymentProcessorID,
     );
     $recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams);
 
@@ -129,7 +121,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
       'from_email_address' => "{$firstName}.{$lastName}@example.com",
       'receive_date' => date('Ymd'),
       'receipt_date_time' => '',
-      'payment_processor_id' => $this->processorParams->id,
+      'payment_processor_id' => $this->_paymentProcessorID,
       'price_set_id' => '',
       'total_amount' => $amount,
       'currency' => 'USD',
@@ -176,7 +168,7 @@ class CRM_Core_Payment_AuthorizeNetTest extends CiviUnitTestCase {
 
     // turn verifySSL off
     CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
-    $this->processor->doDirectPayment($params);
+    $this->processor->doPayment($params);
     // turn verifySSL on
     CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
 
diff --git a/tests/phpunit/CiviTest/AuthorizeNet.php b/tests/phpunit/CiviTest/AuthorizeNet.php
deleted file mode 100644 (file)
index 15cd2e1..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-/**
- * Class AuthorizeNet
- */
-class AuthorizeNet extends PHPUnit_Framework_Testcase {
-  /**
-   * Helper function to create
-   * a payment processor of type Authorize.net
-   * @return CRM_Financial_DAO_PaymentProcessor
-   */
-  public function create() {
-
-    $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
-    $paymentParams = array(
-      'name' => 'Authorize',
-      'domain_id' => CRM_Core_Config::domainID(),
-      'payment_processor_type' => 'AuthNet',
-      'is_active' => 1,
-      'is_default' => 0,
-      'is_test' => 1,
-      'user_name' => '4y5BfuW7jm',
-      'password' => '4cAmW927n8uLf5J8',
-      'url_site' => 'https://test.authorize.net/gateway/transact.dll',
-      'url_recur' => 'https://apitest.authorize.net/xml/v1/request.api',
-      'class_name' => 'Payment_AuthorizeNet',
-      'billing_mode' => 1,
-    );
-    $paymentProcessor->copyValues($paymentParams);
-    $paymentProcessor->save();
-    return $paymentProcessor;
-  }
-
-  /**
-   * Helper function to delete a PayPal Pro
-   * payment processor
-   * @param int $id
-   *   Id of the PayPal Pro payment processor.
-   *   to be deleted
-   * @return bool
-   *   true if payment processor deleted, false otherwise
-   */
-  public function delete($id) {
-    $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
-    $paymentProcessor->id = $id;
-    if ($paymentProcessor->find(TRUE)) {
-      $result = $paymentProcessor->delete();
-    }
-    return $result;
-  }
-
-}
index adde913aca06c5266462604fd65625b20480d0cd..aa27dfda3ab3bd58c71a72e0576dbd4af69fe0e4 100755 (executable)
@@ -1439,6 +1439,35 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     return $result['id'];
   }
 
+  /**
+   * Create test Authorize.net instance.
+   *
+   * @param array $params
+   *
+   * @return mixed
+   */
+  public function paymentProcessorAuthorizeNetCreate($params = array()) {
+    $params = array_merge(array(
+      'name' => 'Authorize',
+      'domain_id' => CRM_Core_Config::domainID(),
+      'payment_processor_type_id' => 'AuthNet',
+      'title' => 'AuthNet',
+      'is_active' => 1,
+      'is_default' => 0,
+      'is_test' => 1,
+      'is_recur' => 1,
+      'user_name' => '4y5BfuW7jm',
+      'password' => '4cAmW927n8uLf5J8',
+      'url_site' => 'https://test.authorize.net/gateway/transact.dll',
+      'url_recur' => 'https://apitest.authorize.net/xml/v1/request.api',
+      'class_name' => 'Payment_AuthorizeNet',
+      'billing_mode' => 1,
+    ), $params);
+
+    $result = $this->callAPISuccess('payment_processor', 'create', $params);
+    return $result['id'];
+  }
+
   /**
    * Create Participant.
    *
@@ -1607,8 +1636,8 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
   /**
    * Create contribution.
    *
-   * @param int $cID
-   *   Contact_id.
+   * @param int|array $params
+   *   Array of parameters or Contact_id (legacy) .
    * @param int $cTypeID
    *   Id of financial type.
    * @param int $invoiceID
@@ -1619,21 +1648,23 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
    * @return int
    *   id of created contribution
    */
-  public function contributionCreate($cID, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID = 1, $isFee = TRUE) {
-    $params = array(
+  public function contributionCreate($params, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, $paymentInstrumentID
+  = 1, $isFee = TRUE) {
+    if (!is_array($params)) {
+      $params = array('contact_id' => $params);
+    }
+    $params = array_merge(array(
       'domain_id' => 1,
-      'contact_id' => $cID,
       'receive_date' => date('Ymd'),
       'total_amount' => 100.00,
-      'financial_type_id' => empty($cTypeID) ? 1 : $cTypeID,
+      'financial_type_id' => $cTypeID,
       'payment_instrument_id' => empty($paymentInstrumentID) ? 1 : $paymentInstrumentID,
       'non_deductible_amount' => 10.00,
       'trxn_id' => $trxnID,
       'invoice_id' => $invoiceID,
       'source' => 'SSF',
       'contribution_status_id' => 1,
-      // 'note'                   => 'Donating for Nobel Cause', *Fixme
-    );
+    ), $params);
 
     if ($isFee) {
       $params['fee_amount'] = 5.00;
@@ -3179,6 +3210,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
         'contact_id' => $this->_contactID,
         'contribution_page_id' => $this->_contributionPageID,
         'payment_processor_id' => $this->_paymentProcessorID,
+        'is_test' => 1,
       ),
     ));
     $this->_contributionRecurID = $contributionRecur['id'];
@@ -3191,7 +3223,10 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   public function setupMembershipRecurringPaymentProcessorTransaction() {
     $this->ids['membership_type'] = $this->membershipTypeCreate();
     //create a contribution so our membership & contribution don't both have id = 1
-    $this->contributionCreate($this->_contactID, 1, 'abcd', '345j');
+    $this->contributionCreate(array(
+      'contact_id' => $this->_contactID,
+      'is_test' => 1),
+      1, 'abcd', '345j');
     $this->setupRecurringPaymentProcessorTransaction();
 
     $this->ids['membership'] = $this->callAPISuccess('membership', 'create', array(