Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAssertTaxWithCrossBorderApplying.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11 use Magento\Catalog\Test\Page\Product\CatalogProductView;
12 use Magento\Checkout\Test\Page\CheckoutCart;
13 use Magento\Cms\Test\Page\CmsIndex;
14 use Magento\Mtf\Constraint\AbstractConstraint;
15 use Magento\Mtf\Fixture\FixtureInterface;
16 
21 abstract class AbstractAssertTaxWithCrossBorderApplying extends AbstractConstraint
22 {
28  protected $cmsIndex;
29 
36 
43 
49  protected $checkoutCart;
50 
57  abstract protected function assert($actualPrices);
58 
71  public function processAssert(
72  CatalogProductSimple $product,
73  CmsIndex $cmsIndex,
74  CatalogCategoryView $catalogCategoryView,
75  CatalogProductView $catalogProductView,
77  array $customers
78  ) {
79  $this->cmsIndex = $cmsIndex;
80  $this->catalogCategoryView = $catalogCategoryView;
81  $this->catalogProductView = $catalogProductView;
82  $this->checkoutCart = $checkoutCart;
83  $actualPrices = $this->getPricesForCustomers($product, $customers);
84  $this->assert($actualPrices);
85  }
86 
94  protected function getPricesForCustomers(CatalogProductSimple $product, $customers)
95  {
96  $prices = [];
97  foreach ($customers as $customer) {
98  $this->loginCustomer($customer);
99  $this->openCategory($product);
100  $actualPrices = [];
101  $actualPrices = $this->getCategoryPrice($product, $actualPrices);
102  $this->catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
103  $actualPrices = $this->addToCart($product, $actualPrices);
104  $actualPrices = $this->getCartPrice($product, $actualPrices);
105  $prices[] = $actualPrices;
106  $this->clearShoppingCart();
107  }
108  return $prices;
109  }
110 
117  protected function openCategory(CatalogProductSimple $product)
118  {
119  $this->cmsIndex->open();
120  $this->cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
121  }
122 
130  protected function getCategoryPrice(FixtureInterface $product, $actualPrices)
131  {
132  $actualPrices['category_price_incl_tax'] =
133  $this->catalogCategoryView
134  ->getListProductBlock()
135  ->getProductItem($product)
136  ->getPriceBlock()
137  ->getPriceIncludingTax();
138  return $actualPrices;
139  }
140 
148  protected function addToCart(CatalogProductSimple $product, $actualPrices)
149  {
150  $this->catalogProductView->getViewBlock()->fillOptions($product);
151  $actualPrices['product_page_price'] =
152  $this->catalogProductView->getViewBlock()->getPriceBlock()->getPrice();
153  $this->catalogProductView->getViewBlock()->clickAddToCart();
154  $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
155  return $actualPrices;
156  }
157 
165  protected function getCartPrice(CatalogProductSimple $product, $actualPrices)
166  {
167  $this->checkoutCart->open();
168  $actualPrices['cart_item_price_incl_tax'] =
169  $this->checkoutCart->getCartBlock()->getCartItem($product)->getPriceInclTax();
170  $actualPrices['cart_item_subtotal_incl_tax'] =
171  $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceInclTax();
172  $actualPrices['grand_total'] =
173  $this->checkoutCart->getTotalsBlock()->getGrandTotalIncludingTax();
174  return $actualPrices;
175  }
176 
183  protected function loginCustomer($customer)
184  {
185  $this->objectManager->create(
186  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
187  ['customer' => $customer]
188  )->run();
189  }
190 
196  protected function clearShoppingCart()
197  {
198  $this->checkoutCart->open();
199  $this->checkoutCart->getCartBlock()->clearShoppingCart();
200  }
201 }
$customer
Definition: customers.php:11
processAssert(CatalogProductSimple $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, array $customers)