88namespace Magento \GraphQl \ConfigurableProduct ;
99
1010use Exception ;
11+ use Magento \Config \Model \ResourceModel \Config ;
12+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
13+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1114use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
1215use Magento \TestFramework \Helper \Bootstrap ;
1316use Magento \TestFramework \TestCase \GraphQlAbstract ;
17+ use Magento \CatalogInventory \Model \Configuration ;
1418
1519/**
1620 * Add configurable product to cart testcases
@@ -22,13 +26,31 @@ class AddConfigurableProductToCartSingleMutationTest extends GraphQlAbstract
2226 */
2327 private $ getMaskedQuoteIdByReservedOrderId ;
2428
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+
2544 /**
2645 * @inheritdoc
2746 */
2847 protected function setUp (): void
2948 {
3049 $ objectManager = Bootstrap::getObjectManager ();
3150 $ 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);
3254 }
3355
3456 /**
@@ -166,9 +188,20 @@ public function testAddNonExistentConfigurableProductParentToCart()
166188 */
167189 public function testOutOfStockVariationToCart ()
168190 {
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+
169197 $ product = $ this ->getConfigurableProductInfo ();
170198 $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
171199 $ 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+ );
172205 $ parentSku = $ product ['sku ' ];
173206
174207 $ configurableOptionsQuery = $ this ->generateSuperAttributesUIDQuery ($ attributeId , $ valueIndex );
@@ -191,6 +224,8 @@ public function testOutOfStockVariationToCart()
191224 $ response ['addProductsToCart ' ]['user_errors ' ][0 ]['message ' ],
192225 $ expectedErrorMessages
193226 );
227+ $ this ->resourceConfig ->saveConfig (Configuration::XML_PATH_SHOW_OUT_OF_STOCK , $ showOutOfStock );
228+ $ this ->reinitConfig ->reinit ();
194229 }
195230
196231 /**
0 commit comments