From c364c544451218f7649e69d686a7f934f9a41d81 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 2 Feb 2018 16:57:56 +0000 Subject: [PATCH] Add unit test for createProportionalEntry with zero amount --- .../CRM/Contribute/BAO/ContributionTest.php | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 8a3afc8514..c8a69b00ec 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1123,6 +1123,44 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); } + /** + * Test for function createProportionalEntry with zero amount(). + * + * @param string $thousandSeparator + * punctuation used to refer to thousands. + * + * @dataProvider getThousandSeparators + */ + public function testCreateProportionalEntryZeroAmount($thousandSeparator) { + $this->setCurrencySeparators($thousandSeparator); + list($contribution, $financialAccount) = $this->createContributionWithTax(array('total_amount' => 0)); + $params = array( + 'total_amount' => 0, + 'to_financial_account_id' => $financialAccount->financial_account_id, + 'payment_instrument_id' => 1, + 'trxn_date' => date('Ymd'), + 'status_id' => 1, + 'entity_id' => $contribution['id'], + ); + $financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params); + $entityParams = array( + 'contribution_total_amount' => $contribution['total_amount'], + 'trxn_total_amount' => 0, + 'line_item_amount' => 0, + ); + $previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']); + $eftParams = array( + 'entity_table' => 'civicrm_financial_item', + 'entity_id' => $previousLineItem['id'], + 'financial_trxn_id' => (string) $financialTrxn['id'], + ); + CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); + $trxnTestArray = array_merge($eftParams, array( + 'amount' => '0.00', + )); + $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); + } + /** * Test for function getLastFinancialItemIds(). */ @@ -1196,7 +1234,10 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; /** * Function to create contribution with tax. */ - public function createContributionWithTax() { + public function createContributionWithTax($params = array()) { + if (!isset($params['total_amount'])) { + $params['total_amount'] = 100; + } $contactId = $this->individualCreate(); $this->enableTaxAndInvoicing(); $financialType = $this->createFinancialType(); @@ -1204,7 +1245,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $form = new CRM_Contribute_Form_Contribution(); $form->testSubmit(array( - 'total_amount' => 100, + 'total_amount' => $params['total_amount'], 'financial_type_id' => $financialType['id'], 'contact_id' => $contactId, 'contribution_status_id' => 1, -- 2.25.1