Skip to content

Commit 373f320

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1865 from magento-engcom/2.1-develop-prs
Public Pull Requests #12629 [2.1-develop] Add customer login url from Customer Url model to checkout config so … by @quisse Fixed Public Issues #12627 Referer is not added to login url in checkout config
2 parents ae9b691 + 5ecb9e7 commit 373f320

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

app/code/Magento/Customer/Model/Checkout/ConfigProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Checkout\Model\ConfigProviderInterface;
99
use Magento\Customer\Model\Url;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\UrlInterface;
1112
use Magento\Store\Model\StoreManagerInterface;
1213
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -22,6 +23,7 @@ class ConfigProvider implements ConfigProviderInterface
2223

2324
/**
2425
* @var UrlInterface
26+
* @deprecated
2527
*/
2628
protected $urlBuilder;
2729

@@ -30,19 +32,28 @@ class ConfigProvider implements ConfigProviderInterface
3032
*/
3133
protected $scopeConfig;
3234

35+
/**
36+
* @var Url
37+
*/
38+
private $customerUrl;
39+
3340
/**
3441
* @param UrlInterface $urlBuilder
3542
* @param StoreManagerInterface $storeManager
3643
* @param ScopeConfigInterface $scopeConfig
44+
* @param Url|null $customerUrl
3745
*/
3846
public function __construct(
3947
UrlInterface $urlBuilder,
4048
StoreManagerInterface $storeManager,
41-
ScopeConfigInterface $scopeConfig
49+
ScopeConfigInterface $scopeConfig,
50+
Url $customerUrl = null
4251
) {
4352
$this->urlBuilder = $urlBuilder;
4453
$this->storeManager = $storeManager;
4554
$this->scopeConfig = $scopeConfig;
55+
$this->customerUrl = $customerUrl ?: ObjectManager::getInstance()
56+
->get(Url::class);
4657
}
4758

4859
/**
@@ -78,7 +89,7 @@ protected function isAutocompleteEnabled()
7889
*/
7990
protected function getLoginUrl()
8091
{
81-
return $this->urlBuilder->getUrl(Url::ROUTE_ACCOUNT_LOGIN);
92+
return $this->customerUrl->getLoginUrl();
8293
}
8394

8495
/**

app/code/Magento/Customer/Test/Unit/Model/Checkout/ConfigProviderTest.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,35 @@ class ConfigProviderTest extends \PHPUnit_Framework_TestCase
4141
*/
4242
protected $store;
4343

44+
/**
45+
* @var Url|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $customerUrl;
48+
4449
protected function setUp()
4550
{
4651
$this->storeManager = $this->getMockForAbstractClass(
47-
'Magento\Store\Model\StoreManagerInterface',
52+
\Magento\Store\Model\StoreManagerInterface::class,
4853
[],
4954
'',
5055
false
5156
);
57+
5258
$this->urlBuilder = $this->getMockForAbstractClass(
53-
'Magento\Framework\UrlInterface',
59+
\Magento\Framework\UrlInterface::class,
5460
[],
5561
'',
5662
false
5763
);
64+
5865
$this->scopeConfig = $this->getMockForAbstractClass(
59-
'Magento\Framework\App\Config\ScopeConfigInterface',
66+
\Magento\Framework\App\Config\ScopeConfigInterface::class,
6067
[],
6168
'',
6269
false
6370
);
6471
$this->store = $this->getMockForAbstractClass(
65-
'Magento\Store\Api\Data\StoreInterface',
72+
\Magento\Store\Api\Data\StoreInterface::class,
6673
[],
6774
'',
6875
false,
@@ -71,10 +78,16 @@ protected function setUp()
7178
['getBaseUrl']
7279
);
7380

81+
$this->customerUrl = $this->getMockBuilder(\Magento\Customer\Model\Url::class)
82+
->disableOriginalConstructor()
83+
->setMethods(['getLoginUrl'])
84+
->getMock();
85+
7486
$this->provider = new ConfigProvider(
7587
$this->urlBuilder,
7688
$this->storeManager,
77-
$this->scopeConfig
89+
$this->scopeConfig,
90+
$this->customerUrl
7891
);
7992
}
8093

@@ -83,9 +96,8 @@ public function testGetConfigWithoutRedirect()
8396
$loginUrl = 'http://url.test/customer/login';
8497
$baseUrl = 'http://base-url.test';
8598

86-
$this->urlBuilder->expects($this->exactly(2))
87-
->method('getUrl')
88-
->with(Url::ROUTE_ACCOUNT_LOGIN)
99+
$this->customerUrl->expects($this->exactly(2))
100+
->method('getLoginUrl')
89101
->willReturn($loginUrl);
90102
$this->storeManager->expects($this->once())
91103
->method('getStore')
@@ -112,9 +124,8 @@ public function testGetConfig()
112124
$loginUrl = 'http://base-url.test/customer/login';
113125
$baseUrl = 'http://base-url.test';
114126

115-
$this->urlBuilder->expects($this->exactly(2))
116-
->method('getUrl')
117-
->with(Url::ROUTE_ACCOUNT_LOGIN)
127+
$this->customerUrl->expects($this->exactly(2))
128+
->method('getLoginUrl')
118129
->willReturn($loginUrl);
119130
$this->storeManager->expects($this->once())
120131
->method('getStore')

0 commit comments

Comments
 (0)