5
5
*/
6
6
namespace Magento \Catalog \Model \Indexer \Product \Flat \Action ;
7
7
8
+ use Magento \Catalog \Api \Data \ProductInterface ;
9
+ use Magento \Catalog \Block \Product \ListProduct ;
10
+ use Magento \Catalog \Model \CategoryFactory ;
11
+ use Magento \Catalog \Model \Indexer \Product \Flat \Processor ;
12
+ use Magento \Catalog \Model \Indexer \Product \Flat \State ;
13
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory as ProductCollectionFactory ;
14
+ use Magento \Store \Model \StoreManagerInterface ;
15
+ use Magento \TestFramework \Helper \Bootstrap ;
16
+ use Magento \TestFramework \ObjectManager ;
17
+
8
18
/**
9
19
* Full reindex Test
10
20
*/
11
21
class FullTest extends \Magento \TestFramework \Indexer \TestCase
12
22
{
13
23
/**
14
- * @var \Magento\Catalog\Model\Indexer\Product\Flat\ State
24
+ * @var State
15
25
*/
16
26
protected $ _state ;
17
27
18
28
/**
19
- * @var \Magento\Catalog\Model\Indexer\Product\Flat\ Processor
29
+ * @var Processor
20
30
*/
21
31
protected $ _processor ;
22
32
33
+ /**
34
+ * @var ObjectManager
35
+ */
36
+ private $ objectManager ;
37
+
38
+ /**
39
+ * @inheritdoc
40
+ */
23
41
protected function setUp ()
24
42
{
25
- $ this ->_state = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
26
- \Magento \Catalog \Model \Indexer \Product \Flat \State::class
27
- );
28
- $ this ->_processor = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
29
- \Magento \Catalog \Model \Indexer \Product \Flat \Processor::class
30
- );
43
+ $ this ->objectManager = Bootstrap::getObjectManager ();
44
+ $ this ->_state = $ this ->objectManager ->get (State::class);
45
+ $ this ->_processor = $ this ->objectManager ->get (Processor::class);
31
46
}
32
47
33
48
/**
@@ -41,12 +56,8 @@ public function testReindexAll()
41
56
$ this ->assertTrue ($ this ->_state ->isFlatEnabled ());
42
57
$ this ->_processor ->reindexAll ();
43
58
44
- $ categoryFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
45
- \Magento \Catalog \Model \CategoryFactory::class
46
- );
47
- $ listProduct = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
48
- \Magento \Catalog \Block \Product \ListProduct::class
49
- );
59
+ $ categoryFactory = $ this ->objectManager ->get (CategoryFactory::class);
60
+ $ listProduct = $ this ->objectManager ->get (ListProduct::class);
50
61
51
62
$ category = $ categoryFactory ->create ()->load (2 );
52
63
$ layer = $ listProduct ->getLayer ();
@@ -61,4 +72,49 @@ public function testReindexAll()
61
72
$ this ->assertEquals ('Short description ' , $ product ->getShortDescription ());
62
73
}
63
74
}
75
+
76
+ /**
77
+ * @magentoAppArea frontend
78
+ * @magentoDbIsolation disabled
79
+ * @magentoAppIsolation enabled
80
+ * @magentoDataFixture Magento/Catalog/_files/product_simple_multistore.php
81
+ * @magentoDataFixture Magento/Catalog/_files/enable_catalog_product_flat_indexer.php
82
+ */
83
+ public function testReindexAllMultipleStores ()
84
+ {
85
+ $ this ->_state = $ this ->objectManager ->create (State::class);
86
+ $ this ->_processor = $ this ->objectManager ->create (Processor::class);
87
+
88
+ $ this ->assertTrue ($ this ->_state ->isFlatEnabled ());
89
+ $ this ->_processor ->reindexAll ();
90
+
91
+ /** @var ProductCollectionFactory $productCollectionFactory */
92
+ $ productCollectionFactory = $ this ->objectManager ->create (ProductCollectionFactory::class);
93
+ /** @var StoreManagerInterface $storeManager */
94
+ $ storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
95
+ $ store = $ storeManager ->getStore ('fixturestore ' );
96
+
97
+ $ expectedData = [
98
+ $ storeManager ->getDefaultStoreView ()->getId () => 'Simple Product One ' ,
99
+ $ store ->getId () => 'StoreTitle ' ,
100
+ ];
101
+
102
+ foreach ($ expectedData as $ storeId => $ productName ) {
103
+ $ storeManager ->setCurrentStore ($ storeId );
104
+ $ productCollection = $ productCollectionFactory ->create ();
105
+
106
+ $ this ->assertTrue (
107
+ $ productCollection ->isEnabledFlat (),
108
+ 'Flat should be enabled for product collection. '
109
+ );
110
+
111
+ $ productCollection ->addIdFilter (1 )->addAttributeToSelect (ProductInterface::NAME );
112
+
113
+ $ this ->assertEquals (
114
+ $ productName ,
115
+ $ productCollection ->getFirstItem ()->getName (),
116
+ 'Wrong product name specified per store. '
117
+ );
118
+ }
119
+ }
64
120
}
0 commit comments