7
7
8
8
namespace Magento \GraphQl \CatalogInventory ;
9
9
10
+ use Magento \Config \Model \ResourceModel \Config ;
11
+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
13
+ use Magento \TestFramework \ObjectManager ;
10
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
15
+ use Magento \CatalogInventory \Model \Configuration ;
11
16
12
17
/**
13
18
* Test for the product only x left in stock
14
19
*/
15
20
class ProductOnlyXLeftInStockTest extends GraphQlAbstract
16
21
{
22
+ /**
23
+ * @var Config $config
24
+ */
25
+ private $ resourceConfig ;
26
+
27
+ /**
28
+ * @var ScopeConfigInterface
29
+ */
30
+ private $ scopeConfig ;
31
+
32
+ /**
33
+ * @var ReinitableConfigInterface
34
+ */
35
+ private $ reinitConfig ;
36
+
37
+ /**
38
+ * @inheritdoc
39
+ */
40
+ protected function setUp (): void
41
+ {
42
+ parent ::setUp ();
43
+
44
+ $ objectManager = ObjectManager::getInstance ();
45
+ $ this ->resourceConfig = $ objectManager ->get (Config::class);
46
+ $ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
47
+ $ this ->reinitConfig = $ objectManager ->get (ReinitableConfigInterface::class);
48
+ }
49
+
17
50
/**
18
51
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_all_fields.php
19
52
*/
@@ -67,11 +100,17 @@ public function testQueryProductOnlyXLeftInStockEnabled()
67
100
/**
68
101
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock_without_categories.php
69
102
* @magentoConfigFixture default_store cataloginventory/options/stock_threshold_qty 120
70
- * @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
71
103
*/
72
104
public function testQueryProductOnlyXLeftInStockOutstock ()
73
105
{
74
106
$ productSku = 'simple ' ;
107
+ $ showOutOfStock = $ this ->scopeConfig ->getValue (Configuration::XML_PATH_SHOW_OUT_OF_STOCK );
108
+
109
+
110
+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK ,
111
+ 1 ,
112
+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT );
113
+ $ this ->reinitConfig ->reinit ();
75
114
76
115
$ query = <<<QUERY
77
116
{
@@ -85,6 +124,9 @@ public function testQueryProductOnlyXLeftInStockOutstock()
85
124
QUERY ;
86
125
$ response = $ this ->graphQlQuery ($ query );
87
126
127
+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK , $ showOutOfStock );
128
+ $ this ->reinitConfig ->reinit ();
129
+
88
130
$ this ->assertArrayHasKey (0 , $ response ['products ' ]['items ' ]);
89
131
$ this ->assertArrayHasKey ('only_x_left_in_stock ' , $ response ['products ' ]['items ' ][0 ]);
90
132
$ this ->assertEquals (0 , $ response ['products ' ]['items ' ][0 ]['only_x_left_in_stock ' ]);
0 commit comments