@@ -417,41 +417,79 @@ public function testAddConfigurableProductToCartWithCustomOption()
417417 }
418418
419419 /**
420- * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
420+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image itself
421+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
421422 * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422- * @magentoApiDataFixture Magento/Store/_files/second_store.php
423423 */
424- public function testAddConfigurableProductToCartWithDifferentStoreHeader ()
424+ public function testAddConfigurableProductWithImageToCartItselfImage (): void
425425 {
426426 $ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
427427 $ product = current ($ searchResponse ['products ' ]['items ' ]);
428428
429- $ quantity = 2 ;
430- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
429+ $ quantity = 1 ;
431430 $ parentSku = $ product ['sku ' ];
432431 $ sku = 'simple_20 ' ;
433- $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
434- $ optionId = $ product ['configurable_options ' ][0 ]['values ' ][1 ]['value_index ' ];
435432
436- $ query = $ this ->getQuery (
437- $ maskedQuoteId ,
433+ $ query = $ this ->graphQlQueryForVariant (
434+ $ this -> getMaskedQuoteIdByReservedOrderId -> execute ( ' test_order_1 ' ) ,
438435 $ parentSku ,
439436 $ sku ,
440437 $ quantity
441438 );
442- $ headerMap = [ ' Store ' => ' fixture_second_store ' ];
443- $ response = $ this ->graphQlMutation ($ query, [], '' , $ headerMap );
439+
440+ $ response = $ this ->graphQlMutation ($ query );
444441
445442 $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
446443 self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
447444 self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
448- self ::assertArrayHasKey ('configurable_options ' , $ cartItem );
445+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
449446
450- $ option = current ($ cartItem ['configurable_options ' ]);
451- self ::assertEquals ($ attributeId , $ option ['id ' ]);
452- self ::assertEquals ($ optionId , $ option ['value_id ' ]);
453- self ::assertArrayHasKey ('option_label ' , $ option );
454- self ::assertArrayHasKey ('value_label ' , $ option );
447+ $ variant = $ cartItem ['configured_variant ' ];
448+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
449+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
450+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
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+ $ sku = 'simple_20 ' ;
470+
471+ $ query = $ this ->graphQlQueryForVariant (
472+ $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' ),
473+ $ parentSku ,
474+ 'simple_20 ' ,
475+ $ quantity
476+ );
477+
478+ $ response = $ this ->graphQlMutation ($ query );
479+
480+ $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
481+ self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
482+ self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
483+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
484+
485+ $ variant = $ cartItem ['configured_variant ' ];
486+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
487+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
488+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
489+
490+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
491+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
492+ self ::assertEquals ($ sku , $ variant ['sku ' ]);
455493 }
456494
457495 /**
@@ -499,6 +537,52 @@ private function getQuery(string $maskedQuoteId, string $parentSku, string $sku,
499537QUERY ;
500538 }
501539
540+ /**
541+ * @param string $maskedQuoteId
542+ * @param string $parentSku
543+ * @param string $sku
544+ * @param int $quantity
545+ * @return string
546+ */
547+ private function graphQlQueryForVariant (string $ maskedQuoteId , string $ parentSku , string $ sku , int $ quantity ): string
548+ {
549+ return <<<QUERY
550+ mutation {
551+ addConfigurableProductsToCart(
552+ input:{
553+ cart_id:" {$ maskedQuoteId }"
554+ cart_items:{
555+ parent_sku: " {$ parentSku }"
556+ data:{
557+ sku:" {$ sku }"
558+ quantity: {$ quantity }
559+ }
560+ }
561+ }
562+ ) {
563+ cart {
564+ items {
565+ id
566+ quantity
567+ product {
568+ sku
569+ }
570+ ... on ConfigurableCartItem {
571+ configured_variant {
572+ sku
573+ thumbnail {
574+ label
575+ url
576+ }
577+ }
578+ }
579+ }
580+ }
581+ }
582+ }
583+ QUERY ;
584+ }
585+
502586 private function getFetchProductQuery (string $ term ): string
503587 {
504588 return <<<QUERY
@@ -538,6 +622,7 @@ private function getFetchProductQuery(string $term): string
538622 *
539623 * @param string $productSku
540624 * @return array
625+ * @throws Exception
541626 */
542627 private function getAvailableProductCustomOption (string $ productSku ): array
543628 {
0 commit comments