66namespace Magento \CatalogRule \Model \Indexer ;
77
88use Magento \Catalog \Api \ProductRepositoryInterface ;
9+ use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
10+ use Magento \Framework \App \ResourceConnection ;
911use Magento \Store \Model \StoreManagerInterface ;
1012use Magento \TestFramework \Helper \Bootstrap ;
1113
@@ -46,6 +48,16 @@ class IndexerBuilderTest extends \PHPUnit\Framework\TestCase
4648 */
4749 private $ productRepository ;
4850
51+ /**
52+ * @var ResourceConnection
53+ */
54+ private $ connection ;
55+
56+ /**
57+ * @var Processor
58+ */
59+ private $ indexProductProcessor ;
60+
4961 protected function setUp (): void
5062 {
5163 $ this ->indexerBuilder = Bootstrap::getObjectManager ()->get (
@@ -55,6 +67,8 @@ protected function setUp(): void
5567 $ this ->product = Bootstrap::getObjectManager ()->get (\Magento \Catalog \Model \Product::class);
5668 $ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
5769 $ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
70+ $ this ->connection = Bootstrap::getObjectManager ()->get (ResourceConnection::class);
71+ $ this ->indexProductProcessor = Bootstrap::getObjectManager ()->get (Processor::class);
5872 }
5973
6074 protected function tearDown (): void
@@ -171,6 +185,45 @@ public function testReindexFull()
171185 $ this ->assertFalse ($ this ->resourceRule ->getRulePrice (new \DateTime (), 1 , 1 , $ this ->productThird ->getId ()));
172186 }
173187
188+ /**
189+ * Tests restoring triggers on `catalogrule_product_price` table after full reindexing in 'Update by schedule' mode.
190+ *
191+ * @magentoDbIsolation disabled
192+ * @magentoAppIsolation enabled
193+ */
194+ public function testRestoringTriggersAfterFullReindex ()
195+ {
196+ $ tableName = $ this ->connection ->getTableName ('catalogrule_product_price ' );
197+
198+ $ this ->indexProductProcessor ->getIndexer ()->setScheduled (false );
199+ $ this ->assertEquals (0 , $ this ->getTriggersCount ($ tableName ));
200+
201+ $ this ->indexProductProcessor ->getIndexer ()->setScheduled (true );
202+ $ this ->assertGreaterThan (0 , $ this ->getTriggersCount ($ tableName ));
203+
204+ $ this ->indexerBuilder ->reindexFull ();
205+ $ this ->assertGreaterThan (0 , $ this ->getTriggersCount ($ tableName ));
206+
207+ $ this ->indexProductProcessor ->getIndexer ()->setScheduled (false );
208+ $ this ->assertEquals (0 , $ this ->getTriggersCount ($ tableName ));
209+ }
210+
211+ /**
212+ * Returns triggers count.
213+ *
214+ * @param string $tableName
215+ * @return int
216+ * @throws \Zend_Db_Statement_Exception
217+ */
218+ private function getTriggersCount (string $ tableName ): int
219+ {
220+ return count (
221+ $ this ->connection ->getConnection ()
222+ ->query ('SHOW TRIGGERS LIKE \'' . $ tableName . '\'' )
223+ ->fetchAll ()
224+ );
225+ }
226+
174227 protected function prepareProducts ()
175228 {
176229 $ product = $ this ->product ->loadByAttribute ('sku ' , 'simple ' );
0 commit comments