Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertTaxRuleApplying.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Checkout\Test\Page\CheckoutCart;
12 use Magento\Customer\Test\Fixture\Address;
15 use Magento\Mtf\Client\BrowserInterface;
16 use Magento\Mtf\Constraint\AbstractConstraint;
17 use Magento\Mtf\Fixture\FixtureFactory;
18 
22 abstract class AssertTaxRuleApplying extends AbstractConstraint
23 {
29  protected $initialTaxRule;
30 
36  protected $taxRule;
37 
43  protected $productSimple;
44 
50  protected $checkoutCart;
51 
57  protected $shipping;
58 
64  protected $taxRuleCode;
65 
71  abstract protected function assert();
72 
91  public function processAssert(
92  FixtureFactory $fixtureFactory,
93  TaxRule $taxRule,
94  Customer $customer,
95  CatalogProductView $catalogProductView,
98  array $shipping,
99  BrowserInterface $browser,
100  TaxRule $initialTaxRule = null
101  ) {
102  $this->initialTaxRule = $initialTaxRule;
103  $this->taxRule = $taxRule;
104  $this->checkoutCart = $checkoutCart;
105  $this->shipping = $shipping;
106 
107  if ($this->initialTaxRule !== null) {
108  $this->taxRuleCode = ($this->taxRule->hasData('code'))
109  ? $this->taxRule->getCode()
110  : $this->initialTaxRule->getCode();
111  } else {
112  $this->taxRuleCode = $this->taxRule->getCode();
113  }
114  // Creating simple product with custom tax class
116  $taxProductClass = $taxRule->getDataFieldConfig('tax_product_class')['source']->getFixture()[0];
117  $this->productSimple = $fixtureFactory->createByCode(
118  'catalogProductSimple',
119  [
120  'dataset' => 'product_100_dollar_for_tax_rule',
121  'data' => [
122  'tax_class_id' => ['tax_product_class' => $taxProductClass],
123  ]
124  ]
125  );
126  $this->productSimple->persist();
127  // Customer login
128  $this->objectManager->create(
129  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
130  ['customer' => $customer]
131  )->run();
132  // Clearing shopping cart and adding product to shopping cart
133  $checkoutCart->open()->getCartBlock()->clearShoppingCart();
134  $browser->open($_ENV['app_frontend_url'] . $this->productSimple->getUrlKey() . '.html');
135  $catalogProductView->getViewBlock()->clickAddToCart();
136  $catalogProductView->getMessagesBlock()->waitSuccessMessage();
137  // Estimate Shipping and Tax
138  $checkoutCart->open();
139  $checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
140  $checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
141  $this->assert();
142  }
143 }
$customer
Definition: customers.php:11
$address
Definition: customer.php:38