7
7
8
8
namespace Magento \PageCache \Test \Unit \Model \App \Request \Http ;
9
9
10
+ use Laminas \Stdlib \Parameters ;
11
+ use Laminas \Uri \Http as HttpUri ;
10
12
use Magento \Framework \App \Http \Context ;
11
13
use Magento \Framework \App \ObjectManager ;
12
14
use Magento \Framework \App \PageCache \Identifier ;
@@ -49,6 +51,9 @@ class IdentifierForSaveTest extends TestCase
49
51
*/
50
52
private $ identifierStoreReader ;
51
53
54
+ /** @var Parameters|MockObject */
55
+ private $ fileParams ;
56
+
52
57
/**
53
58
* @var Identifier
54
59
*/
@@ -76,6 +81,7 @@ function ($value) {
76
81
return json_encode ($ value );
77
82
}
78
83
);
84
+ $ this ->fileParams = $ this ->createMock (Parameters::class);
79
85
80
86
$ this ->identifierStoreReader = $ this ->getMockBuilder (IdentifierStoreReader::class)
81
87
->onlyMethods (['getPageTagsWithStoreCacheTags ' ])
@@ -120,10 +126,24 @@ public function testGetValue(): void
120
126
->method ('getUriString ' )
121
127
->willReturn ('http://example.com/path1/ ' );
122
128
129
+ $ this ->requestMock ->expects ($ this ->any ())
130
+ ->method ('getQuery ' )
131
+ ->willReturn ($ this ->fileParams );
132
+
133
+ $ this ->fileParams ->expects ($ this ->any ())
134
+ ->method ('toArray ' )
135
+ ->willReturn ([]);
136
+
123
137
$ this ->contextMock ->expects ($ this ->any ())
124
138
->method ('getVaryString ' )
125
139
->willReturn (self ::VARY );
126
140
141
+ $ uri = $ this ->createMock (HttpUri::class);
142
+ $ uri ->expects ($ this ->any ())->method ('getQueryAsArray ' )->willReturn ('' );
143
+ $ this ->requestMock ->expects ($ this ->any ())
144
+ ->method ('getUri ' )
145
+ ->willReturn ($ uri );
146
+
127
147
$ this ->identifierStoreReader ->method ('getPageTagsWithStoreCacheTags ' )->willReturnCallback (
128
148
function ($ value ) {
129
149
return $ value ;
@@ -136,6 +156,67 @@ function ($value) {
136
156
[
137
157
true ,
138
158
'http://example.com/path1/ ' ,
159
+ '' ,
160
+ self ::VARY
161
+ ]
162
+ )
163
+ ),
164
+ $ this ->model ->getValue ()
165
+ );
166
+ }
167
+
168
+ /**
169
+ * Test get identifier for save value with query parameters.
170
+ *
171
+ * @return void
172
+ */
173
+ public function testGetValueWithQuery (): void
174
+ {
175
+ $ this ->requestMock ->expects ($ this ->any ())
176
+ ->method ('isSecure ' )
177
+ ->willReturn (true );
178
+
179
+ $ this ->requestMock ->expects ($ this ->any ())
180
+ ->method ('getUriString ' )
181
+ ->willReturn ('http://example.com/path1/?b=2&a=1 ' );
182
+
183
+ $ this ->requestMock ->expects ($ this ->any ())
184
+ ->method ('getQuery ' )
185
+ ->willReturn ($ this ->fileParams );
186
+
187
+ $ this ->fileParams ->expects ($ this ->any ())
188
+ ->method ('toArray ' )
189
+ ->willReturn ([
190
+ 'b ' => 2 ,
191
+ 'a ' => 1 ,
192
+ ]);
193
+
194
+ $ this ->contextMock ->expects ($ this ->any ())
195
+ ->method ('getVaryString ' )
196
+ ->willReturn (self ::VARY );
197
+
198
+ $ uri = $ this ->createMock (HttpUri::class);
199
+ $ uri ->expects ($ this ->any ())->method ('getQueryAsArray ' )->willReturn ([
200
+ 'b ' => 2 ,
201
+ 'a ' => 1 ,
202
+ ]);
203
+ $ this ->requestMock ->expects ($ this ->any ())
204
+ ->method ('getUri ' )
205
+ ->willReturn ($ uri );
206
+
207
+ $ this ->identifierStoreReader ->method ('getPageTagsWithStoreCacheTags ' )->willReturnCallback (
208
+ function ($ value ) {
209
+ return $ value ;
210
+ }
211
+ );
212
+
213
+ $ this ->assertEquals (
214
+ sha1 (
215
+ json_encode (
216
+ [
217
+ true ,
218
+ 'http://example.com/path1/ ' ,
219
+ 'a=1&b=2 ' ,
139
220
self ::VARY
140
221
]
141
222
)
@@ -167,18 +248,24 @@ public function testGetValueWithMarketingParameters(): void
167
248
->method ('getVaryString ' )
168
249
->willReturn (self ::VARY );
169
250
251
+ $ uri = $ this ->createMock (HttpUri::class);
252
+ $ uri ->expects ($ this ->any ())->method ('getQueryAsArray ' )->willReturn (['abc ' => '123 ' ]);
253
+ $ this ->requestMock ->expects ($ this ->any ())
254
+ ->method ('getUri ' )
255
+ ->willReturn ($ uri );
256
+
170
257
$ this ->identifierStoreReader ->method ('getPageTagsWithStoreCacheTags ' )->willReturnCallback (
171
258
function ($ value ) {
172
259
return $ value ;
173
260
}
174
261
);
175
-
176
262
$ this ->assertEquals (
177
263
sha1 (
178
264
json_encode (
179
265
[
180
266
true ,
181
- 'http://example.com/path1/?abc=123 ' ,
267
+ 'http://example.com/path1/ ' ,
268
+ 'abc=123 ' ,
182
269
self ::VARY
183
270
]
184
271
)
0 commit comments