Skip to content

Commit

Permalink
Merge pull request #11623 from mattwire/CRM-21721_unit_test
Browse files Browse the repository at this point in the history
CRM-21721 Add unit test for createProportionalEntry with zero amount
  • Loading branch information
eileenmcnaughton authored Feb 6, 2018
2 parents 1a34d42 + c364c54 commit 0396305
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,44 @@ public function testCreateProportionalEntry($thousandSeparator) {
$this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
}

/**
* Test for function createProportionalEntry with zero amount().
*
* @param string $thousandSeparator
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
*/
public function testCreateProportionalEntryZeroAmount($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
list($contribution, $financialAccount) = $this->createContributionWithTax(array('total_amount' => 0));
$params = array(
'total_amount' => 0,
'to_financial_account_id' => $financialAccount->financial_account_id,
'payment_instrument_id' => 1,
'trxn_date' => date('Ymd'),
'status_id' => 1,
'entity_id' => $contribution['id'],
);
$financialTrxn = $this->callAPISuccess('FinancialTrxn', 'create', $params);
$entityParams = array(
'contribution_total_amount' => $contribution['total_amount'],
'trxn_total_amount' => 0,
'line_item_amount' => 0,
);
$previousLineItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($contribution['id']);
$eftParams = array(
'entity_table' => 'civicrm_financial_item',
'entity_id' => $previousLineItem['id'],
'financial_trxn_id' => (string) $financialTrxn['id'],
);
CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams);
$trxnTestArray = array_merge($eftParams, array(
'amount' => '0.00',
));
$this->callAPISuccessGetSingle('EntityFinancialTrxn', $eftParams, $trxnTestArray);
}

/**
* Test for function getLastFinancialItemIds().
*/
Expand Down Expand Up @@ -1196,15 +1234,18 @@ public function testProportionallyAssignedForPIChange() {
/**
* Function to create contribution with tax.
*/
public function createContributionWithTax() {
public function createContributionWithTax($params = array()) {
if (!isset($params['total_amount'])) {
$params['total_amount'] = 100;
}
$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,
'total_amount' => $params['total_amount'],
'financial_type_id' => $financialType['id'],
'contact_id' => $contactId,
'contribution_status_id' => 1,
Expand Down

0 comments on commit 0396305

Please sign in to comment.