Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertChildProductIsNotDisplayedSeparately.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;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
18 class AssertChildProductIsNotDisplayedSeparately extends AbstractConstraint
19 {
20  /* tags */
21  const SEVERITY = 'middle';
22  /* end tags */
23 
32  public function processAssert(
33  CatalogsearchResult $catalogSearchResult,
34  CmsIndex $cmsIndex,
36  ) {
37  $configurableAttributesData = $product->getConfigurableAttributesData();
38  $errors = [];
39 
40  $cmsIndex->open();
41  foreach ($configurableAttributesData['matrix'] as $variation) {
42  $product = $this->objectManager->create(
43  \Magento\Catalog\Test\Fixture\CatalogProductSimple::class,
44  [
45  'data' => [
46  'name' => $variation['name']
47  ]
48  ]
49  );
50 
51  $cmsIndex->getSearchBlock()->search($variation['sku']);
52  $isVisibleProduct = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible();
53  while (!$isVisibleProduct && $catalogSearchResult->getBottomToolbar()->nextPage()) {
54  $isVisibleProduct = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible();
55  }
56  if ($isVisibleProduct) {
57  $errors[] = sprintf(
58  "\nChild product with sku: \"%s\" is visible on frontend(by default).",
59  $variation['sku']
60  );
61  }
62  }
63 
64  \PHPUnit\Framework\Assert::assertEmpty($errors, implode(' ', $errors));
65  }
66 
72  public function toString()
73  {
74  return 'Child products generated during configurable product creation are not visible on frontend(by default)';
75  }
76 }
processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, ConfigurableProduct $product)
$configurableAttributesData
$errors
Definition: overview.phtml:9
$isVisibleProduct
Definition: default.phtml:13