Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAssertTaxCalculationAfterCheckout.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Cms\Test\Page\CmsIndex;
10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Checkout\Test\Page\CheckoutCart;
12 use Magento\Checkout\Test\Page\CheckoutOnepage;
13 use Magento\Checkout\Test\Page\CheckoutOnepageSuccess;
15 use Magento\Sales\Test\Page\CustomerOrderView;
16 use Magento\Mtf\Fixture\InjectableFixture;
17 
21 abstract class AbstractAssertTaxCalculationAfterCheckout extends AbstractConstraint
22 {
28  protected $checkoutOnepage;
29 
35  protected $customerOrderView;
36 
42  protected $severeness = 'high';
43 
50  abstract protected function getReviewTotals($actualPrices);
51 
58  abstract protected function getOrderTotals($actualPrices);
59 
72  public function processAssert(
73  array $prices,
74  InjectableFixture $product,
75  CheckoutCart $checkoutCart,
76  CheckoutOnepage $checkoutOnepage,
77  CheckoutOnepageSuccess $checkoutOnepageSuccess,
78  CustomerOrderView $customerOrderView,
79  CmsIndex $cmsIndex
80  ) {
81  $this->checkoutOnepage = $checkoutOnepage;
82  $this->customerOrderView = $customerOrderView;
83 
84  $checkoutCart->getProceedToCheckoutBlock()->proceedToCheckout();
85  $cmsIndex->getCmsPageBlock()->waitPageInit();
86 
87  $shippingMethod = ['shipping_service' => 'Flat Rate', 'shipping_method' => 'Fixed'];
88  $checkoutOnepage->getShippingMethodBlock()->selectShippingMethod($shippingMethod);
89  $checkoutOnepage->getShippingMethodBlock()->clickContinue();
90  $checkoutOnepage->getPaymentBlock()->selectPaymentMethod(['method' => 'checkmo']);
91  $actualPrices = [];
92  $actualPrices = $this->getReviewPrices($actualPrices, $product);
93  $actualPrices = $this->getReviewTotals($actualPrices);
94  $prices = $this->preparePrices($prices);
95  //Order review prices verification
96  $message = 'Prices on order review should be equal to defined in dataset.';
97  \PHPUnit\Framework\Assert::assertEquals(
98  array_diff_key($prices, ['cart_item_price_excl_tax' => null, 'cart_item_price_incl_tax' => null]),
99  array_diff_key($actualPrices, ['cart_item_price_excl_tax' => null, 'cart_item_price_incl_tax' => null]),
100  $message
101  );
102 
103  $checkoutOnepage->getPaymentBlock()->placeOrder();
104  $checkoutOnepageSuccess->getSuccessBlock()->getGuestOrderId();
105  $checkoutOnepageSuccess->getSuccessBlock()->openOrder();
106  $actualPrices = [];
107  $actualPrices = $this->getOrderPrices($actualPrices, $product);
108  $actualPrices = $this->getOrderTotals($actualPrices);
109 
110  //Frontend order prices verification
111  $message = 'Prices on order view page should be equal to defined in dataset.';
112  \PHPUnit\Framework\Assert::assertEquals($prices, $actualPrices, $message);
113  }
114 
121  protected function preparePrices($prices)
122  {
123  return array_diff_key(
124  $prices,
125  array_flip([
126  'category_price',
127  'category_special_price',
128  'category_price_excl_tax',
129  'category_price_incl_tax',
130  'product_view_price',
131  'product_view_special_price',
132  'product_view_price_excl_tax',
133  'product_view_price_incl_tax'
134  ])
135  );
136  }
137 
145  public function getReviewPrices($actualPrices, InjectableFixture $product)
146  {
147  $reviewBlock = $this->checkoutOnepage->getReviewBlock();
148  $actualPrices['cart_item_price_excl_tax'] = $reviewBlock->getItemPriceExclTax($product->getName());
149  $actualPrices['cart_item_price_incl_tax'] = $reviewBlock->getItemPriceInclTax($product->getName());
150  $actualPrices['cart_item_subtotal_excl_tax'] = $reviewBlock->getItemSubExclTax($product->getName());
151  $actualPrices['cart_item_subtotal_incl_tax'] = $reviewBlock->getItemSubInclTax($product->getName());
152  return $actualPrices;
153  }
154 
162  public function getOrderPrices($actualPrices, InjectableFixture $product)
163  {
164  $viewBlock = $this->customerOrderView->getOrderViewBlock();
165  $actualPrices['cart_item_price_excl_tax'] = $viewBlock->getItemPriceExclTax($product->getName());
166  $actualPrices['cart_item_price_incl_tax'] = $viewBlock->getItemPriceInclTax($product->getName());
167  $actualPrices['cart_item_subtotal_excl_tax'] = $viewBlock->getItemSubExclTax($product->getName());
168  $actualPrices['cart_item_subtotal_incl_tax'] = $viewBlock->getItemSubInclTax($product->getName());
169  return $actualPrices;
170  }
171 
177  public function toString()
178  {
179  return 'Prices on front after order creation is correct.';
180  }
181 }
$message
processAssert(array $prices, InjectableFixture $product, CheckoutCart $checkoutCart, CheckoutOnepage $checkoutOnepage, CheckoutOnepageSuccess $checkoutOnepageSuccess, CustomerOrderView $customerOrderView, CmsIndex $cmsIndex)
$shippingMethod
Definition: popup.phtml:12