5
5
*/
6
6
namespace Magento \CatalogInventory \Model \Indexer \Stock \Action ;
7
7
8
+ use Magento \TestFramework \Helper \Bootstrap ;
9
+ use Magento \Framework \ObjectManagerInterface ;
10
+ use Magento \CatalogInventory \Model \Indexer \Stock \Processor ;
11
+ use Magento \Catalog \Model \CategoryFactory ;
12
+ use Magento \Catalog \Block \Product \ListProduct ;
13
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
14
+ use Magento \Catalog \Model \Product ;
15
+ use PHPUnit \Framework \TestCase ;
16
+
8
17
/**
9
18
* Full reindex Test
10
19
*/
11
- class FullTest extends \ PHPUnit \ Framework \ TestCase
20
+ class FullTest extends TestCase
12
21
{
13
22
/**
14
- * @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
23
+ * @var ObjectManagerInterface
24
+ */
25
+ private $ objectManager ;
26
+
27
+ /**
28
+ * @var Processor
15
29
*/
16
30
protected $ _processor ;
17
31
32
+ /**
33
+ * @inheritdoc
34
+ */
18
35
protected function setUp ()
19
36
{
20
- $ this ->_processor = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
21
- \Magento \CatalogInventory \Model \Indexer \Stock \Processor::class
22
- );
37
+ $ this ->objectManager = Bootstrap::getObjectManager ();
38
+ $ this ->_processor = $ this ->objectManager ->get (Processor::class);
23
39
}
24
40
25
41
/**
42
+ * Reindex all
43
+ *
26
44
* @magentoDbIsolation disabled
27
45
* @magentoAppIsolation enabled
28
46
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
@@ -31,13 +49,9 @@ public function testReindexAll()
31
49
{
32
50
$ this ->_processor ->reindexAll ();
33
51
34
- $ categoryFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
35
- \Magento \Catalog \Model \CategoryFactory::class
36
- );
37
- /** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
38
- $ listProduct = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
39
- \Magento \Catalog \Block \Product \ListProduct::class
40
- );
52
+ $ categoryFactory = $ this ->objectManager ->get (CategoryFactory::class);
53
+ /** @var ListProduct $listProduct */
54
+ $ listProduct = $ this ->objectManager ->get (ListProduct::class);
41
55
42
56
$ category = $ categoryFactory ->create ()->load (2 );
43
57
$ layer = $ listProduct ->getLayer ();
@@ -61,4 +75,37 @@ public function testReindexAll()
61
75
$ this ->assertEquals (100 , $ product ->getQty ());
62
76
}
63
77
}
78
+
79
+ /**
80
+ * Reindex with disabled product
81
+ *
82
+ * @return void
83
+ * @magentoDbIsolation disabled
84
+ * @magentoAppIsolation enabled
85
+ * @magentoDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
86
+ */
87
+ public function testReindexAllWithDisabledProduct (): void
88
+ {
89
+ $ productCollectionFactory = $ this ->objectManager ->get (CollectionFactory::class);
90
+ $ productCollection = $ productCollectionFactory
91
+ ->create ()
92
+ ->addAttributeToSelect ('* ' )
93
+ ->addAttributeToFilter ('sku ' , ['eq ' => 'simple3 ' ])
94
+ ->addAttributeToSort ('created_at ' , 'DESC ' )
95
+ ->joinField (
96
+ 'stock_status ' ,
97
+ 'cataloginventory_stock_status ' ,
98
+ 'stock_status ' ,
99
+ 'product_id=entity_id ' ,
100
+ '{{table}}.stock_id=1 ' ,
101
+ 'left '
102
+ )->load ();
103
+
104
+ $ this ->assertCount (1 , $ productCollection );
105
+
106
+ /** @var Product $product */
107
+ foreach ($ productCollection as $ product ) {
108
+ $ this ->assertEquals (1 , $ product ->getData ('stock_status ' ));
109
+ }
110
+ }
64
111
}
0 commit comments