55 */
66namespace Magento \Wishlist \Test \Unit \Controller \Index ;
77
8+ use Magento \Captcha \Helper \Data as CaptchaHelper ;
9+ use Magento \Captcha \Model \DefaultModel as CaptchaModel ;
810use Magento \Customer \Model \Data \Customer as CustomerData ;
11+ use Magento \Customer \Model \Session ;
912use Magento \Framework \App \Action \Context as ActionContext ;
1013use Magento \Framework \App \RequestInterface ;
1114use Magento \Framework \Controller \Result \Redirect as ResultRedirect ;
1417use Magento \Framework \Event \ManagerInterface as EventManagerInterface ;
1518use Magento \Framework \Mail \TransportInterface ;
1619use Magento \Framework \Message \ManagerInterface ;
20+ use Magento \Framework \Phrase ;
21+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1722use Magento \Framework \UrlInterface ;
1823use Magento \Framework \View \Result \Layout as ResultLayout ;
1924use Magento \Store \Model \Store ;
2025use Magento \Wishlist \Controller \Index \Send ;
2126use 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 ;
2627
2728/**
2829 * @SuppressWarnings(PHPMD.TooManyFields)
@@ -212,7 +213,12 @@ protected function setUp()
212213 );
213214 }
214215
215- public function testExecuteNoFormKeyValidated ()
216+ /**
217+ * Verify execute method without Form Key validated
218+ *
219+ * @return void
220+ */
221+ public function testExecuteNoFormKeyValidated (): void
216222 {
217223 $ this ->formKeyValidator ->expects ($ this ->once ())
218224 ->method ('validate ' )
@@ -228,8 +234,43 @@ public function testExecuteNoFormKeyValidated()
228234 }
229235
230236 /**
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+ 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
233274 */
234275 public function testExecuteNoWishlistAvailable ()
235276 {
@@ -241,6 +282,8 @@ public function testExecuteNoWishlistAvailable()
241282 $ this ->wishlistProvider ->expects ($ this ->once ())
242283 ->method ('getWishlist ' )
243284 ->willReturn (null );
285+ $ this ->expectException (\Magento \Framework \Exception \NotFoundException::class);
286+ $ this ->expectExceptionMessage ('Page not found ' );
244287
245288 $ this ->model ->execute ();
246289 }
0 commit comments