Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertAttributeSearchableByLabel.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Cms\Test\Page\CmsIndex;
10 use Magento\Mtf\Fixture\InjectableFixture;
11 use Magento\Mtf\Constraint\AbstractConstraint;
12 use Magento\CatalogSearch\Test\Page\CatalogsearchResult;
13 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
14 
18 class AssertAttributeSearchableByLabel extends AbstractConstraint
19 {
29  public function processAssert(
30  CatalogProductAttribute $attribute,
31  CmsIndex $cmsIndex,
32  InjectableFixture $product,
33  CatalogsearchResult $catalogSearchResult
34  ) {
35  $searchValue = $this->getSearchValue($attribute);
36 
37  $cmsIndex->open();
38  $cmsIndex->getSearchBlock()->search($searchValue);
39 
40  do {
41  $isVisible = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible();
42  } while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage());
43 
44  \PHPUnit\Framework\Assert::assertTrue($isVisible, 'Product attribute is not searchable on Frontend.');
45  }
46 
53  protected function getSearchValue(CatalogProductAttribute $attribute)
54  {
55  $searchValue = '';
56 
57  switch ($attribute->getFrontendInput()) {
58  case 'Multiple Select':
59  case 'Dropdown':
60  foreach ($attribute->getOptions() as $option) {
61  if ($option['is_default'] == 'Yes') {
62  $searchValue = $option['admin'];
63  }
64  }
65  break;
66  case 'Text Field':
67  $searchValue = $attribute->getDefaultValueText();
68  break;
69  case 'Text Area':
70  $searchValue = $attribute->getDefaultValueTextarea();
71  break;
72  case 'Date':
73  $searchValue = $attribute->getDefaultValueDate();
74  break;
75  case 'Yes/No':
76  $searchValue = $attribute->getDefaultValueYesno();
77  break;
78  }
79 
80  return $searchValue;
81  }
82 
88  public function toString()
89  {
90  return 'Product attribute is searchable on Frontend.';
91  }
92 }
processAssert(CatalogProductAttribute $attribute, CmsIndex $cmsIndex, InjectableFixture $product, CatalogsearchResult $catalogSearchResult)