Skip to content

Commit add2bbb

Browse files
committed
cover changes with unit test
1 parent 0802b48 commit add2bbb

File tree

1 file changed

+50
-7
lines changed
  • app/code/Magento/Wishlist/Test/Unit/Controller/Index

1 file changed

+50
-7
lines changed

app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
*/
66
namespace Magento\Wishlist\Test\Unit\Controller\Index;
77

8+
use Magento\Captcha\Helper\Data as CaptchaHelper;
9+
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
810
use Magento\Customer\Model\Data\Customer as CustomerData;
11+
use Magento\Customer\Model\Session;
912
use Magento\Framework\App\Action\Context as ActionContext;
1013
use Magento\Framework\App\RequestInterface;
1114
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
@@ -14,15 +17,13 @@
1417
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
1518
use Magento\Framework\Mail\TransportInterface;
1619
use Magento\Framework\Message\ManagerInterface;
20+
use Magento\Framework\Phrase;
21+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1722
use Magento\Framework\UrlInterface;
1823
use Magento\Framework\View\Result\Layout as ResultLayout;
1924
use Magento\Store\Model\Store;
2025
use Magento\Wishlist\Controller\Index\Send;
2126
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;
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+
->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
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

Comments
 (0)