From 7a1f3919e29343546382af9f76720b88e6260479 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 29 Dec 2016 04:50:16 +0530 Subject: [PATCH] CRM-19585, added test ---------------------------------------- * CRM-19585: Sales tax issue https://issues.civicrm.org/jira/browse/CRM-19585 --- .../CRM/Contribute/Form/ContributionTest.php | 35 +++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 26 ++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 6face96582..e903d82463 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -775,4 +775,39 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 ); } + /** + * Test the submit function for FT with tax. + */ + public function testSubmitSaleTax() { + $this->enableTaxAndInvoicing(); + $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId); + $form = new CRM_Contribute_Form_Contribution(); + + $form->testSubmit(array( + 'total_amount' => 100, + 'financial_type_id' => $this->_financialTypeId, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Check', $this->paymentInstruments), + 'contribution_status_id' => 1, + 'price_set_id' => 0, + ), + CRM_Core_Action::ADD + ); + $contribution = $this->callAPISuccessGetSingle('Contribution', + array( + 'contact_id' => $this->_individualId, + 'return' => array('tax_amount', 'total_amount'), + ) + ); + $this->assertEquals(110, $contribution['total_amount']); + $this->assertEquals(10, $contribution['tax_amount']); + $this->callAPISuccessGetCount('FinancialTrxn', array(), 1); + $this->callAPISuccessGetCount('FinancialItem', array(), 2); + $lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id'])); + $this->assertEquals(100, $lineItem['line_total']); + $this->assertEquals(10, $lineItem['tax_amount']); + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index bb661a2ef8..296dc5ec7d 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3650,6 +3650,32 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) return Civi::settings()->set('contribution_invoice_settings', $contributeSetting); } + /** + * Add Sales Tax relation for financial type with financial account. + * + * @param int $financialTypeId + * + * @return obj + */ + protected function relationForFinancialTypeWithFinancialAccount($financialTypeId) { + $params = array( + 'name' => 'Sales tax account ' . substr(sha1(rand()), 0, 4), + 'financial_account_type_id' => key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' ")), + 'is_deductible' => 1, + 'is_tax' => 1, + 'tax_rate' => 10, + 'is_active' => 1, + ); + $account = CRM_Financial_BAO_FinancialAccount::add($params); + $entityParams = array( + 'entity_table' => 'civicrm_financial_type', + 'account_relationship' => key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Sales Tax Account is' ")), + 'entity_id' => $financialTypeId, + 'financial_account_id' => $account->id, + ); + return CRM_Financial_BAO_FinancialTypeAccount::add($entityParams); + } + /** * Create price set with contribution test for test setup. * -- 2.25.1