From: eileenmcnaugton Date: Mon, 4 Apr 2016 03:07:48 +0000 (+1200) Subject: CRM-18355 Fix repeat transaction for test contributions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=893a550c0c2a22898874422415e5a0f19b03310a;p=civicrm-core.git CRM-18355 Fix repeat transaction for test contributions --- 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; + } + }