Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertSearchTermOnFrontend.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Cms\Test\Page\CmsIndex;
12 use Magento\Mtf\Client\BrowserInterface;
13 use Magento\Mtf\Constraint\AbstractConstraint;
14 
19 class AssertSearchTermOnFrontend extends AbstractConstraint
20 {
26  protected $searchBlock;
27 
40  public function processAssert(CmsIndex $cmsIndex, CatalogSearchQuery $searchTerm, BrowserInterface $browser)
41  {
42  $errors = [];
43  $this->searchBlock = $cmsIndex->open()->getSearchBlock();
44 
45  if ($searchTerm->hasData('display_in_terms') && $searchTerm->getDisplayInTerms() === 'Yes') {
46  $errors = $this->checkSuggestSearch($searchTerm);
47  }
48 
49  $this->searchBlock->search($searchTerm->getQueryText());
50  $windowUrl = $browser->getUrl();
51  $redirectUrl = $searchTerm->getRedirect();
52  if ($windowUrl !== $redirectUrl) {
53  $errors[] = '- url window (' . $windowUrl . ') does not match the url redirect(' . $redirectUrl . ')';
54  }
55 
56  \PHPUnit\Framework\Assert::assertEmpty(
57  $errors,
58  'When checking on the frontend "Search terms" arose following errors:' . PHP_EOL . implode(PHP_EOL, $errors)
59  );
60  }
61 
68  protected function checkSuggestSearch(CatalogSearchQuery $searchTerm)
69  {
70  $queryText = $searchTerm->getQueryText();
71  $this->searchBlock->fillSearch($queryText);
72  if ($searchTerm->hasData('num_results')) {
73  $isVisible = $this->searchBlock->isSuggestSearchVisible(
74  $queryText,
75  $searchTerm->getNumResults()
76  );
77  } else {
78  $isVisible = $this->searchBlock->isSuggestSearchVisible($queryText);
79  }
80 
81  return $isVisible ? [] : ['- block "Suggest Search" when searching was not found'];
82  }
83 
89  public function toString()
90  {
91  return 'Checking "Search terms" on frontend successful.';
92  }
93 }
processAssert(CmsIndex $cmsIndex, CatalogSearchQuery $searchTerm, BrowserInterface $browser)
$errors
Definition: overview.phtml:9