Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductSearchableBySku.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\CatalogSearch\Test\Page\CatalogsearchResult;
10 use Magento\Cms\Test\Page\CmsIndex;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 
17 class AssertProductSearchableBySku extends AbstractConstraint
18 {
19  /* tags */
20  const SEVERITY = 'low';
21  /* end tags */
22 
28  protected $errorMessage = 'The product has not been found by SKU';
29 
35  protected $successfulMessage = 'Product successfully found by SKU.';
36 
47  public function processAssert(
48  CatalogsearchResult $catalogSearchResult,
49  CmsIndex $cmsIndex,
50  FixtureInterface $product
51  ) {
52  $cmsIndex->open();
53  $sku = ($product->hasData('sku') !== false) ? $product->getSku() : $product->getName();
54  $cmsIndex->getSearchBlock()->search($sku);
55 
56  $quantityAndStockStatus = $product->getQuantityAndStockStatus();
57  $stockStatus = isset($quantityAndStockStatus['is_in_stock'])
58  ? $quantityAndStockStatus['is_in_stock']
59  : null;
60 
61  $isVisible = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible();
62  while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage()) {
63  $isVisible = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible();
64  }
65 
66  if ($product->getVisibility() === 'Catalog' || $stockStatus === 'Out of Stock') {
67  $isVisible = !$isVisible;
68  list($this->errorMessage, $this->successfulMessage) = [$this->successfulMessage, $this->errorMessage];
69  }
70 
71  \PHPUnit\Framework\Assert::assertTrue(
72  $isVisible,
73  $this->errorMessage
74  );
75  }
76 
82  public function toString()
83  {
85  }
86 }
processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, FixtureInterface $product)