77
88namespace Magento \PageCache \Test \Unit \Model \App \Request \Http ;
99
10+ use Laminas \Stdlib \Parameters ;
11+ use Laminas \Uri \Http as HttpUri ;
1012use Magento \Framework \App \Http \Context ;
1113use Magento \Framework \App \ObjectManager ;
1214use Magento \Framework \App \PageCache \Identifier ;
@@ -49,6 +51,9 @@ class IdentifierForSaveTest extends TestCase
4951 */
5052 private $ identifierStoreReader ;
5153
54+ /** @var Parameters|MockObject */
55+ private $ fileParams ;
56+
5257 /**
5358 * @var Identifier
5459 */
@@ -76,6 +81,7 @@ function ($value) {
7681 return json_encode ($ value );
7782 }
7883 );
84+ $ this ->fileParams = $ this ->createMock (Parameters::class);
7985
8086 $ this ->identifierStoreReader = $ this ->getMockBuilder (IdentifierStoreReader::class)
8187 ->onlyMethods (['getPageTagsWithStoreCacheTags ' ])
@@ -120,10 +126,24 @@ public function testGetValue(): void
120126 ->method ('getUriString ' )
121127 ->willReturn ('http://example.com/path1/ ' );
122128
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+
123137 $ this ->contextMock ->expects ($ this ->any ())
124138 ->method ('getVaryString ' )
125139 ->willReturn (self ::VARY );
126140
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+
127147 $ this ->identifierStoreReader ->method ('getPageTagsWithStoreCacheTags ' )->willReturnCallback (
128148 function ($ value ) {
129149 return $ value ;
@@ -136,6 +156,67 @@ function ($value) {
136156 [
137157 true ,
138158 '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 ' ,
139220 self ::VARY
140221 ]
141222 )
@@ -167,18 +248,24 @@ public function testGetValueWithMarketingParameters(): void
167248 ->method ('getVaryString ' )
168249 ->willReturn (self ::VARY );
169250
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+
170257 $ this ->identifierStoreReader ->method ('getPageTagsWithStoreCacheTags ' )->willReturnCallback (
171258 function ($ value ) {
172259 return $ value ;
173260 }
174261 );
175-
176262 $ this ->assertEquals (
177263 sha1 (
178264 json_encode (
179265 [
180266 true ,
181- 'http://example.com/path1/?abc=123 ' ,
267+ 'http://example.com/path1/ ' ,
268+ 'abc=123 ' ,
182269 self ::VARY
183270 ]
184271 )
0 commit comments