Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BatchIndexTest.php
Go to the documentation of this file.
1 <?php
8 
10 
17 class BatchIndexTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $productRepository;
23 
27  protected $product;
28 
32  protected $resourceRule;
33 
34  protected function setUp()
35  {
36  $this->resourceRule = Bootstrap::getObjectManager()->get(\Magento\CatalogRule\Model\ResourceModel\Rule::class);
37  $this->product = Bootstrap::getObjectManager()->get(\Magento\Catalog\Model\Product::class);
38  $this->productRepository = Bootstrap::getObjectManager()->get(\Magento\Catalog\Model\ProductRepository::class);
39  }
40 
41  protected function tearDown()
42  {
45  ->get(\Magento\Framework\Registry::class);
46 
47  $registry->unregister('isSecureArea');
48  $registry->register('isSecureArea', true);
49 
52  \Magento\Catalog\Model\ResourceModel\Product\Collection::class
53  );
54  $productCollection->delete();
55 
56  $registry->unregister('isSecureArea');
57  $registry->register('isSecureArea', false);
58 
59  parent::tearDown();
60  }
61 
70  public function testPriceForSmallBatch($batchCount, $price, $expectedPrice)
71  {
73 
77  $indexerBuilder = Bootstrap::getObjectManager()->create(
78  \Magento\CatalogRule\Model\Indexer\IndexBuilder::class,
79  ['batchCount' => $batchCount]
80  );
81 
82  $indexerBuilder->reindexFull();
83 
84  foreach ([0, 1] as $customerGroupId) {
85  foreach ($productIds as $productId) {
86  $this->assertEquals(
87  $expectedPrice,
88  $this->resourceRule->getRulePrice(new \DateTime(), 1, $customerGroupId, $productId)
89  );
90  }
91  }
92  }
93 
97  protected function prepareProducts($price)
98  {
99  $this->product = $this->productRepository->get('simple');
101  $productSecond->setId(null)
102  ->setUrlKey(null)
103  ->setSku(uniqid($this->product->getSku() . '-'))
104  ->setName(uniqid($this->product->getName() . '-'))
105  ->setWebsiteIds([1]);
106  $productSecond->save();
107  $productSecond->setPrice($price)->save();
109  $productThird->setId(null)
110  ->setUrlKey(null)
111  ->setSku(uniqid($this->product->getSku() . '-'))
112  ->setName(uniqid($this->product->getName() . '-'))
113  ->setWebsiteIds([1])
114  ->save();
115  $productThird->setPrice($price)->save();
116  return [
117  $productSecond->getEntityId(),
118  $productThird->getEntityId(),
119  ];
120  }
121 
125  public function dataProvider()
126  {
127  return [
128  [1, 20, 17],
129  [3, 40, 36],
130  [3, 60, 55],
131  [5, 100, 93],
132  [8, 200, 188],
133  [10, 500, 473],
134  [11, 760, 720],
135  ];
136  }
137 }
$price