Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductAbsentRelatedProducts.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 AssertProductAbsentRelatedProducts extends AbstractConstraint
19 {
29  public function processAssert(
30  BrowserInterface $browser,
31  CatalogProductSimple $product,
32  CatalogProductView $catalogProductView,
33  array $promotedProducts = null
34  ) {
35  if (!$promotedProducts) {
36  $promotedProducts = $product->hasData('related_products')
37  ? $product->getDataFieldConfig('related_products')['source']->getProducts()
38  : [];
39  }
40 
41  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
42  foreach ($promotedProducts as $promotedProduct) {
43  \PHPUnit\Framework\Assert::assertFalse(
44  $catalogProductView->getRelatedProductBlock()->getProductItem($promotedProduct)->isVisible(),
45  'Product \'' . $promotedProduct->getName() . '\' exists in related products.'
46  );
47  }
48  }
49 
55  public function toString()
56  {
57  return 'Product is not displayed in related products section.';
58  }
59 }