Skip to content

Commit

Permalink
ENGCOM-6518: 26064 issuefix #26066
Browse files Browse the repository at this point in the history
 - Merge Pull Request #26066 from divyajyothi5321/magento2:fix-#26064
 - Merged commits:
   1. a882be9
   2. e830f2e
   3. 0d22017
   4. 8251bc9
   5. 0802b48
   6. add2bbb
  • Loading branch information
magento-engcom-team committed Jan 2, 2020
2 parents 10ab84e + add2bbb commit 8266270
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
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('some.Email@gmail.com', 'some.email2@gmail.com');
$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

0 comments on commit 8266270

Please sign in to comment.