Skip to content

Commit

Permalink
Fix name of Image Prioritizer function
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Dec 23, 2024
1 parent ebec285 commit 2ea897a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
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
10 changes: 7 additions & 3 deletions plugins/image-prioritizer/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,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
4 changes: 3 additions & 1 deletion plugins/image-prioritizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
}

add_action( 'od_init', 'image_prioritizer_init' );

// TODO: The remainder filters should be added in 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( '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 );
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' ) );
}
}

0 comments on commit 2ea897a

Please sign in to comment.