5
5
*/
6
6
namespace Magento \Wishlist \Test \Unit \Controller \Index ;
7
7
8
+ use Magento \Captcha \Helper \Data as CaptchaHelper ;
9
+ use Magento \Captcha \Model \DefaultModel as CaptchaModel ;
8
10
use Magento \Customer \Model \Data \Customer as CustomerData ;
11
+ use Magento \Customer \Model \Session ;
9
12
use Magento \Framework \App \Action \Context as ActionContext ;
10
13
use Magento \Framework \App \RequestInterface ;
11
14
use Magento \Framework \Controller \Result \Redirect as ResultRedirect ;
14
17
use Magento \Framework \Event \ManagerInterface as EventManagerInterface ;
15
18
use Magento \Framework \Mail \TransportInterface ;
16
19
use Magento \Framework \Message \ManagerInterface ;
20
+ use Magento \Framework \Phrase ;
21
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
17
22
use Magento \Framework \UrlInterface ;
18
23
use Magento \Framework \View \Result \Layout as ResultLayout ;
19
24
use Magento \Store \Model \Store ;
20
25
use Magento \Wishlist \Controller \Index \Send ;
21
26
use Magento \Wishlist \Controller \WishlistProviderInterface ;
22
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
23
- use Magento \Captcha \Helper \Data as CaptchaHelper ;
24
- use Magento \Captcha \Model \DefaultModel as CaptchaModel ;
25
- use Magento \Customer \Model \Session ;
26
27
27
28
/**
28
29
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -212,7 +213,12 @@ protected function setUp()
212
213
);
213
214
}
214
215
215
- public function testExecuteNoFormKeyValidated ()
216
+ /**
217
+ * Verify execute method without Form Key validated
218
+ *
219
+ * @return void
220
+ */
221
+ public function testExecuteNoFormKeyValidated (): void
216
222
{
217
223
$ this ->formKeyValidator ->expects ($ this ->once ())
218
224
->method ('validate ' )
@@ -228,8 +234,43 @@ public function testExecuteNoFormKeyValidated()
228
234
}
229
235
230
236
/**
231
- * @expectedException \Magento\Framework\Exception\NotFoundException
232
- * @expectedExceptionMessage Page not found.
237
+ * Verify execute with no emails left
238
+ *
239
+ * @return void
240
+ */
241
+ public function testExecuteWithNoEmailLeft (): void
242
+ {
243
+ $ expectedMessage = new Phrase ('Maximum of %1 emails can be sent. ' , [0 ]);
244
+
245
+ $ this ->formKeyValidator ->expects ($ this ->once ())
246
+ ->method ('validate ' )
247
+ ->with ($ this ->request )
248
+ ->willReturn (true );
249
+
250
+ $ this ->request ->expects ($ this ->at (0 ))
251
+ ->method ('getPost ' )
252
+ ->with ('emails ' )
253
+ ->willReturn ('some.Email@gmail.com ' , 'some.email2@gmail.com ' );
254
+ $ this ->request ->expects ($ this ->at (1 ))
255
+ ->method ('getPost ' )
256
+ ->with ('message ' );
257
+ $ wishlist = $ this ->createMock (\Magento \Wishlist \Model \Wishlist::class);
258
+ $ this ->wishlistProvider ->expects ($ this ->once ())
259
+ ->method ('getWishlist ' )
260
+ ->willReturn ($ wishlist );
261
+ $ this ->resultRedirect ->expects ($ this ->once ())
262
+ ->method ('setPath ' )
263
+ ->with ('*/*/share ' )
264
+ ->willReturnSelf ();
265
+ $ this ->messageManager ->expects ($ this ->once ())
266
+ ->method ('addErrorMessage ' )
267
+ ->with ($ expectedMessage );
268
+
269
+ $ this ->assertEquals ($ this ->resultRedirect , $ this ->model ->execute ());
270
+ }
271
+
272
+ /**
273
+ * Execute method with no wishlist available
233
274
*/
234
275
public function testExecuteNoWishlistAvailable ()
235
276
{
@@ -241,6 +282,8 @@ public function testExecuteNoWishlistAvailable()
241
282
$ this ->wishlistProvider ->expects ($ this ->once ())
242
283
->method ('getWishlist ' )
243
284
->willReturn (null );
285
+ $ this ->expectException (\Magento \Framework \Exception \NotFoundException::class);
286
+ $ this ->expectExceptionMessage ('Page not found ' );
244
287
245
288
$ this ->model ->execute ();
246
289
}
0 commit comments