Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductRuleTest.php
Go to the documentation of this file.
1 <?php
7 
10 
15 class ProductRuleTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $resourceRule;
21 
22  protected function setUp()
23  {
24  $this->resourceRule = Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\ResourceModel\Rule::class);
25 
26  Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor::class)
27  ->getIndexer()->isScheduled(false);
28  }
29 
36  public function testReindexAfterSuitableProductSaving()
37  {
40  ProductRepository::class
41  );
42  $product = $productRepository->get('simple');
43  $product->setData('test_attribute', 'test_attribute_value')->save();
44 
45  $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $product->getId()));
46  }
47 
54  public function testReindexWithProductNotVisibleIndividually()
55  {
58  ProductRepository::class
59  );
60  $product = $productRepository->get('simple-3');
61 
63  IndexBuilder::class
64  );
65  $indexBuilder->reindexById($product->getId());
66 
67  $this->assertEquals(
68  7.5,
69  $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $product->getId()),
70  "Catalog price rule doesn't apply to product with visibility value \"Not Visibility Individually\""
71  );
72  }
73 }