3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Catalog \Model \Indexer \Product \Flat ;
7
9
8
10
use 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 ;
9
17
10
18
/**
11
19
* Integration tests for \Magento\Catalog\Model\Indexer\Product\Flat\Processor.
12
20
*/
13
- class ProcessorTest extends \ Magento \ TestFramework \ Indexer \ TestCase
21
+ class ProcessorTest extends TestCase
14
22
{
15
23
/**
16
- * @var \Magento\Catalog\Model\Indexer\Product\Flat\State
24
+ * @var ObjectManager
17
25
*/
18
- protected $ _state ;
26
+ private $ objectManager ;
19
27
20
28
/**
21
- * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
29
+ * @var State
22
30
*/
23
- protected $ _processor ;
31
+ private $ state ;
24
32
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
+ */
25
51
protected function setUp (): void
26
52
{
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);
33
58
}
34
59
35
60
/**
36
61
* @magentoDbIsolation enabled
37
62
* @magentoAppIsolation enabled
38
63
* @magentoAppArea adminhtml
39
64
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
65
+ *
66
+ * @return void
40
67
*/
41
- public function testEnableProductFlat ()
68
+ public function testEnableProductFlat (): void
42
69
{
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 ());
45
72
}
46
73
47
74
/**
@@ -50,8 +77,10 @@ public function testEnableProductFlat()
50
77
* @magentoAppArea adminhtml
51
78
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
52
79
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
80
+ *
81
+ * @return void
53
82
*/
54
- public function testSaveAttribute ()
83
+ public function testSaveAttribute (): void
55
84
{
56
85
/** @var $product \Magento\Catalog\Model\Product */
57
86
$ product = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -61,8 +90,7 @@ public function testSaveAttribute()
61
90
/** @var \Magento\Catalog\Model\ResourceModel\Product $productResource */
62
91
$ productResource = $ product ->getResource ();
63
92
$ 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 ());
66
94
}
67
95
68
96
/**
@@ -71,8 +99,10 @@ public function testSaveAttribute()
71
99
* @magentoAppArea adminhtml
72
100
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_attribute_in_flat.php
73
101
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
102
+ *
103
+ * @return void
74
104
*/
75
- public function testDeleteAttribute ()
105
+ public function testDeleteAttribute (): void
76
106
{
77
107
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $model */
78
108
$ model = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
@@ -83,8 +113,7 @@ public function testDeleteAttribute()
83
113
$ productAttrubute = $ productAttributeRepository ->get ('flat_attribute ' );
84
114
$ productAttributeId = $ productAttrubute ->getAttributeId ();
85
115
$ model ->load ($ productAttributeId )->delete ();
86
-
87
- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
116
+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
88
117
}
89
118
90
119
/**
@@ -93,19 +122,23 @@ public function testDeleteAttribute()
93
122
* @magentoAppArea adminhtml
94
123
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
95
124
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
125
+ *
126
+ * @return void
96
127
*/
97
- public function testAddNewStore ()
128
+ public function testAddNewStore (): void
98
129
{
99
- $ this ->assertTrue ($ this ->_processor ->getIndexer ()->isInvalid ());
130
+ $ this ->assertTrue ($ this ->processor ->getIndexer ()->isInvalid ());
100
131
}
101
132
102
133
/**
103
134
* @magentoDbIsolation enabled
104
135
* @magentoAppIsolation enabled
105
136
* @magentoAppArea adminhtml
106
137
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
138
+ *
139
+ * @return void
107
140
*/
108
- public function testAddNewStoreGroup ()
141
+ public function testAddNewStoreGroup (): void
109
142
{
110
143
/** @var \Magento\Store\Model\Group $storeGroup */
111
144
$ storeGroup = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
@@ -115,6 +148,45 @@ public function testAddNewStoreGroup()
115
148
['website_id ' => 1 , 'name ' => 'New Store Group ' , 'root_category_id ' => 2 , 'group_id ' => null ]
116
149
);
117
150
$ 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 );
119
191
}
120
192
}
0 commit comments