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 committed Dec 28, 2016
1 parent 83e1baa commit 7a1f391
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,39 @@ protected function getCreditCardParams() {
);
}

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

}
26 changes: 26 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3650,6 +3650,32 @@ protected function enableTaxAndInvoicing($params = array()) {
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.
*
Expand Down

0 comments on commit 7a1f391

Please sign in to comment.