CRM-18355 Fix repeat transaction for test contributions
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 4 Apr 2016 03:07:48 +0000 (15:07 +1200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 4 Apr 2016 03:11:58 +0000 (15:11 +1200)
CRM/Contribute/BAO/ContributionRecur.php
tests/phpunit/api/v3/ContributionTest.php

index 8bf212b9b64cde25f2cc5c03edf7cd877e9e37ed..7478d39c52cd9ad24b3a9bb015b1fb5f108050e3 100644 (file)
@@ -459,6 +459,7 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
       'contribution_recur_id' => $id,
       'options' => array('limit' => 1, 'sort' => array('id DESC')),
       'sequential' => 1,
+      'contribution_test' => '',
     ));
     if ($templateContribution['count']) {
       return $templateContribution['values'][0];
index 93a7ea5a17334fc08502686161fa3d04dcedf9f1..1b56f901c427fcd78baef69d6215bf402dd932c0 100644 (file)
@@ -1614,22 +1614,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
    * Test repeat contribution successfully creates line items.
    */
   public function testRepeatTransaction() {
-    $paymentProcessorID = $this->paymentProcessorCreate();
-    $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
-      'contact_id' => $this->_individualId,
-      'installments' => '12',
-      'frequency_interval' => '1',
-      'amount' => '500',
-      'contribution_status_id' => 1,
-      'start_date' => '2012-01-01 00:00:00',
-      'currency' => 'USD',
-      'frequency_unit' => 'month',
-      'payment_processor_id' => $paymentProcessorID,
-    ));
-    $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
-      $this->_params,
-      array('contribution_recur_id' => $contributionRecur['id']))
-    );
+    $originalContribution = $this->setUpRepeatTransaction();
 
     $this->callAPISuccess('contribution', 'repeattransaction', array(
       'original_contribution_id' => $originalContribution['id'],
@@ -1664,6 +1649,21 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->quickCleanUpFinancialEntities();
   }
 
+  /**
+   * Test repeat contribution successfully creates line items.
+   */
+  public function testRepeatTransactionIsTest() {
+    $this->_params['is_test'] = 1;
+    $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1));
+
+    $this->callAPISuccess('contribution', 'repeattransaction', array(
+      'original_contribution_id' => $originalContribution['id'],
+      'contribution_status_id' => 'Completed',
+      'trxn_id' => uniqid(),
+    ));
+    $this->callAPISuccessGetCount('Contribution', array('contribution_test' => 1), 2);
+  }
+
   /**
    * Test repeat contribution accepts recur_id instead of original_contribution_id.
    */
@@ -2651,4 +2651,31 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     return $originalContribution;
   }
 
+  /**
+   * Set up a repeat transaction.
+   *
+   * @param array $recurParams
+   *
+   * @return array
+   */
+  protected function setUpRepeatTransaction($recurParams = array()) {
+    $paymentProcessorID = $this->paymentProcessorCreate();
+    $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
+      'contact_id' => $this->_individualId,
+      'installments' => '12',
+      'frequency_interval' => '1',
+      'amount' => '500',
+      'contribution_status_id' => 1,
+      'start_date' => '2012-01-01 00:00:00',
+      'currency' => 'USD',
+      'frequency_unit' => 'month',
+      'payment_processor_id' => $paymentProcessorID,
+    ), $recurParams));
+    $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
+      $this->_params,
+      array('contribution_recur_id' => $contributionRecur['id']))
+    );
+    return $originalContribution;
+  }
+
 }