Skip to content

Commit f43fd4b

Browse files
Merge forwardport of #12759 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12759.patch (created by @StasKozar) based on commit(s): 1. 946382c 2. faee0fc Fixed GitHub Issues in 2.3-develop branch: - #12715: Storefront Back to Sign in button does not work as expected (reported by @alena-marchenko)
2 parents 93fe4d1 + 4e64c41 commit f43fd4b

File tree

2 files changed

+129
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)