7
7
8
8
namespace Magento \Framework \App \Test \Unit \PageCache ;
9
9
10
+ use Laminas \Stdlib \Parameters ;
10
11
use Magento \Framework \App \Http \Context ;
11
12
use Magento \Framework \App \PageCache \Identifier ;
12
13
use Magento \Framework \App \Request \Http as HttpRequest ;
@@ -20,7 +21,7 @@ class IdentifierTest extends TestCase
20
21
/**
21
22
* Test value for cache vary string
22
23
*/
23
- const VARY = '123 ' ;
24
+ private const VARY = '123 ' ;
24
25
25
26
/**
26
27
* @var ObjectManager
@@ -47,6 +48,9 @@ class IdentifierTest extends TestCase
47
48
*/
48
49
private $ serializerMock ;
49
50
51
+ /** @var Parameters|MockObject */
52
+ private $ fileParams ;
53
+
50
54
/**
51
55
* @inheritdoc
52
56
*/
@@ -72,6 +76,7 @@ function ($value) {
72
76
return json_encode ($ value );
73
77
}
74
78
);
79
+ $ this ->fileParams = $ this ->createMock (Parameters::class);
75
80
76
81
$ this ->model = $ this ->objectManager ->getObject (
77
82
Identifier::class,
@@ -95,6 +100,12 @@ public function testSecureDifferentiator(): void
95
100
$ this ->requestMock ->method ('getUriString ' )
96
101
->willReturn ('http://example.com/path/ ' );
97
102
$ this ->contextMock ->method ('getVaryString ' )->willReturn (self ::VARY );
103
+ $ this ->requestMock ->expects ($ this ->any ())
104
+ ->method ('getQuery ' )
105
+ ->willReturn ($ this ->fileParams );
106
+ $ this ->fileParams ->expects ($ this ->any ())
107
+ ->method ('toArray ' )
108
+ ->willReturn ([]);
98
109
99
110
$ valueWithSecureRequest = $ this ->model ->getValue ();
100
111
$ valueWithInsecureRequest = $ this ->model ->getValue ();
@@ -111,6 +122,12 @@ public function testDomainDifferentiator(): void
111
122
->method ('getUriString ' )
112
123
->willReturnOnConsecutiveCalls ('http://example.com/path/ ' , 'http://example.net/path/ ' );
113
124
$ this ->contextMock ->method ('getVaryString ' )->willReturn (self ::VARY );
125
+ $ this ->requestMock ->expects ($ this ->any ())
126
+ ->method ('getQuery ' )
127
+ ->willReturn ($ this ->fileParams );
128
+ $ this ->fileParams ->expects ($ this ->any ())
129
+ ->method ('toArray ' )
130
+ ->willReturn ([]);
114
131
115
132
$ valueDomain1 = $ this ->model ->getValue ();
116
133
$ valueDomain2 = $ this ->model ->getValue ();
@@ -127,6 +144,12 @@ public function testPathDifferentiator(): void
127
144
->method ('getUriString ' )
128
145
->willReturnOnConsecutiveCalls ('http://example.com/path/ ' , 'http://example.com/path1/ ' );
129
146
$ this ->contextMock ->method ('getVaryString ' )->willReturn (self ::VARY );
147
+ $ this ->requestMock ->expects ($ this ->any ())
148
+ ->method ('getQuery ' )
149
+ ->willReturn ($ this ->fileParams );
150
+ $ this ->fileParams ->expects ($ this ->any ())
151
+ ->method ('toArray ' )
152
+ ->willReturn ([]);
130
153
131
154
$ valuePath1 = $ this ->model ->getValue ();
132
155
$ valuePath2 = $ this ->model ->getValue ();
@@ -143,6 +166,12 @@ public function testVaryStringSource($cookieExists): void
143
166
{
144
167
$ this ->requestMock ->method ('get ' )->willReturn ($ cookieExists ? 'vary-string-from-cookie ' : null );
145
168
$ this ->contextMock ->expects ($ cookieExists ? $ this ->never () : $ this ->once ())->method ('getVaryString ' );
169
+ $ this ->requestMock ->expects ($ this ->any ())
170
+ ->method ('getQuery ' )
171
+ ->willReturn ($ this ->fileParams );
172
+ $ this ->fileParams ->expects ($ this ->any ())
173
+ ->method ('toArray ' )
174
+ ->willReturn ([]);
146
175
$ this ->model ->getValue ();
147
176
}
148
177
@@ -173,12 +202,59 @@ public function testGetValue(): void
173
202
->method ('getVaryString ' )
174
203
->willReturn (self ::VARY );
175
204
205
+ $ this ->requestMock ->expects ($ this ->any ())
206
+ ->method ('getQuery ' )
207
+ ->willReturn ($ this ->fileParams );
208
+ $ this ->fileParams ->expects ($ this ->any ())
209
+ ->method ('toArray ' )
210
+ ->willReturn ([]);
211
+
212
+ $ this ->assertEquals (
213
+ sha1 (
214
+ json_encode (
215
+ [
216
+ true ,
217
+ 'http://example.com/path1/ ' ,
218
+ '' ,
219
+ self ::VARY
220
+ ]
221
+ )
222
+ ),
223
+ $ this ->model ->getValue ()
224
+ );
225
+ }
226
+
227
+ public function testGetValueWithQuery (): void
228
+ {
229
+ $ this ->requestMock ->expects ($ this ->any ())
230
+ ->method ('isSecure ' )
231
+ ->willReturn (true );
232
+
233
+ $ this ->requestMock ->expects ($ this ->any ())
234
+ ->method ('getUriString ' )
235
+ ->willReturn ('http://example.com/path1/?b=2&a=1 ' );
236
+
237
+ $ this ->contextMock ->expects ($ this ->any ())
238
+ ->method ('getVaryString ' )
239
+ ->willReturn (self ::VARY );
240
+
241
+ $ this ->requestMock ->expects ($ this ->any ())
242
+ ->method ('getQuery ' )
243
+ ->willReturn ($ this ->fileParams );
244
+ $ this ->fileParams ->expects ($ this ->any ())
245
+ ->method ('toArray ' )
246
+ ->willReturn ([
247
+ 'b ' => 2 ,
248
+ 'a ' => 1 ,
249
+ ]);
250
+
176
251
$ this ->assertEquals (
177
252
sha1 (
178
253
json_encode (
179
254
[
180
255
true ,
181
256
'http://example.com/path1/ ' ,
257
+ 'a=1&b=2 ' ,
182
258
self ::VARY
183
259
]
184
260
)
0 commit comments