6
6
namespace Magento \CatalogRule \Model \Indexer ;
7
7
8
8
use Magento \Catalog \Api \ProductRepositoryInterface ;
9
+ use Magento \Catalog \Model \Indexer \Product \Price \Processor ;
10
+ use Magento \Framework \App \ResourceConnection ;
9
11
use Magento \Store \Model \StoreManagerInterface ;
10
12
use Magento \TestFramework \Helper \Bootstrap ;
11
13
@@ -46,6 +48,16 @@ class IndexerBuilderTest extends \PHPUnit\Framework\TestCase
46
48
*/
47
49
private $ productRepository ;
48
50
51
+ /**
52
+ * @var ResourceConnection
53
+ */
54
+ private $ connection ;
55
+
56
+ /**
57
+ * @var Processor
58
+ */
59
+ private $ indexProductProcessor ;
60
+
49
61
protected function setUp (): void
50
62
{
51
63
$ this ->indexerBuilder = Bootstrap::getObjectManager ()->get (
@@ -55,6 +67,8 @@ protected function setUp(): void
55
67
$ this ->product = Bootstrap::getObjectManager ()->get (\Magento \Catalog \Model \Product::class);
56
68
$ this ->storeManager = Bootstrap::getObjectManager ()->get (StoreManagerInterface::class);
57
69
$ this ->productRepository = Bootstrap::getObjectManager ()->get (ProductRepositoryInterface::class);
70
+ $ this ->connection = Bootstrap::getObjectManager ()->get (ResourceConnection::class);
71
+ $ this ->indexProductProcessor = Bootstrap::getObjectManager ()->get (Processor::class);
58
72
}
59
73
60
74
protected function tearDown (): void
@@ -171,6 +185,45 @@ public function testReindexFull()
171
185
$ this ->assertFalse ($ this ->resourceRule ->getRulePrice (new \DateTime (), 1 , 1 , $ this ->productThird ->getId ()));
172
186
}
173
187
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
+
174
227
protected function prepareProducts ()
175
228
{
176
229
$ product = $ this ->product ->loadByAttribute ('sku ' , 'simple ' );
0 commit comments