Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductCanBeOpenedFromSearchResult.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Constraint\AbstractConstraint;
10 use Magento\CatalogSearch\Test\Page\AdvancedResult;
11 use Magento\Catalog\Test\Page\Product\CatalogProductView;
13 
17 class AssertProductCanBeOpenedFromSearchResult extends AbstractConstraint
18 {
27  public function processAssert(
28  CatalogSearchQuery $catalogSearch,
29  AdvancedResult $resultPage,
30  CatalogProductView $catalogProductViewPage
31  ) {
32  $product = $catalogSearch->getDataFieldConfig('query_text')['source']->getFirstProduct();
33 
34  do {
35  $isProductVisible = $resultPage->getListProductBlock()->getProductItem($product)->isVisible();
36  } while (!$isProductVisible && $resultPage->getBottomToolbar()->nextPage());
37 
38  $productName = $product->getName();
39  \PHPUnit\Framework\Assert::assertTrue($isProductVisible, "A product with name $productName was not found.");
40 
41  $resultPage->getListProductBlock()->getProductItem($product)->open();
42  \PHPUnit\Framework\Assert::assertEquals(
43  $productName,
44  $catalogProductViewPage->getViewBlock()->getProductName(),
45  'Wrong product page has been opened.'
46  );
47  }
48 
54  public function toString()
55  {
56  return 'Product can be opened from search results page.';
57  }
58 }
processAssert(CatalogSearchQuery $catalogSearch, AdvancedResult $resultPage, CatalogProductView $catalogProductViewPage)