Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductsCountInLayeredNavigationTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use Magento\Mtf\TestCase\Injectable;
12 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
13 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
14 use Magento\Mtf\Fixture\FixtureFactory;
15 
46 class ProductsCountInLayeredNavigationTest extends Injectable
47 {
54 
60  protected $editProductPage;
61 
67  protected $fixtureFactory;
68 
77  public function __inject(
78  CatalogProductIndex $catalogProductIndex,
79  CatalogProductEdit $editProductPage,
80  FixtureFactory $fixtureFactory
81  ) {
82  $this->catalogProductIndex = $catalogProductIndex;
83  $this->editProductPage = $editProductPage;
84  $this->fixtureFactory = $fixtureFactory;
85  }
86 
94  public function test(
95  Category $category,
96  bool $disableFromProductsGreed = true
97  ) {
98  // Preconditions
99  $category->persist();
100  // Steps
101  $products = $category->getDataFieldConfig('category_products')['source']->getProducts();
104  foreach ($products as $product) {
105  $configurableOptions = array_merge(
107  $product->getConfigurableAttributesData()['matrix']
108  );
109  }
110  // Disable configurable options
111  if ($disableFromProductsGreed) {
112  $this->catalogProductIndex->open();
113  $this->catalogProductIndex->getProductGrid()->massaction(
114  array_map(
115  function ($assignedProduct) {
116  return ['sku' => $assignedProduct['sku']];
117  },
119  ),
120  ['Change status' => 'Disable']
121  );
122  } else {
123  $productToDisable = $this->fixtureFactory->createByCode(
124  'catalogProductSimple',
125  ['data' => ['status' => 'No']]
126  );
127  foreach ($configurableOptions as $configurableOption) {
128  $filter = ['sku' => $configurableOption['sku']];
129  $this->catalogProductIndex->open();
130  $this->catalogProductIndex->getProductGrid()->searchAndOpen($filter);
131  $this->editProductPage->getProductForm()->fill($productToDisable);
132  $this->editProductPage->getFormPageActions()->save();
133  }
134  }
135 
136  return [
137  'products' => $configurableOptions,
138  ];
139  }
140 }
__inject(CatalogProductIndex $catalogProductIndex, CatalogProductEdit $editProductPage, FixtureFactory $fixtureFactory)