From 6960a2871e478380390b96c634ab373851421bee Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 1 Dec 2024 18:12:21 -0800 Subject: [PATCH] Fix checked logic in old_url_metric test case --- .../tests/test-class-od-url-metrics-group.php | 7 ++++++- tests/class-optimization-detective-test-helpers.php | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php b/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php index 62924cc34..2b1538c7a 100644 --- a/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php +++ b/plugins/optimization-detective/tests/test-class-od-url-metrics-group.php @@ -251,7 +251,12 @@ public function data_provider_test_is_complete(): array { // Note: Test cases for empty URL Metrics and for exact sample size are already covered in the test_add_url_metric() method. return array( 'old_url_metric' => array( - 'url_metric' => $this->get_sample_url_metric( array( 'timestamp' => microtime( true ) - ( HOUR_IN_SECONDS + 1 ) ) ), + 'url_metric' => $this->get_sample_url_metric( + array( + 'timestamp' => microtime( true ) - ( HOUR_IN_SECONDS + 1 ), + 'etag' => md5( '' ), + ) + ), 'expected_is_group_complete' => false, ), // Note: The following test case will not be required once the ETag is mandatory in a future release. diff --git a/tests/class-optimization-detective-test-helpers.php b/tests/class-optimization-detective-test-helpers.php index 448fbfd8d..c7924480a 100644 --- a/tests/class-optimization-detective-test-helpers.php +++ b/tests/class-optimization-detective-test-helpers.php @@ -67,6 +67,7 @@ public function get_sample_dom_rect(): array { * Gets a sample URL metric. * * @phpstan-param array{ + * timestamp?: float, * etag?: non-empty-string, * url?: string, * viewport_width?: int, @@ -84,6 +85,7 @@ public function get_sample_url_metric( array $params ): OD_URL_Metric { 'url' => home_url( '/' ), 'viewport_width' => 480, 'elements' => array(), + 'timestamp' => microtime( true ), ), $params ); @@ -100,7 +102,7 @@ public function get_sample_url_metric( array $params ): OD_URL_Metric { 'width' => $params['viewport_width'], 'height' => $params['viewport_height'] ?? ceil( $params['viewport_width'] / 2 ), ), - 'timestamp' => microtime( true ), + 'timestamp' => $params['timestamp'], 'elements' => array_map( function ( array $element ): array { return array_merge(