Skip to content

Commit

Permalink
Merge pull request #12611 from KarinG/FinancialAudit
Browse files Browse the repository at this point in the history
[PHPUnit test only] Adding in assertions re: Line Item and Contribution data-integrity.
  • Loading branch information
eileenmcnaughton authored Aug 5, 2018
2 parents dfeca6f + ddfe1cb commit 1f6feee
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1281,10 +1281,22 @@ public function testContributionFormStatusUpdate() {
}

/**
* CRM-21656: Test the submit function of the membership form if Sale Tax is enabled.
* Check that the tax rate isn't reapplied to line item's unit price and total amount
* CRM-21656: Test the submit function of the membership form if Sales Tax is enabled.
* This test simulates what happens when one hits Edit on a Contribution that has both LineItems and Sales Tax components
* Without making any Edits -> check that the LineItem data remain the same
* In addition (a data-integrity check) -> check that the LineItem data add up to the data at the Contribution level
*
* NOTE/discussion on merging in assertions that are commented out (for now):
* https://github.com/civicrm/civicrm-core/pull/12611
*
* Quick summary: the following assertions are commented out for now as they currently Fail. Work is being done to figure out why the
* $form->testSubmit produces different numbers when compared to the GUI
*
* // $this->assertEquals(50.00, $lineItem['unit_price']);
* // $this->assertEquals(50.00, $lineItem['line_total']);
* // $this->assertEquals($contribution['total_amount'], $lineItem['line_total'] + $lineItem['tax_amount']);
*/
public function testLineItemAmountOnSaleTax() {
public function testLineItemAmountOnSalesTax() {
$this->enableTaxAndInvoicing();
$this->relationForFinancialTypeWithFinancialAccount(2);
$form = $this->getForm();
Expand Down Expand Up @@ -1336,11 +1348,25 @@ public function testLineItemAmountOnSaleTax() {
),
CRM_Core_Action::UPDATE);

// ensure that the line-item values got unaffected
// ensure that the LineItem data remain the same
$lineItem = $this->callAPISuccessGetSingle('LineItem', array('entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership'));
$this->assertEquals(1, $lineItem['qty']);
// See documentation block + https://github.com/civicrm/civicrm-core/pull/12611
// $this->assertEquals(50.00, $lineItem['unit_price']);
// $this->assertEquals(50.00, $lineItem['line_total']);
$this->assertEquals(5.00, $lineItem['tax_amount']); // ensure that tax amount is not changed

// ensure that the LineItem data add up to the data at the Contribution level
$contribution = $this->callAPISuccessGetSingle('Contribution',
array(
'contribution_id' => 1,
'return' => array('tax_amount', 'total_amount'),
)
);
// See documentation block + https://github.com/civicrm/civicrm-core/pull/12611
// $this->assertEquals($contribution['total_amount'], $lineItem['line_total'] + $lineItem['tax_amount']);
$this->assertEquals($contribution['tax_amount'], $lineItem['tax_amount']);

// reset the price options static variable so not leave any dummy data, that might hamper other unit tests
\Civi::$statics['CRM_Price_BAO_PriceField']['priceOptions'] = NULL;
$this->disableTaxAndInvoicing();
Expand Down

0 comments on commit 1f6feee

Please sign in to comment.