From 6c612dfd8edf0d4cb9036c86b14bd1e7bf51fdf3 Mon Sep 17 00:00:00 2001
From: Ievgen Shakhsuvarov <ishakhsuvarov@ebay.com>
Date: Thu, 9 Jul 2015 15:27:15 +0300
Subject: [PATCH] MAGETWO-34317: Wishlist Sharing is available after session
 expiration

---
 .../Wishlist/Controller/Index/Share.php       | 27 ++++++--
 .../Test/Unit/Controller/Index/ShareTest.php  | 66 +++++++++++++++++++
 2 files changed, 89 insertions(+), 4 deletions(-)
 create mode 100644 app/code/Magento/Wishlist/Test/Unit/Controller/Index/ShareTest.php

diff --git a/app/code/Magento/Wishlist/Controller/Index/Share.php b/app/code/Magento/Wishlist/Controller/Index/Share.php
index 0971a293d33..b8da8ea7422 100644
--- a/app/code/Magento/Wishlist/Controller/Index/Share.php
+++ b/app/code/Magento/Wishlist/Controller/Index/Share.php
@@ -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;
+        }
     }
 }
diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/ShareTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/ShareTest.php
new file mode 100644
index 00000000000..b34b4e185a7
--- /dev/null
+++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/ShareTest.php
@@ -0,0 +1,66 @@
+<?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());
+    }
+}
-- 
GitLab