Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCatalogSearchResultOrder.php
Go to the documentation of this file.
1 <?php
10 
12 use Magento\CatalogSearch\Test\Page\AdvancedResult;
13 use Magento\Mtf\Constraint\AbstractConstraint;
14 
18 class AssertCatalogSearchResultOrder extends AbstractConstraint
19 {
20  /* tags */
21  const SEVERITY = 'high';
22  /* end tags */
23 
31  public function processAssert(CatalogSearchQuery $catalogSearch, AdvancedResult $resultPage)
32  {
34  $queryText = $catalogSearch->getDataFieldConfig('query_text')['source'];
35  $products = $queryText->getProducts();
36 
37  $productsOrder = [];
38  foreach ($products as $productFixture) {
39  $productsOrder[] = $productFixture->getData('name');
40  }
41 
42  do {
43  $productNamesOnPage = $resultPage->getListProductBlock()->getProductNames();
44 
45  foreach ($productNamesOnPage as $productOnPage) {
46  $idxInArray = array_search($productOnPage, $productsOrder, true);
47  if (false !== $idxInArray) {
48  if (0 !== $idxInArray) {
49  \PHPUnit\Framework\Assert::assertEmpty(
50  $productsOrder,
51  'Products are in incorrect order on the search result page'
52  );
53  }
54  array_shift($productsOrder);
55  }
56  }
57  } while (count($productsOrder) && $resultPage->getBottomToolbar()->nextPage());
58 
59  \PHPUnit\Framework\Assert::assertEmpty(
60  $productsOrder,
61  'Products are in incorrect order on the search result page'
62  );
63  }
64 
70  public function toString()
71  {
72  return "Searched products were successfully found and they're in the right order.";
73  }
74 }