@@ -417,39 +417,78 @@ public function testAddConfigurableProductToCartWithCustomOption()
417417 }
418418
419419 /**
420+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image itself
420421 * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
421422 * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422423 */
423- public function testAddConfigurableProductWithImageToCart ()
424+ public function testAddConfigurableProductWithImageToCartItselfImage (): void
424425 {
425426 $ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
426427 $ product = current ($ searchResponse ['products ' ]['items ' ]);
427-
428+
428429 $ quantity = 1 ;
429- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
430430 $ parentSku = $ product ['sku ' ];
431431 $ sku = 'simple_20 ' ;
432- $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
433- $ optionId = $ product ['configurable_options ' ][0 ]['values ' ][1 ]['value_index ' ];
434432
435433 $ query = $ this ->graphQlQueryForVariant (
436- $ maskedQuoteId ,
434+ $ this -> getMaskedQuoteIdByReservedOrderId -> execute ( ' test_order_1 ' ) ,
437435 $ parentSku ,
438436 $ sku ,
439437 $ quantity
440438 );
441-
439+
442440 $ response = $ this ->graphQlMutation ($ query );
443-
441+
444442 $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
445443 self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
446444 self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
447445 self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
448446
449447 $ variant = $ cartItem ['configured_variant ' ];
450- $ expectedThumbnailUrl = "magento_thumbnail.jpg " ;
448+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
449+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
451450 $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
452- $ this ->assertEquals ($ expectedThumbnailUrl , $ variantImage );
451+
452+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
453+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
454+ self ::assertEquals ($ sku , $ variant ['sku ' ]);
455+ }
456+
457+ /**
458+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image parent
459+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
460+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
461+ */
462+ public function testAddConfigurableProductWithImageToCartParentImage (): void
463+ {
464+ $ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
465+ $ product = current ($ searchResponse ['products ' ]['items ' ]);
466+
467+ $ quantity = 1 ;
468+ $ parentSku = $ product ['sku ' ];
469+
470+ $ query = $ this ->graphQlQueryForVariant (
471+ $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' ),
472+ $ parentSku ,
473+ 'simple_20 ' ,
474+ $ quantity
475+ );
476+
477+ $ response = $ this ->graphQlMutation ($ query );
478+
479+ $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
480+ self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
481+ self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
482+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
483+
484+ $ variant = $ cartItem ['configured_variant ' ];
485+ $ expectedThumbnailUrl = 'thumbnail.jpg ' ;
486+ $ expectedThumbnailLabel = 'Configurable Product ' ;
487+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
488+
489+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
490+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
491+ self ::assertEquals ($ parentSku , $ variant ['sku ' ]);
453492 }
454493
455494 /**
@@ -497,12 +536,12 @@ private function getQuery(string $maskedQuoteId, string $parentSku, string $sku,
497536QUERY ;
498537 }
499538
500- /**
539+ /**
501540 * @param string $maskedQuoteId
502541 * @param string $parentSku
503542 * @param string $sku
504543 * @param int $quantity
505- * @return cart items with variants details
544+ * @return string
506545 */
507546 private function graphQlQueryForVariant (string $ maskedQuoteId , string $ parentSku , string $ sku , int $ quantity ): string
508547 {
@@ -582,6 +621,7 @@ private function getFetchProductQuery(string $term): string
582621 *
583622 * @param string $productSku
584623 * @return array
624+ * @throws Exception
585625 */
586626 private function getAvailableProductCustomOption (string $ productSku ): array
587627 {
0 commit comments