From e8e1d7d52484400eacb4da7f93a1997d20a3d0d1 Mon Sep 17 00:00:00 2001
From: Weston Ruter
Date: Sun, 15 Dec 2024 20:33:04 -0800
Subject: [PATCH 1/3] Add test cases demonstrating erroneous behavior
---
.../img-non-native-lazy-loading.php | 86 +++++++++++++++++++
.../tests/test-cases/noscript.php | 31 +++++++
2 files changed, 117 insertions(+)
create mode 100644 plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
create mode 100644 plugins/optimization-detective/tests/test-cases/noscript.php
diff --git a/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
new file mode 100644
index 0000000000..37fa084e60
--- /dev/null
+++ b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
@@ -0,0 +1,86 @@
+ static function ( Test_Image_Prioritizer_Helper $test_case ): void {
+ $slug = od_get_url_metrics_slug( od_get_normalized_query_vars() );
+
+ // Populate one URL Metric so that none of the IMG elements are unknown.
+ OD_URL_Metrics_Post_Type::store_url_metric(
+ $slug,
+ $test_case->get_sample_url_metric(
+ array(
+ 'viewport_width' => 1000,
+ 'elements' => array(
+ array(
+ 'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
+ 'isLCP' => true,
+ ),
+ array(
+ 'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
+ 'isLCP' => false,
+ ),
+ ),
+ )
+ )
+ );
+ },
+ 'buffer' => '
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+ ',
+ 'expected' => '
+
+
+
+ ...
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ',
+);
diff --git a/plugins/optimization-detective/tests/test-cases/noscript.php b/plugins/optimization-detective/tests/test-cases/noscript.php
new file mode 100644
index 0000000000..916c270e8a
--- /dev/null
+++ b/plugins/optimization-detective/tests/test-cases/noscript.php
@@ -0,0 +1,31 @@
+ static function (): void {},
+ 'buffer' => '
+
+
+
+ ...
+
+
+
+
+
+ ',
+ 'expected' => '
+
+
+
+ ...
+
+
+
+
+
+
+ ',
+);
From d6c07efeeac7f98b3a2f8fef166b7395c1214e51 Mon Sep 17 00:00:00 2001
From: Weston Ruter
Date: Sun, 15 Dec 2024 20:36:00 -0800
Subject: [PATCH 2/3] Skip visiting any tag inside of a NOSCRIPT since never in
DOM for detection
---
.../tests/test-cases/img-non-native-lazy-loading.php | 2 +-
plugins/optimization-detective/optimization.php | 5 +++++
plugins/optimization-detective/tests/test-cases/noscript.php | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
index 37fa084e60..d83e4ebb2b 100644
--- a/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
+++ b/plugins/image-prioritizer/tests/test-cases/img-non-native-lazy-loading.php
@@ -77,7 +77,7 @@ class="lazyload wp-image-1"