Skip to content

Commit 73efb7f

Browse files
committed
MAGETWO-65719: [GitHub][PR] Replace Zend_Json from the Magento Review module #8835
- Merge Pull Request #8835 from dmanners/magento2:remove-zend-json-from-review
2 parents f1dc91b + 67a28f5 commit 73efb7f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

app/code/Magento/Review/Block/Form.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,24 @@ class Form extends \Magento\Framework\View\Element\Template
6767
protected $jsLayout;
6868

6969
/**
70+
* @var \Magento\Framework\Serialize\Serializer\Json
71+
*/
72+
private $serializer;
73+
74+
/**
75+
* Form constructor.
76+
*
7077
* @param \Magento\Framework\View\Element\Template\Context $context
7178
* @param \Magento\Framework\Url\EncoderInterface $urlEncoder
7279
* @param \Magento\Review\Helper\Data $reviewData
7380
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
7481
* @param \Magento\Review\Model\RatingFactory $ratingFactory
7582
* @param \Magento\Framework\Message\ManagerInterface $messageManager
7683
* @param \Magento\Framework\App\Http\Context $httpContext
77-
* @param \Magento\Customer\Model\Url $customerUrl
84+
* @param Url $customerUrl
7885
* @param array $data
86+
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
87+
* @throws \RuntimeException
7988
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8089
*/
8190
public function __construct(
@@ -87,7 +96,8 @@ public function __construct(
8796
\Magento\Framework\Message\ManagerInterface $messageManager,
8897
\Magento\Framework\App\Http\Context $httpContext,
8998
\Magento\Customer\Model\Url $customerUrl,
90-
array $data = []
99+
array $data = [],
100+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
91101
) {
92102
$this->urlEncoder = $urlEncoder;
93103
$this->_reviewData = $reviewData;
@@ -98,6 +108,8 @@ public function __construct(
98108
$this->customerUrl = $customerUrl;
99109
parent::__construct($context, $data);
100110
$this->jsLayout = isset($data['jsLayout']) ? $data['jsLayout'] : [];
111+
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
112+
->get(\Magento\Framework\Serialize\Serializer\Json::class);
101113
}
102114

103115
/**
@@ -133,13 +145,13 @@ protected function _construct()
133145
*/
134146
public function getJsLayout()
135147
{
136-
return \Zend_Json::encode($this->jsLayout);
148+
return $this->serializer->serialize($this->jsLayout);
137149
}
138150

139151
/**
140152
* Get product info
141153
*
142-
* @return Product
154+
* @return \Magento\Catalog\Api\Data\ProductInterface
143155
* @throws \Magento\Framework\Exception\NoSuchEntityException
144156
*/
145157
public function getProductInfo()
@@ -171,6 +183,7 @@ public function getAction()
171183
* Get collection of ratings
172184
*
173185
* @return RatingCollection
186+
* @throws \Magento\Framework\Exception\LocalizedException
174187
*/
175188
public function getRatings()
176189
{

app/code/Magento/Review/Test/Unit/Block/FormTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class FormTest extends \PHPUnit_Framework_TestCase
3737
/** @var \Magento\Framework\UrlInterface|PHPUnit_Framework_MockObject_MockObject */
3838
protected $urlBuilder;
3939

40+
/** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
41+
private $serializerMock;
42+
4043
protected function setUp()
4144
{
4245
$this->storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
@@ -64,13 +67,21 @@ protected function setUp()
6467
$this->context->expects($this->any())->method('getUrlBuilder')->willReturn($this->urlBuilder);
6568
$this->productRepository = $this->getMock(\Magento\Catalog\Api\ProductRepositoryInterface::class);
6669

70+
$this->serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)->getMock();
71+
6772
$this->objectManagerHelper = new ObjectManagerHelper($this);
6873
$this->object = $this->objectManagerHelper->getObject(
6974
\Magento\Review\Block\Form::class,
7075
[
7176
'context' => $this->context,
7277
'reviewData' => $this->reviewDataMock,
7378
'productRepository' => $this->productRepository,
79+
'data' => [
80+
'jsLayout' => [
81+
'some-layout' => 'layout information'
82+
]
83+
],
84+
'serializer' => $this->serializerMock
7485
]
7586
);
7687
}
@@ -132,4 +143,15 @@ public function getActionDataProvider()
132143
[true, 'https://localhost/review/product/post' ,3],
133144
];
134145
}
146+
147+
public function testGetJsLayout()
148+
{
149+
$jsLayout = [
150+
'some-layout' => 'layout information'
151+
];
152+
153+
$this->serializerMock->expects($this->once())->method('serialize')
154+
->will($this->returnValue(json_encode($jsLayout)));
155+
$this->assertEquals('{"some-layout":"layout information"}', $this->object->getJsLayout());
156+
}
135157
}

0 commit comments

Comments
 (0)