Skip to content

Commit aa50fe4

Browse files
committed
Update tests to mock GET requests instead of HEAD for asset size measurement
1 parent 6e27de3 commit aa50fe4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,30 @@ public function mock_requests(): void {
320320
remove_all_filters( 'pre_http_request' );
321321
add_filter(
322322
'pre_http_request',
323-
static function ( $preempt, $parsed_args ) use ( $mock_html ) {
324-
// Mock a HEAD request to return a content length header.
325-
if ( isset( $parsed_args['method'] ) && 'HEAD' === $parsed_args['method'] ) {
323+
static function ( $preempt, $parsed_args, $url ) use ( $mock_html ) {
324+
// Mock GET request for the home page to return mocked HTML content.
325+
if ( home_url( '/' ) === $url ) {
326326
return array(
327327
'response' => array(
328328
'code' => 200,
329329
),
330-
'body' => '',
331-
'headers' => array(
332-
'content-length' => '10000', // Mocked size of the asset.
333-
),
330+
'body' => $mock_html,
331+
'headers' => array(),
334332
);
335333
}
336334

337-
// Mock a GET request to return the HTML content.
335+
// This simulates downloading the actual asset content.
336+
$mock_asset_content = str_repeat( 'A', 5000 );
338337
return array(
339338
'response' => array(
340339
'code' => 200,
341340
),
342-
'body' => $mock_html,
341+
'body' => $mock_asset_content,
343342
'headers' => array(),
344343
);
345344
},
346345
10,
347-
2
346+
3
348347
);
349348
}
350349
}

0 commit comments

Comments
 (0)