Skip to content

Commit b339166

Browse files
committed
#31332:Schema changes implementation for configurable option selection - fixed webapi tests
1 parent 6831e52 commit b339166

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Options/SelectionUidFormatter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ public function __construct(Uid $idEncoder)
4646
*/
4747
public function encode(int $attributeId, int $indexId): string
4848
{
49-
return $this->idEncoder->encode(implode(self::UID_SEPARATOR, [
50-
self::UID_PREFIX,
51-
$attributeId,
52-
$indexId
53-
]));
49+
return $this->idEncoder->encode(implode(self::UID_SEPARATOR, [self::UID_PREFIX, $attributeId, $indexId]));
5450
}
5551

5652
/**

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

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\GraphQl\ConfigurableProduct;
910

1011
use Exception;
12+
use Magento\CatalogInventory\Model\Configuration;
1113
use Magento\Config\Model\ResourceModel\Config;
14+
use Magento\ConfigurableProductGraphQl\Model\Options\SelectionUidFormatter;
1215
use Magento\Framework\App\Config\ReinitableConfigInterface;
1316
use Magento\Framework\App\Config\ScopeConfigInterface;
1417
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1518
use Magento\TestFramework\Helper\Bootstrap;
1619
use Magento\TestFramework\TestCase\GraphQlAbstract;
17-
use Magento\CatalogInventory\Model\Configuration;
1820

1921
/**
2022
* Add configurable product to cart testcases
@@ -41,6 +43,11 @@ class AddConfigurableProductToCartSingleMutationTest extends GraphQlAbstract
4143
*/
4244
private $reinitConfig;
4345

46+
/**
47+
* @var SelectionUidFormatter
48+
*/
49+
private $selectionUidFormatter;
50+
4451
/**
4552
* @inheritdoc
4653
*/
@@ -51,13 +58,14 @@ protected function setUp(): void
5158
$this->resourceConfig = $objectManager->get(Config::class);
5259
$this->scopeConfig = $objectManager->get(ScopeConfigInterface::class);
5360
$this->reinitConfig = $objectManager->get(ReinitableConfigInterface::class);
61+
$this->selectionUidFormatter = $objectManager->get(SelectionUidFormatter::class);
5462
}
5563

5664
/**
5765
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
5866
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
5967
*/
60-
public function testAddConfigurableProductToCart()
68+
public function testAddConfigurableProductToCart(): void
6169
{
6270
$product = $this->getConfigurableProductInfo();
6371
$quantity = 2;
@@ -77,7 +85,8 @@ public function testAddConfigurableProductToCart()
7785
);
7886

7987
$response = $this->graphQlMutation($query);
80-
$expectedProductOptionsValueUid = $this->generateConfigurableSelectionUID($attributeId, $valueIndex);
88+
89+
$expectedProductOptionsValueUid = $this->selectionUidFormatter->encode($attributeId, $valueIndex);
8190
$expectedProductOptionsUid = base64_encode("configurable/$productRowId/$attributeId");
8291
$cartItem = current($response['addProductsToCart']['cart']['items']);
8392
self::assertEquals($quantity, $cartItem['quantity']);
@@ -94,35 +103,11 @@ public function testAddConfigurableProductToCart()
94103
self::assertArrayHasKey('value_label', $option);
95104
}
96105

