Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdvancedSearchWithAttributeTest.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\CatalogSearch\Test\Page\AdvancedSearch;
11 use Magento\Indexer\Test\Page\Adminhtml\IndexManagement;
12 use Magento\Mtf\TestCase\Injectable;
17 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductAttributeIndex;
18 use Magento\Mtf\Fixture\FixtureFactory;
19 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductNew;
20 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
21 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
22 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductAttributeNew;
23 use Magento\CatalogSearch\Test\Page\AdvancedResult;
26 use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
29 
72 class AdvancedSearchWithAttributeTest extends Injectable
73 {
74  /* tags */
75  const MVP = 'yes';
76  /* end tags */
77 
83  private $assertSearchAttributeTest;
84 
90  private $products;
91 
97  private $attributeForSearch;
98 
104  private $attributeDisable;
105 
111  private $indexers;
112 
118  private $advancedSearch;
119 
125  private $indexManagement;
126 
132  private $cli;
133 
139  private $resultPage;
140 
146  private $productGrid;
147 
153  private $newProductPage;
154 
160  private $productEdit;
161 
167  private $attributeNewPage;
168 
174  private $assertIndexerStatus;
175 
181  private $assertCreateProducts;
182 
188  private $productAttributePage;
189 
195  private $assertSuccessSaveMessage;
196 
202  private $assertAdvancedSearchResult;
203 
209  private $assertAttributeStatus;
210 
232  public function __inject(
233  IndexManagement $indexManagement,
234  AdvancedSearch $advancedSearch,
235  AdvancedResult $resultPage,
236  CatalogProductIndex $productGrid,
237  CatalogProductNew $newProductPage,
238  CatalogProductEdit $productEdit,
239  AssertIndexerStatus $assertIndexerStatus,
240  AssertProductSaveMessage $assertCreateProducts,
241  CatalogProductAttributeIndex $productAttributePage,
242  CatalogProductAttributeNew $attributeNewPage,
243  AssertSuccessSaveMessage $assertSuccessSaveMessage,
244  AssertSearchAttributeTest $assertSearchAttributeTest,
245  AssertAdvancedSearchProductResult $assertAdvancedSearchResult,
246  AssertProductAttributeSaveMessage $assertAttributeStatus
247  ) {
248  $this->indexManagement = $indexManagement;
249  $this->advancedSearch = $advancedSearch;
250  $this->resultPage = $resultPage;
251  $this->productGrid = $productGrid;
252  $this->newProductPage = $newProductPage;
253  $this->productEdit = $productEdit;
254  $this->assertIndexerStatus = $assertIndexerStatus;
255  $this->assertCreateProducts = $assertCreateProducts;
256  $this->productAttributePage = $productAttributePage;
257  $this->attributeNewPage = $attributeNewPage;
258  $this->assertSuccessSaveMessage = $assertSuccessSaveMessage;
259  $this->assertSearchAttributeTest = $assertSearchAttributeTest;
260  $this->assertAdvancedSearchResult = $assertAdvancedSearchResult;
261  $this->assertAttributeStatus = $assertAttributeStatus;
262  }
263 
283  public function test(
284  Indexer $cli,
285  Category $category,
286  FixtureFactory $fixtureFactory,
287  CatalogProductSimple $productSearch,
288  CatalogProductAttribute $attributeEnable,
289  CatalogProductAttribute $attributeDisable,
290  CatalogProductAttribute $attributeGlobalStatus,
291  $attributeForSearch,
292  array $isVisibleInAdvancedSearch,
293  array $productDropDownList,
294  array $products,
295  $indexers = null
296  ) {
297  $this->cli = $cli;
298  $this->products = $products;
299  $this->attributeDisable = $attributeDisable;
300  $this->attributeForSearch = $attributeForSearch;
301  $this->indexers = explode(',', $indexers);
302 
303  $category->persist();
304 
305  // Indexers Update bu Schedule
306  $this->indexManagement->open();
307  $this->indexManagement->getMainBlock()->updateBySchedule($this->indexers);
308  //Assert attribute Update by Schedule
309  $this->assertSuccessSaveMessage->processAssert($this->indexManagement, $this->indexers);
310 
311  // Full indexers reindex
312  $cli->reindex();
313  // Assert indexers status
314  $this->assertIndexerStatus->processAssert($this->indexManagement, $this->indexers);
315  $this->productAttributePage->open();
316  $this->productAttributePage->getGrid()->searchAndOpen(['attribute_code' => $attributeForSearch['name']]);
317  $this->attributeNewPage->getAttributeForm()->fill($attributeEnable);
318  $this->attributeNewPage->getPageActions()->save();
319  // Assert attribute status
320  $this->assertAttributeStatus->processAssert($this->productAttributePage);
321 
322  // Assert indexers status
323  $this->assertIndexerStatus->processAssert($this->indexManagement, $this->indexers, false);
324 
325  $this->assertSearchAttributeTest->processAssert($this->advancedSearch, $attributeForSearch);
326  $cli->reindex();
327 
328  // Change attribute 'scope mode'
329  $this->productAttributePage->open();
330  $this->productAttributePage->getGrid()->searchAndOpen(['attribute_code' => $attributeForSearch['name']]);
331  $this->attributeNewPage->getAttributeForm()->fill($attributeGlobalStatus);
332  $this->attributeNewPage->getPageActions()->save();
333  // Assert attribute status
334  $this->assertAttributeStatus->processAssert($this->productAttributePage);
335 
336  // Assert indexers status
337  $this->assertIndexerStatus->processAssert($this->indexManagement, $this->indexers, false);
338 
339  // Assert advanced attribute is present(or absent) in Advanced Search Page.
340  $this->assertSearchAttributeTest->processAssert($this->advancedSearch, $attributeForSearch);
341  $cli->reindex();
342 
343  // Create Products
344  $allProducts = [];
345  foreach ($products as $key => $product) {
346  list($fixtureCode, $dataset) = explode('::', $product);
347  $this->productGrid->open();
348  $this->productGrid->getGridPageActionBlock()->addProduct($productDropDownList[$key]);
349  $product = $fixtureFactory->createByCode($fixtureCode, ['dataset' => $dataset]);
350  $this->newProductPage->getProductForm()->fill($product, null, $category);
351  $this->newProductPage->getFormPageActions()->save($product);
352 
353  $this->assertCreateProducts->processAssert($this->productEdit);
354  $allProducts[] = $product;
355  }
356 
357  $cli->reindex();
358  $this->advancedSearch->open();
359  $this->advancedSearch->getForm()->fill($productSearch)->submit();
360 
361  // Assert that Advanced Search result page contains only product(s) according to requested from fixture
362  $this->assertAdvancedSearchResult->processAssert($isVisibleInAdvancedSearch, $allProducts, $this->resultPage);
363  $this->productAttributePage->open();
364  $this->productAttributePage->getGrid()->searchAndOpen(['attribute_code' => $this->attributeForSearch['name']]);
365  $this->attributeNewPage->getAttributeForm()->fill($this->attributeDisable);
366  $this->attributeNewPage->getPageActions()->save();
367  // Assert attribute status
368  $this->assertAttributeStatus->processAssert($this->productAttributePage);
369 
370  $this->assertIndexerStatus->processAssert($this->indexManagement, $this->indexers, false);
371  $cli->reindex();
372  unset($this->attributeForSearch['isVisible']);
373  $this->assertSearchAttributeTest->processAssert($this->advancedSearch, $this->attributeForSearch);
374  }
375 
381  protected function tearDown()
382  {
383  $this->productAttributePage->open();
384  $this->productAttributePage->getGrid()->searchAndOpen(['attribute_code' => $this->attributeForSearch['name']]);
385  $this->attributeNewPage->getAttributeForm()->fill($this->attributeDisable);
386  $this->attributeNewPage->getPageActions()->save();
387  $this->indexManagement->open();
388  $this->indexManagement->getMainBlock()->massaction([], 'Update on Save', false, 'Select All');
389  $this->cli->reindex();
390  }
391 }
__inject(IndexManagement $indexManagement, AdvancedSearch $advancedSearch, AdvancedResult $resultPage, CatalogProductIndex $productGrid, CatalogProductNew $newProductPage, CatalogProductEdit $productEdit, AssertIndexerStatus $assertIndexerStatus, AssertProductSaveMessage $assertCreateProducts, CatalogProductAttributeIndex $productAttributePage, CatalogProductAttributeNew $attributeNewPage, AssertSuccessSaveMessage $assertSuccessSaveMessage, AssertSearchAttributeTest $assertSearchAttributeTest, AssertAdvancedSearchProductResult $assertAdvancedSearchResult, AssertProductAttributeSaveMessage $assertAttributeStatus)
test(Indexer $cli, Category $category, FixtureFactory $fixtureFactory, CatalogProductSimple $productSearch, CatalogProductAttribute $attributeEnable, CatalogProductAttribute $attributeDisable, CatalogProductAttribute $attributeGlobalStatus, $attributeForSearch, array $isVisibleInAdvancedSearch, array $productDropDownList, array $products, $indexers=null)