From 6a52ffd6f310a1828bf3c242ce26b42f483d8611 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Mon, 16 Jan 2017 20:41:05 +0530 Subject: [PATCH] CRM-19585, added test ---------------------------------------- * CRM-19585: Sales tax issue https://issues.civicrm.org/jira/browse/CRM-19585 --- .../CRM/Contribute/BAO/ContributionTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 4d76bad800ec..78c6b6102a2c 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1228,4 +1228,60 @@ public function createContributionWithTax() { return array($contribution, $financialAccount); } + /* + * test for change in FT + */ + public function testChangePaymentInstrumentTax() { + $contactId = $this->individualCreate(); + $this->enableTaxAndInvoicing(); + $financialType = $this->createFinancialType(); + $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']); + $params = array( + 'contact_id' => $contactId, + 'currency' => 'USD', + 'financial_type_id' => 1, + 'contribution_status_id' => 1, + 'payment_instrument_id' => 1, + 'total_amount' => 200.00, + 'fee_amount' => 0, + 'non_deductible_amount' => 0, + ); + $id = $this->contributionCreate($params); + $financialTrxn = $this->callAPISuccess('financial_trxn', 'get', array( + 'trxn_id' => 12345, + )); + $this->assertEquals($financialTrxn['count'], 1, 'Counts do not match.'); + $this->assertEquals($financialTrxn['values'][1]['payment_instrument_id'], 1, 'Payment Instrument is not the same.'); + $this->assertEquals($financialTrxn['values'][1]['total_amount'], 220.00, 'Amount does not match.'); + $financialItem = $this->callAPISuccess('financial_item', 'get', array( + 'contact_id' => $contactId, + )); + $this->assertEquals($financialItem['count'], 2, 'Counts do not match.'); + $this->assertEquals($financialItem['values'][1]['amount'], 200.00, 'Amount does not match.'); + $this->assertEquals($financialItem['values'][2]['amount'], 20.00, 'Amount does not match.'); + $this->assertEquals($financialItem['values'][2]['financial_account_id'], $financialAccount->financial_account_id, 'Account is not sales tax related.'); + $this->assertEquals($financialItem['values'][2]['description'], 'Sales Tax', 'Account is not sales tax.'); + // Change payment instrument. + $params['id'] = $id; + $params['payment_instrument_id'] = 2; + $this->contributionCreate($params); + $financialTrxn = $this->callAPISuccess('financial_trxn', 'get', array( + 'trxn_id' => 12345, + )); + $this->assertEquals($financialTrxn['count'], 3, 'Counts do not match.'); + $this->assertEquals($financialTrxn['values'][2]['payment_instrument_id'], 1, 'Payment Instrument is not the same.'); + $this->assertEquals($financialTrxn['values'][2]['total_amount'], -220.00, 'Amount does not match.'); + $this->assertEquals($financialTrxn['values'][3]['total_amount'], 220.00, 'Amount does not match.'); + $this->assertEquals($financialTrxn['values'][3]['payment_instrument_id'], 2, 'Payment Instrument is not the same.'); + // Asserting no changes in financial item. + $financialItem = $this->callAPISuccess('financial_item', 'get', array( + 'contact_id' => $contactId, + )); + $this->assertEquals($financialItem['count'], 2, 'Counts do not match.'); + $this->assertEquals($financialItem['values'][1]['amount'], 200.00, 'Amount does not match.'); + $this->assertEquals($financialItem['values'][2]['amount'], 20.00, 'Amount does not match.'); + $this->assertEquals($financialItem['values'][2]['financial_account_id'], $financialAccount->financial_account_id, 'Account is not sales tax related.'); + $this->assertEquals($financialItem['values'][2]['description'], 'Sales Tax', 'Account is not sales tax.'); + } + }