Skip to content

Commit c74b6b7

Browse files
author
Magento CICD
authored
MAGETWO-64898: [GitHub][PR] Remove Zend_Json from Customer module #8617
2 parents 15de93d + 7dd8d4c commit c74b6b7

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed

app/code/Magento/Customer/Block/Account/AuthenticationPopup.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,34 @@ class AuthenticationPopup extends \Magento\Framework\View\Element\Template
1515
*/
1616
protected $jsLayout;
1717

18+
/**
19+
* @var \Magento\Framework\Serialize\Serializer\Json
20+
*/
21+
private $serializer;
22+
1823
/**
1924
* @param \Magento\Framework\View\Element\Template\Context $context
2025
* @param array $data
26+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
27+
* @throws \RuntimeException
2128
*/
2229
public function __construct(
2330
\Magento\Framework\View\Element\Template\Context $context,
24-
array $data = []
31+
array $data = [],
32+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
2533
) {
2634
parent::__construct($context, $data);
2735
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
36+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
37+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
2838
}
2939

3040
/**
3141
* @return string
3242
*/
3343
public function getJsLayout()
3444
{
35-
return \Zend_Json::encode($this->jsLayout);
45+
return $this->serializer->serialize($this->jsLayout);
3646
}
3747

3848
/**
@@ -50,6 +60,18 @@ public function getConfig()
5060
];
5161
}
5262

63+
/**
64+
* Returns popup config in JSON format.
65+
*
66+
* Added in scope of https://github.com/magento/magento2/pull/8617
67+
*
68+
* @return bool|string
69+
*/
70+
public function getSerializedConfig()
71+
{
72+
return $this->serializer->serialize($this->getConfig());
73+
}
74+
5375
/**
5476
* Is autocomplete enabled for storefront
5577
*

app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php

+57-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class AuthenticationPopupTest extends \PHPUnit_Framework_TestCase
3131
/** @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject */
3232
private $urlBuilderMock;
3333

34+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
35+
private $serializerMock;
36+
3437
protected function setUp()
3538
{
3639
$this->contextMock = $this->getMockBuilder(Context::class)
@@ -72,8 +75,13 @@ function ($string) {
7275
->method('getEscaper')
7376
->willReturn($escaperMock);
7477

78+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
79+
->getMock();
80+
7581
$this->model = new AuthenticationPopup(
76-
$this->contextMock
82+
$this->contextMock,
83+
[],
84+
$this->serializerMock
7785
);
7886
}
7987

@@ -83,6 +91,7 @@ function ($string) {
8391
* @param string $registerUrl
8492
* @param string $forgotUrl
8593
* @param array $result
94+
* @throws \PHPUnit_Framework_Exception
8695
*
8796
* @dataProvider dataProviderGetConfig
8897
*/
@@ -172,4 +181,51 @@ public function dataProviderGetConfig()
172181
],
173182
];
174183
}
184+
185+
/**
186+
* @param mixed $isAutocomplete
187+
* @param string $baseUrl
188+
* @param string $registerUrl
189+
* @param string $forgotUrl
190+
* @param array $result
191+
* @throws \PHPUnit_Framework_Exception
192+
*
193+
* @dataProvider dataProviderGetConfig
194+
*/
195+
public function testGetSerializedConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, array $result)
196+
{
197+
$this->scopeConfigMock->expects($this->any())
198+
->method('getValue')
199+
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
200+
->willReturn($isAutocomplete);
201+
202+
/** @var StoreInterface||\PHPUnit_Framework_MockObject_MockObject $storeMock */
203+
$storeMock = $this->getMockBuilder(StoreInterface::class)
204+
->setMethods(['getBaseUrl'])
205+
->getMockForAbstractClass();
206+
207+
$this->storeManagerMock->expects($this->any())
208+
->method('getStore')
209+
->with(null)
210+
->willReturn($storeMock);
211+
212+
$storeMock->expects($this->any())
213+
->method('getBaseUrl')
214+
->willReturn($baseUrl);
215+
216+
$this->urlBuilderMock->expects($this->any())
217+
->method('getUrl')
218+
->willReturnMap(
219+
[
220+
['customer/account/create', [], $registerUrl],
221+
['customer/account/forgotpassword', [], $forgotUrl],
222+
]
223+
);
224+
$this->serializerMock->expects($this->any())->method('serialize')
225+
->willReturn(
226+
json_encode($this->model->getConfig())
227+
);
228+
229+
$this->assertEquals(json_encode($result), $this->model->getSerializedConfig());
230+
}
175231
}

app/code/Magento/Customer/view/frontend/templates/account/authentication-popup.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
?>
1111
<div id="authenticationPopup" data-bind="scope:'authenticationPopup'" style="display: none;">
1212
<script>
13-
window.authenticationPopup = <?php /* @noEscape */ echo \Zend_Json::encode($block->getConfig()); ?>;
13+
window.authenticationPopup = <?php /* @noEscape */ echo $block->getSerializedConfig(); ?>;
1414
</script>
1515
<!-- ko template: getTemplate() --><!-- /ko -->
1616
<script type="text/x-magento-init">

0 commit comments

Comments
 (0)