Skip to content

26064 issuefix #26066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/code/Magento/Wishlist/Controller/Index/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
use Magento\Customer\Model\Customer;

/**
* Class Send
* Class Send Email Wishlist Controller
*
* @package Magento\Wishlist\Controller\Index
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Send extends \Magento\Wishlist\Controller\AbstractIndex implements Action\HttpPostActionInterface
Expand Down Expand Up @@ -204,7 +203,7 @@ public function execute()
$error = __('Please enter an email address.');
} else {
if (count($emails) > $emailsLeft) {
$error = __('This wish list can be shared %1 more times.', $emailsLeft);
$error = __('Maximum of %1 emails can be sent.', $emailsLeft);
} else {
foreach ($emails as $index => $email) {
$email = trim($email);
Expand Down Expand Up @@ -319,7 +318,6 @@ protected function addLayoutHandles(ResultLayout $resultLayout)
*
* @param int $wishlistId
* @param \Magento\Framework\View\Result\Layout $resultLayout
* @return mixed
*/
protected function getRssLink($wishlistId, ResultLayout $resultLayout)
{
Expand Down
57 changes: 50 additions & 7 deletions app/code/Magento/Wishlist/Test/Unit/Controller/Index/SendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/
namespace Magento\Wishlist\Test\Unit\Controller\Index;

use Magento\Captcha\Helper\Data as CaptchaHelper;
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
use Magento\Customer\Model\Data\Customer as CustomerData;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context as ActionContext;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
Expand All @@ -14,15 +17,13 @@
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
use Magento\Framework\Mail\TransportInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Phrase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Result\Layout as ResultLayout;
use Magento\Store\Model\Store;
use Magento\Wishlist\Controller\Index\Send;
use Magento\Wishlist\Controller\WishlistProviderInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Captcha\Helper\Data as CaptchaHelper;
use Magento\Captcha\Model\DefaultModel as CaptchaModel;
use Magento\Customer\Model\Session;

/**
* @SuppressWarnings(PHPMD.TooManyFields)
Expand Down Expand Up @@ -212,7 +213,12 @@ protected function setUp()
);
}

public function testExecuteNoFormKeyValidated()
/**
* Verify execute method without Form Key validated
*
* @return void
*/
public function testExecuteNoFormKeyValidated(): void
{
$this->formKeyValidator->expects($this->once())
->method('validate')
Expand All @@ -228,8 +234,43 @@ public function testExecuteNoFormKeyValidated()
}

/**
* @expectedException \Magento\Framework\Exception\NotFoundException
* @expectedExceptionMessage Page not found.
* Verify execute with no emails left
*
* @return void
*/
public function testExecuteWithNoEmailLeft(): void
{
$expectedMessage = new Phrase('Maximum of %1 emails can be sent.', [0]);

$this->formKeyValidator->expects($this->once())
->method('validate')
->with($this->request)
->willReturn(true);

$this->request->expects($this->at(0))
->method('getPost')
->with('emails')
->willReturn('[email protected]', '[email protected]');
$this->request->expects($this->at(1))
->method('getPost')
->with('message');
$wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class);
$this->wishlistProvider->expects($this->once())
->method('getWishlist')
->willReturn($wishlist);
$this->resultRedirect->expects($this->once())
->method('setPath')
->with('*/*/share')
->willReturnSelf();
$this->messageManager->expects($this->once())
->method('addErrorMessage')
->with($expectedMessage);

$this->assertEquals($this->resultRedirect, $this->model->execute());
}

/**
* Execute method with no wishlist available
*/
public function testExecuteNoWishlistAvailable()
{
Expand All @@ -241,6 +282,8 @@ public function testExecuteNoWishlistAvailable()
$this->wishlistProvider->expects($this->once())
->method('getWishlist')
->willReturn(null);
$this->expectException(\Magento\Framework\Exception\NotFoundException::class);
$this->expectExceptionMessage('Page not found');

$this->model->execute();
}
Expand Down