Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHPUnit test only] Adding in assertions re: Line Item and Contribution data-integrity. #12611

Merged
merged 4 commits into from
Aug 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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