From 893a550c0c2a22898874422415e5a0f19b03310a Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 4 Apr 2016 15:07:48 +1200 Subject: [PATCH] CRM-18355 Fix repeat transaction for test contributions --- CRM/Contribute/BAO/ContributionRecur.php | 1 + tests/phpunit/api/v3/ContributionTest.php | 59 +++++++++++++++++------ 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 8bf212b9b6..7478d39c52 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -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]; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 93a7ea5a17..1b56f901c4 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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; + } + } -- 2.25.1