Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ViewedProductsReportEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\BrowserInterface;
10 use Magento\Mtf\TestCase\Injectable;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Reports\Test\Page\Adminhtml\ProductReportView;
13 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
14 use Magento\Cms\Test\Page\CmsIndex;
15 
32 class ViewedProductsReportEntityTest extends Injectable
33 {
34  /* tags */
35  const MVP = 'no';
36  const STABLE = 'no';
37  /* end tags */
38 
44  protected $productReportView;
45 
51  protected $fixtureFactory;
52 
58  protected $browser;
59 
66 
72  protected $cmsIndex;
73 
84  public function __inject(
85  CmsIndex $cmsIndex,
86  ProductReportView $productReportView,
87  FixtureFactory $fixtureFactory,
88  BrowserInterface $browser,
89  CatalogProductIndex $catalogProductIndexPage
90  ) {
91  $this->cmsIndex = $cmsIndex;
92  $this->productReportView = $productReportView;
93  $this->fixtureFactory = $fixtureFactory;
94  $this->browser = $browser;
95  $this->catalogProductIndexPage = $catalogProductIndexPage;
96  }
97 
106  public function test($products, array $viewsReport, $total)
107  {
108  // Preconditions
109  $this->catalogProductIndexPage->open();
110  $this->catalogProductIndexPage->getProductGrid()->massaction([], 'Delete', true, 'Select All');
111  $productsList = $this->prepareProducts($products);
112  $this->openProducts($productsList, $total);
113  $this->productReportView->open();
114  $this->productReportView->getMessagesBlock()->clickLinkInMessage('notice', 'here');
115 
116  // Steps
117  $this->productReportView->getFilterBlock()->viewsReport($viewsReport);
118  $this->productReportView->getActionsBlock()->showReport();
119  return ['productsList' => $productsList];
120  }
121 
128  protected function prepareProducts($productList)
129  {
130  $productsData = explode(', ', $productList);
131  $products = [];
132  foreach ($productsData as $productConfig) {
133  $product = explode('::', $productConfig);
134  $productFixture = $this->fixtureFactory->createByCode($product[0], ['dataset' => $product[1]]);
135  $productFixture->persist();
136  $products[] = $productFixture;
137  }
138  return $products;
139  }
140 
148  protected function openProducts(array $products, $total)
149  {
150  $total = explode(', ', $total);
151  foreach ($products as $key => $product) {
152  for ($i = 0; $i < $total[$key]; $i++) {
153  $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
154  $this->assertEquals(
155  $product->getName(),
156  $this->cmsIndex->getTitleBlock()->getTitle(),
157  'Could not open product page.'
158  );
159  }
160  }
161  }
162 }
$productsData
Definition: products.php:19
if(empty($quote)) $productList
Definition: items.php:20
$i
Definition: gallery.phtml:31
__inject(CmsIndex $cmsIndex, ProductReportView $productReportView, FixtureFactory $fixtureFactory, BrowserInterface $browser, CatalogProductIndex $catalogProductIndexPage)