@@ -134,6 +134,39 @@ public function testAddItemsToCartWithInvalidId(): void
134
134
$ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
135
135
}
136
136
137
+ /**
138
+ * Add all items from customer's wishlist to cart
139
+ *
140
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
141
+ * @magentoConfigFixture wishlist/general/active 1
142
+ * @magentoApiDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
143
+ */
144
+ public function testAddAllWishlistItemsToCart (): void
145
+ {
146
+ $ wishlist = $ this ->getWishlist ();
147
+ $ this ->assertNotEmpty ($ wishlist ['customer ' ]['wishlists ' ], 'No wishlist found ' );
148
+ $ customerWishlist = $ wishlist ['customer ' ]['wishlists ' ][0 ];
149
+ $ wishlistId = $ customerWishlist ['id ' ];
150
+
151
+ $ sku2 = 'simple_product ' ;
152
+ $ quantity2 = 2 ;
153
+ $ addProductsToWishlistQuery = $ this ->addSecondProductToWishlist ($ wishlistId , $ sku2 , $ quantity2 );
154
+ $ this ->graphQlMutation ($ addProductsToWishlistQuery , [], '' , $ this ->getHeaderMap ());
155
+ $ addWishlistToCartQuery = $ this ->addWishlistItemToCartWithNoItemId ($ wishlistId );
156
+
157
+ $ response = $ this ->graphQlMutation ($ addWishlistToCartQuery , [], '' , $ this ->getHeaderMap ());
158
+
159
+ $ this ->assertArrayHasKey ('addWishlistItemsToCart ' , $ response );
160
+ $ this ->assertArrayHasKey ('status ' , $ response ['addWishlistItemsToCart ' ]);
161
+ $ this ->assertEquals ($ response ['addWishlistItemsToCart ' ]['status ' ], true );
162
+ $ wishlistAfterItemsAddedToCart = $ this ->getWishlist ();
163
+ $ this ->assertEmpty ($ wishlistAfterItemsAddedToCart ['customer ' ]['wishlists ' ][0 ]['items_v2 ' ]['items ' ]);
164
+ $ customerCart = $ this ->getCustomerCart ('customer@example.com ' );
165
+ $ this ->assertCount (2 , $ customerCart ['customerCart ' ]['items ' ]);
166
+ $ this ->assertEquals ('simple-1 ' , $ customerCart ['customerCart ' ]['items ' ][0 ]['product ' ]['sku ' ]);
167
+ $ this ->assertEquals ($ sku2 , $ customerCart ['customerCart ' ]['items ' ][1 ]['product ' ]['sku ' ]);
168
+ }
169
+
137
170
/**
138
171
* Authentication header map
139
172
*
@@ -192,6 +225,11 @@ public function getWishlist(string $username = 'customer@example.com'): array
192
225
return $ this ->graphQlQuery ($ this ->getCustomerWishlistQuery (), [], '' , $ this ->getHeaderMap ($ username ));
193
226
}
194
227
228
+ public function getCustomerCart (string $ username ): array
229
+ {
230
+ return $ this ->graphQlQuery ($ this ->getCustomerCartQuery (), [], '' , $ this ->getHeaderMap ($ username ));
231
+ }
232
+
195
233
/**
196
234
* Get customer wishlist query
197
235
*
@@ -222,4 +260,97 @@ private function getCustomerWishlistQuery(): string
222
260
}
223
261
QUERY ;
224
262
}
263
+
264
+ /**
265
+ * Returns the GraphQl mutation string for products added to wishlist
266
+ *
267
+ * @param string $wishlistId
268
+ * @param string $sku2
269
+ * @param int $quantity2
270
+ * @return string
271
+ */
272
+ private function addSecondProductToWishlist (
273
+ string $ wishlistId ,
274
+ string $ sku ,
275
+ int $ quantity
276
+ ): string {
277
+ return <<<MUTATION
278
+ mutation {
279
+ addProductsToWishlist(
280
+ wishlistId: " {$ wishlistId }",
281
+ wishlistItems: [
282
+ {
283
+ sku: " {$ sku }"
284
+ quantity: {$ quantity }
285
+ }
286
+ ]
287
+ ) {
288
+ user_errors {
289
+ code
290
+ message
291
+ }
292
+ wishlist {
293
+ id
294
+ items_count
295
+ items_v2 {
296
+ items {
297
+ quantity
298
+ id
299
+ product {sku name}
300
+ }
301
+ page_info {current_page page_size total_pages}
302
+ }
303
+ }
304
+ }
305
+ }
306
+ MUTATION ;
307
+ }
308
+
309
+ /**
310
+ * Returns GraphQl mutation string to add wishlist items to Cart
311
+ *
312
+ * @param string $wishlistId
313
+ * @return string
314
+ */
315
+ private function addWishlistItemToCartWithNoItemId (
316
+ string $ wishlistId
317
+ ): string {
318
+ return <<<MUTATION
319
+ mutation {
320
+ addWishlistItemsToCart
321
+ (
322
+ wishlistId: " {$ wishlistId }"
323
+ ) {
324
+ status
325
+ add_wishlist_items_to_cart_user_errors{
326
+ message
327
+ code
328
+ }
329
+ }
330
+ }
331
+ MUTATION ;
332
+ }
333
+
334
+ /**
335
+ * Get customer cart query
336
+ *
337
+ * @return string
338
+ */
339
+ private function getCustomerCartQuery (): string
340
+ {
341
+ return <<<QUERY
342
+ {customerCart {
343
+ id
344
+ total_quantity
345
+ items {
346
+ uid
347
+ quantity
348
+ product{sku}
349
+ }
350
+ }
351
+ }
352
+ QUERY ;
353
+ }
354
+
355
+
225
356
}
0 commit comments