Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 4215a8b

Browse files
committed
MAGETWO-80177: [2.2.x] - Remove zend json from customer data #10259
- rework fix for 2.2.1 without minor change
1 parent 14e613b commit 4215a8b

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
lines changed

app/code/Magento/Customer/Block/CustomerScopeData.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
*/
66
namespace Magento\Customer\Block;
77

8-
use Magento\Framework\App\ObjectManager;
9-
use Magento\Framework\Serialize\Serializer\Json;
10-
118
/**
129
* Class CustomerScopeData provide scope (website, store or store_group) information on front
1310
* Can be used, for example, on store front, in order to determine
1411
* that private cache invalid for current scope, by comparing
1512
* with appropriate value in store front private cache.
16-
*
1713
* @api
1814
* @since 100.2.0
1915
*/
@@ -25,27 +21,24 @@ class CustomerScopeData extends \Magento\Framework\View\Element\Template
2521
private $storeManager;
2622

2723
/**
28-
* @var Json
24+
* @var \Magento\Framework\Json\EncoderInterface
2925
*/
30-
private $serializer;
26+
private $jsonEncoder;
3127

3228
/**
3329
* @param \Magento\Framework\View\Element\Template\Context $context
3430
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
3531
* @param array $data
36-
* @param Json|null $serializer
37-
* @throws \RuntimeException
38-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
32+
* @since 100.2.0
3933
*/
4034
public function __construct(
4135
\Magento\Framework\View\Element\Template\Context $context,
4236
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
43-
array $data = [],
44-
Json $serializer = null
37+
array $data = []
4538
) {
4639
parent::__construct($context, $data);
4740
$this->storeManager = $context->getStoreManager();
48-
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
41+
$this->jsonEncoder = $jsonEncoder;
4942
}
5043

5144
/**
@@ -60,16 +53,4 @@ public function getWebsiteId()
6053
{
6154
return (int)$this->_storeManager->getStore()->getWebsiteId();
6255
}
63-
64-
/**
65-
* Encode invalidation rules.
66-
*
67-
* @param array $configuration
68-
* @return bool|string
69-
* @throws \InvalidArgumentException
70-
*/
71-
public function encodeConfiguration(array $configuration)
72-
{
73-
return $this->serializer->serialize($configuration);
74-
}
7556
}

app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Store\Api\Data\StoreInterface;
1111
use Magento\Store\Model\StoreManagerInterface;
1212
use Magento\Customer\Block\CustomerScopeData;
13+
use Magento\Framework\Json\EncoderInterface;
1314

1415
class CustomerScopeDataTest extends \PHPUnit\Framework\TestCase
1516
{
@@ -28,9 +29,6 @@ class CustomerScopeDataTest extends \PHPUnit\Framework\TestCase
2829
/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
2930
private $encoderMock;
3031

31-
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
32-
private $serializerMock;
33-
3432
protected function setUp()
3533
{
3634
$this->contextMock = $this->getMockBuilder(Context::class)
@@ -43,10 +41,7 @@ protected function setUp()
4341
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
4442
->getMock();
4543

46-
$this->encoderMock = $this->getMockBuilder(\Magento\Framework\Json\EncoderInterface::class)
47-
->getMock();
48-
49-
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
44+
$this->encoderMock = $this->getMockBuilder(EncoderInterface::class)
5045
->getMock();
5146

5247
$this->contextMock->expects($this->exactly(2))
@@ -60,8 +55,7 @@ protected function setUp()
6055
$this->model = new CustomerScopeData(
6156
$this->contextMock,
6257
$this->encoderMock,
63-
[],
64-
$this->serializerMock
58+
[]
6559
);
6660
}
6761

@@ -84,33 +78,4 @@ public function testGetWebsiteId()
8478

8579
$this->assertEquals($storeId, $this->model->getWebsiteId());
8680
}
87-
88-
public function testEncodeConfiguration()
89-
{
90-
$rules = [
91-
'*' => [
92-
'Magento_Customer/js/invalidation-processor' => [
93-
'invalidationRules' => [
94-
'website-rule' => [
95-
'Magento_Customer/js/invalidation-rules/website-rule' => [
96-
'scopeConfig' => [
97-
'websiteId' => 1,
98-
]
99-
]
100-
]
101-
]
102-
]
103-
],
104-
];
105-
106-
$this->serializerMock->expects($this->any())
107-
->method('serialize')
108-
->with($rules)
109-
->willReturn(json_encode($rules));
110-
111-
$this->assertEquals(
112-
json_encode($rules),
113-
$this->model->encodeConfiguration($rules)
114-
);
115-
}
11681
}

app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
/* @var $block \Magento\Customer\Block\CustomerScopeData */
99
?>
1010
<script type="text/x-magento-init">
11-
<?= /* @noEscape */ $block->encodeConfiguration([
11+
<?php
12+
/* @noEscape */
13+
echo \Magento\Framework\Serialize\JsonConverter::convert([
1214
'*' => ['Magento_Customer/js/invalidation-processor' => [
1315
'invalidationRules' => [
1416
'website-rule' => [

0 commit comments

Comments
 (0)