Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertCategoryOnCustomStore.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;
11 use Magento\Mtf\Client\BrowserInterface;
14 
19 {
23  const NOT_FOUND_MESSAGE = 'Whoops, our bad...';
24 
30  private $categoryViewPage;
31 
37  private $cmsIndexPage;
38 
44  protected $browser;
45 
59  public function processAssert(
60  BrowserInterface $browser,
61  CatalogCategoryView $categoryView,
62  Category $category,
63  Category $initialCategory,
64  CmsIndex $cmsIndex
65  ) {
66  $this->browser = $browser;
67  $this->categoryViewPage = $categoryView;
68  $this->cmsIndexPage = $cmsIndex;
69 
70  $this->verifyUnavailabilityCategoryOnMainStore($category);
71  $this->verifyAvailabilityCategoryOnMainStore($initialCategory);
72  $this->verifyCategoryOnCustomStore($category);
73  }
74 
81  private function verifyUnavailabilityCategoryOnMainStore(Category $category)
82  {
83  $this->browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
84 
85  \PHPUnit\Framework\Assert::assertEquals(
86  self::NOT_FOUND_MESSAGE,
87  $this->categoryViewPage->getTitleBlock()->getTitle(),
88  'Category ' . $category->getName() . ' is available on Main Store, but should not.'
89  );
90  }
91 
98  private function verifyAvailabilityCategoryOnMainStore(Category $category)
99  {
100  $this->browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
101 
102  \PHPUnit\Framework\Assert::assertEquals(
103  $category->getName(),
104  $this->categoryViewPage->getTitleBlock()->getTitle(),
105  'Category ' . $category->getName() . ' is not available on Main Store, but should.'
106  );
107  }
108 
115  private function verifyCategoryOnCustomStore(Category $category)
116  {
117  $this->cmsIndexPage->getStoreSwitcherBlock()->selectStoreView($category->getStoreId()['source']->getName());
118  $this->cmsIndexPage->getLinksBlock()->waitWelcomeMessage();
119 
120  $this->browser->open($_ENV['app_frontend_url'] . $category->getUrlKey() . '.html');
121 
122  \PHPUnit\Framework\Assert::assertEquals(
123  $category->getName(),
124  $this->categoryViewPage->getTitleBlock()->getTitle(),
125  'Category ' . $category->getName() . ' is not available on custom store.'
126  );
127  }
128 
134  public function toString()
135  {
136  return 'Category displayed in appropriate store.';
137  }
138 }
processAssert(BrowserInterface $browser, CatalogCategoryView $categoryView, Category $category, Category $initialCategory, CmsIndex $cmsIndex)