6
6
7
7
namespace Magento \Widget \Test \Unit \Helper ;
8
8
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
10
+ use Magento \Widget \Model \Widget \Wysiwyg \Normalizer ;
11
+
9
12
/**
10
13
* Class ConditionsTest
11
14
*/
@@ -21,39 +24,48 @@ class ConditionsTest extends \PHPUnit_Framework_TestCase
21
24
*/
22
25
private $ serializer ;
23
26
27
+ /**
28
+ * @var Normalizer|\PHPUnit_Framework_MockObject_MockObject
29
+ */
30
+ private $ normalizer ;
31
+
24
32
/**
25
33
* {@inheritdoc}
26
34
*/
27
35
protected function setUp ()
28
36
{
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
+ ]
32
45
);
33
46
}
34
47
35
48
public function testEncodeDecode ()
36
49
{
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 );
57
69
$ encoded = $ this ->conditions ->encode ($ value );
58
70
$ this ->assertEquals ($ value , $ this ->conditions ->decode ($ encoded ));
59
71
}
0 commit comments