97-
/**
98-
* Generates UID configurable product
99-
*
100-
* @param int $attributeId
101-
* @param int $valueIndex
102-
* @return string
103-
*/
104-
private function generateConfigurableSelectionUID(int $attributeId, int $valueIndex): string
105-
{
106-
return base64_encode("configurable/$attributeId/$valueIndex");
107-
}
108-
109-
/**
110-
* Generates UID for super configurable product super attributes
111-
*
112-
* @param int $attributeId
113-
* @param int $valueIndex
114-
* @return string
115-
*/
116-
private function generateSuperAttributesUIDQuery(int $attributeId, int $valueIndex): string
117-
{
118-
return 'selected_options: ["' . $this->generateConfigurableSelectionUID($attributeId, $valueIndex) . '"]';
119-
}
120-
121106
/**
122107
* @magentoApiDataFixture Magento/Catalog/_files/configurable_products_with_custom_attribute_layered_navigation.php
123108
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
124109
*/
125-
public function testAddConfigurableProductWithWrongSuperAttributes()
110+
public function testAddConfigurableProductWithWrongSuperAttributes(): void
126111
{
127112
$product = $this->getConfigurableProductInfo();
128113
$quantity = 2;
@@ -150,7 +135,7 @@ public function testAddConfigurableProductWithWrongSuperAttributes()
150135
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
151136
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
152137
*/
153-
public function testAddProductIfQuantityIsNotAvailable()
138+
public function testAddProductIfQuantityIsNotAvailable(): void
154139
{
155140
$product = $this->getConfigurableProductInfo();
156141
$parentSku = $product['sku'];
@@ -179,7 +164,7 @@ public function testAddProductIfQuantityIsNotAvailable()
179164
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
180165
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
181166
*/
182-
public function testAddNonExistentConfigurableProductParentToCart()
167+
public function testAddNonExistentConfigurableProductParentToCart(): void
183168
{
184169
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
185170
$parentSku = 'configurable_no_exist';
@@ -203,7 +188,7 @@ public function testAddNonExistentConfigurableProductParentToCart()
203188
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_zero_qty_first_child.php
204189
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
205190
*/
206-
public function testOutOfStockVariationToCart()
191+
public function testOutOfStockVariationToCart(): void
207192
{
208193
$showOutOfStock = $this->scopeConfig->getValue(Configuration::XML_PATH_SHOW_OUT_OF_STOCK);
209194

@@ -215,7 +200,7 @@ public function testOutOfStockVariationToCart()
215200
$attributeId = (int) $product['configurable_options'][0]['attribute_id'];
216201
$valueIndex = $product['configurable_options'][0]['values'][0]['value_index'];
217202
// Asserting that the first value is the right option we want to add to cart
218-
$this->assertEquals(
203+
self::assertEquals(
219204
$product['configurable_options'][0]['values'][0]['label'],
220205
'Option 1'
221206
);
@@ -237,7 +222,7 @@ public function testOutOfStockVariationToCart()
237222
'There are no source items with the in stock status',
238223
'This product is out of stock.'
239224
];
240-
$this->assertContains(
225+
self::assertContains(
241226
$response['addProductsToCart']['user_errors'][0]['message'],
242227
$expectedErrorMessages
243228
);
@@ -312,6 +297,18 @@ private function getConfigurableProductInfo(): array
312297
return current($searchResponse['products']['items']);
313298
}
314299

300+
/**
301+
* Generates UID for super configurable product super attributes
302+
*
303+
* @param int $attributeId
304+
* @param int $valueIndex
305+
* @return string
306+
*/
307+
private function generateSuperAttributesUIDQuery(int $attributeId, int $valueIndex): string
308+
{
309+
return 'selected_options: ["' . $this->selectionUidFormatter->encode($attributeId, $valueIndex) . '"]';
310+
}
311+
315312
/**
316313
* Returns GraphQl query for fetching configurable product information
317314
*
@@ -349,15 +346,28 @@ private function getFetchProductQuery(string $term): string
349346
value_index
350347
}
351348
}
352-
configurable_options_selection_metadata {
353-
options_available_for_selection {
349+
configurable_product_options_selection {
350+
configurable_options {
351+
uid
354352
attribute_code
355-
option_value_uids
353+
label
354+
values {
355+
uid
356+
is_available
357+
is_use_default
358+
label
359+
}
356360
}
357361
variant {
358362
uid
359-
name
360-
attribute_set_id
363+
sku
364+
url_key
365+
url_path
366+
}
367+
media_gallery {
368+
url
369+
label
370+
disabled
361371
}
362372
}
363373
}

0 commit comments

Comments
 (0)