55 */
66namespace Magento \Catalog \Model \Indexer \Product \Flat \Action ;
77
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+
818/**
919 * Full reindex Test
1020 */
1121class FullTest extends \Magento \TestFramework \Indexer \TestCase
1222{
1323 /**
14- * @var \Magento\Catalog\Model\Indexer\Product\Flat\ State
24+ * @var State
1525 */
1626 protected $ _state ;
1727
1828 /**
19- * @var \Magento\Catalog\Model\Indexer\Product\Flat\ Processor
29+ * @var Processor
2030 */
2131 protected $ _processor ;
2232
33+ /**
34+ * @var ObjectManager
35+ */
36+ private $ objectManager ;
37+
38+ /**
39+ * @inheritdoc
40+ */
2341 protected function setUp ()
2442 {
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);
3146 }
3247
3348 /**
@@ -41,12 +56,8 @@ public function testReindexAll()
4156 $ this ->assertTrue ($ this ->_state ->isFlatEnabled ());
4257 $ this ->_processor ->reindexAll ();
4358
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);
5061
5162 $ category = $ categoryFactory ->create ()->load (2 );
5263 $ layer = $ listProduct ->getLayer ();
@@ -61,4 +72,49 @@ public function testReindexAll()
6172 $ this ->assertEquals ('Short description ' , $ product ->getShortDescription ());
6273 }
6374 }
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+ }
64120}
0 commit comments