Skip to content

Commit 1d80c33

Browse files
author
Magento CICD
authored
MAGETWO-64536: [GitHub] [PR] Remove zend json checkout #8481
2 parents 9940a71 + f796c3a commit 1d80c33

File tree

9 files changed

+120
-14
lines changed

9 files changed

+120
-14
lines changed

app/code/Magento/Checkout/Block/Cart/Shipping.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,36 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
2020
*/
2121
protected $layoutProcessors;
2222

23+
/**
24+
* @var \Magento\Framework\Serialize\Serializer\Json
25+
*/
26+
private $serializer;
27+
2328
/**
2429
* @param \Magento\Framework\View\Element\Template\Context $context
2530
* @param \Magento\Customer\Model\Session $customerSession
2631
* @param \Magento\Checkout\Model\Session $checkoutSession
2732
* @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
2833
* @param array $layoutProcessors
2934
* @param array $data
30-
* @codeCoverageIgnore
35+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
36+
* @throws \RuntimeException
3137
*/
3238
public function __construct(
3339
\Magento\Framework\View\Element\Template\Context $context,
3440
\Magento\Customer\Model\Session $customerSession,
3541
\Magento\Checkout\Model\Session $checkoutSession,
3642
\Magento\Checkout\Model\CompositeConfigProvider $configProvider,
3743
array $layoutProcessors = [],
38-
array $data = []
44+
array $data = [],
45+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
3946
) {
4047
$this->configProvider = $configProvider;
4148
$this->layoutProcessors = $layoutProcessors;
4249
parent::__construct($context, $customerSession, $checkoutSession, $data);
4350
$this->_isScopePrivate = true;
51+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
52+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
4453
}
4554

4655
/**
@@ -64,7 +73,7 @@ public function getJsLayout()
6473
foreach ($this->layoutProcessors as $processor) {
6574
$this->jsLayout = $processor->process($this->jsLayout);
6675
}
67-
return \Zend_Json::encode($this->jsLayout);
76+
return $this->serializer->serialize($this->jsLayout);
6877
}
6978

7079
/**
@@ -77,4 +86,12 @@ public function getBaseUrl()
7786
{
7887
return $this->_storeManager->getStore()->getBaseUrl();
7988
}
89+
90+
/**
91+
* @return bool|string
92+
*/
93+
public function getSerializedCheckoutConfig()
94+
{
95+
return $this->serializer->serialize($this->getCheckoutConfig());
96+
}
8097
}

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,29 @@ class Sidebar extends AbstractCart
2727
*/
2828
protected $imageHelper;
2929

