Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductCrossSells.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\FixtureInterface;
15 
19 class AssertProductCrossSells extends AbstractConstraint
20 {
31  public function processAssert(
32  BrowserInterface $browser,
33  CheckoutCart $checkoutCart,
34  CatalogProductSimple $product,
35  CatalogProductView $catalogProductView,
36  array $promotedProducts = null
37  ) {
38  $errors = [];
39  if (!$promotedProducts) {
40  $promotedProducts = $product->hasData('cross_sell_products')
41  ? $product->getDataFieldConfig('cross_sell_products')['source']->getProducts()
42  : [];
43  }
44 
45  $checkoutCart->open();
46  $checkoutCart->getCartBlock()->clearShoppingCart();
47 
48  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
49  $catalogProductView->getViewBlock()->addToCart($product);
50  $catalogProductView->getMessagesBlock()->waitSuccessMessage();
51  $checkoutCart->open();
52  foreach ($promotedProducts as $promotedProduct) {
53  if (!$checkoutCart->getCrosssellBlock()->getProductItem($promotedProduct)->isVisible()) {
54  $errors[] = 'Product \'' . $promotedProduct->getName()
55  . '\' is absent in cross-sell section of a product \'' . $product->getName() . '\'.';
56  }
57  }
58 
59  \PHPUnit\Framework\Assert::assertEmpty($errors, implode(" ", $errors));
60  }
61 
67  public function toString()
68  {
69  return 'Product is displayed in cross-sell section.';
70  }
71 }
processAssert(BrowserInterface $browser, CheckoutCart $checkoutCart, CatalogProductSimple $product, CatalogProductView $catalogProductView, array $promotedProducts=null)
$errors
Definition: overview.phtml:9