From 646bc565e0bbebb5a127d81c7f219c667544a88b Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 3 Jan 2017 19:23:27 +0530 Subject: [PATCH] CRM-19585, moved set of code into function anad added test for getLastFinancialItemIds() ---------------------------------------- * CRM-19585: Sales tax issue https://issues.civicrm.org/jira/browse/CRM-19585 --- .../CRM/Contribute/BAO/ContributionTest.php | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index d859c61fd4..a1e68638de 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1088,29 +1088,7 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; * Test for function createProportionalEntry(). */ public function testcreateProportionalEntry() { - $contactId = $this->individualCreate(); - $this->enableTaxAndInvoicing(); - $financialType = $this->createFinancialType(); - $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); - $form = new CRM_Contribute_Form_Contribution(); - - $form->testSubmit(array( - 'total_amount' => 100, - 'financial_type_id' => $financialType['id'], - 'receive_date' => '04/21/2015', - 'receive_date_time' => '11:27PM', - 'contact_id' => $contactId, - 'contribution_status_id' => 1, - 'price_set_id' => 0, - ), - CRM_Core_Action::ADD - ); - $contribution = $this->callAPISuccessGetSingle('Contribution', - array( - 'contact_id' => $contactId, - 'return' => array('tax_amount', 'total_amount'), - ) - ); + $contribution = $this->createContributionWithTax(); $params = array( 'total_amount' => 55, 'to_financial_account_id' => $financialAccount->financial_account_id, @@ -1144,4 +1122,47 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $entityFinancialTrxn = $this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray); } + /** + * Test for function getLastFinancialItemIds(). + */ + public function testgetLastFinancialItemIds() { + $contribution = $this->createContributionWithTax(); + list($ftIds, $taxItems) = CRM_Contribute_BAO_Contribution::getLastFinancialItemIds($contribution['id']); + $this->assertEquals(count($ftIds), 1, 'Invalid count.'); + $this->assertEquals(count($taxItems), 1, 'Invalid count.'); + foreach ($taxItems as $value) { + $this->assertEquals($value['amount'], 10, 'Invalid tax amount.'); + } + } + + /** + * Function to create contribution with tax. + */ + public function createContributionWithTax() { + $contactId = $this->individualCreate(); + $this->enableTaxAndInvoicing(); + $financialType = $this->createFinancialType(); + $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); + $form = new CRM_Contribute_Form_Contribution(); + + $form->testSubmit(array( + 'total_amount' => 100, + 'financial_type_id' => $financialType['id'], + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $contactId, + 'contribution_status_id' => 1, + 'price_set_id' => 0, + ), + CRM_Core_Action::ADD + ); + $contribution = $this->callAPISuccessGetSingle('Contribution', + array( + 'contact_id' => $contactId, + 'return' => array('tax_amount', 'total_amount'), + ) + ); + return $contribution; + } + } -- 2.25.1