Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RuleProductTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class RuleProductTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $indexBuilder;
20 
24  protected $resourceRule;
25 
26  protected function setUp()
27  {
28  $this->indexBuilder = Bootstrap::getObjectManager()->get(
29  \Magento\CatalogRule\Model\Indexer\IndexBuilder::class
30  );
31  $this->resourceRule = Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\ResourceModel\Rule::class);
32  }
33 
40  public function testReindexAfterRuleCreation()
41  {
44  \Magento\Catalog\Model\ProductRepository::class
45  );
46  $product = $productRepository->get('simple');
47  $product->setData('test_attribute', 'test_attribute_value')->save();
48  $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $product->getId()));
49 
50  // apply all rules
51  $this->indexBuilder->reindexFull();
52 
53  $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $product->getId()));
54  }
55 }