From 9a8cf3a5affede83010fa31879a59f7f482b1db3 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 28 Aug 2019 11:10:25 +0300 Subject: [PATCH] graphQl-812: test Add Variation From Another Configurable ProductToCart --- .../AddConfigurableProductToCartTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php index 0e334999599b4..36120c0535d49 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php @@ -67,6 +67,48 @@ public function testAddConfigurableProductToCart() self::assertArrayHasKey('value_label', $option); } + /** + * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products.php + * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php + */ + public function testAddVariationFromAnotherConfigurableProductToCart() + { + $searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable_12345')); + $product = current($searchResponse['products']['items']); + $attributeId = (int) $product['configurable_options'][0]['attribute_id']; + $optionId = $product['configurable_options'][0]['values'][1]['value_index']; + + $quantity = 2; + $maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1'); + $parentSku = $product['sku']; + + //'configurable' -> ['simple_10', 'simple_20'] + //'configurable_12345' -> ['simple_30', 'simple_40'] + //'simple_20' has same configurable option value index (super attribute) as 'simple_40' + //therefore 'simple_40' should be added to cart + $sku = 'simple_20'; + + $query = $this->getQuery( + $maskedQuoteId, + $parentSku, + $sku, + $quantity + ); + + $response = $this->graphQlMutation($query); + + $cartItem = current($response['addConfigurableProductsToCart']['cart']['items']); + self::assertEquals($quantity, $cartItem['quantity']); + self::assertEquals($parentSku, $cartItem['product']['sku']); + self::assertArrayHasKey('configurable_options', $cartItem); + + $option = current($cartItem['configurable_options']); + self::assertEquals($attributeId, $option['id']); + self::assertEquals($optionId, $option['value_id']); + self::assertArrayHasKey('option_label', $option); + self::assertArrayHasKey('value_label', $option); + } + /** * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php