Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement full support for intersectionRect/boundingClientRect, fix viewportRect typing, and harden JSON schema #1411

Merged
merged 14 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/auto-sizes/tests/test-optimization-detective.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Tests for auto-sizes plugin's optimization-detective.php.
*
* @package auto-sizes
*
* @noinspection PhpUnhandledExceptionInspection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a PHPStorm thing, right? Do we usually have IDE-specific annotations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, elsewhere in the codebase I've been using them.

*/

class Test_Auto_Sizes_Optimization_Detective extends WP_UnitTestCase {
Expand Down Expand Up @@ -100,8 +102,7 @@ public function data_provider_test_od_optimize_template_output_buffer(): array {
* @covers ::auto_sizes_visit_tag
*
* @dataProvider data_provider_test_od_optimize_template_output_buffer
* @throws Exception But it won't.
* @phpstan-param array<string, mixed> $element_metrics
* @phpstan-param array{ xpath: string, isLCP: bool, intersectionRatio: int } $element_metrics
*/
public function test_od_optimize_template_output_buffer( array $element_metrics, string $buffer, string $expected ): void {
$this->populate_url_metrics( array( $element_metrics ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Tests for embed-optimizer plugin hooks.php.
*
* @package embed-optimizer
*
* @noinspection PhpUnhandledExceptionInspection
*/

class Test_Embed_Optimizer_Optimization_Detective extends WP_UnitTestCase {
Expand Down Expand Up @@ -51,7 +53,6 @@ public function data_provider_test_od_optimize_template_output_buffer(): array {
* @covers ::embed_optimizer_update_markup
*
* @dataProvider data_provider_test_od_optimize_template_output_buffer
* @throws Exception But it won't.
*/
public function test_od_optimize_template_output_buffer( Closure $set_up, string $buffer, string $expected ): void {
$set_up( $this );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@
for ( $i = 0; $i < $sample_size; $i++ ) {
OD_URL_Metrics_Post_Type::store_url_metric(
$slug,
$test_case->get_validated_url_metric(
$viewport_width,
$test_case->get_sample_url_metric(
array(
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'isLCP' => true,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0 === $i ? 0.5 : 0.0, // Make sure that the _max_ intersection ratio is considered.
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[6][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[7][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
'viewport_width' => $viewport_width,
'elements' => array(
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'isLCP' => true,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[3][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0 === $i ? 0.5 : 0.0, // Make sure that the _max_ intersection ratio is considered.
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[5][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[6][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
array(
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[7][self::IMG]',
'isLCP' => false,
'intersectionRatio' => 0.0,
),
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
for ( $i = 0; $i < $sample_size; $i++ ) {
OD_URL_Metrics_Post_Type::store_url_metric(
$slug,
$test_case->get_validated_url_metric(
1000,
$test_case->get_sample_url_metric(
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,
'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,
),
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,40 @@
'set_up' => static function ( Test_Image_Prioritizer_Helper $test_case ): void {
OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
400,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'intersectionRatio' => 1.0,
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'intersectionRatio' => 0.0,
'viewport_width' => 400,
'elements' => array(
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'intersectionRatio' => 1.0,
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'intersectionRatio' => 0.0,
),
),
)
)
);
OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
800,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'intersectionRatio' => 0.0,
),
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'intersectionRatio' => 1.0,
'viewport_width' => 800,
'elements' => array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
'intersectionRatio' => 0.0,
),
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'intersectionRatio' => 1.0,
),
),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,72 @@ static function () {

OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
500,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'viewport_width' => 500,
'elements' => array(
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
),
),
)
)
);
OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
650,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'viewport_width' => 650,
'elements' => array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
),
),
)
)
);
OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
800,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'viewport_width' => 800,
'elements' => array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => true,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
),
),
)
)
);
OD_URL_Metrics_Post_Type::store_url_metric(
od_get_url_metrics_slug( od_get_normalized_query_vars() ),
$test_case->get_validated_url_metric(
800,
$test_case->get_sample_url_metric(
array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
'viewport_width' => 800,
'elements' => array(
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[1][self::IMG]',
),
array(
'isLCP' => false,
'xpath' => '/*[1][self::HTML]/*[2][self::BODY]/*[2][self::IMG]',
),
),
)
)
Expand Down
Loading
Loading