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

Fix name of function to refer to root schema instead of element item schema; move filter addition to init function #1768

Merged
merged 2 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion plugins/embed-optimizer/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function initialize( { isDebug } ) {
'.wp-block-embed > .wp-block-embed__wrapper[data-od-xpath]'
);

for ( const embedWrapper of embedWrappers ) {
for ( /** @type {HTMLElement} */ const embedWrapper of embedWrappers ) {
monitorEmbedWrapperForResizes( embedWrapper, isDebug );
}

Expand Down
13 changes: 10 additions & 3 deletions plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ static function (): void {

add_action( 'wp_head', 'image_prioritizer_render_generator_meta_tag' );
add_action( 'od_register_tag_visitors', 'image_prioritizer_register_tag_visitors' );
add_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' );
add_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_root_schema_properties' );
add_filter( 'rest_request_before_callbacks', 'image_prioritizer_filter_rest_request_before_callbacks', 10, 3 );
}

/**
Expand Down Expand Up @@ -98,15 +101,19 @@ function image_prioritizer_filter_extension_module_urls( $extension_module_urls
}

/**
* Filters additional properties for the element item schema for Optimization Detective.
* Filters additional properties for the root schema for Optimization Detective.
*
* @since 0.3.0
* @access private
*
* @param array<string, array{type: string}> $additional_properties Additional properties.
* @param array<string, array{type: string}>|mixed $additional_properties Additional properties.
* @return array<string, array{type: string}> Additional properties.
*/
function image_prioritizer_add_element_item_schema_properties( array $additional_properties ): array {
function image_prioritizer_add_root_schema_properties( $additional_properties ): array {
if ( ! is_array( $additional_properties ) ) {
$additional_properties = array();
}

$additional_properties['lcpElementExternalBackgroundImage'] = array(
'type' => 'object',
'properties' => array(
Expand Down
3 changes: 0 additions & 3 deletions plugins/image-prioritizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,3 @@
}

add_action( 'od_init', 'image_prioritizer_init' );
add_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' );
add_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_element_item_schema_properties' );
add_filter( 'rest_request_before_callbacks', 'image_prioritizer_filter_rest_request_before_callbacks', 10, 3 );
Comment on lines -14 to -16
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to plugins/image-prioritizer/helper.php

18 changes: 9 additions & 9 deletions plugins/image-prioritizer/tests/test-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,17 @@ public function test_image_prioritizer_filter_extension_module_urls(): void {
}

/**
* Test image_prioritizer_add_element_item_schema_properties.
* Test image_prioritizer_add_root_schema_properties.
*
* @covers ::image_prioritizer_add_element_item_schema_properties
* @covers ::image_prioritizer_add_root_schema_properties
*/
public function test_image_prioritizer_add_element_item_schema_properties(): void {
public function test_image_prioritizer_add_root_schema_properties(): void {
$initial_schema = array(
'foo' => array(
'type' => 'string',
),
);
$filtered_schema = image_prioritizer_add_element_item_schema_properties( $initial_schema );
$filtered_schema = image_prioritizer_add_root_schema_properties( $initial_schema );
$this->assertCount( 2, $filtered_schema );
$this->assertArrayHasKey( 'foo', $filtered_schema );
$this->assertArrayHasKey( 'lcpElementExternalBackgroundImage', $filtered_schema );
Expand All @@ -286,7 +286,7 @@ public function test_image_prioritizer_add_element_item_schema_properties(): voi
/**
* @return array<string, mixed>
*/
public function data_provider_for_test_image_prioritizer_add_element_item_schema_properties_inputs(): array {
public function data_provider_for_test_image_prioritizer_add_root_schema_properties_inputs(): array {
return array(
'bad_type' => array(
'input_value' => 'not_an_object',
Expand Down Expand Up @@ -437,17 +437,17 @@ public function data_provider_for_test_image_prioritizer_add_element_item_schema
}

/**
* Test image_prioritizer_add_element_item_schema_properties for various inputs.
* Test image_prioritizer_add_root_schema_properties for various inputs.
*
* @covers ::image_prioritizer_add_element_item_schema_properties
* @covers ::image_prioritizer_add_root_schema_properties
*
* @dataProvider data_provider_for_test_image_prioritizer_add_element_item_schema_properties_inputs
* @dataProvider data_provider_for_test_image_prioritizer_add_root_schema_properties_inputs
*
* @param mixed $input_value Input value.
* @param string|null $expected_exception Expected exception message.
* @param array<string, mixed>|null $output_value Output value.
*/
public function test_image_prioritizer_add_element_item_schema_properties_inputs( $input_value, ?string $expected_exception, ?array $output_value ): void {
public function test_image_prioritizer_add_root_schema_properties_inputs( $input_value, ?string $expected_exception, ?array $output_value ): void {
$data = $this->get_sample_url_metric( array() )->jsonSerialize();
$data['lcpElementExternalBackgroundImage'] = $input_value;
$exception_message = null;
Expand Down
2 changes: 1 addition & 1 deletion plugins/image-prioritizer/tests/test-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Test_Image_Prioritizer_Hooks extends WP_UnitTestCase {
public function test_hooks_added(): void {
$this->assertEquals( 10, has_action( 'od_init', 'image_prioritizer_init' ) );
$this->assertEquals( 10, has_filter( 'od_extension_module_urls', 'image_prioritizer_filter_extension_module_urls' ) );
$this->assertEquals( 10, has_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_element_item_schema_properties' ) );
$this->assertEquals( 10, has_filter( 'od_url_metric_schema_root_additional_properties', 'image_prioritizer_add_root_schema_properties' ) );
$this->assertEquals( 10, has_filter( 'rest_request_before_callbacks', 'image_prioritizer_filter_rest_request_before_callbacks' ) );
}
}
Loading