Media: Ensure custom header image tag supports loading optimization attributes.

This changeset is a follow up to [56037] and ensures that the `get_header_image_tag()` function receives the benefits of `wp_get_loading_optimization_attributes()` as well. Prior to `fetchpriority` support, this was not needed since the header image should never be lazy-loaded, but the image certainly is a `fetchpriority` candidate, so therefore it is crucial to have it supported.

Props felipeelia, spacedmonkey, mukesh27, westonruter, flixos90.
Fixes #58680.


git-svn-id: https://develop.svn.wordpress.org/trunk@56142 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz
2023-07-05 19:28:02 +00:00
parent f7dbb2462b
commit aee525ee6f
3 changed files with 109 additions and 4 deletions
@@ -174,6 +174,82 @@ class Tests_Theme_CustomHeader extends WP_UnitTestCase {
$this->assertStringContainsString( sprintf( 'src="%s"', $custom ), $html );
}
/**
* Tests default values of performance attributes for "get_header_image_tag".
*
* @ticket 58680
*/
public function test_get_header_image_tag_with_default_performance_attributes() {
$this->add_theme_support(
array(
'default-image' => 'http://localhost/default-header.jpg',
'width' => 60,
'height' => 60,
)
);
add_filter(
'wp_min_priority_img_pixels',
static function() {
return 2500; // 50*50=2500
}
);
wp_high_priority_element_flag( true );
$html = get_header_image_tag();
$this->assertStringNotContainsString( ' loading="lazy"', $html );
$this->assertStringContainsString( ' fetchpriority="high"', $html );
$this->assertStringContainsString( ' decoding="async"', $html );
}
/**
* Tests custom values of performance attributes for "get_header_image_tag".
*
* @ticket 58680
*/
public function test_get_header_image_tag_with_custom_performance_attributes() {
$this->add_theme_support(
array(
'default-image' => 'http://localhost/default-header.jpg',
'width' => 500,
'height' => 500,
)
);
$html = get_header_image_tag(
array(
'fetchpriority' => '',
'decoding' => '',
)
);
$this->assertStringNotContainsString( ' fetchpriority="high"', $html );
$this->assertStringNotContainsString( ' decoding="async"', $html );
}
/**
* Tests custom lazy loading for "get_header_image_tag".
*
* @ticket 58680
*/
public function test_get_header_image_tag_with_custom_lazy_loading() {
$this->add_theme_support(
array(
'default-image' => 'http://localhost/default-header.jpg',
'width' => 500,
'height' => 500,
)
);
$html = get_header_image_tag(
array(
'loading' => 'lazy',
)
);
$this->assertStringNotContainsString( ' fetchpriority="high"', $html );
$this->assertStringContainsString( ' loading="lazy"', $html );
}
public function test_get_custom_header_markup_without_registered_default_image() {
$this->add_theme_support();