8
8
namespace Magento \GraphQl \ConfigurableProduct ;
9
9
10
10
use Exception ;
11
+ use Magento \Config \Model \ResourceModel \Config ;
12
+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
13
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
14
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
12
15
use Magento \TestFramework \Helper \Bootstrap ;
13
16
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
+ use Magento \CatalogInventory \Model \Configuration ;
14
18
15
19
/**
16
20
* Add configurable product to cart testcases
@@ -22,13 +26,31 @@ class AddConfigurableProductToCartSingleMutationTest extends GraphQlAbstract
22
26
*/
23
27
private $ getMaskedQuoteIdByReservedOrderId ;
24
28
29
+ /**
30
+ * @var Config $config
31
+ */
32
+ private $ resourceConfig ;
33
+
34
+ /**
35
+ * @var ScopeConfigInterface
36
+ */
37
+ private $ scopeConfig ;
38
+
39
+ /**
40
+ * @var ReinitableConfigInterface
41
+ */
42
+ private $ reinitConfig ;
43
+
25
44
/**
26
45
* @inheritdoc
27
46
*/
28
47
protected function setUp (): void
29
48
{
30
49
$ objectManager = Bootstrap::getObjectManager ();
31
50
$ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
51
+ $ this ->resourceConfig = $ objectManager ->get (Config::class);
52
+ $ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
53
+ $ this ->reinitConfig = $ objectManager ->get (ReinitableConfigInterface::class);
32
54
}
33
55
34
56
/**
@@ -166,9 +188,20 @@ public function testAddNonExistentConfigurableProductParentToCart()
166
188
*/
167
189
public function testOutOfStockVariationToCart ()
168
190
{
191
+ $ showOutOfStock = $ this ->scopeConfig ->getValue (Configuration::XML_PATH_SHOW_OUT_OF_STOCK );
192
+
193
+ // Changing SHOW_OUT_OF_STOCK to show the out of stock option, otherwise graphql won't display it.
194
+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK , 1 );
195
+ $ this ->reinitConfig ->reinit ();
196
+
169
197
$ product = $ this ->getConfigurableProductInfo ();
170
198
$ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
171
199
$ valueIndex = $ product ['configurable_options ' ][0 ]['values ' ][0 ]['value_index ' ];
200
+ // Asserting that the first value is the right option we want to add to cart
201
+ $ this ->assertEquals (
202
+ $ product ['configurable_options ' ][0 ]['values ' ][0 ]['label ' ],
203
+ 'Option 1 '
204
+ );
172
205
$ parentSku = $ product ['sku ' ];
173
206
174
207
$ configurableOptionsQuery = $ this ->generateSuperAttributesUIDQuery ($ attributeId , $ valueIndex );
@@ -191,6 +224,8 @@ public function testOutOfStockVariationToCart()
191
224
$ response ['addProductsToCart ' ]['user_errors ' ][0 ]['message ' ],
192
225
$ expectedErrorMessages
193
226
);
227
+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK , $ showOutOfStock );
228
+ $ this ->reinitConfig ->reinit ();
194
229
}
195
230
196
231
/**
0 commit comments