Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertWidgetOnFrontendInCatalog.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
10 use Magento\Cms\Test\Page\CmsIndex;
12 use Magento\Mtf\Constraint\AbstractConstraint;
14 
18 class AssertWidgetOnFrontendInCatalog extends AbstractConstraint
19 {
29  public function processAssert(
30  CmsIndex $cmsIndex,
31  CatalogCategoryView $catalogCategoryView,
32  Widget $widget,
34  ) {
35  // Flush cache
36  $cache->flush();
37 
38  $cmsIndex->open();
39  if (isset($widget->getWidgetInstance()[0]['entities'])) {
40  $categoryName = $widget->getWidgetInstance()[0]['entities']->getName();
41  } else {
42  $categoryName = $widget->getParameters()['entities']->getCategoyId()[0];
43  }
44  if ($widget->getCode() == 'CMS Static Block') {
45  $widgetText = $widget->getParameters()['entities'][0]->getContent();
46  } else {
47  $widgetText = $widget->getParameters()['anchor_text'];
48  }
49  $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
50  \PHPUnit\Framework\Assert::assertTrue(
51  $catalogCategoryView->getWidgetView()->isWidgetVisible($widget, $widgetText),
52  'Widget is absent on Category page.'
53  );
54  }
55 
61  public function toString()
62  {
63  return "Widget is present on Category page.";
64  }
65 }
processAssert(CmsIndex $cmsIndex, CatalogCategoryView $catalogCategoryView, Widget $widget, Cache $cache)