10
10
use Magento \Store \Api \Data \StoreInterface ;
11
11
use Magento \Store \Model \StoreManagerInterface ;
12
12
use Magento \Customer \Block \CustomerScopeData ;
13
- use Magento \Framework \Json \EncoderInterface ;
14
13
15
14
class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
16
15
{
@@ -29,6 +28,9 @@ class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
29
28
/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
30
29
private $ encoderMock ;
31
30
31
+ /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
32
+ private $ serializerMock ;
33
+
32
34
protected function setUp ()
33
35
{
34
36
$ this ->contextMock = $ this ->getMockBuilder (Context::class)
@@ -41,7 +43,10 @@ protected function setUp()
41
43
$ this ->scopeConfigMock = $ this ->getMockBuilder (ScopeConfigInterface::class)
42
44
->getMock ();
43
45
44
- $ this ->encoderMock = $ this ->getMockBuilder (EncoderInterface::class)
46
+ $ this ->encoderMock = $ this ->getMockBuilder (\Magento \Framework \Json \EncoderInterface::class)
47
+ ->getMock ();
48
+
49
+ $ this ->serializerMock = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
45
50
->getMock ();
46
51
47
52
$ this ->contextMock ->expects ($ this ->exactly (2 ))
@@ -55,7 +60,8 @@ protected function setUp()
55
60
$ this ->model = new CustomerScopeData (
56
61
$ this ->contextMock ,
57
62
$ this ->encoderMock ,
58
- []
63
+ [],
64
+ $ this ->serializerMock
59
65
);
60
66
}
61
67
@@ -78,4 +84,84 @@ public function testGetWebsiteId()
78
84
79
85
$ this ->assertEquals ($ storeId , $ this ->model ->getWebsiteId ());
80
86
}
87
+
88
+ public function testGetInvalidationRules ()
89
+ {
90
+ $ storeId = 1 ;
91
+
92
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)
93
+ ->setMethods (['getWebsiteId ' ])
94
+ ->getMockForAbstractClass ();
95
+
96
+ $ storeMock ->expects ($ this ->any ())
97
+ ->method ('getWebsiteId ' )
98
+ ->willReturn ($ storeId );
99
+
100
+ $ this ->storeManagerMock ->expects ($ this ->any ())
101
+ ->method ('getStore ' )
102
+ ->with (null )
103
+ ->willReturn ($ storeMock );
104
+
105
+ $ this ->assertEquals (
106
+ [
107
+ '* ' => [
108
+ 'Magento_Customer/js/invalidation-processor ' => [
109
+ 'invalidationRules ' => [
110
+ 'website-rule ' => [
111
+ 'Magento_Customer/js/invalidation-rules/website-rule ' => [
112
+ 'scopeConfig ' => [
113
+ 'websiteId ' => 1 ,
114
+ ]
115
+ ]
116
+ ]
117
+ ]
118
+ ]
119
+ ],
120
+ ],
121
+ $ this ->model ->getInvalidationRules ()
122
+ );
123
+ }
124
+
125
+ public function testGetSerializedInvalidationRules ()
126
+ {
127
+ $ storeId = 1 ;
128
+ $ rules = [
129
+ '* ' => [
130
+ 'Magento_Customer/js/invalidation-processor ' => [
131
+ 'invalidationRules ' => [
132
+ 'website-rule ' => [
133
+ 'Magento_Customer/js/invalidation-rules/website-rule ' => [
134
+ 'scopeConfig ' => [
135
+ 'websiteId ' => 1 ,
136
+ ]
137
+ ]
138
+ ]
139
+ ]
140
+ ]
141
+ ],
142
+ ];
143
+
144
+ $ storeMock = $ this ->getMockBuilder (StoreInterface::class)
145
+ ->setMethods (['getWebsiteId ' ])
146
+ ->getMockForAbstractClass ();
147
+
148
+ $ storeMock ->expects ($ this ->any ())
149
+ ->method ('getWebsiteId ' )
150
+ ->willReturn ($ storeId );
151
+
152
+ $ this ->storeManagerMock ->expects ($ this ->any ())
153
+ ->method ('getStore ' )
154
+ ->with (null )
155
+ ->willReturn ($ storeMock );
156
+
157
+ $ this ->serializerMock ->expects ($ this ->any ())
158
+ ->method ('serialize ' )
159
+ ->with ($ rules )
160
+ ->willReturn (json_encode ($ rules ));
161
+
162
+ $ this ->assertEquals (
163
+ json_encode ($ rules ),
164
+ $ this ->model ->getSerializedInvalidationRules ()
165
+ );
166
+ }
81
167
}
0 commit comments