30+
/**
31+
* @var \Magento\Framework\Serialize\Serializer\Json
32+
*/
33+
private $serializer;
34+
3035
/**
3136
* @param \Magento\Framework\View\Element\Template\Context $context
3237
* @param \Magento\Customer\Model\Session $customerSession
3338
* @param \Magento\Checkout\Model\Session $checkoutSession
3439
* @param \Magento\Catalog\Helper\Image $imageHelper
3540
* @param \Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface $jsLayoutDataProvider
3641
* @param array $data
37-
* @codeCoverageIgnore
42+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
43+
* @throws \RuntimeException
3844
*/
3945
public function __construct(
4046
\Magento\Framework\View\Element\Template\Context $context,
4147
\Magento\Customer\Model\Session $customerSession,
4248
\Magento\Checkout\Model\Session $checkoutSession,
4349
\Magento\Catalog\Helper\Image $imageHelper,
4450
\Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface $jsLayoutDataProvider,
45-
array $data = []
51+
array $data = [],
52+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4653
) {
4754
if (isset($data['jsLayout'])) {
4855
$this->jsLayout = array_merge_recursive($jsLayoutDataProvider->getData(), $data['jsLayout']);
@@ -53,6 +60,8 @@ public function __construct(
5360
parent::__construct($context, $customerSession, $checkoutSession, $data);
5461
$this->_isScopePrivate = false;
5562
$this->imageHelper = $imageHelper;
63+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
64+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
5665
}
5766

5867
/**
@@ -75,6 +84,14 @@ public function getConfig()
7584
];
7685
}
7786

87+
/**
88+
* @return string
89+
*/
90+
public function getSerializedConfig()
91+
{
92+
return $this->serializer->serialize($this->getConfig());
93+
}
94+
7895
/**
7996
* @return string
8097
*/

app/code/Magento/Checkout/Block/Onepage.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,36 @@ class Onepage extends \Magento\Framework\View\Element\Template
3636
*/
3737
protected $layoutProcessors;
3838

39+
/**
40+
* @var \Magento\Framework\Serialize\Serializer\Json
41+
*/
42+
private $serializer;
43+
3944
/**
4045
* @param \Magento\Framework\View\Element\Template\Context $context
4146
* @param \Magento\Framework\Data\Form\FormKey $formKey
4247
* @param \Magento\Checkout\Model\CompositeConfigProvider $configProvider
4348
* @param array $layoutProcessors
4449
* @param array $data
50+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
51+
* @throws \RuntimeException
4552
*/
4653
public function __construct(
4754
\Magento\Framework\View\Element\Template\Context $context,
4855
\Magento\Framework\Data\Form\FormKey $formKey,
4956
\Magento\Checkout\Model\CompositeConfigProvider $configProvider,
5057
array $layoutProcessors = [],
51-
array $data = []
58+
array $data = [],
59+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
5260
) {
5361
parent::__construct($context, $data);
5462
$this->formKey = $formKey;
5563
$this->_isScopePrivate = true;
5664
$this->jsLayout = isset($data['jsLayout']) && is_array($data['jsLayout']) ? $data['jsLayout'] : [];
5765
$this->configProvider = $configProvider;
5866
$this->layoutProcessors = $layoutProcessors;
67+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
68+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
5969
}
6070

6171
/**
@@ -66,7 +76,7 @@ public function getJsLayout()
6676
foreach ($this->layoutProcessors as $processor) {
6777
$this->jsLayout = $processor->process($this->jsLayout);
6878
}
69-
return \Zend_Json::encode($this->jsLayout);
79+
return $this->serializer->serialize($this->jsLayout);
7080
}
7181

7282
/**
@@ -101,4 +111,12 @@ public function getBaseUrl()
101111
{
102112
return $this->_storeManager->getStore()->getBaseUrl();
103113
}
114+
115+
/**
116+
* @return bool|string
117+
*/
118+
public function getSerializedCheckoutConfig()
119+
{
120+
return $this->serializer->serialize($this->getCheckoutConfig());
121+
}
104122
}

app/code/Magento/Checkout/Test/Unit/Block/Cart/ShippingTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class ShippingTest extends \PHPUnit_Framework_TestCase
4747
*/
4848
protected $layout;
4949

50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
private $serializer;
54+
5055
protected function setUp()
5156
{
5257
$this->context = $this->getMock(\Magento\Framework\View\Element\Template\Context::class, [], [], '', false);
@@ -69,14 +74,16 @@ protected function setUp()
6974

7075
$this->storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
7176
$this->context->expects($this->once())->method('getStoreManager')->willReturn($this->storeManager);
77+
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);
7278

7379
$this->model = new \Magento\Checkout\Block\Cart\Shipping(
7480
$this->context,
7581
$this->customerSession,
7682
$this->checkoutSession,
7783
$this->configProvider,
7884
[$this->layoutProcessor],
79-
['jsLayout' => $this->layout]
85+
['jsLayout' => $this->layout],
86+
$this->serializer
8087
);
8188
}
8289

@@ -91,13 +98,18 @@ public function testGetJsLayout()
9198
{
9299
$layoutProcessed = $this->layout;
93100
$layoutProcessed['components']['thirdComponent'] = ['param' => 'value'];
101+
$jsonLayoutProcessed = json_encode($layoutProcessed);
94102

95103
$this->layoutProcessor->expects($this->once())
96104
->method('process')
97105
->with($this->layout)
98106
->willReturn($layoutProcessed);
107+
108+
$this->serializer->expects($this->once())->method('serialize')->will(
109+
$this->returnValue($jsonLayoutProcessed)
110+
);
99111
$this->assertEquals(
100-
\Zend_Json::encode($layoutProcessed),
112+
$jsonLayoutProcessed,
101113
$this->model->getJsLayout()
102114
);
103115
}
@@ -110,4 +122,15 @@ public function testGetBaseUrl()
110122
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
111123
$this->assertEquals($baseUrl, $this->model->getBaseUrl());
112124
}
125+
126+
public function testGetSerializedCheckoutConfig()
127+
{
128+
$checkoutConfig = ['checkout', 'config'];
129+
$this->configProvider->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
130+
$this->serializer->expects($this->once())->method('serialize')->will(
131+
$this->returnValue(json_encode($checkoutConfig))
132+
);
133+
134+
$this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig());
135+
}
113136
}

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class SidebarTest extends \PHPUnit_Framework_TestCase
5353
*/
5454
protected $requestMock;
5555

