CRM-16923 test to demonstrate point of failure
authoreileenmcnaughton <eileen@fuzion.co.nz>
Wed, 29 Jul 2015 08:44:05 +0000 (08:44 +0000)
committereileenmcnaughton <eileen@fuzion.co.nz>
Wed, 29 Jul 2015 08:44:05 +0000 (08:44 +0000)
CRM/Contribute/BAO/ContributionPage.php
tests/phpunit/api/v3/ContributionPageTest.php

index fb5b9913884f669d9d6bde47f2d204fdf11ddd1a..eb53397d8cfea119901f5b2144c675e9039bc969 100644 (file)
 class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage {
 
   /**
-   * Takes an associative array and creates a contribution page object.
+   * Creates a contribution page.
    *
    * @param array $params
-   *   (reference ) an assoc array of name/value pairs.
    *
    * @return CRM_Contribute_DAO_ContributionPage
    */
-  public static function &create(&$params) {
+  public static function create($params) {
     $financialTypeId = NULL;
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
       $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
+
+    if (isset($params['payment_processor']) && is_array($params['payment_processor'])) {
+      $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
+    }
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params);
     $dao = new CRM_Contribute_DAO_ContributionPage();
index 009d3c9684ff9c0e97e0aa7244c8772646891627..92d33434eb381e5704afac7bda7c7e3ee332fb94 100644 (file)
@@ -149,6 +149,45 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
   }
 
+  /**
+   * Test process with instant payment when more than one configured for the page.
+   *
+   * CRM-16923
+   */
+  public function testSubmitRecurMultiProcessorInstantPayment() {
+    $this->setUpContributionPage();
+    $this->setupPaymentProcessor();
+    $paymentProcessor2ID =  $this->paymentProcessorCreate(array(
+      'payment_processor_type_id' => 'Dummy',
+      'name' => 'processor 2',
+      'class_name' => 'Payment_Dummy',
+      'billing_mode' => 1,
+    ));
+    $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID);
+    $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+    $this->callAPISuccess('ContributionPage', 'create', array(
+      'id' =>$this->_ids['contribution_page'],
+      'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor'])
+    ));
+
+    $priceFieldID = reset($this->_ids['price_field']);
+    $priceFieldValueID = reset($this->_ids['price_field_value']);
+    $submitParams = array(
+      'price_' . $priceFieldID => $priceFieldValueID,
+      'id' => (int) $this->_ids['contribution_page'],
+      'amount' => 10,
+      'is_recur' => 1,
+      'frequency_interval' => 1,
+      'frequency_unit' => 'month',
+      'payment_processor_id' => $paymentProcessor2ID,
+    );
+
+    $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+    $this->callAPISuccess('contribution', 'getsingle', array(
+      'contribution_page_id' => $this->_ids['contribution_page'],
+      'contribution_status_id' => 1,
+    ));
+  }
   /**
    * Test submit with a membership block in place.
    */
@@ -238,7 +277,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'billing_middle_name' => 'Goat',
       'billing_last_name' => 'Gruff',
       'selectMembership' => $this->_ids['membership_type'],
-      'payment_processor_id' => 1,
+      'payment_processor_id' => $this->_paymentProcessor['id'],
       'credit_card_number' => '4111111111111111',
       'credit_card_type' => 'Visa',
       'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),