-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Embeds: Fix get_site_icon_url() dropping fallback when attachment URL… #11601
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
b6392f5
38f4066
8548ea9
ee74671
df80e51
0c97d27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,6 +122,27 @@ public function test_get_site_icon_url() { | |||||||||||||||||
| $this->assertEmpty( get_site_icon_url(), 'Site icon URL should not be set after removal.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::get_site_icon_url | ||||||||||||||||||
| * @requires function imagejpeg | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_get_site_icon_url_returns_fallback_when_attachment_url_fails() { | ||||||||||||||||||
| $this->set_site_icon(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $fallback = 'https://example.com/fallback-icon.png'; | ||||||||||||||||||
| add_filter( 'wp_get_attachment_image_src', '__return_false' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| $url = get_site_icon_url( 32, $fallback ); | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| remove_filter( 'wp_get_attachment_image_src', '__return_false' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertSame( $fallback, $url, 'Fallback URL should be returned when attachment URL lookup fails.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::site_icon_url | ||||||||||||||||||
|
|
@@ -807,4 +828,116 @@ public function test_get_the_archive_title_is_correct_for_author_queries() { | |||||||||||||||||
| $this->assertSame( $user_with_posts->display_name, $title_when_posts ); | ||||||||||||||||||
| $this->assertSame( $user_with_no_posts->display_name, $title_when_no_posts ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::the_embed_site_title | ||||||||||||||||||
| * @requires function imagejpeg | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_the_embed_site_title_contains_site_icon_when_set() { | ||||||||||||||||||
| $this->set_site_icon(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $url_32 = get_site_icon_url( 32 ); | ||||||||||||||||||
| $url_64 = get_site_icon_url( 64 ); | ||||||||||||||||||
|
|
||||||||||||||||||
| ob_start(); | ||||||||||||||||||
| the_embed_site_title(); | ||||||||||||||||||
| $output = ob_get_clean(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertStringContainsString( 'wp-embed-site-icon', $output, 'Output should contain site icon img tag.' ); | ||||||||||||||||||
| $this->assertStringContainsString( esc_url( $url_32 ), $output, 'Output should contain 32px site icon URL.' ); | ||||||||||||||||||
| $this->assertStringContainsString( esc_url( $url_64 ), $output, 'Output should contain 64px site icon URL in srcset.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::the_embed_site_title | ||||||||||||||||||
| * @requires function imagejpeg | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_the_embed_site_title_uses_fallback_when_attachment_url_fails() { | ||||||||||||||||||
| $this->set_site_icon(); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Simulate wp_get_attachment_image_url() failing. | ||||||||||||||||||
| add_filter( 'wp_get_attachment_image_src', '__return_false' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| ob_start(); | ||||||||||||||||||
| the_embed_site_title(); | ||||||||||||||||||
| $output = ob_get_clean(); | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| remove_filter( 'wp_get_attachment_image_src', '__return_false' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+865
to
+872
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||
| $fallback = includes_url( 'images/w-logo-blue.png' ); | ||||||||||||||||||
| $this->assertStringContainsString( 'wp-embed-site-icon', $output, 'Output should contain site icon img tag with fallback.' ); | ||||||||||||||||||
| $this->assertStringContainsString( esc_url( $fallback ), $output, 'Output should contain fallback URL when attachment URL fails.' ); | ||||||||||||||||||
| $this->assertStringNotContainsString( 'src=""', $output, 'Output should not contain empty src attribute.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::the_embed_site_title | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_the_embed_site_title_omits_img_when_url_is_empty() { | ||||||||||||||||||
| // Force get_site_icon_url() to return empty string via filter. | ||||||||||||||||||
| add_filter( 'get_site_icon_url', '__return_empty_string' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| ob_start(); | ||||||||||||||||||
| the_embed_site_title(); | ||||||||||||||||||
| $output = ob_get_clean(); | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| remove_filter( 'get_site_icon_url', '__return_empty_string' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+888
to
+894
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertStringNotContainsString( 'wp-embed-site-icon', $output, 'img tag should be omitted when URL is empty.' ); | ||||||||||||||||||
| $this->assertStringNotContainsString( 'src=""', $output, 'Output should not contain empty src attribute.' ); | ||||||||||||||||||
| $this->assertStringContainsString( get_bloginfo( 'name' ), $output, 'Site name should still be present.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::the_embed_site_title | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_the_embed_site_title_omits_srcset_when_1x_and_2x_urls_are_identical() { | ||||||||||||||||||
| // Force both sizes to return the same URL. | ||||||||||||||||||
| $svg_url = 'https://example.com/icon.svg'; | ||||||||||||||||||
| $filter = static function () use ( $svg_url ) { | ||||||||||||||||||
| return $svg_url; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| add_filter( 'get_site_icon_url', $filter ); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| ob_start(); | ||||||||||||||||||
| the_embed_site_title(); | ||||||||||||||||||
| $output = ob_get_clean(); | ||||||||||||||||||
| } finally { | ||||||||||||||||||
| remove_filter( 'get_site_icon_url', $filter ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+915
to
+921
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertStringNotContainsString( 'srcset=', $output, 'srcset should be omitted when 1x and 2x URLs are identical.' ); | ||||||||||||||||||
| $this->assertStringContainsString( esc_url( $svg_url ), $output, '1x URL should still be present in src.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * @ticket 65098 | ||||||||||||||||||
| * @group site_icon | ||||||||||||||||||
| * @covers ::the_embed_site_title | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function test_the_embed_site_title_uses_fallback_without_srcset_when_no_site_icon_set() { | ||||||||||||||||||
| ob_start(); | ||||||||||||||||||
| the_embed_site_title(); | ||||||||||||||||||
| $output = ob_get_clean(); | ||||||||||||||||||
|
Comment on lines
+933
to
+935
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| $fallback = includes_url( 'images/w-logo-blue.png' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| $this->assertStringContainsString( 'wp-embed-site-icon', $output, 'Fallback icon img should be present when no site icon is set.' ); | ||||||||||||||||||
| $this->assertStringContainsString( esc_url( $fallback ), $output, 'Output should contain fallback icon URL.' ); | ||||||||||||||||||
| $this->assertStringNotContainsString( 'srcset=', $output, 'srcset should be omitted when 1x and 2x fallback URLs are identical.' ); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to remove the filter. This is done automatically during test cleanup.