@@ -182,10 +182,15 @@ function () {
182
182
$ this ->http ->launch ();
183
183
}
184
184
185
- public function testLaunchHeadRequest ()
185
+
186
+ /**
187
+ * Test that HEAD requests lead to an empty body and a Content-Length header matching the original body size.
188
+ * @dataProvider dataProviderForTestLaunchHeadRequest
189
+ * @param string $body
190
+ * @param int $expectedLength
191
+ */
192
+ public function testLaunchHeadRequest ($ body , $ expectedLength )
186
193
{
187
- $ body = "<html><head></head><body>Test</body></html> " ;
188
- $ contentLength = strlen ($ body );
189
194
$ this ->setUpLaunch ();
190
195
$ this ->requestMock ->expects ($ this ->once ())->method ('isHead ' )->will ($ this ->returnValue (true ));
191
196
$ this ->responseMock ->expects ($ this ->once ())
@@ -199,7 +204,7 @@ public function testLaunchHeadRequest()
199
204
->will ($ this ->returnValue ($ this ->responseMock ));
200
205
$ this ->responseMock ->expects ($ this ->once ())
201
206
->method ('setHeader ' )
202
- ->with ('Content-Length ' , $ contentLength )
207
+ ->with ('Content-Length ' , $ expectedLength )
203
208
->will ($ this ->returnValue ($ this ->responseMock ));
204
209
$ this ->eventManagerMock ->expects ($ this ->once ())
205
210
->method ('dispatch ' )
@@ -210,6 +215,32 @@ public function testLaunchHeadRequest()
210
215
$ this ->assertSame ($ this ->responseMock , $ this ->http ->launch ());
211
216
}
212
217
218
+ /**
219
+ * Different test content for responseMock with their expected lengths in bytes.
220
+ * @return array
221
+ */
222
+ public function dataProviderForTestLaunchHeadRequest ()
223
+ {
224
+ return [
225
+ [
226
+ '<html><head></head><body>Test</body></html> ' , // Ascii text
227
+ 43 // Expected Content-Length
228
+ ],
229
+ [
230
+ '<html><head></head><body>部落格</body></html> ' , // Multi-byte characters
231
+ 48 // Expected Content-Length
232
+ ],
233
+ [
234
+ '<html><head></head><body> ' .chr (0 ).'</body></html> ' , // Null byte
235
+ 40 // Expected Content-Length
236
+ ],
237
+ [
238
+ '<html><head></head>خرید<body></body></html> ' , // LTR text
239
+ 47 // Expected Content-Length
240
+ ]
241
+ ];
242
+ }
243
+
213
244
public function testHandleDeveloperModeNotInstalled ()
214
245
{
215
246
$ dir = $ this ->getMockForAbstractClass (\Magento \Framework \Filesystem \Directory \ReadInterface::class);
0 commit comments