33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Catalog \Model \Indexer \Product \Flat ;
79
810use Magento \Catalog \Model \Product \Attribute \Repository ;
11+ use Magento \Framework \Indexer \StateInterface ;
12+ use Magento \Framework \Indexer \StateInterfaceFactory ;
13+ use Magento \Indexer \Model \ResourceModel \Indexer \State as StateResource ;
14+ use Magento \TestFramework \Helper \Bootstrap ;
15+ use Magento \TestFramework \Indexer \TestCase ;
16+ use Magento \TestFramework \ObjectManager ;
917
1018/**
1119 * Integration tests for \Magento\Catalog\Model\Indexer\Product\Flat\Processor.
1220 */
13- class ProcessorTest extends \ Magento \ TestFramework \ Indexer \ TestCase
21+ class ProcessorTest extends TestCase
1422{
1523 /**
16- * @var \Magento\Catalog\Model\Indexer\Product\Flat\State
24+ * @var ObjectManager
1725 */
18- protected $ _state ;
26+ private $ objectManager ;
1927
2028 /**
21- * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
29+ * @var State
2230 */
23- protected $ _processor ;
31+ private $ state ;
2432
33+ /**
34+ * @var Processor
35+ */
36+ private $ processor ;
37+
38+ /**
39+ * @var StateResource
40+ */
41+ private $ stateResource ;
42+
43+ /**
44+ * @var StateInterfaceFactory;
45+ */
46+ private $ stateFactory ;
47+
48+ /**
49+ * @inheritdoc
50+ */
2551 protected function setUp (): void
2652 {
27- $ this ->_state = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
28- \Magento \Catalog \Model \Indexer \Product \Flat \State::class
29- );
30- $ this ->_processor = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
31- \Magento \Catalog \Model \Indexer \Product \Flat \Processor::class
32- );
53+ $ this ->objectManager = Bootstrap::getObjectManager ();
54+ $ this ->state = $ this ->objectManager ->get (State::class);
55+ $ this ->processor = $ this ->objectManager ->get (Processor::class);
56+ $ this ->stateResource = $ this ->objectManager ->get (StateResource::class);
57+ $ this ->stateFactory = $ this ->objectManager ->get (StateInterfaceFactory::class);
3358 }
3459
3560 /**
3661 * @magentoDbIsolation enabled
3762 * @magentoAppIsolation enabled
3863 * @magentoAppArea adminhtml
3964 * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
65+ *
66+ * @return void
4067 */
41- public function testEnableProductFlat ()
68+ public function testEnableProductFlat (): void
4269 {
43- $ this ->assertTrue ($ this ->_state ->isFlatEnabled ());
44- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
70+ $ this ->assertTrue ($ this ->state ->isFlatEnabled ());
71+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
4572 }
4673
4774 /**
@@ -50,8 +77,10 @@ public function testEnableProductFlat()
5077 * @magentoAppArea adminhtml
5178 * @magentoDataFixture Magento/Catalog/_files/multiple_products.php
5279 * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
80+ *
81+ * @return void
5382 */
54- public function testSaveAttribute ()
83+ public function testSaveAttribute (): void
5584 {
5685 /** @var $product \Magento\Catalog\Model\Product */
5786 $ product = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -61,8 +90,7 @@ public function testSaveAttribute()
6190 /** @var \Magento\Catalog\Model\ResourceModel\Product $productResource */
6291 $ productResource = $ product ->getResource ();
6392 $ productResource ->getAttribute ('sku ' )->setData ('used_for_sort_by ' , 1 )->save ();
64-
65- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
93+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
6694 }
6795
6896 /**
@@ -71,8 +99,10 @@ public function testSaveAttribute()
7199 * @magentoAppArea adminhtml
72100 * @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_attribute_in_flat.php
73101 * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
102+ *
103+ * @return void
74104 */
75- public function testDeleteAttribute ()
105+ public function testDeleteAttribute (): void
76106 {
77107 /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $model */
78108 $ model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
@@ -83,8 +113,7 @@ public function testDeleteAttribute()
83113 $ productAttrubute = $ productAttributeRepository ->get ('flat_attribute ' );
84114 $ productAttributeId = $ productAttrubute ->getAttributeId ();
85115 $ model ->load ($ productAttributeId )->delete ();
86-
87- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
116+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
88117 }
89118
90119 /**
@@ -93,19 +122,23 @@ public function testDeleteAttribute()
93122 * @magentoAppArea adminhtml
94123 * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
95124 * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
125+ *
126+ * @return void
96127 */
97- public function testAddNewStore ()
128+ public function testAddNewStore (): void
98129 {
99- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
130+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
100131 }
101132
102133 /**
103134 * @magentoDbIsolation enabled
104135 * @magentoAppIsolation enabled
105136 * @magentoAppArea adminhtml
106137 * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
138+ *
139+ * @return void
107140 */
108- public function testAddNewStoreGroup ()
141+ public function testAddNewStoreGroup (): void
109142 {
110143 /** @var \Magento\Store\Model\Group $storeGroup */
111144 $ storeGroup = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -115,6 +148,45 @@ public function testAddNewStoreGroup()
115148 ['website_id ' => 1 , 'name ' => 'New Store Group ' , 'root_category_id ' => 2 , 'group_id ' => null ]
116149 );
117150 $ storeGroup ->save ();
118- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
151+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
152+ }
153+
154+ /**
155+ * @magentoDbIsolation disabled
156+ * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 0
157+ *
158+ * @return void
159+ */
160+ public function testReindexAllWithProductFlatDisabled (): void
161+ {
162+ $ this ->updateIndexerStatus ();
163+ $ this ->processor ->reindexAll ();
164+ $ state = $ this ->getIndexerState ();
165+ $ this ->assertEquals (StateInterface::STATUS_INVALID , $ state ->getStatus ());
166+ }
167+
168+ /**
169+ * Update status for indexer
170+ *
171+ * @param string $status
172+ * @return void
173+ */
174+ private function updateIndexerStatus (string $ status = StateInterface::STATUS_INVALID ): void
175+ {
176+ $ state = $ this ->getIndexerState ();
177+ $ state ->setStatus ($ status );
178+ $ this ->stateResource ->save ($ state );
179+ }
180+
181+ /**
182+ * Get Indexer state
183+ *
184+ * @return StateInterface
185+ */
186+ private function getIndexerState (): StateInterface
187+ {
188+ $ state = $ this ->stateFactory ->create ();
189+
190+ return $ state ->loadByIndexer (State::INDEXER_ID );
119191 }
120192}
0 commit comments