Skip to content

Commit 4e6f316

Browse files
ENGCOM-6518: 26064 issuefix #26066
2 parents 10ab84e + 8266270 commit 4e6f316

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

app/code/Magento/Wishlist/Controller/Index/Send.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
use Magento\Customer\Model\Customer;
2626

2727
/**
28-
* Class Send
28+
* Class Send Email Wishlist Controller
2929
*
30-
* @package Magento\Wishlist\Controller\Index
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
3332
class Send extends \Magento\Wishlist\Controller\AbstractIndex implements Action\HttpPostActionInterface
@@ -204,7 +203,7 @@ public function execute()
204203
$error = __('Please enter an email address.');
205204
} else {
206205
if (count($emails) > $emailsLeft) {
207-
$error = __('This wish list can be shared %1 more times.', $emailsLeft);
206+
$error = __('Maximum of %1 emails can be sent.', $emailsLeft);
208207
} else {
209208
foreach ($emails as $index => $email) {
210209
$email = trim($email);
@@ -319,7 +318,6 @@ protected function addLayoutHandles(ResultLayout $resultLayout)
319318
*
320319
* @param int $wishlistId
321320
* @param \Magento\Framework\View\Result\Layout $resultLayout
322-
* @return mixed
323321
*/
324322
protected function getRssLink($wishlistId, ResultLayout $resultLayout)
325323
{

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)