Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertTaxRuleIsApplied.php
Go to the documentation of this file.
1 <?php
8 
13 {
19  protected function assert()
20  {
21  $errorMessages = [];
22 
23  // Preparing data to compare
24  $taxRate = $this->taxRule->getDataFieldConfig('tax_rate')['source']->getFixture()[0]->getRate();
25  $expectedGrandTotal = $this->productSimple->getPrice() + $taxRate + $this->shipping['price'];
26  $expectedGrandTotal = number_format($expectedGrandTotal, 2);
27  $actualGrandTotal = $this->checkoutCart->getTotalsBlock()->getGrandTotal();
28 
29  if ($this->checkoutCart->getTotalsBlock()->isTaxVisible()) {
30  $expectedTax = number_format($taxRate, 2);
31  $actualTax = $this->checkoutCart->getTotalsBlock()->getTax();
32  if ($expectedTax !== $actualTax) {
33  $errorMessages[] = 'Tax Rule \'' . $this->taxRuleCode . '\' is applied wrong.'
34  . "\nExpected: " . $expectedTax
35  . "\nActual: " . $actualTax;
36  }
37  }
38 
39  if ($expectedGrandTotal !== $actualGrandTotal) {
40  $errorMessages[] = 'Grand Total is not correct.'
41  . "\nExpected: " . $expectedGrandTotal
42  . "\nActual: " . $actualGrandTotal;
43  }
44 
45  \PHPUnit\Framework\Assert::assertTrue(empty($errorMessages), implode(";\n", $errorMessages));
46  }
47 
53  public function toString()
54  {
55  return "Tax rule applied on product in shopping cart.";
56  }
57 }
$taxRate
Definition: tax_rule.php:12