Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertFptApplied.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 
20 class AssertFptApplied extends AbstractConstraint
21 {
27  protected $cmsIndex;
28 
35 
42 
48  protected $checkoutCart;
49 
55  protected $fptLabel;
56 
68  public function processAssert(
69  CatalogProductSimple $product,
70  CmsIndex $cmsIndex,
71  CatalogCategoryView $catalogCategoryView,
72  CatalogProductView $catalogProductView,
74  array $prices
75  ) {
76  $this->cmsIndex = $cmsIndex;
77  $this->catalogCategoryView = $catalogCategoryView;
78  $this->catalogProductView = $catalogProductView;
79  $this->checkoutCart = $checkoutCart;
80  $this->fptLabel = $product->getDataFieldConfig('attribute_set_id')['source']
81  ->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']
82  ->getAttributes()[0]->getFrontendLabel();
83  $this->clearShoppingCart();
84  $actualPrices = $this->getPrices($product);
85  //Prices verification
86  \PHPUnit\Framework\Assert::assertEquals(
87  $prices,
88  $actualPrices,
89  'Prices on front should be equal to defined in dataset'
90  );
91  }
92 
98  protected function clearShoppingCart()
99  {
100  $this->checkoutCart->open();
101  $this->checkoutCart->getCartBlock()->clearShoppingCart();
102  }
103 
110  protected function getPrices(CatalogProductSimple $product)
111  {
112  $actualPrices = [];
113  // Get prices with fpt on category page
114  $this->cmsIndex->open();
115  $this->cmsIndex->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]);
116  $actualPrices = $this->getCategoryPrice($product, $actualPrices);
117  // Get prices with fpt on product page
118  $this->catalogCategoryView->getListProductBlock()->getProductItem($product)->open();
119  $actualPrices = $this->addToCart($product, $actualPrices);
120  // Get prices with fpt on cart page
121  $actualPrices = $this->getCartPrice($product, $actualPrices);
122 
123  return array_filter($actualPrices);
124  }
125 
133  protected function getCategoryPrice(FixtureInterface $product, $actualPrices)
134  {
135  $priceBlock = $this->catalogCategoryView->getWeeeListProductBlock()->getProductItem($product)->getPriceBlock();
136  $actualPrices['category_price'] = $priceBlock->getPrice();
137  $actualPrices['fpt_category'] = $priceBlock->getFptPrice();
138  $actualPrices['fpt_total_category'] = $priceBlock->getFinalPrice();
139 
140  return $actualPrices;
141  }
142 
150  protected function addToCart(CatalogProductSimple $product, array $actualPrices)
151  {
152  $viewBlock = $this->catalogProductView->getViewBlock();
153  $priceBlock = $this->catalogProductView->getWeeeViewBlock()->getPriceBlock();
154 
155  $viewBlock->fillOptions($product);
156  $actualPrices['product_page_price'] = $priceBlock->getPrice();
157  $actualPrices['product_page_fpt'] = $priceBlock->getFptPrice();
158  $actualPrices['product_page_fpt_total'] = $priceBlock->getFinalPrice();
159 
160  $viewBlock->clickAddToCart();
161  $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
162  return $actualPrices;
163  }
164 
172  protected function getCartPrice(CatalogProductSimple $product, array $actualPrices)
173  {
174  $this->checkoutCart->open();
175  $productItem = $this->checkoutCart->getCartBlock()->getCartItem($product);
176  $productWeeeItem = $this->checkoutCart->getWeeeCartBlock()->getCartItem($product);
177  $actualPrices['cart_item_price'] = $productItem->getPrice();
178  $actualPrices['cart_item_fpt'] = $productWeeeItem->getPriceFptBlock()->getFpt();
179  $actualPrices['cart_item_fpt_total'] = $productWeeeItem->getPriceFptBlock()->getFptTotal();
180  $actualPrices['cart_item_subtotal'] = $productItem->getSubtotalPrice();
181  $actualPrices['cart_item_subtotal_fpt'] = $productWeeeItem->getSubtotalFptBlock()->getFpt();
182  $actualPrices['cart_item_subtotal_fpt_total'] = $productWeeeItem->getSubtotalFptBlock()->getFptTotal();
183  $actualPrices['grand_total'] = $this->checkoutCart->getTotalsBlock()->getGrandTotal();
184  $actualPrices['grand_total_excl_tax'] = $this->checkoutCart->getTotalsBlock()->getGrandTotalExcludingTax();
185  $actualPrices['grand_total_incl_tax'] = $this->checkoutCart->getTotalsBlock()->getGrandTotalIncludingTax();
186  $actualPrices['total_fpt'] = $this->checkoutCart->getWeeeTotalsBlock()->getFptBlock()->getTotalFpt();
187 
188  return $actualPrices;
189  }
190 
196  public function toString()
197  {
198  return 'FPT is applied to product.';
199  }
200 }
addToCart(CatalogProductSimple $product, array $actualPrices)
getCategoryPrice(FixtureInterface $product, $actualPrices)
processAssert(CatalogProductSimple $product, CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, array $prices)
getCartPrice(CatalogProductSimple $product, array $actualPrices)