Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductAbsentCrossSells.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Checkout\Test\Page\CheckoutCart;
12 use Magento\Mtf\Client\BrowserInterface;
13 use Magento\Mtf\Constraint\AbstractConstraint;
14 use Magento\Mtf\Fixture\InjectableFixture;
15 
19 class AssertProductAbsentCrossSells extends AbstractConstraint
20 {
21  /* tags */
22  const SEVERITY = 'middle';
23  /* end tags */
24 
35  public function processAssert(
36  BrowserInterface $browser,
37  CatalogProductSimple $product,
38  CatalogProductView $catalogProductView,
39  CheckoutCart $checkoutCart,
40  array $promotedProducts = null
41  ) {
42  if (!$promotedProducts) {
43  $promotedProducts = $product->hasData('cross_sell_products')
44  ? $product->getDataFieldConfig('cross_sell_products')['source']->getProducts()
45  : [];
46  }
47 
48  $checkoutCart->open();
49  $checkoutCart->getCartBlock()->clearShoppingCart();
50 
51  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
52  $catalogProductView->getViewBlock()->addToCart($product);
53  $catalogProductView->getMessagesBlock()->waitSuccessMessage();
54  $checkoutCart->open();
55  foreach ($promotedProducts as $promotedProduct) {
56  \PHPUnit\Framework\Assert::assertFalse(
57  $checkoutCart->getCrosssellBlock()->getProductItem($promotedProduct)->isVisible(),
58  'Product \'' . $promotedProduct->getName() . '\' exists in cross-sell section.'
59  );
60  }
61  }
62 
68  public function toString()
69  {
70  return 'Product is not displayed in cross-sell section.';
71  }
72 }
processAssert(BrowserInterface $browser, CatalogProductSimple $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCart, array $promotedProducts=null)