Skip to content

Commit 762e52a

Browse files
authored
Merge pull request #1797 from WordPress/add/od-xpath-body-children-disambiguation
Disambiguate XPaths for children of BODY with `id`, `class`, or `role` attributes
2 parents d44b4c1 + 4f2779a commit 762e52a

File tree

93 files changed

+1747
-1354
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1747
-1354
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
# Improve highlighting for PHPStan stub files.
44
*.stub linguist-language=PHP
5+
6+
# Hide diffs for Optimization Detective snapshots.
7+
plugins/*/tests/test-cases/*/expected.html linguist-generated=true

plugins/embed-optimizer/tests/test-cases/all-embeds-inside-viewport/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$elements[] = array_merge(
1313
$element_data,
1414
array(
15-
'xpath' => "/HTML/BODY/DIV/*[{$i}][self::FIGURE]/*[1][self::DIV]",
15+
'xpath' => "/HTML/BODY/DIV[@class='wp-site-blocks']/*[{$i}][self::FIGURE]/*[1][self::DIV]",
1616
)
1717
);
1818
}

plugins/embed-optimizer/tests/test-cases/nested-figure-embed/expected.html

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/nested-figure-embed/set-up.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
$test_case->populate_url_metrics(
44
array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => false,
88
'intersectionRatio' => 1,
99
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),
1010
),
1111
array(
12-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]/*[1][self::VIDEO]',
12+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]/*[1][self::VIDEO]',
1313
'isLCP' => false,
1414
'intersectionRatio' => 1,
1515
),
1616
array(
17-
'xpath' => '/HTML/BODY/DIV/*[2][self::FIGURE]/*[1][self::DIV]',
17+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[2][self::FIGURE]/*[1][self::DIV]',
1818
'isLCP' => false,
1919
'intersectionRatio' => 0,
2020
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 654 ) ),
2121
),
2222
array(
23-
'xpath' => '/HTML/BODY/DIV/*[2][self::FIGURE]/*[1][self::DIV]/*[1][self::FIGURE]/*[2][self::VIDEO]',
23+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[2][self::FIGURE]/*[1][self::DIV]/*[1][self::FIGURE]/*[2][self::VIDEO]',
2424
'isLCP' => false,
2525
'intersectionRatio' => 0,
2626
),

plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/expected.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/embed-optimizer/tests/test-cases/single-spotify-embed-outside-viewport-with-subsequent-script/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$test_case->populate_url_metrics(
44
array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => false,
88
'intersectionRatio' => 0,
99
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport-without-resized-data/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$test_case->populate_url_metrics(
44
array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => true,
88
'intersectionRatio' => 1,
99
// Intentionally omitting resizedBoundingClientRect here to test behavior when data isn't supplied.

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-inside-viewport/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$test_case->populate_url_metrics(
44
array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => true,
88
'intersectionRatio' => 1,
99
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport-on-mobile/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
foreach ( array_merge( od_get_breakpoint_max_widths(), array( 1000 ) ) as $i => $viewport_width ) {
44
$elements = array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => true,
88
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 + $i * 100 ) ),
99
),

plugins/embed-optimizer/tests/test-cases/single-twitter-embed-outside-viewport/set-up.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$test_case->populate_url_metrics(
44
array(
55
array(
6-
'xpath' => '/HTML/BODY/DIV/*[1][self::FIGURE]/*[1][self::DIV]',
6+
'xpath' => '/HTML/BODY/DIV[@class=\'wp-site-blocks\']/*[1][self::FIGURE]/*[1][self::DIV]',
77
'isLCP' => false,
88
'intersectionRatio' => 0,
99
'resizedBoundingClientRect' => array_merge( $test_case->get_sample_dom_rect(), array( 'height' => 500 ) ),

0 commit comments

Comments
 (0)