Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SearchTermsReportEntityTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Cms\Test\Page\CmsIndex;
10 use Magento\Reports\Test\Page\Adminhtml\SearchIndex;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\TestCase\Injectable;
13 
27 class SearchTermsReportEntityTest extends Injectable
28 {
29  /* tags */
30  const MVP = 'no';
31  /* end tags */
32 
38  protected $cmsIndex;
39 
45  protected $searchIndex;
46 
52  protected $fixtureFactory;
53 
62  public function __inject(CmsIndex $cmsIndex, SearchIndex $searchIndex, FixtureFactory $fixtureFactory)
63  {
64  $this->cmsIndex = $cmsIndex;
65  $this->searchIndex = $searchIndex;
66  $this->fixtureFactory = $fixtureFactory;
67  }
68 
77  public function test($product, $countProducts, $countSearch)
78  {
79  // Preconditions
80  $productName = $this->createProducts($product, $countProducts);
81 
82  // Steps
83  $this->cmsIndex->open();
84  $this->searchProducts($productName, $countSearch);
85  $this->searchIndex->open();
86 
87  return ['productName' => $productName];
88  }
89 
97  protected function createProducts($product, $countProduct)
98  {
99  $name = 'simpleProductName' . mt_rand();
100  for ($i = 0; $i < $countProduct; $i++) {
101  $productFixture = $this->fixtureFactory->createByCode(
102  'catalogProductSimple',
103  ['dataset' => $product, 'data' => ['name' => $name]]
104  );
105  $productFixture->persist();
106  }
107  return $name;
108  }
109 
117  protected function searchProducts($productName, $countSearch)
118  {
119  for ($i = 0; $i < $countSearch; $i++) {
120  $this->cmsIndex->getSearchBlock()->search($productName);
121  }
122  }
123 }
__inject(CmsIndex $cmsIndex, SearchIndex $searchIndex, FixtureFactory $fixtureFactory)
$i
Definition: gallery.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14