From 996d7e6055773e7d08016443c57232432404c685 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:10:18 +0000 Subject: [PATCH 1/2] Tests: Cover get_comment_author_url() and comment_author_url(). Add unit tests for URL retrieval, empty fallback, filters, and display output.\n\nSee #65819. --- .../tests/comment/commentAuthorUrl.php | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tests/phpunit/tests/comment/commentAuthorUrl.php diff --git a/tests/phpunit/tests/comment/commentAuthorUrl.php b/tests/phpunit/tests/comment/commentAuthorUrl.php new file mode 100644 index 0000000000000..e977c8ece4cd4 --- /dev/null +++ b/tests/phpunit/tests/comment/commentAuthorUrl.php @@ -0,0 +1,117 @@ +post->create(); + self::$comment = $factory->comment->create_and_get( + array( + 'comment_post_ID' => self::$post_id, + 'comment_author_url' => 'https://example.com/author', + ) + ); + } + + public function tear_down() { + unset( $GLOBALS['comment'] ); + parent::tear_down(); + } + + /** + * @ticket 65819 + * + * @covers ::get_comment_author_url + */ + public function test_returns_comment_author_url() { + $this->assertSame( 'https://example.com/author', get_comment_author_url( self::$comment->comment_ID ) ); + } + + /** + * @ticket 65819 + * + * @covers ::get_comment_author_url + */ + public function test_accepts_comment_object() { + $this->assertSame( 'https://example.com/author', get_comment_author_url( self::$comment ) ); + } + + /** + * @ticket 65819 + * + * @covers ::get_comment_author_url + */ + public function test_uses_global_comment_when_unspecified() { + $GLOBALS['comment'] = self::$comment; + + $this->assertSame( 'https://example.com/author', get_comment_author_url() ); + } + + /** + * @ticket 65819 + * + * @covers ::get_comment_author_url + */ + public function test_returns_empty_string_when_url_missing() { + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => self::$post_id, + 'comment_author_url' => '', + ) + ); + + $this->assertSame( '', get_comment_author_url( $comment_id ) ); + } + + /** + * @ticket 65819 + * + * @covers ::get_comment_author_url + */ + public function test_filter_can_modify_url() { + add_filter( + 'get_comment_author_url', + static function () { + return 'https://filtered.example.com'; + } + ); + + $this->assertSame( 'https://filtered.example.com', get_comment_author_url( self::$comment->comment_ID ) ); + } + + /** + * @ticket 65819 + * + * @covers ::comment_author_url + * @covers ::get_comment_author_url + */ + public function test_comment_author_url_echoes_value() { + add_filter( + 'comment_url', + static function () { + return 'https://display.example.com'; + } + ); + + $this->expectOutputString( 'https://display.example.com' ); + comment_author_url( self::$comment->comment_ID ); + } +} From abf8a89244f00457b3f02ad79de79e28c0241c66 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sat, 31 Oct 2026 10:44:01 +0530 Subject: [PATCH 2/2] Apply Feedback changes Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/phpunit/tests/comment/commentAuthorUrl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/comment/commentAuthorUrl.php b/tests/phpunit/tests/comment/commentAuthorUrl.php index e977c8ece4cd4..91b65f9e02626 100644 --- a/tests/phpunit/tests/comment/commentAuthorUrl.php +++ b/tests/phpunit/tests/comment/commentAuthorUrl.php @@ -106,7 +106,8 @@ static function () { public function test_comment_author_url_echoes_value() { add_filter( 'comment_url', - static function () { + function ( $url ) { + $this->assertSame( 'https://example.com/author', $url ); return 'https://display.example.com'; } );