@@ -172,48 +172,6 @@ public function testAddToNotExistingWishList(): void
172
172
$ this ->assert404NotFound ();
173
173
}
174
174
175
- /**
176
- * Perform request add item to wish list.
177
- *
178
- * @param array $params
179
- * @return void
180
- */
181
- private function performAddToWishListRequest (array $ params ): void
182
- {
183
- $ this ->getRequest ()->setParams ($ params )->setMethod (HttpRequest::METHOD_POST );
184
- $ this ->dispatch ('wishlist/index/add ' );
185
- }
186
-
187
- /**
188
- * Assert success response and items count.
189
- *
190
- * @param int $customerId
191
- * @param int $itemsCount
192
- * @param string $productName
193
- * @return void
194
- */
195
- private function assertSuccess (int $ customerId , int $ itemsCount , string $ productName ): void
196
- {
197
- $ expectedMessage = sprintf ("\n%s has been added to your Wish List. " , $ productName )
198
- . " Click <a href= \"http://localhost/test \">here</a> to continue shopping. " ;
199
- $ this ->assertSessionMessages ($ this ->equalTo ([(string )__ ($ expectedMessage )]), MessageInterface::TYPE_SUCCESS );
200
- $ wishlist = $ this ->getWishlistByCustomerId ->execute ($ customerId );
201
- $ this ->assertCount ($ itemsCount , $ wishlist ->getItemCollection ());
202
- $ this ->assertRedirect ($ this ->stringContains ('wishlist/index/index/wishlist_id/ ' . $ wishlist ->getId ()));
203
- }
204
-
205
- /**
206
- * Prepare referer to test.
207
- *
208
- * @return void
209
- */
210
- private function prepareReferer (): void
211
- {
212
- $ parameters = $ this ->_objectManager ->create (Parameters::class);
213
- $ parameters ->set ('HTTP_REFERER ' , 'http://localhost/test ' );
214
- $ this ->getRequest ()->setServer ($ parameters );
215
- }
216
-
217
175
/**
218
176
* Add Product to Wishlist Before Login, Create Customer & Send Confirmation Email
219
177
*
@@ -229,8 +187,8 @@ public function testCreateCustomerWithEmailConfirmationAfterAddToWishlist(): voi
229
187
$ data = [];
230
188
$ data ['product ' ] = (int ) $ product ->getId ();
231
189
$ this ->customerSession ->setBeforeWishlistRequest ($ data );
232
- $ email = 'test_example_new @email.com ' ;
233
- $ this ->fillRequestWithAccountData ($ email );
190
+ $ email = 'test_example_new31 @email.com ' ;
191
+ $ this ->fillRequestWithCustomerData ($ email );
234
192
$ this ->dispatch ('customer/account/createPost ' );
235
193
$ this ->assertRedirect ($ this ->stringContains ('customer/account/index ' ));
236
194
$ message = 'You must confirm your account. '
@@ -261,25 +219,8 @@ public function testCreateCustomerWithEmailConfirmationAfterAddToWishlist(): voi
261
219
}
262
220
263
221
/**
264
- * Fills request with customer data.
265
- *
266
- * @param string $email
267
- * @return void
268
- */
269
- private function fillRequestWithAccountData (string $ email ): void
270
- {
271
- $ this ->getRequest ()
272
- ->setMethod (HttpRequest::METHOD_POST )
273
- ->setParam (CustomerInterface::FIRSTNAME , 'firstname1 ' )
274
- ->setParam (CustomerInterface::LASTNAME , 'lastname1 ' )
275
- ->setParam (CustomerInterface::EMAIL , $ email )
276
- ->setParam ('password ' , '_Password1 ' )
277
- ->setParam ('password_confirmation ' , '_Password1 ' );
278
- }
279
-
280
- /**
281
- * Save Wishlist Product Data into Cache, Prepare Customer Email Confirmation Link
282
- * Also Confirm the Customer & Add Product To Wishlist based on the data retrieved from Cache
222
+ * Save Wishlist Product Data into Cache.
223
+ * Also Add Product To Wishlist based on the data retrieved from Cache Token
283
224
*
284
225
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
285
226
* @magentoDataFixture Magento/Customer/_files/customer_confirmation_config_enable.php
@@ -290,21 +231,76 @@ private function fillRequestWithAccountData(string $email): void
290
231
*/
291
232
public function testAddToWishlistOnCustomerConfirmation (): void
292
233
{
234
+ $ this ->prepareReferer ();
293
235
$ product = $ this ->productRepository ->get ('simple ' );
294
236
$ data = [];
295
237
$ data ['product ' ] = (int ) $ product ->getId ();
296
- $ token = $ this ->dataSerializer ->serialize ($ data );
297
-
238
+ $ token = $ this ->dataSerializer ->serialize ($ data );//Save into Cache
298
239
$ customer = $ this ->customerRepository ->get ('unconfirmedcustomer@example.com ' );
240
+ $ customer ->setConfirmation (null );
241
+ $ this ->customerRepository ->save ($ customer );
242
+ $ this ->assertEquals (null , $ customer ->getConfirmation ());
243
+ $ this ->customerSession ->setCustomerId ((int ) $ customer ->getId ());
244
+ $ this ->performAddToWishListRequest (['token ' => $ token ]);
245
+ $ this ->assertSuccess ((int ) $ customer ->getId (), 1 , $ product ->getName ());
246
+ }
299
247
300
- $ this ->getRequest ()
301
- ->setParam ('back_url ' , $ this ->urlBuilder ->getUrl (
302
- 'wishlist/index/add ' , ['_query ' => ['token ' => $ token ]]
303
- ))
304
- ->setParam ('id ' , (int ) $ customer ->getId ())
305
- ->setParam ('key ' , $ customer ->getConfirmation ());
248
+ /**
249
+ * Perform request add item to wish list.
250
+ *
251
+ * @param array $params
252
+ * @return void
253
+ */
254
+ private function performAddToWishListRequest (array $ params ): void
255
+ {
256
+ $ this ->getRequest ()->setParams ($ params )->setMethod (HttpRequest::METHOD_POST );
257
+ $ this ->dispatch ('wishlist/index/add ' );
258
+ }
306
259
307
- $ this ->dispatch ('customer/account/confirm ' );
308
- $ this ->assertSuccess ((int ) $ customer ->getId (), 1 , $ product ->getName ());
260
+ /**
261
+ * Assert success response and items count.
262
+ *
263
+ * @param int $customerId
264
+ * @param int $itemsCount
265
+ * @param string $productName
266
+ * @return void
267
+ */
268
+ private function assertSuccess (int $ customerId , int $ itemsCount , string $ productName ): void
269
+ {
270
+ $ expectedMessage = sprintf ("\n%s has been added to your Wish List. " , $ productName )
271
+ . " Click <a href= \"http://localhost/test \">here</a> to continue shopping. " ;
272
+ $ this ->assertSessionMessages ($ this ->equalTo ([(string )__ ($ expectedMessage )]), MessageInterface::TYPE_SUCCESS );
273
+ $ wishlist = $ this ->getWishlistByCustomerId ->execute ($ customerId );
274
+ $ this ->assertCount ($ itemsCount , $ wishlist ->getItemCollection ());
275
+ $ this ->assertRedirect ($ this ->stringContains ('wishlist/index/index/wishlist_id/ ' . $ wishlist ->getId ()));
276
+ }
277
+
278
+ /**
279
+ * Prepare referer to test.
280
+ *
281
+ * @return void
282
+ */
283
+ private function prepareReferer (): void
284
+ {
285
+ $ parameters = $ this ->_objectManager ->create (Parameters::class);
286
+ $ parameters ->set ('HTTP_REFERER ' , 'http://localhost/test ' );
287
+ $ this ->getRequest ()->setServer ($ parameters );
288
+ }
289
+
290
+ /**
291
+ * Fills request with customer data.
292
+ *
293
+ * @param string $email
294
+ * @return void
295
+ */
296
+ private function fillRequestWithCustomerData (string $ email ): void
297
+ {
298
+ $ this ->getRequest ()
299
+ ->setMethod (HttpRequest::METHOD_POST )
300
+ ->setParam (CustomerInterface::FIRSTNAME , 'firstname1 ' )
301
+ ->setParam (CustomerInterface::LASTNAME , 'lastname1 ' )
302
+ ->setParam (CustomerInterface::EMAIL , $ email )
303
+ ->setParam ('password ' , '_Password1 ' )
304
+ ->setParam ('password_confirmation ' , '_Password1 ' );
309
305
}
310
306
}
0 commit comments