Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAssertTaxRuleIsAppliedToAllPrices.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Checkout\Test\Page\CheckoutCart;
12 use Magento\Cms\Test\Page\CmsIndex;
13 use Magento\Customer\Test\Fixture\Address;
14 use Magento\Mtf\Constraint\AbstractConstraint;
15 use Magento\Mtf\Fixture\FixtureFactory;
16 use Magento\Mtf\Fixture\FixtureInterface;
17 use Magento\Mtf\Fixture\InjectableFixture;
18 
24 abstract class AbstractAssertTaxRuleIsAppliedToAllPrices extends AbstractConstraint
25 {
31  protected $cmsIndex;
32 
39 
46 
52  protected $checkoutCart;
53 
59  protected $severeness = 'high';
60 
68  abstract protected function getCategoryPrices(FixtureInterface $product, $actualPrices);
69 
76  abstract protected function getProductPagePrices($actualPrices);
77 
84  abstract protected function getTotals($actualPrices);
85 
99  public function processAssert(
100  InjectableFixture $product,
101  array $prices,
102  $qty,
103  CmsIndex $cmsIndex,
104  CatalogCategoryView $catalogCategoryView,
105  CatalogProductView $catalogProductView,
107  FixtureFactory $fixtureFactory
108  ) {
109  $this->cmsIndex = $cmsIndex;
110  $this->catalogCategoryView = $catalogCategoryView;
111  $this->catalogProductView = $catalogProductView;
112  $this->checkoutCart = $checkoutCart;
113  //Preconditions
114  $address = $fixtureFactory->createByCode('address', ['dataset' => 'US_address_NY']);
115  $shipping = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed'];
116  $actualPrices = [];
117  //Assertion steps
118  $productCategory = $product->getCategoryIds()[0];
119  $this->openCategory($productCategory);
120  $actualPrices = $this->getCategoryPrices($product, $actualPrices);
121  $catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
122  $catalogProductView->getViewBlock()->fillOptions($product);
123  $actualPrices = $this->getProductPagePrices($actualPrices);
124  $catalogProductView->getViewBlock()->setQtyAndClickAddToCart($qty);
125  $catalogProductView->getMessagesBlock()->waitSuccessMessage();
126  $this->checkoutCart->open();
127  $this->fillEstimateBlock($address, $shipping);
128  $actualPrices = $this->getCartPrices($product, $actualPrices);
129  $actualPrices = $this->getTotals($actualPrices);
130  //Prices verification
131  $message = 'Prices from dataset should be equal to prices on frontend.';
132  \PHPUnit\Framework\Assert::assertEquals($prices, $actualPrices, $message);
133  }
134 
141  public function openCategory($productCategory)
142  {
143  $this->cmsIndex->open();
144  $this->cmsIndex->getTopmenu()->selectCategoryByName($productCategory);
145  }
146 
154  public function getCartPrices(InjectableFixture $product, $actualPrices)
155  {
156  $actualPrices['cart_item_price_excl_tax'] =
157  $this->checkoutCart->getCartBlock()->getCartItem($product)->getPriceExclTax();
158  $actualPrices['cart_item_price_incl_tax'] =
159  $this->checkoutCart->getCartBlock()->getCartItem($product)->getPriceInclTax();
160  $actualPrices['cart_item_subtotal_excl_tax'] =
161  $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceExclTax();
162  $actualPrices['cart_item_subtotal_incl_tax'] =
163  $this->checkoutCart->getCartBlock()->getCartItem($product)->getSubtotalPriceInclTax();
164 
165  return $actualPrices;
166  }
167 
175  public function fillEstimateBlock(Address $address, $shipping)
176  {
177  $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
178  $this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
179  }
180 
186  public function toString()
187  {
188  return 'Prices on front is correct.';
189  }
190 }
processAssert(InjectableFixture $product, array $prices, $qty, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, FixtureFactory $fixtureFactory)
$message
$address
Definition: customer.php:38
getCategoryPrices(FixtureInterface $product, $actualPrices)