@@ -177,6 +177,37 @@ public function testAddItemsToCartWithInvalidItemId(): void
177
177
$ query = $ this ->getQuery ($ customerWishlist ['id ' ], $ itemId );
178
178
$ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
179
179
}
180
+ /** Add all items from customer's wishlist to cart
181
+ *
182
+ * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
183
+ * @magentoConfigFixture wishlist/general/active 1
184
+ * @magentoApiDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
185
+ */
186
+ public function testAddAllWishlistItemsToCart (): void
187
+ {
188
+ $ wishlist = $ this ->getWishlist ();
189
+ $ this ->assertNotEmpty ($ wishlist ['customer ' ]['wishlists ' ], 'No wishlist found ' );
190
+ $ customerWishlist = $ wishlist ['customer ' ]['wishlists ' ][0 ];
191
+ $ wishlistId = $ customerWishlist ['id ' ];
192
+
193
+ $ sku2 = 'simple_product ' ;
194
+ $ quantity2 = 2 ;
195
+ $ addProductsToWishlistQuery = $ this ->addSecondProductToWishlist ($ wishlistId , $ sku2 , $ quantity2 );
196
+ $ this ->graphQlMutation ($ addProductsToWishlistQuery , [], '' , $ this ->getHeaderMap ());
197
+ $ addWishlistToCartQuery = $ this ->addWishlistItemToCartWithNoItemId ($ wishlistId );
198
+
199
+ $ response = $ this ->graphQlMutation ($ addWishlistToCartQuery , [], '' , $ this ->getHeaderMap ());
200
+
201
+ $ this ->assertArrayHasKey ('addWishlistItemsToCart ' , $ response );
202
+ $ this ->assertArrayHasKey ('status ' , $ response ['addWishlistItemsToCart ' ]);
203
+ $ this ->assertEquals ($ response ['addWishlistItemsToCart ' ]['status ' ], true );
204
+ $ wishlistAfterItemsAddedToCart = $ this ->getWishlist ();
205
+ $ this ->assertEmpty ($ wishlistAfterItemsAddedToCart ['customer ' ]['wishlists ' ][0 ]['items_v2 ' ]['items ' ]);
206
+ $ customerCart = $ this ->getCustomerCart ('customer@example.com ' );
207
+ $ this ->assertCount (2 , $ customerCart ['customerCart ' ]['items ' ]);
208
+ $ this ->assertEquals ('simple-1 ' , $ customerCart ['customerCart ' ]['items ' ][0 ]['product ' ]['sku ' ]);
209
+ $ this ->assertEquals ($ sku2 , $ customerCart ['customerCart ' ]['items ' ][1 ]['product ' ]['sku ' ]);
210
+ }
180
211
181
212
/**
182
213
* Authentication header map
@@ -276,6 +307,11 @@ public function getWishlist(string $username = 'customer@example.com'): array
276
307
return $ this ->graphQlQuery ($ this ->getCustomerWishlistQuery (), [], '' , $ this ->getHeaderMap ($ username ));
277
308
}
278
309
310
+ public function getCustomerCart (string $ username ): array
311
+ {
312
+ return $ this ->graphQlQuery ($ this ->getCustomerCartQuery (), [], '' , $ this ->getHeaderMap ($ username ));
313
+ }
314
+
279
315
/**
280
316
* Get customer wishlist query
281
317
*
@@ -306,4 +342,97 @@ private function getCustomerWishlistQuery(): string
306
342
}
307
343
QUERY ;
308
344
}
345
+
346
+ /**
347
+ * Returns the GraphQl mutation string for products added to wishlist
348
+ *
349
+ * @param string $wishlistId
350
+ * @param string $sku2
351
+ * @param int $quantity2
352
+ * @return string
353
+ */
354
+ private function addSecondProductToWishlist (
355
+ string $ wishlistId ,
356
+ string $ sku ,
357
+ int $ quantity
358
+ ): string {
359
+ return <<<MUTATION
360
+ mutation {
361
+ addProductsToWishlist(
362
+ wishlistId: " {$ wishlistId }",
363
+ wishlistItems: [
364
+ {
365
+ sku: " {$ sku }"
366
+ quantity: {$ quantity }
367
+ }
368
+ ]
369
+ ) {
370
+ user_errors {
371
+ code
372
+ message
373
+ }
374
+ wishlist {
375
+ id
376
+ items_count
377
+ items_v2 {
378
+ items {
379
+ quantity
380
+ id
381
+ product {sku name}
382
+ }
383
+ page_info {current_page page_size total_pages}
384
+ }
385
+ }
386
+ }
387
+ }
388
+ MUTATION ;
389
+ }
390
+
391
+ /**
392
+ * Returns GraphQl mutation string to add wishlist items to Cart
393
+ *
394
+ * @param string $wishlistId
395
+ * @return string
396
+ */
397
+ private function addWishlistItemToCartWithNoItemId (
398
+ string $ wishlistId
399
+ ): string {
400
+ return <<<MUTATION
401
+ mutation {
402
+ addWishlistItemsToCart
403
+ (
404
+ wishlistId: " {$ wishlistId }"
405
+ ) {
406
+ status
407
+ add_wishlist_items_to_cart_user_errors{
408
+ message
409
+ code
410
+ }
411
+ }
412
+ }
413
+ MUTATION ;
414
+ }
415
+
416
+ /**
417
+ * Get customer cart query
418
+ *
419
+ * @return string
420
+ */
421
+ private function getCustomerCartQuery (): string
422
+ {
423
+ return <<<QUERY
424
+ {customerCart {
425
+ id
426
+ total_quantity
427
+ items {
428
+ uid
429
+ quantity
430
+ product{sku}
431
+ }
432
+ }
433
+ }
434
+ QUERY ;
435
+ }
436
+
437
+
309
438
}
0 commit comments