3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
declare (strict_types=1 );
7
8
8
9
namespace Magento \GraphQl \ConfigurableProduct ;
9
10
10
11
use Exception ;
12
+ use Magento \CatalogInventory \Model \Configuration ;
11
13
use Magento \Config \Model \ResourceModel \Config ;
14
+ use Magento \ConfigurableProductGraphQl \Model \Options \SelectionUidFormatter ;
12
15
use Magento \Framework \App \Config \ReinitableConfigInterface ;
13
16
use Magento \Framework \App \Config \ScopeConfigInterface ;
14
17
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
15
18
use Magento \TestFramework \Helper \Bootstrap ;
16
19
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
- use Magento \CatalogInventory \Model \Configuration ;
18
20
19
21
/**
20
22
* Add configurable product to cart testcases
@@ -41,6 +43,11 @@ class AddConfigurableProductToCartSingleMutationTest extends GraphQlAbstract
41
43
*/
42
44
private $ reinitConfig ;
43
45
46
+ /**
47
+ * @var SelectionUidFormatter
48
+ */
49
+ private $ selectionUidFormatter ;
50
+
44
51
/**
45
52
* @inheritdoc
46
53
*/
@@ -51,13 +58,14 @@ protected function setUp(): void
51
58
$ this ->resourceConfig = $ objectManager ->get (Config::class);
52
59
$ this ->scopeConfig = $ objectManager ->get (ScopeConfigInterface::class);
53
60
$ this ->reinitConfig = $ objectManager ->get (ReinitableConfigInterface::class);
61
+ $ this ->selectionUidFormatter = $ objectManager ->get (SelectionUidFormatter::class);
54
62
}
55
63
56
64
/**
57
65
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
58
66
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
59
67
*/
60
- public function testAddConfigurableProductToCart ()
68
+ public function testAddConfigurableProductToCart (): void
61
69
{
62
70
$ product = $ this ->getConfigurableProductInfo ();
63
71
$ quantity = 2 ;
@@ -77,7 +85,8 @@ public function testAddConfigurableProductToCart()
77
85
);
78
86
79
87
$ response = $ this ->graphQlMutation ($ query );
80
- $ expectedProductOptionsValueUid = $ this ->generateConfigurableSelectionUID ($ attributeId , $ valueIndex );
88
+
89
+ $ expectedProductOptionsValueUid = $ this ->selectionUidFormatter ->encode ($ attributeId , $ valueIndex );
81
90
$ expectedProductOptionsUid = base64_encode ("configurable/ $ productRowId/ $ attributeId " );
82
91
$ cartItem = current ($ response ['addProductsToCart ' ]['cart ' ]['items ' ]);
83
92
self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
@@ -94,35 +103,11 @@ public function testAddConfigurableProductToCart()
94
103
self ::assertArrayHasKey ('value_label ' , $ option );
95
104
}
96
105
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
-
121
106
/**
122
107
* @magentoApiDataFixture Magento/Catalog/_files/configurable_products_with_custom_attribute_layered_navigation.php
123
108
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
124
109
*/
125
- public function testAddConfigurableProductWithWrongSuperAttributes ()
110
+ public function testAddConfigurableProductWithWrongSuperAttributes (): void
126
111
{
127
112
$ product = $ this ->getConfigurableProductInfo ();
128
113
$ quantity = 2 ;
@@ -150,7 +135,7 @@ public function testAddConfigurableProductWithWrongSuperAttributes()
150
135
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
151
136
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
152
137
*/
153
- public function testAddProductIfQuantityIsNotAvailable ()
138
+ public function testAddProductIfQuantityIsNotAvailable (): void
154
139
{
155
140
$ product = $ this ->getConfigurableProductInfo ();
156
141
$ parentSku = $ product ['sku ' ];
@@ -179,7 +164,7 @@ public function testAddProductIfQuantityIsNotAvailable()
179
164
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
180
165
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
181
166
*/
182
- public function testAddNonExistentConfigurableProductParentToCart ()
167
+ public function testAddNonExistentConfigurableProductParentToCart (): void
183
168
{
184
169
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
185
170
$ parentSku = 'configurable_no_exist ' ;
@@ -203,7 +188,7 @@ public function testAddNonExistentConfigurableProductParentToCart()
203
188
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_zero_qty_first_child.php
204
189
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
205
190
*/
206
- public function testOutOfStockVariationToCart ()
191
+ public function testOutOfStockVariationToCart (): void
207
192
{
208
193
$ showOutOfStock = $ this ->scopeConfig ->getValue (Configuration::XML_PATH_SHOW_OUT_OF_STOCK );
209
194
@@ -215,7 +200,7 @@ public function testOutOfStockVariationToCart()
215
200
$ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
216
201
$ valueIndex = $ product ['configurable_options ' ][0 ]['values ' ][0 ]['value_index ' ];
217
202
// Asserting that the first value is the right option we want to add to cart
218
- $ this -> assertEquals (
203
+ self :: assertEquals (
219
204
$ product ['configurable_options ' ][0 ]['values ' ][0 ]['label ' ],
220
205
'Option 1 '
221
206
);
@@ -237,7 +222,7 @@ public function testOutOfStockVariationToCart()
237
222
'There are no source items with the in stock status ' ,
238
223
'This product is out of stock. '
239
224
];
240
- $ this -> assertContains (
225
+ self :: assertContains (
241
226
$ response ['addProductsToCart ' ]['user_errors ' ][0 ]['message ' ],
242
227
$ expectedErrorMessages
243
228
);
@@ -312,6 +297,18 @@ private function getConfigurableProductInfo(): array
312
297
return current ($ searchResponse ['products ' ]['items ' ]);
313
298
}
314
299
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
+
315
312
/**
316
313
* Returns GraphQl query for fetching configurable product information
317
314
*
@@ -349,15 +346,28 @@ private function getFetchProductQuery(string $term): string
349
346
value_index
350
347
}
351
348
}
352
- configurable_options_selection_metadata {
353
- options_available_for_selection {
349
+ configurable_product_options_selection {
350
+ configurable_options {
351
+ uid
354
352
attribute_code
355
- option_value_uids
353
+ label
354
+ values {
355
+ uid
356
+ is_available
357
+ is_use_default
358
+ label
359
+ }
356
360
}
357
361
variant {
358
362
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
361
371
}
362
372
}
363
373
}
0 commit comments