Skip to content

Commit

Permalink
CRM-19585, added test
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-19585: Sales tax issue
  https://issues.civicrm.org/jira/browse/CRM-19585
  • Loading branch information
pradpnayak authored and monishdeb committed Apr 17, 2017
1 parent 6703952 commit 15ecc74
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,4 +1251,57 @@ public function testReplaceContributionTokens() {
<p>Contribution Receive Date: May 11th, 2015</p></br>", $contributionDetails[$contactId2]['html'], "The html does not match");
}

/*
* test for function calculateFTChangeAmount()
*/
public function testCalculateFTChangeAmount() {
list($contribution, $financialAccount) = $this->createContributionWithTax();

$params = $this->alterLineItemsAndOtherParams($contribution, 0, 300, 0);
$trxnAmount = 110;
$totalAmount = 300;
list($changeFTAmount, $ignoreChangeAmount, $oldTaxAmounts) = CRM_Contribute_BAO_Contribution::calculateFTChangeAmount($params, $trxnAmount, $totalAmount);
$this->assertEquals($totalAmount, 310, 'Amount does not match.');
$this->assertEquals($ignoreChangeAmount, FALSE);
$this->assertEquals($changeFTAmount, 100, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['new_tax_amount'], 0, 'Amount does not match.');
$this->assertEquals(CRM_Utils_Array::value('previous_tax_amount', $oldTaxAmounts), NULL, 'Amount does not match.');

$params = $this->alterLineItemsAndOtherParams($contribution, 20, 300, 60);
$totalAmount = 360;
list($changeFTAmount, $ignoreChangeAmount, $oldTaxAmounts) = CRM_Contribute_BAO_Contribution::calculateFTChangeAmount($params, $trxnAmount, $totalAmount);
$this->assertEquals($totalAmount, 350, 'Amount does not match.');
$this->assertEquals($ignoreChangeAmount, FALSE);
$this->assertEquals($changeFTAmount, 120, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['new_tax_amount'], 50, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['previous_tax_amount'], 10, 'Amount does not match.');

$params = $this->alterLineItemsAndOtherParams($contribution, 20, 100, 20);
$totalAmount = 120;
list($changeFTAmount, $ignoreChangeAmount, $oldTaxAmounts) = CRM_Contribute_BAO_Contribution::calculateFTChangeAmount($params, $trxnAmount, $totalAmount);
$this->assertEquals($totalAmount, 120, 'Amount does not match.');
$this->assertEquals($ignoreChangeAmount, TRUE);
$this->assertEquals($changeFTAmount, 120, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['new_tax_amount'], 20, 'Amount does not match.');
$this->assertEquals(CRM_Utils_Array::value('previous_tax_amount', $oldTaxAmounts), NULL, 'Amount does not match.');

$financialType = $this->createFinancialType();
$contributionParams = array(
'contact_id' => $contribution['contact_id'],
'financial_type_id' => $financialType['id'],
'total_amount' => 100,
'contribution_status_id' => 1,
);
$contribution = CRM_Contribute_BAO_Contribution::add($contributionParams);
$params = $this->alterLineItemsAndOtherParams($contribution, 10, 300, 30);
$trxnAmount = 100;
$totalAmount = 330;
list($changeFTAmount, $ignoreChangeAmount, $oldTaxAmounts) = CRM_Contribute_BAO_Contribution::calculateFTChangeAmount($params, $trxnAmount, $totalAmount);
$this->assertEquals($totalAmount, 320, 'Amount does not match.');
$this->assertEquals($ignoreChangeAmount, FALSE);
$this->assertEquals($changeFTAmount, 110, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['new_tax_amount'], 20, 'Amount does not match.');
$this->assertEquals($oldTaxAmounts['previous_tax_amount'], 0, 'Amount does not match.');
}

}

0 comments on commit 15ecc74

Please sign in to comment.