Skip to content

Commit

Permalink
CRM-19585, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
pradpnayak authored and monishdeb committed Apr 17, 2017
1 parent b3de5af commit 32e81d3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3598,7 +3598,7 @@ public static function updateFinancialAccounts(&$params, $context = NULL, $skipT
'previous_line_total' => CRM_Utils_Array::value('line_total', CRM_Utils_Array::value($fieldValues['id'], $previousLineItem)),
'item_amount' => $itemAmount,
);
$amount = self::calcluateFinancialItemAmount($params, $amountParams, $context, $fieldValues);
$amount = self::calculateFinancialItemAmount($params, $amountParams, $context, $fieldValues);
$itemParams = array(
'transaction_date' => $receiveDate,
'contact_id' => $params['prevContribution']->contact_id,
Expand Down
56 changes: 56 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,60 @@ public function alterLineItemsAndOtherParams($contribution, $taxRate, $totalAmou
return $params;
}

/**
* 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.');
}

}

0 comments on commit 32e81d3

Please sign in to comment.