Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCartPriceRuleApplying.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\Customer\Test\Fixture\Address;
16 use Magento\Customer\Test\Page\CustomerAccountLogin;
18 use Magento\Mtf\Constraint\AbstractConstraint;
20 
26 abstract class AssertCartPriceRuleApplying extends AbstractConstraint
27 {
33  protected $checkoutCart;
34 
40  protected $cmsIndex;
41 
48 
55 
62 
69 
75  protected $customer;
76 
83 
90 
96  protected $cartPrice;
97 
103  abstract protected function assert();
104 
144  public function processAssert(
146  CmsIndex $cmsIndex,
147  CustomerAccountLogin $customerAccountLogin,
149  CatalogCategoryView $catalogCategoryView,
150  CatalogProductView $catalogProductView,
151  SalesRule $salesRule,
152  SalesRule $salesRuleOrigin,
153  array $productQuantity,
154  CatalogProductSimple $productForSalesRule1,
155  CatalogProductSimple $productForSalesRule2 = null,
156  Customer $customer = null,
157  Address $address = null,
158  $isLoggedIn = null,
159  $couponCode = null,
160  array $shipping = [],
161  array $cartPrice = []
162  ) {
163  $this->checkoutCart = $checkoutCart;
164  $this->cmsIndex = $cmsIndex;
165  $this->customerAccountLogin = $customerAccountLogin;
166  $this->customerAccountLogout = $customerAccountLogout;
167  $this->catalogCategoryView = $catalogCategoryView;
168  $this->catalogProductView = $catalogProductView;
169  $this->productForSalesRule1 = $productForSalesRule1;
170  $this->productForSalesRule2 = $productForSalesRule2;
171  $this->cartPrice = $cartPrice;
172  if ($customer !== null) {
173  $this->customer = $customer;
174  }
175  $isLoggedIn ? $this->login() : $this->customerAccountLogout->open();
176  $this->checkoutCart->open()->getCartBlock()->clearShoppingCart();
177  $this->addProductsToCart($productQuantity);
178  $this->checkoutCart->open();
179  if ($address !== null) {
180  $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
181  $this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
182  }
183 
184  if ($salesRule->getCouponCode()) {
185  $couponCode = $salesRule->getCouponCode();
186  } elseif ($salesRuleOrigin->getCouponCode()) {
187  $couponCode = $salesRuleOrigin->getCouponCode();
188  }
189 
190  if ($salesRule->getCouponCode() || $salesRuleOrigin->getCouponCode() || $couponCode) {
191  $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($couponCode);
192  }
193  $this->assert();
194  }
195 
201  protected function login()
202  {
203  $this->objectManager->create(
204  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
205  ['customer' => $this->customer]
206  )->run();
207  }
208 
215  protected function addProductsToCart(array $productQuantity)
216  {
217  foreach ($productQuantity as $product => $quantity) {
218  if ($quantity > 0) {
219  $categoryName = $this->$product->getCategoryIds()[0];
220  $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
221  $this->catalogCategoryView->getListProductBlock()->getProductItem($this->$product)->open();
222  $this->catalogProductView->getViewBlock()->setQtyAndClickAddToCart($quantity);
223  $this->catalogProductView->getMessagesBlock()->waitSuccessMessage();
224  }
225  }
226  }
227 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$address
Definition: customer.php:38
processAssert(CheckoutCart $checkoutCart, CmsIndex $cmsIndex, CustomerAccountLogin $customerAccountLogin, CustomerAccountLogout $customerAccountLogout, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, SalesRule $salesRule, SalesRule $salesRuleOrigin, array $productQuantity, CatalogProductSimple $productForSalesRule1, CatalogProductSimple $productForSalesRule2=null, Customer $customer=null, Address $address=null, $isLoggedIn=null, $couponCode=null, array $shipping=[], array $cartPrice=[])