Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCategoryIsNotActive.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
11 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
18 class AssertCategoryIsNotActive extends AbstractConstraint
19 {
20  const NOT_FOUND_MESSAGE = 'Whoops, our bad...';
21 
30  public function processAssert(
31  Category $category,
32  CatalogCategoryView $categoryView,
33  BrowserInterface $browser
34  ) {
35  $browser->open($this->getCategoryUrl($category));
36  \PHPUnit\Framework\Assert::assertFalse(
37  $categoryView->getTopmenu()->isCategoryVisible($category->getName()),
38  'Category can be accessed from the navigation bar in the frontend.'
39  );
40  \PHPUnit\Framework\Assert::assertEquals(
41  self::NOT_FOUND_MESSAGE,
42  $categoryView->getTitleBlock()->getTitle(),
43  'Wrong page is displayed.'
44  );
45  }
46 
53  protected function getCategoryUrl(Category $category)
54  {
55  $categoryUrlKey = [];
56  while ($category) {
57  $categoryUrlKey[] = $category->hasData('url_key')
58  ? strtolower($category->getUrlKey())
59  : trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $category->getName())), '-');
60 
61  $category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
62  if (1 == $category->getParentId()) {
63  $category = null;
64  }
65  }
66 
67  return $_ENV['app_frontend_url'] . implode('/', array_reverse($categoryUrlKey)) . '.html';
68  }
69 
75  public function toString()
76  {
77  return 'Category cannot be accessed from the navigation bar.';
78  }
79 }
processAssert(Category $category, CatalogCategoryView $categoryView, BrowserInterface $browser)