7
7
8
8
namespace Magento \Wishlist \Controller \Index ;
9
9
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
10
11
use Magento \Checkout \Model \CartFactory ;
11
12
use Magento \Customer \Model \Session ;
12
13
use Magento \Framework \App \Request \Http as HttpRequest ;
@@ -35,6 +36,9 @@ class CartTest extends AbstractController
35
36
/** @var Escaper */
36
37
private $ escaper ;
37
38
39
+ /** @var ProductRepositoryInterface */
40
+ private $ productRepository ;
41
+
38
42
/**
39
43
* @inheritdoc
40
44
*/
@@ -46,6 +50,7 @@ protected function setUp(): void
46
50
$ this ->getWishlistByCustomerId = $ this ->_objectManager ->get (GetWishlistByCustomerId::class);
47
51
$ this ->cartFactory = $ this ->_objectManager ->get (CartFactory::class);
48
52
$ this ->escaper = $ this ->_objectManager ->get (Escaper::class);
53
+ $ this ->productRepository = $ this ->_objectManager ->get (ProductRepositoryInterface::class);
49
54
}
50
55
51
56
/**
@@ -107,6 +112,38 @@ public function testAddNotExistingItemToCart(): void
107
112
$ this ->assertRedirect ($ this ->stringContains ('wishlist/index/ ' ));
108
113
}
109
114
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
+
110
147
/**
111
148
* Perform request add to cart from wish list.
112
149
*
0 commit comments