public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparator) {
to two Line Items hoping to be able to then run a test that checks if the tax_amount at the Contribution level matches the sum of the tax_amount for the two Line Items, but the
@KarinG I tried this locally and seemed to do something half sensible for me
diff--gita/tests/phpunit/api/v3/ContributionPageTest.phpb/tests/phpunit/api/v3/ContributionPageTest.phpindex25eb05e65f..a5d47d9864100644---a/tests/phpunit/api/v3/ContributionPageTest.php+++b/tests/phpunit/api/v3/ContributionPageTest.php@@-1988,7+1988,9@@classapi_v3_ContributionPageTestextendsCiviUnitTestCase{$lineItem_TaxAmount=round($lineItem['tax_amount'],2);$this->assertEquals($lineItem['line_total'],$contribution['total_amount'],'Contribution total should match line total');-$this->assertEquals($lineItem_TaxAmount,round(180*16.95*0.10,2),'Wrong Sales Tax Amount is calculated and stored.');+$this->assertEquals(round(180*16.95*0.10,2),$lineItem_TaxAmount,'Wrong Sales Tax Amount is calculated and stored.');+$finalContribution=$this->callAPISuccess('Contribution','getsingle',['id'=>$contribution['id'],'return'=>['tax_amount']]);+$this->assertEquals($lineItem_TaxAmount,$finalContribution['tax_amount']);}/**
But the $315 make no sense:
a) is not reproducing the bug that's being reported (is only recording the Tax on the last item -> so that would be $10 not $315
b) total tax should be $315.10 (lineItem 1 tax = $305.10 and lineItem 2 tax = $10);
Ok I can get the two new assertions to work now [changed the $thousandSeparator], however they all pass and they should be failing.
$this->assertEquals($lineItem1['line_total'] + $lineItem2['line_total'], round(180 * 16.95 + 110 * 2.95, 2), 'Line Item Total is incorrect.');$this->assertEquals($lineItem1['line_total'] + $lineItem2['line_total'], $finalContribution['total_amount'], 'Contribution total should match line item totals');$this->assertEquals(round($lineItem1['tax_amount'] + $lineItem2['tax_amount'], 2), round(180 * 16.95 * 0.10 + 110 * 2.95 * 0.10, 2), 'Wrong Sales Tax Amount is calculated and stored.');$this->assertEquals(round($lineItem1['tax_amount'] + $lineItem2['tax_amount'], 2), $finalContribution['tax_amount'], 'Sales Tax Amount on Contribution does not match sum of Sales Tax Amount across the Line Items.');
I've put up https://github.com/civicrm/civicrm-core/pull/18290 - thanks to @pradeep & @KarinG this was very easy to hone in on and my version is substantatively the same as @pradeep's - it just removes the weird construct of expecting a function called 'getLineItem' to also manage a running total