Skip to content

Commit 946382c

Browse files
committed
#12715 Storefront Back to Sign in button does not work
- add Back to Sign in url
1 parent b1cc3ea commit 946382c

File tree

2 files changed

+131
-1
lines changed

2 files changed

+131
-1
lines changed

app/code/Magento/Customer/Controller/Account/Confirmation.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
*/
77
namespace Magento\Customer\Controller\Account;
88

9+
use Magento\Customer\Model\Url;
910
use Magento\Framework\App\Action\Context;
1011
use Magento\Customer\Model\Session;
12+
use Magento\Framework\App\ObjectManager;
1113
use Magento\Framework\View\Result\PageFactory;
1214
use Magento\Store\Model\StoreManagerInterface;
1315
use Magento\Customer\Api\AccountManagementInterface;
@@ -35,24 +37,32 @@ class Confirmation extends \Magento\Customer\Controller\AbstractAccount
3537
*/
3638
protected $resultPageFactory;
3739

40+
/**
41+
* @var Url
42+
*/
43+
private $customerUrl;
44+
3845
/**
3946
* @param Context $context
4047
* @param Session $customerSession
4148
* @param PageFactory $resultPageFactory
4249
* @param StoreManagerInterface $storeManager
4350
* @param AccountManagementInterface $customerAccountManagement
51+
* @param Url $customerUrl
4452
*/
4553
public function __construct(
4654
Context $context,
4755
Session $customerSession,
4856
PageFactory $resultPageFactory,
4957
StoreManagerInterface $storeManager,
50-
AccountManagementInterface $customerAccountManagement
58+
AccountManagementInterface $customerAccountManagement,
59+
Url $customerUrl = null
5160
) {
5261
$this->session = $customerSession;
5362
$this->resultPageFactory = $resultPageFactory;
5463
$this->storeManager = $storeManager;
5564
$this->customerAccountManagement = $customerAccountManagement;
65+
$this->customerUrl = $customerUrl ?: ObjectManager::getInstance()->get(Url::class);
5666
parent::__construct($context);
5767
}
5868

@@ -98,6 +108,8 @@ public function execute()
98108
$resultPage = $this->resultPageFactory->create();
99109
$resultPage->getLayout()->getBlock('accountConfirmation')->setEmail(
100110
$this->getRequest()->getParam('email', $email)
111+
)->setLoginUrl(
112+
$this->customerUrl->getLoginUrl()
101113
);
102114
return $resultPage;
103115
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: skozar
5+
* Date: 15.12.17
6+
* Time: 15:19
7+
*/
8+
9+
namespace Magento\Customer\Test\Unit\Controller\Account;
10+
11+
use Magento\Customer\Controller\Account\Confirmation;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
15+
class ConfirmationTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var Confirmation
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $customerSessionMock;
26+
27+
/**
28+
* @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $contextMock;
31+
32+
/**
33+
* @var \Magento\Framework\View\Result\PageFactory|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $resultPageFactoryMock;
36+
37+
/**
38+
* @var \Magento\Customer\Model\Url|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $customerUrlMock;
41+
42+
/**
43+
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
44+
*/
45+
private $requestMock;
46+
47+
public function setUp()
48+
{
49+
$this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
50+
->disableOriginalConstructor()
51+
->setMethods(['isLoggedIn'])
52+
->getMock();
53+
$this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
54+
->disableOriginalConstructor()
55+
->setMethods(['getRequest'])
56+
->getMock();
57+
$this->requestMock = $this->getMockBuilder(Http::class)
58+
->disableOriginalConstructor()
59+
->setMethods(['getPost', 'getParam'])
60+
->getMock();
61+
$this->contextMock->expects($this->any())
62+
->method('getRequest')
63+
->willReturn($this->requestMock);
64+
65+
$this->resultPageFactoryMock = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
66+
->disableOriginalConstructor()
67+
->setMethods(['create'])
68+
->getMock();
69+
$this->customerUrlMock = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
70+
->disableOriginalConstructor()
71+
->setMethods(['getLoginUrl'])
72+
->getMock();
73+
$this->model = (new ObjectManagerHelper($this))->getObject(
74+
Confirmation::class,
75+
[
76+
'context' => $this->contextMock,
77+
'customerSession' => $this->customerSessionMock,
78+
'resultPageFactory' => $this->resultPageFactoryMock,
79+
'customerUrl' => $this->customerUrlMock,
80+
]
81+
);
82+
}
83+
84+
public function testGetLoginUrl()
85+
{
86+
$this->customerSessionMock->expects($this->once())
87+
->method('isLoggedIn')
88+
->willReturn(false);
89+
90+
$this->requestMock->expects($this->once())->method('getPost')->with('email')->willReturn(null);
91+
92+
$resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
93+
->disableOriginalConstructor()
94+
->setMethods(['getLayout'])
95+
->getMock();
96+
97+
$this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock);
98+
99+
$layoutMock = $this->getMockBuilder(\Magento\Framework\View\Layout::class)
100+
->disableOriginalConstructor()
101+
->setMethods(['getBlock'])
102+
->getMock();
103+
104+
$resultPageMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
105+
106+
$blockMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template::class)
107+
->disableOriginalConstructor()
108+
->setMethods(['setEmail', 'setLoginUrl'])
109+
->getMock();
110+
111+
$layoutMock->expects($this->once())->method('getBlock')->with('accountConfirmation')->willReturn($blockMock);
112+
113+
$blockMock->expects($this->once())->method('setEmail')->willReturnSelf();
114+
$blockMock->expects($this->once())->method('setLoginUrl')->willReturnSelf();
115+
116+
$this->model->execute();
117+
}
118+
}

0 commit comments

Comments
 (0)