Skip to content

Commit

Permalink
MAGETWO-53628: JS error in the authentication-popup
Browse files Browse the repository at this point in the history
  • Loading branch information
slavvka committed Jun 8, 2016
1 parent 7edfd0c commit 362f62f
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/code/Magento/Customer/Block/Account/AuthenticationPopup.php
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\Customer\Block\Account;

use Magento\Customer\Model\Form;
use Magento\Store\Model\ScopeInterface;

class AuthenticationPopup extends \Magento\Framework\View\Element\Template
{
/**
Expand Down Expand Up @@ -40,12 +43,26 @@ public function getJsLayout()
public function getConfig()
{
return [
'autocomplete' => $this->isAutocompleteEnabled(),
'customerRegisterUrl' => $this->getCustomerRegisterUrlUrl(),
'customerForgotPasswordUrl' => $this->getCustomerForgotPasswordUrl(),
'baseUrl' => $this->getBaseUrl()
];
}

/**
* Is autocomplete enabled for storefront
*
* @return string
*/
private function isAutocompleteEnabled()
{
return $this->_scopeConfig->getValue(
Form::XML_PATH_ENABLE_AUTOCOMPLETE,
ScopeInterface::SCOPE_STORE
) ? 'on' : 'off';
}

/**
* Return base url.
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Model/Customer.php
Expand Up @@ -1340,7 +1340,7 @@ public function getPasswordConfirm()
}

/**
* Return Password Confirmation
* Return Password
*
* @return string
*/
Expand Down
@@ -0,0 +1,157 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Test\Unit\Block\Account;

use Magento\Customer\Block\Account\AuthenticationPopup;
use Magento\Customer\Model\Form;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase
{
/** @var AuthenticationPopup */
private $model;

/** @var Context|\PHPUnit_Framework_MockObject_MockObject */
private $contextMock;

/** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
private $storeManagerMock;

/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
private $scopeConfigMock;

/** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
private $urlBuilderMock;

protected function setUp()
{
$this->contextMock = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();

$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
->getMock();
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
->getMock();
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
->getMock();

$this->contextMock->expects($this->once())
->method('getStoreManager')
->willReturn($this->storeManagerMock);
$this->contextMock->expects($this->once())
->method('getScopeConfig')
->willReturn($this->scopeConfigMock);
$this->contextMock->expects($this->once())
->method('getUrlBuilder')
->willReturn($this->urlBuilderMock);

$this->model = new AuthenticationPopup(
$this->contextMock
);
}

/**
* @param mixed $isAutocomplete
* @param string $baseUrl
* @param string $registerUrl
* @param string $forgotUrl
* @param array $result
*
* @dataProvider dataProviderGetConfig
*/
public function testGetConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result)
{
$this->scopeConfigMock->expects($this->any())
->method('getValue')
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
->willReturn($isAutocomplete);

/** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */
$storeMock = $this->getMockBuilder(StoreInterface::class)
->setMethods(['getBaseUrl'])
->getMockForAbstractClass();

$this->storeManagerMock->expects($this->any())
->method('getStore')
->with(null)
->willReturn($storeMock);

$storeMock->expects($this->any())
->method('getBaseUrl')
->willReturn($baseUrl);

$this->urlBuilderMock->expects($this->any())
->method('getUrl')
->willReturnMap(
[
['customer/account/create', [], $registerUrl],
['customer/account/forgotpassword', [], $forgotUrl],
]
);

$this->assertEquals($result, $this->model->getConfig());
}

public function dataProviderGetConfig()
{
return [
[
0,
'base',
'reg',
'forgot',
[
'autocomplete' => 'off',
'customerRegisterUrl' => 'reg',
'customerForgotPasswordUrl' => 'forgot',
'baseUrl' => 'base',
],
],
[
1,
'',
'reg',
'forgot',
[
'autocomplete' => 'on',
'customerRegisterUrl' => 'reg',
'customerForgotPasswordUrl' => 'forgot',
'baseUrl' => '',
],
],
[
'',
'base',
'',
'forgot',
[
'autocomplete' => 'off',
'customerRegisterUrl' => '',
'customerForgotPasswordUrl' => 'forgot',
'baseUrl' => 'base',
],
],
[
true,
'base',
'reg',
'',
[
'autocomplete' => 'on',
'customerRegisterUrl' => 'reg',
'customerForgotPasswordUrl' => '',
'baseUrl' => 'base',
],
],
];
}
}
Expand Up @@ -5,6 +5,7 @@
*/

// @codingStandardsIgnoreFile
/** @var $block \Magento\Customer\Block\Account\AuthenticationPopup */
?>
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'" style="display: none;">
<script>
Expand Down
Expand Up @@ -23,7 +23,7 @@ define(
return Component.extend({
registerUrl: window.authenticationPopup.customerRegisterUrl,
forgotPasswordUrl: window.authenticationPopup.customerForgotPasswordUrl,
autocomplete: window.checkout.autocomplete,
autocomplete: window.authenticationPopup.autocomplete,
modalWindow: null,
isLoading: ko.observable(false),

Expand Down

0 comments on commit 362f62f

Please sign in to comment.