From f252d21fb5e19d41550152e3b5b9da2a42837f63 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sat, 7 Nov 2026 11:42:50 +0600 Subject: [PATCH 1/2] Tests: Cover wp_rel_callback(). See #65819. Props devmuhib009. --- .../tests/formatting/wpRelCallback.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/phpunit/tests/formatting/wpRelCallback.php diff --git a/tests/phpunit/tests/formatting/wpRelCallback.php b/tests/phpunit/tests/formatting/wpRelCallback.php new file mode 100644 index 0000000000000..aeac5cf216e39 --- /dev/null +++ b/tests/phpunit/tests/formatting/wpRelCallback.php @@ -0,0 +1,86 @@ +', 'href="https://example.com"' ); + $actual = wp_rel_callback( $matches, 'nofollow' ); + + $this->assertSame( '', $actual ); + } + + /** + * Tests merging a new rel value with an existing rel attribute. + * + * @ticket 65819 + */ + public function test_wp_rel_callback_merges_with_existing_rel() { + $matches = array( '', 'href="https://example.com" rel="external"' ); + $actual = wp_rel_callback( $matches, 'nofollow' ); + + $this->assertSame( '', $actual ); + } + + /** + * Tests that existing rel values are not duplicated. + * + * @ticket 65819 + */ + public function test_wp_rel_callback_does_not_duplicate_existing_rel() { + $matches = array( '', 'href="https://example.com" rel="nofollow ugc"' ); + $actual = wp_rel_callback( $matches, 'nofollow' ); + + $this->assertSame( '', $actual ); + } + + /** + * Tests that nofollow is stripped when the link is internal. + * + * @ticket 65819 + */ + public function test_wp_rel_callback_removes_nofollow_for_internal_links() { + $home_url = home_url( '/test-page/' ); + $matches = array( '', 'href="' . $home_url . '"' ); + $actual = wp_rel_callback( $matches, 'nofollow' ); + + $this->assertSame( '', $actual ); + } + + /** + * Tests that internal links keep existing rel and can add other rel values like ugc. + * + * @ticket 65819 + */ + public function test_wp_rel_callback_preserves_other_rel_for_internal_links() { + $home_url = home_url( '/internal/' ); + $matches = array( '', $actual ); + } + + /** + * Tests handling of valueless attributes on the anchor. + * + * @ticket 65819 + */ + public function test_wp_rel_callback_handles_valueless_attributes() { + $matches = array( '', 'href="https://example.com" download rel="opener"' ); + $actual = wp_rel_callback( $matches, 'noreferrer' ); + + $this->assertStringContainsString( 'download', $actual ); + $this->assertStringContainsString( 'rel="opener noreferrer"', $actual ); + } +} From 996a6e3a3765baaebe2158d31390bd5a83a708f9 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sat, 7 Nov 2026 20:50:21 +0600 Subject: [PATCH 2/2] Tests: Cover wp_rel_callback(). See #66610. Props devmuhib009. --- tests/phpunit/tests/formatting/wpRelCallback.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/formatting/wpRelCallback.php b/tests/phpunit/tests/formatting/wpRelCallback.php index aeac5cf216e39..64034161ef4c0 100644 --- a/tests/phpunit/tests/formatting/wpRelCallback.php +++ b/tests/phpunit/tests/formatting/wpRelCallback.php @@ -12,7 +12,7 @@ class Tests_Formatting_WpRelCallback extends WP_UnitTestCase { /** * Tests adding a rel attribute to an anchor that does not have one. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_adds_rel_to_link() { $matches = array( '', 'href="https://example.com"' ); @@ -24,7 +24,7 @@ public function test_wp_rel_callback_adds_rel_to_link() { /** * Tests merging a new rel value with an existing rel attribute. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_merges_with_existing_rel() { $matches = array( '', 'href="https://example.com" rel="external"' ); @@ -36,7 +36,7 @@ public function test_wp_rel_callback_merges_with_existing_rel() { /** * Tests that existing rel values are not duplicated. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_does_not_duplicate_existing_rel() { $matches = array( '', 'href="https://example.com" rel="nofollow ugc"' ); @@ -48,7 +48,7 @@ public function test_wp_rel_callback_does_not_duplicate_existing_rel() { /** * Tests that nofollow is stripped when the link is internal. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_removes_nofollow_for_internal_links() { $home_url = home_url( '/test-page/' ); @@ -61,7 +61,7 @@ public function test_wp_rel_callback_removes_nofollow_for_internal_links() { /** * Tests that internal links keep existing rel and can add other rel values like ugc. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_preserves_other_rel_for_internal_links() { $home_url = home_url( '/internal/' ); @@ -74,7 +74,7 @@ public function test_wp_rel_callback_preserves_other_rel_for_internal_links() { /** * Tests handling of valueless attributes on the anchor. * - * @ticket 65819 + * @ticket 66610 */ public function test_wp_rel_callback_handles_valueless_attributes() { $matches = array( '', 'href="https://example.com" download rel="opener"' );