Skip to content
Snippets Groups Projects
Commit 6c612dfd authored by Ievgen Shakhsuvarov's avatar Ievgen Shakhsuvarov
Browse files

MAGETWO-34317: Wishlist Sharing is available after session expiration

parent 6dfc0913
No related merge requests found
......@@ -11,15 +11,34 @@ use Magento\Framework\Controller\ResultFactory;
class Share extends Action\Action implements IndexInterface
{
/**
* @var \Magento\Customer\Model\Session
*/
protected $customerSession;
/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Customer\Model\Session $customerSession
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Customer\Model\Session $customerSession
) {
$this->customerSession = $customerSession;
parent::__construct($context);
}
/**
* Prepare wishlist for share
*
* @return \Magento\Framework\View\Result\Page
* @return void|\Magento\Framework\View\Result\Page
*/
public function execute()
{
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $resultPage;
if ($this->customerSession->authenticate($this)) {
/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
return $resultPage;
}
}
}
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Wishlist\Test\Unit\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
class ShareTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Wishlist\Controller\Index\Share
*/
protected $model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $customerSessionMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $contextMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $resultFactoryMock;
protected function setUp()
{
$this->customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false);
$this->contextMock = $this->getMock('\Magento\Framework\App\Action\Context', [], [], '', false);
$this->resultFactoryMock = $this->getMock('\Magento\Framework\Controller\ResultFactory', [], [], '', false);
$this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock);
$this->model = new \Magento\Wishlist\Controller\Index\Share(
$this->contextMock,
$this->customerSessionMock
);
}
public function testExecute()
{
$resultMock = $this->getMock('\Magento\Framework\Controller\ResultInterface', [], [], '', false);
$this->customerSessionMock->expects($this->once())->method('authenticate')->with($this->model)
->willReturn(true);
$this->resultFactoryMock->expects($this->once())->method('create')->with(ResultFactory::TYPE_PAGE)
->willReturn($resultMock);
$this->assertEquals($resultMock, $this->model->execute());
}
public function testExecuteAuthenticationFail()
{
$this->customerSessionMock->expects($this->once())->method('authenticate')->with($this->model)
->willReturn(false);
$this->assertEmpty($this->model->execute());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment