Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateCatalogRulesIndexerTest.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\TestCase\Injectable;
10 use Magento\CatalogRule\Test\Fixture\CatalogRule;
13 use Magento\Mtf\TestStep\TestStepFactory;
18 use Magento\Indexer\Test\Page\Adminhtml\IndexManagement;
19 use Magento\Cms\Test\Page\CmsIndex;
20 use Magento\Catalog\Test\Page\Category\CatalogCategoryView;
21 use Magento\Catalog\Test\Page\Product\CatalogProductView;
22 use Magento\CatalogRule\Test\Page\Adminhtml\CatalogRuleIndex;
23 use Magento\CatalogRule\Test\Page\Adminhtml\CatalogRuleNew;
25 
58 class CreateCatalogRulesIndexerTest extends Injectable
59 {
60  /* tags */
61  const SEVERITY = 'S2';
62  /* end tags */
63 
69  private $catalogRuleIndex;
70 
76  private $catalogRuleNew;
77 
83  private $indexManagement;
84 
90  private $cmsIndexPage;
91 
97  private $catalogProductViewPage;
98 
104  private $catalogCategoryViewPage;
105 
111  private $assertIndexerStatus;
112 
118  private $assertCatalogPriceRuleNotAppliedProductPage;
119 
125  private $assertCatalogPriceRuleAppliedProductPage;
126 
132  private $stepFactory;
133 
150  public function __inject(
151  IndexManagement $indexManagement,
152  CatalogRuleIndex $catalogRuleIndex,
153  CatalogRuleNew $catalogRuleNew,
154  CmsIndex $cmsIndexPage,
155  CatalogProductView $catalogProductViewPage,
156  CatalogCategoryView $catalogCategoryViewPage,
157  AssertIndexerStatus $assertIndexerStatus,
158  AssertCatalogPriceRuleNotAppliedProductPage $assertCatalogPriceRuleNotAppliedProductPage,
159  AssertCatalogPriceRuleAppliedProductPage $assertCatalogPriceRuleAppliedProductPage,
160  TestStepFactory $stepFactory
161  ) {
162  $this->indexManagement = $indexManagement;
163  $this->catalogRuleIndex = $catalogRuleIndex;
164  $this->catalogRuleNew = $catalogRuleNew;
165  $this->cmsIndexPage = $cmsIndexPage;
166  $this->catalogProductViewPage = $catalogProductViewPage;
167  $this->catalogCategoryViewPage = $catalogCategoryViewPage;
168  $this->assertIndexerStatus = $assertIndexerStatus;
169  $this->assertCatalogPriceRuleNotAppliedProductPage = $assertCatalogPriceRuleNotAppliedProductPage;
170  $this->assertCatalogPriceRuleAppliedProductPage = $assertCatalogPriceRuleAppliedProductPage;
171  $this->stepFactory = $stepFactory;
172  }
173 
188  public function test(
189  Indexer $cli,
190  CatalogRule $catalogPriceRule,
191  CatalogRule $catalogPriceRuleOriginal,
192  Cron $cron,
193  array $productPrice1 = null,
194  array $productPrice2 = null,
195  Customer $customer = null,
196  array $products = null,
197  $indexers = null
198  ) {
199  $products = $this->stepFactory->create(CreateProductsStep::class, ['products' => $products])->run()['products'];
200  $cli->reindex();
201  if ($customer !== null) {
202  $customer->persist();
203  }
204  $catalogPriceRuleOriginal->persist();
205  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, true);
206  $this->objectManager->create(\Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep::class)->run();
207  $this->assertCatalogPriceRuleNotAppliedProductPage->processAssert(
208  $this->catalogProductViewPage,
209  $this->cmsIndexPage,
210  $this->catalogCategoryViewPage,
211  $products
212  );
213  $filter = [
214  'name' => $catalogPriceRuleOriginal->getName(),
215  'rule_id' => $catalogPriceRuleOriginal->getId(),
216  ];
217  $this->catalogRuleIndex->open();
218  $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
219  $this->catalogRuleNew->getFormPageActions()->saveAndApply();
220  $cron->run();
221  $cron->run();
222  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, true);
223  $this->assertCatalogPriceRuleAppliedProductPage->processAssert(
224  $this->catalogProductViewPage,
225  $this->cmsIndexPage,
226  $this->catalogCategoryViewPage,
227  $products,
228  $productPrice1,
229  $customer
230  );
231  $this->catalogRuleIndex->open();
232  $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
233  $this->catalogRuleNew->getEditForm()->fill($catalogPriceRule);
234  $this->catalogRuleNew->getFormPageActions()->saveAndApply();
235  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, false);
236  $this->objectManager->create(\Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep::class)->run();
237  $this->assertCatalogPriceRuleNotAppliedProductPage->processAssert(
238  $this->catalogProductViewPage,
239  $this->cmsIndexPage,
240  $this->catalogCategoryViewPage,
241  $products
242  );
243  $cron->run();
244  $cron->run();
245  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, true);
246  $this->assertCatalogPriceRuleAppliedProductPage->processAssert(
247  $this->catalogProductViewPage,
248  $this->cmsIndexPage,
249  $this->catalogCategoryViewPage,
250  $products,
251  $productPrice2,
252  $customer
253  );
254  $this->catalogRuleIndex->open();
255  $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
256  $this->catalogRuleNew->getFormPageActions()->delete();
257  $this->catalogRuleNew->getModalBlock()->acceptAlert();
258  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, false);
259  $this->assertCatalogPriceRuleAppliedProductPage->processAssert(
260  $this->catalogProductViewPage,
261  $this->cmsIndexPage,
262  $this->catalogCategoryViewPage,
263  $products,
264  $productPrice2,
265  $customer
266  );
267  $cron->run();
268  $cron->run();
269  $this->assertIndexerStatus->processAssert($this->indexManagement, $indexers, true);
270  $this->objectManager->create(\Magento\Customer\Test\TestStep\LogoutCustomerOnFrontendStep::class)->run();
271  $this->assertCatalogPriceRuleNotAppliedProductPage->processAssert(
272  $this->catalogProductViewPage,
273  $this->cmsIndexPage,
274  $this->catalogCategoryViewPage,
275  $products
276  );
277  }
278 
284  public function tearDown()
285  {
286  $this->objectManager->create(\Magento\CatalogRule\Test\TestStep\DeleteAllCatalogRulesStep::class)->run();
287  }
288 }
test(Indexer $cli, CatalogRule $catalogPriceRule, CatalogRule $catalogPriceRuleOriginal, Cron $cron, array $productPrice1=null, array $productPrice2=null, Customer $customer=null, array $products=null, $indexers=null)
$customer
Definition: customers.php:11
__inject(IndexManagement $indexManagement, CatalogRuleIndex $catalogRuleIndex, CatalogRuleNew $catalogRuleNew, CmsIndex $cmsIndexPage, CatalogProductView $catalogProductViewPage, CatalogCategoryView $catalogCategoryViewPage, AssertIndexerStatus $assertIndexerStatus, AssertCatalogPriceRuleNotAppliedProductPage $assertCatalogPriceRuleNotAppliedProductPage, AssertCatalogPriceRuleAppliedProductPage $assertCatalogPriceRuleAppliedProductPage, TestStepFactory $stepFactory)