Skip to content

Commit 9a8cf3a

Browse files
author
Vitaliy Boyko
committed
graphQl-812: test Add Variation From Another Configurable ProductToCart
1 parent 7cf99d1 commit 9a8cf3a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,48 @@ public function testAddConfigurableProductToCart()
6767
self::assertArrayHasKey('value_label', $option);
6868
}
6969

70+
/**
71+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_products.php
72+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
73+
*/
74+
public function testAddVariationFromAnotherConfigurableProductToCart()
75+
{
76+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable_12345'));
77+
$product = current($searchResponse['products']['items']);
78+
$attributeId = (int) $product['configurable_options'][0]['attribute_id'];
79+
$optionId = $product['configurable_options'][0]['values'][1]['value_index'];
80+
81+
$quantity = 2;
82+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
83+
$parentSku = $product['sku'];
84+
85+
//'configurable' -> ['simple_10', 'simple_20']
86+
//'configurable_12345' -> ['simple_30', 'simple_40']
87+
//'simple_20' has same configurable option value index (super attribute) as 'simple_40'
88+
//therefore 'simple_40' should be added to cart
89+
$sku = 'simple_20';
90+
91+
$query = $this->getQuery(
92+
$maskedQuoteId,
93+
$parentSku,
94+
$sku,
95+
$quantity
96+
);
97+
98+
$response = $this->graphQlMutation($query);
99+
100+
$cartItem = current($response['addConfigurableProductsToCart']['cart']['items']);
101+
self::assertEquals($quantity, $cartItem['quantity']);
102+
self::assertEquals($parentSku, $cartItem['product']['sku']);
103+
self::assertArrayHasKey('configurable_options', $cartItem);
104+
105+
$option = current($cartItem['configurable_options']);
106+
self::assertEquals($attributeId, $option['id']);
107+
self::assertEquals($optionId, $option['value_id']);
108+
self::assertArrayHasKey('option_label', $option);
109+
self::assertArrayHasKey('value_label', $option);
110+
}
111+
70112
/**
71113
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
72114
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php

0 commit comments

Comments
 (0)