From 7d96cec3a5379a886a71aba001c78d3a595c3a2c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 11 Sep 2019 13:08:17 +1000 Subject: [PATCH] Extend contribution api test to ensure that if check_number is specified in unique field it is still correctly stored Add in a unit test to test setting check_number with original field --- tests/phpunit/api/v3/ContributionTest.php | 41 ++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 0de1e0b4c4..20a5900daf 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -228,12 +228,46 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->callAPISuccessGetSingle('Contribution', ['is_test' => 1]); } + /** + * Test Creating a check contribution with original check_number field + */ + public function testCreateCheckContribution() { + $params = $this->_params; + $params['contribution_check_number'] = 'bouncer'; + $params['payment_instrument_id'] = 'Check'; + $params['cancel_date'] = 'yesterday'; + $params['receipt_date'] = 'yesterday'; + $params['thankyou_date'] = 'yesterday'; + $params['revenue_recognition_date'] = 'yesterday'; + $params['amount_level'] = 'Unreasonable'; + $params['cancel_reason'] = 'You lose sucker'; + $params['creditnote_id'] = 'sudo rm -rf'; + $params['tax_amount'] = '1'; + $address = $this->callAPISuccess('Address', 'create', [ + 'street_address' => 'Knockturn Alley', + 'contact_id' => $this->_individualId, + 'location_type_id' => 'Home', + ]); + $params['address_id'] = $address['id']; + $contributionPage = $this->contributionPageCreate(); + $params['contribution_page_id'] = $contributionPage['id']; + $params['campaign_id'] = $this->campaignCreate(); + $contributionID = $this->contributionCreate($params); + $getResult = $this->callAPISuccess('Contribution', 'get', ['id' => $contributionID]); + $this->assertEquals('bouncer', $getResult['values'][$contributionID]['check_number']); + $entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['entity_id' => $contributionID, 'entity_table' => 'civicrm_contribution']); + foreach ($entityFinancialTrxn['values'] as $eft) { + $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'get', ['id' => $eft['financial_trxn_id']]); + $this->assertEquals('bouncer', $financialTrxn['values'][$financialTrxn['id']]['check_number']); + } + } + /** * Test the 'return' param works for all fields. */ public function testGetContributionReturnFunctionality() { $params = $this->_params; - $params['check_number'] = 'bouncer'; + $params['contribution_check_number'] = 'bouncer'; $params['payment_instrument_id'] = 'Check'; $params['cancel_date'] = 'yesterday'; $params['receipt_date'] = 'yesterday'; @@ -301,6 +335,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } $this->assertTrue((!empty($contribution[$returnField]) || $contribution[$returnField] === "0"), $returnField); } + $entityFinancialTrxn = $this->callAPISuccess('EntityFinancialTrxn', 'get', ['entity_id' => $contributionID, 'entity_table' => 'civicrm_contribution']); + foreach ($entityFinancialTrxn['values'] as $eft) { + $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'get', ['id' => $eft['financial_trxn_id']]); + $this->assertEquals('bouncer', $financialTrxn['values'][$financialTrxn['id']]['check_number']); + } } /** -- 2.25.1