56+
/**
57+
* @var \PHPUnit_Framework_MockObject_MockObject
58+
*/
59+
private $serializer;
60+
5661
protected function setUp()
5762
{
5863
$this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -94,12 +99,15 @@ protected function setUp()
9499
->method('getRequest')
95100
->will($this->returnValue($this->requestMock));
96101

102+
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);
103+
97104
$this->model = $this->_objectManager->getObject(
98105
\Magento\Checkout\Block\Cart\Sidebar::class,
99106
[
100107
'context' => $contextMock,
101108
'imageHelper' => $this->imageHelper,
102-
'checkoutSession' => $this->checkoutSessionMock
109+
'checkoutSession' => $this->checkoutSessionMock,
110+
'serializer' => $this->serializer
103111
]
104112
);
105113
}

app/code/Magento/Checkout/Test/Unit/Block/OnepageTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class OnepageTest extends \PHPUnit_Framework_TestCase
3232
*/
3333
protected $layoutProcessorMock;
3434

35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $serializer;
39+
3540
protected function setUp()
3641
{
3742
$contextMock = $this->getMock(\Magento\Framework\View\Element\Template\Context::class, [], [], '', false);
@@ -54,11 +59,15 @@ protected function setUp()
5459
false
5560
);
5661

62+
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);
63+
5764
$this->model = new \Magento\Checkout\Block\Onepage(
5865
$contextMock,
5966
$this->formKeyMock,
6067
$this->configProviderMock,
61-
[$this->layoutProcessorMock]
68+
[$this->layoutProcessorMock],
69+
[],
70+
$this->serializer
6271
);
6372
}
6473

@@ -94,7 +103,21 @@ public function testGetJsLayout()
94103
$processedLayout = ['layout' => ['processed' => true]];
95104
$jsonLayout = '{"layout":{"processed":true}}';
96105
$this->layoutProcessorMock->expects($this->once())->method('process')->with([])->willReturn($processedLayout);
106+
$this->serializer->expects($this->once())->method('serialize')->will(
107+
$this->returnValue(json_encode($processedLayout))
108+
);
97109

98110
$this->assertEquals($jsonLayout, $this->model->getJsLayout());
99111
}
112+
113+
public function testGetSerializedCheckoutConfig()
114+
{
115+
$checkoutConfig = ['checkout', 'config'];
116+
$this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($checkoutConfig);
117+
$this->serializer->expects($this->once())->method('serialize')->will(
118+
$this->returnValue(json_encode($checkoutConfig))
119+
);
120+
121+
$this->assertEquals(json_encode($checkoutConfig), $this->model->getSerializedCheckoutConfig());
122+
}
100123
}

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</div>
4444
<?php endif ?>
4545
<script>
46-
window.checkout = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getConfig()); ?>;
46+
window.checkout = <?php /* @escapeNotVerified */ echo $block->getSerializedConfig(); ?>;
4747
</script>
4848
<script type="text/x-magento-init">
4949
{

app/code/Magento/Checkout/view/frontend/templates/cart/shipping.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
</script>
2727
<script>
28-
window.checkoutConfig = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getCheckoutConfig()); ?>;
28+
window.checkoutConfig = <?php /* @escapeNotVerified */ echo $block->getSerializedCheckoutConfig(); ?>;
2929
window.customerData = window.checkoutConfig.customerData;
3030
window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
3131
require([

app/code/Magento/Checkout/view/frontend/templates/onepage.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
</script>
2525
<script>
26-
window.checkoutConfig = <?php /* @escapeNotVerified */ echo \Zend_Json::encode($block->getCheckoutConfig()); ?>;
26+
window.checkoutConfig = <?php /* @escapeNotVerified */ echo $block->getSerializedCheckoutConfig(); ?>;
2727
// Create aliases for customer.js model from customer module
2828
window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
2929
window.customerData = window.checkoutConfig.customerData;

0 commit comments

Comments
 (0)