Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductOnCustomWebsite.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 
18 {
22  const NOT_FOUND_MESSAGE = 'Whoops, our bad...';
23 
29  protected $productViewPage;
30 
36  protected $browser;
37 
48  public function processAssert(
49  BrowserInterface $browser,
50  CatalogProductView $catalogProductView,
51  FixtureInterface $product
52  ) {
53  $this->browser = $browser;
54  $this->productViewPage = $catalogProductView;
55 
56  $this->verifyProductOnMainWebsite($product);
57  $this->verifyProductOnCustomWebsite($product);
58  }
59 
66  protected function verifyProductOnMainWebsite(FixtureInterface $product)
67  {
68  $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
69 
70  \PHPUnit\Framework\Assert::assertEquals(
71  self::NOT_FOUND_MESSAGE,
72  $this->productViewPage->getTitleBlock()->getTitle(),
73  'Product ' . $product->getName() . ' is available on Main Website, but should not.'
74  );
75  }
76 
83  protected function verifyProductOnCustomWebsite(FixtureInterface $product)
84  {
85  $websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites();
86  foreach ($websites as $website) {
87  $this->browser->open(
88  $_ENV['app_frontend_url'] . 'websites/' . $website->getCode() . '/' . $product->getUrlKey() . '.html'
89  );
90 
91  \PHPUnit\Framework\Assert::assertEquals(
92  $product->getName(),
93  $this->productViewPage->getViewBlock()->getProductName(),
94  'Product ' . $product->getName() . ' is not available on ' . $website->getName() . ' website.'
95  );
96  }
97  }
98 
104  public function toString()
105  {
106  return 'Product on product view page displayed in appropriate Website.';
107  }
108 }
processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)