Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductUpSells.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 use Magento\Mtf\Fixture\InjectableFixture;
14 
18 class AssertProductUpSells extends AbstractConstraint
19 {
20  /* tags */
21  const SEVERITY = 'middle';
22  /* end tags */
23 
33  public function processAssert(
34  BrowserInterface $browser,
35  CatalogProductView $catalogProductView,
36  CatalogProductSimple $product,
37  array $promotedProducts = null
38  ) {
39  if (!$promotedProducts) {
40  $promotedProducts = $product->hasData('up_sell_products')
41  ? $product->getDataFieldConfig('up_sell_products')['source']->getProducts()
42  : [];
43  }
44 
45  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
46  foreach ($promotedProducts as $promotedProduct) {
47  \PHPUnit\Framework\Assert::assertTrue(
48  $catalogProductView->getUpsellBlock()->getProductItem($promotedProduct)->isVisible(),
49  'Product \'' . $promotedProduct->getName()
50  . '\' is absent in up-sells products of a product \'' . $product->getName() . '\'.'
51  );
52  }
53  }
54 
60  public function toString()
61  {
62  return 'Product is displayed in up-sell section.';
63  }
64 }
processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, CatalogProductSimple $product, array $promotedProducts=null)