Skip to content

Commit 43d061b

Browse files
author
Joan He
committed
MAGETWO-66318: Remove usages of serialize/unserialize in CmsSampleData
- fix build failures
1 parent 7263c0f commit 43d061b

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

app/code/Magento/Widget/Helper/Conditions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Conditions
2626

2727
/**
2828
* @param Json $serializer
29+
* @param Normalizer $normalizer
2930
*/
3031
public function __construct(
3132
Json $serializer = null,

app/code/Magento/Widget/Test/Unit/Helper/ConditionsTest.php

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Widget\Test\Unit\Helper;
88

9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Widget\Model\Widget\Wysiwyg\Normalizer;
11+
912
/**
1013
* Class ConditionsTest
1114
*/
@@ -21,39 +24,48 @@ class ConditionsTest extends \PHPUnit_Framework_TestCase
2124
*/
2225
private $serializer;
2326

27+
/**
28+
* @var Normalizer|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $normalizer;
31+
2432
/**
2533
* {@inheritdoc}
2634
*/
2735
protected function setUp()
2836
{
29-
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, null);
30-
$this->conditions = new \Magento\Widget\Helper\Conditions(
31-
$this->serializer
37+
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class);
38+
$this->normalizer = $this->getMock(Normalizer::class);
39+
$this->conditions = (new ObjectManager($this))->getObject(
40+
\Magento\Widget\Helper\Conditions::class,
41+
[
42+
'serializer' => $this->serializer,
43+
'normalizer' => $this->normalizer
44+
]
3245
);
3346
}
3447

3548
public function testEncodeDecode()
3649
{
37-
$value = [
38-
'1' => [
39-
"type" => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
40-
"aggregator" => "all",
41-
"value" => "1",
42-
"new_child" => "",
43-
],
44-
'1--1' => [
45-
"type" => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
46-
"attribute" => "attribute_set_id",
47-
"value" => "4",
48-
"operator" => "==",
49-
],
50-
'1--2' => [
51-
"type" => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
52-
"attribute" => "category_ids",
53-
"value" => "2",
54-
"operator" => "==",
55-
],
56-
];
50+
$value = ['string'];
51+
$serializedValue = 'serializedString';
52+
$normalizedValue = 'normalizedValue';
53+
$this->serializer->expects($this->once())
54+
->method('serialize')
55+
->with($value)
56+
->willReturn($serializedValue);
57+
$this->serializer->expects($this->once())
58+
->method('unserialize')
59+
->with($serializedValue)
60+
->willReturn($value);
61+
$this->normalizer->expects($this->once())
62+
->method('replaceReservedCharaters')
63+
->with($serializedValue)
64+
->willReturn($normalizedValue);
65+
$this->normalizer->expects($this->once())
66+
->method('restoreReservedCharaters')
67+
->with($normalizedValue)
68+
->willReturn($serializedValue);
5769
$encoded = $this->conditions->encode($value);
5870
$this->assertEquals($value, $this->conditions->decode($encoded));
5971
}

0 commit comments

Comments
 (0)