From fbe598190087a1f730e61b3a86c765a049708df3 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:18:09 +0000 Subject: [PATCH 1/2] Tests: Cover comment_excerpt(). Add unit tests for excerpt display output, comment objects, global fallback, and the display filter. See #65819. --- .../phpunit/tests/comment/commentExcerpt.php | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/phpunit/tests/comment/commentExcerpt.php diff --git a/tests/phpunit/tests/comment/commentExcerpt.php b/tests/phpunit/tests/comment/commentExcerpt.php new file mode 100644 index 0000000000000..c8353aec7acf8 --- /dev/null +++ b/tests/phpunit/tests/comment/commentExcerpt.php @@ -0,0 +1,87 @@ +post->create(); + self::$comment = $factory->comment->create_and_get( + array( + 'comment_post_ID' => self::$post_id, + 'comment_content' => 'Short comment excerpt text.', + ) + ); + } + + public function tear_down() { + unset( $GLOBALS['comment'] ); + parent::tear_down(); + } + + /** + * @ticket 65819 + */ + public function test_comment_excerpt_echoes_excerpt() { + $expected = get_comment_excerpt( self::$comment ); + + $this->expectOutputString( $expected ); + comment_excerpt( self::$comment->comment_ID ); + } + + /** + * @ticket 65819 + */ + public function test_comment_excerpt_accepts_comment_object() { + $expected = get_comment_excerpt( self::$comment ); + + $this->expectOutputString( $expected ); + comment_excerpt( self::$comment ); + } + + /** + * @ticket 65819 + */ + public function test_comment_excerpt_uses_global_comment_when_unspecified() { + $GLOBALS['comment'] = self::$comment; + $expected = get_comment_excerpt( self::$comment ); + + $this->expectOutputString( $expected ); + comment_excerpt(); + } + + /** + * @ticket 65819 + */ + public function test_comment_excerpt_filter_can_modify_output() { + add_filter( + 'comment_excerpt', + static function () { + return 'Filtered excerpt.'; + } + ); + + $this->expectOutputString( 'Filtered excerpt.' ); + comment_excerpt( self::$comment->comment_ID ); + } +} From 63e78b9537bee6af78d5f0ed9e7d6d2231573731 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sun, 1 Nov 2026 05:15:59 +0000 Subject: [PATCH 2/2] Tests: Use literal expected output for comment_excerpt() coverage. Avoid deriving expectations from get_comment_excerpt() so the display assertions stay independent of that getter. See #65819. --- tests/phpunit/tests/comment/commentExcerpt.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/comment/commentExcerpt.php b/tests/phpunit/tests/comment/commentExcerpt.php index c8353aec7acf8..6f4142e495ec6 100644 --- a/tests/phpunit/tests/comment/commentExcerpt.php +++ b/tests/phpunit/tests/comment/commentExcerpt.php @@ -43,9 +43,7 @@ public function tear_down() { * @ticket 65819 */ public function test_comment_excerpt_echoes_excerpt() { - $expected = get_comment_excerpt( self::$comment ); - - $this->expectOutputString( $expected ); + $this->expectOutputString( 'Short comment excerpt text.' ); comment_excerpt( self::$comment->comment_ID ); } @@ -53,9 +51,7 @@ public function test_comment_excerpt_echoes_excerpt() { * @ticket 65819 */ public function test_comment_excerpt_accepts_comment_object() { - $expected = get_comment_excerpt( self::$comment ); - - $this->expectOutputString( $expected ); + $this->expectOutputString( 'Short comment excerpt text.' ); comment_excerpt( self::$comment ); } @@ -64,9 +60,8 @@ public function test_comment_excerpt_accepts_comment_object() { */ public function test_comment_excerpt_uses_global_comment_when_unspecified() { $GLOBALS['comment'] = self::$comment; - $expected = get_comment_excerpt( self::$comment ); - $this->expectOutputString( $expected ); + $this->expectOutputString( 'Short comment excerpt text.' ); comment_excerpt(); }