Skip to content

Commit ea1ebff

Browse files
author
Oleksii Korshenko
authored
MAGETWO-85672: Add customer login url from Customer Url model to checkout config so … #12630
2 parents 0eaac68 + 9b0b867 commit ea1ebff

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
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: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ 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(
@@ -49,12 +54,14 @@ protected function setUp()
4954
'',
5055
false
5156
);
57+
5258
$this->urlBuilder = $this->getMockForAbstractClass(
5359
\Magento\Framework\UrlInterface::class,
5460
[],
5561
'',
5662
false
5763
);
64+
5865
$this->scopeConfig = $this->getMockForAbstractClass(
5966
\Magento\Framework\App\Config\ScopeConfigInterface::class,
6067
[],
@@ -71,10 +78,13 @@ protected function setUp()
7178
['getBaseUrl']
7279
);
7380

81+
$this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class);
82+
7483
$this->provider = new ConfigProvider(
7584
$this->urlBuilder,
7685
$this->storeManager,
77-
$this->scopeConfig
86+
$this->scopeConfig,
87+
$this->customerUrl
7888
);
7989
}
8090

@@ -83,9 +93,8 @@ public function testGetConfigWithoutRedirect()
8393
$loginUrl = 'http://url.test/customer/login';
8494
$baseUrl = 'http://base-url.test';
8595

86-
$this->urlBuilder->expects($this->exactly(2))
87-
->method('getUrl')
88-
->with(Url::ROUTE_ACCOUNT_LOGIN)
96+
$this->customerUrl->expects($this->exactly(2))
97+
->method('getLoginUrl')
8998
->willReturn($loginUrl);
9099
$this->storeManager->expects($this->once())
91100
->method('getStore')
@@ -112,9 +121,8 @@ public function testGetConfig()
112121
$loginUrl = 'http://base-url.test/customer/login';
113122
$baseUrl = 'http://base-url.test';
114123

115-
$this->urlBuilder->expects($this->exactly(2))
116-
->method('getUrl')
117-
->with(Url::ROUTE_ACCOUNT_LOGIN)
124+
$this->customerUrl->expects($this->exactly(2))
125+
->method('getLoginUrl')
118126
->willReturn($loginUrl);
119127
$this->storeManager->expects($this->once())
120128
->method('getStore')

0 commit comments

Comments
 (0)