Skip to content

Commit ac723e1

Browse files
committed
Add test case for new logic
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent 2039994 commit ac723e1

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
return array(
3+
'set_up' => static function ( Test_Image_Prioritizer_Helper $test_case ): void {
4+
$breakpoint_max_widths = array( 480, 600, 782 );
5+
6+
add_filter(
7+
'od_breakpoint_max_widths',
8+
static function () use ( $breakpoint_max_widths ) {
9+
return $breakpoint_max_widths;
10+
}
11+
);
12+
13+
OD_URL_Metrics_Post_Type::store_url_metric(
14+
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
15+
$test_case->get_sample_url_metric(
16+
array(
17+
'viewport_width' => 375,
18+
'elements' => array(
19+
array(
20+
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
21+
'isLCP' => true,
22+
),
23+
),
24+
)
25+
)
26+
);
27+
28+
OD_URL_Metrics_Post_Type::store_url_metric(
29+
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
30+
$test_case->get_sample_url_metric(
31+
array(
32+
'viewport_width' => 1000,
33+
'elements' => array(
34+
array(
35+
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
36+
'isLCP' => true,
37+
),
38+
),
39+
)
40+
)
41+
);
42+
},
43+
'buffer' => '
44+
<html lang="en">
45+
<head>
46+
<meta charset="utf-8">
47+
<title>...</title>
48+
</head>
49+
<body>
50+
<img src="https://example.com/foo.jpg" alt="Foo" width="1200" height="800" fetchpriority="high">
51+
</body>
52+
</html>
53+
',
54+
'expected' => '
55+
<html lang="en">
56+
<head>
57+
<meta charset="utf-8">
58+
<title>...</title>
59+
<link data-od-added-tag rel="preload" fetchpriority="high" as="image" href="https://example.com/foo.jpg" media="screen and (max-width: 480px)">
60+
<link data-od-added-tag rel="preload" fetchpriority="high" as="image" href="https://example.com/foo.jpg" media="screen and (min-width: 783px)">
61+
</head>
62+
<body>
63+
<img data-od-fetchpriority-already-added data-od-xpath="/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]" src="https://example.com/foo.jpg" alt="Foo" width="1200" height="800" fetchpriority="high">
64+
<script type="module">/* import detect ... */</script>
65+
</body>
66+
</html>
67+
',
68+
);

0 commit comments

Comments
 (0)