Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertWidgetRecentlyViewedProducts.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
13 use Magento\Cms\Test\Page\CmsIndex;
15 use Magento\Mtf\Client\BrowserInterface;
16 use Magento\Mtf\Constraint\AbstractConstraint;
17 
21 class AssertWidgetRecentlyViewedProducts extends AbstractConstraint
22 {
28  protected $browser;
29 
35  protected $cmsIndex;
36 
43 
56  public function processAssert(
57  CmsIndex $cmsIndex,
58  Cache $cache,
59  CatalogCategoryView $catalogCategoryView,
60  BrowserInterface $browser,
61  CatalogProductSimple $productSimple,
62  Category $category,
63  Customer $customer
64  ) {
65  $this->browser = $browser;
66  $this->cmsIndex = $cmsIndex;
67  $this->catalogCategoryView = $catalogCategoryView;
68 
69  // Flush cache
70  $cache->flush();
71 
72  // Log in customer
73  $customer->persist();
74  $this->objectManager->create(
75  \Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class,
76  ['customer' => $customer]
77  )->run();
78 
79  // Open products
80  $productSimple->persist();
81  $category->persist();
82  $this->browser->open($_ENV['app_frontend_url'] . $productSimple->getUrlKey() . '.html');
83  $this->waitForJsCoreInitialize();
84  $this->checkRecentlyViewedBlockOnCategory($productSimple, $category);
85  }
86 
91  private function waitForJsCoreInitialize()
92  {
93  sleep(1);
94  }
95 
104  CatalogProductSimple $productSimple,
105  Category $category
106  ) {
107  $this->cmsIndex->open();
108  $this->cmsIndex->getTopmenu()->selectCategoryByName($category->getName());
109 
110  $products = $this->catalogCategoryView->getViewBlock()->getProductsFromRecentlyViewedBlock();
111  \PHPUnit\Framework\Assert::assertTrue(
112  in_array($productSimple->getName(), $products),
113  'Product' . $productSimple->getName() . ' is absent on Recently Viewed block on Category page.'
114  );
115  }
116 
122  public function toString()
123  {
124  return "Widget with type Recently Viewed Products is present on Category page.";
125  }
126 }
$customer
Definition: customers.php:11
processAssert(CmsIndex $cmsIndex, Cache $cache, CatalogCategoryView $catalogCategoryView, BrowserInterface $browser, CatalogProductSimple $productSimple, Category $category, Customer $customer)
checkRecentlyViewedBlockOnCategory(CatalogProductSimple $productSimple, Category $category)