Skip to content

Commit 5181fdd

Browse files
author
okarpenko
committed
MAGETWO-45156: [ZAP-M2]: Password Autocomplete in browser (10/15/15)
1 parent 22629ab commit 5181fdd

File tree

4 files changed

+168
-1
lines changed

4 files changed

+168
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use Magento\Customer\Model\Url;
1010
use Magento\Framework\UrlInterface;
1111
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Customer\Model\Form;
14+
use Magento\Store\Model\ScopeInterface;
1215

1316
class ConfigProvider implements ConfigProviderInterface
1417
{
@@ -22,16 +25,24 @@ class ConfigProvider implements ConfigProviderInterface
2225
*/
2326
protected $urlBuilder;
2427

28+
/**
29+
* @var ScopeConfigInterface
30+
*/
31+
protected $scopeConfig;
32+
2533
/**
2634
* @param UrlInterface $urlBuilder
2735
* @param StoreManagerInterface $storeManager
36+
* @param ScopeConfigInterface $scopeConfig
2837
*/
2938
public function __construct(
3039
UrlInterface $urlBuilder,
31-
StoreManagerInterface $storeManager
40+
StoreManagerInterface $storeManager,
41+
ScopeConfigInterface $scopeConfig
3242
) {
3343
$this->urlBuilder = $urlBuilder;
3444
$this->storeManager = $storeManager;
45+
$this->scopeConfig = $scopeConfig;
3546
}
3647

3748
/**
@@ -42,9 +53,24 @@ public function getConfig()
4253
return [
4354
'customerLoginUrl' => $this->getLoginUrl(),
4455
'isRedirectRequired' => $this->isRedirectRequired(),
56+
'autocomplete' => $this->isAutocompleteEnabled(),
4557
];
4658
}
4759

60+
/**
61+
* Is autocomplete enabled for storefront
62+
*
63+
* @return string
64+
* @codeCoverageIgnore
65+
*/
66+
protected function isAutocompleteEnabled()
67+
{
68+
return $this->scopeConfig->getValue(
69+
Form::XML_PATH_ENABLE_AUTOCOMPLETE,
70+
ScopeInterface::SCOPE_STORE
71+
) ? 'on' : 'off';
72+
}
73+
4874
/**
4975
* Returns URL to login controller action
5076
*
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model\Checkout;
7+
8+
use Magento\Customer\Model\Checkout\ConfigProvider;
9+
use Magento\Framework\UrlInterface;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\Store\Api\Data\StoreInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Customer\Model\Url;
14+
use Magento\Customer\Model\Form;
15+
use Magento\Store\Model\ScopeInterface;
16+
17+
class ConfigProviderTest extends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @var ConfigProvider
21+
*/
22+
protected $provider;
23+
24+
/**
25+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $storeManager;
28+
29+
/**
30+
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $urlBuilder;
33+
34+
/**
35+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $scopeConfig;
38+
39+
/**
40+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $store;
43+
44+
public function setUp()
45+
{
46+
$this->storeManager = $this->getMockForAbstractClass(
47+
'Magento\Store\Model\StoreManagerInterface',
48+
[],
49+
'',
50+
false
51+
);
52+
$this->urlBuilder = $this->getMockForAbstractClass(
53+
'Magento\Framework\UrlInterface',
54+
[],
55+
'',
56+
false
57+
);
58+
$this->scopeConfig = $this->getMockForAbstractClass(
59+
'Magento\Framework\App\Config\ScopeConfigInterface',
60+
[],
61+
'',
62+
false
63+
);
64+
$this->store = $this->getMockForAbstractClass(
65+
'Magento\Store\Api\Data\StoreInterface',
66+
[],
67+
'',
68+
false,
69+
false,
70+
true,
71+
['getBaseUrl']
72+
);
73+
74+
$this->provider = new ConfigProvider(
75+
$this->urlBuilder,
76+
$this->storeManager,
77+
$this->scopeConfig
78+
);
79+
}
80+
81+
public function testGetConfigWithoutRedirect()
82+
{
83+
$loginUrl = 'http://url.test/customer/login';
84+
$baseUrl = 'http://base-url.test';
85+
86+
$this->urlBuilder->expects($this->exactly(2))
87+
->method('getUrl')
88+
->with(Url::ROUTE_ACCOUNT_LOGIN)
89+
->willReturn($loginUrl);
90+
$this->storeManager->expects($this->once())
91+
->method('getStore')
92+
->willReturn($this->store);
93+
$this->store->expects($this->once())
94+
->method('getBaseUrl')
95+
->willReturn($baseUrl);
96+
$this->scopeConfig->expects($this->once())
97+
->method('getValue')
98+
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE)
99+
->willReturn(1);
100+
$this->assertEquals(
101+
[
102+
'customerLoginUrl' => $loginUrl,
103+
'isRedirectRequired' => true,
104+
'autocomplete' => 'on',
105+
],
106+
$this->provider->getConfig()
107+
);
108+
}
109+
110+
public function testGetConfig()
111+
{
112+
$loginUrl = 'http://base-url.test/customer/login';
113+
$baseUrl = 'http://base-url.test';
114+
115+
$this->urlBuilder->expects($this->exactly(2))
116+
->method('getUrl')
117+
->with(Url::ROUTE_ACCOUNT_LOGIN)
118+
->willReturn($loginUrl);
119+
$this->storeManager->expects($this->once())
120+
->method('getStore')
121+
->willReturn($this->store);
122+
$this->store->expects($this->once())
123+
->method('getBaseUrl')
124+
->willReturn($baseUrl);
125+
$this->scopeConfig->expects($this->once())
126+
->method('getValue')
127+
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE)
128+
->willReturn(0);
129+
$this->assertEquals(
130+
[
131+
'customerLoginUrl' => $loginUrl,
132+
'isRedirectRequired' => false,
133+
'autocomplete' => 'off',
134+
],
135+
$this->provider->getConfig()
136+
);
137+
}
138+
}

app/code/Magento/Customer/view/frontend/web/js/view/authentication-popup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ define(
2222
return Component.extend({
2323
registerUrl: window.authenticationPopup.customerRegisterUrl,
2424
forgotPasswordUrl: window.authenticationPopup.customerForgotPasswordUrl,
25+
autocomplete: window.checkout.autocomplete,
2526
modalWindow: null,
2627
isLoading: ko.observable(false),
2728

app/code/Magento/Customer/view/frontend/web/template/authentication-popup.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
id="email"
6161
type="email"
6262
class="input-text"
63+
data-bind="attr: {autocomplete: autocomplete}"
6364
data-validate="{required:true, 'validate-email':true}">
6465
</div>
6566
</div>
@@ -70,6 +71,7 @@
7071
type="password"
7172
class="input-text"
7273
id="pass"
74+
data-bind="attr: {autocomplete: autocomplete}"
7375
data-validate="{required:true, 'validate-password':true}">
7476
</div>
7577
</div>

0 commit comments

Comments
 (0)