77
88namespace Magento \Wishlist \Controller \Index ;
99
10+ use Magento \Catalog \Api \ProductRepositoryInterface ;
1011use Magento \Checkout \Model \CartFactory ;
1112use Magento \Customer \Model \Session ;
1213use Magento \Framework \App \Request \Http as HttpRequest ;
@@ -35,6 +36,9 @@ class CartTest extends AbstractController
3536 /** @var Escaper */
3637 private $ escaper ;
3738
39+ /** @var ProductRepositoryInterface */
40+ private $ productRepository ;
41+
3842 /**
3943 * @inheritdoc
4044 */
@@ -46,6 +50,7 @@ protected function setUp(): void
4650 $ this ->getWishlistByCustomerId = $ this ->_objectManager ->get (GetWishlistByCustomerId::class);
4751 $ this ->cartFactory = $ this ->_objectManager ->get (CartFactory::class);
4852 $ this ->escaper = $ this ->_objectManager ->get (Escaper::class);
53+ $ this ->productRepository = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
4954 }
5055
5156 /**
@@ -107,6 +112,38 @@ public function testAddNotExistingItemToCart(): void
107112 $ this ->assertRedirect ($ this ->stringContains ('wishlist/index/ ' ));
108113 }
109114
115+ /**
116+ * Add wishlist item with related Products to Cart.
117+ *
118+ * @return void
119+ * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
120+ * @magentoDataFixture Magento/Catalog/_files/products.php
121+ */
122+ public function testAddItemWithRelatedProducts (): void
123+ {
124+ $ firstProductId = $ this ->productRepository ->get ('simple ' )->getId ();
125+ $ secondProductID = $ this ->productRepository ->get ('custom-design-simple-product ' )->getId ();
126+ $ relatedIds = $ expectedAddedIds = [$ firstProductId , $ secondProductID ];
127+
128+ $ this ->customerSession ->setCustomerId (1 );
129+ $ item = $ this ->getWishlistByCustomerId ->getItemBySku (1 , 'simple-1 ' );
130+ $ this ->assertNotNull ($ item );
131+
132+ $ this ->performAddToCartRequest ([
133+ 'item ' => $ item ->getId (),
134+ 'qty ' => 1 ,
135+ 'related_product ' => implode (', ' , $ relatedIds ),
136+ ]);
137+
138+ $ this ->assertCount (0 , $ this ->getWishlistByCustomerId ->execute (1 )->getItemCollection ());
139+ $ cart = $ this ->cartFactory ->create ();
140+ $ this ->assertEquals (3 , $ cart ->getItemsCount ());
141+ $ expectedAddedIds [] = $ item ->getProductId ();
142+ foreach ($ expectedAddedIds as $ addedId ) {
143+ $ this ->assertContains ($ addedId , $ cart ->getProductIds ());
144+ }
145+ }
146+
110147 /**
111148 * Perform request add to cart from wish list.
112149 *
0 commit comments