Skip to content

Commit 98e9d67

Browse files
committed
Tests: Cover comment excerpt display.
Verify `comment_excerpt()` output for explicit and current comments, using independent literal expectations and covering the display filter. Developed in: #15281 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65167 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 89f89d7 commit 98e9d67

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/**
4+
* Tests for comment_excerpt().
5+
*
6+
* @group comment
7+
*
8+
* @covers ::comment_excerpt
9+
* @covers ::get_comment_excerpt
10+
*/
11+
class Tests_Comment_CommentExcerpt extends WP_UnitTestCase {
12+
13+
/**
14+
* Post fixture.
15+
*
16+
* @var int
17+
*/
18+
private static $post_id;
19+
20+
/**
21+
* Comment fixture.
22+
*
23+
* @var WP_Comment
24+
*/
25+
private static $comment;
26+
27+
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
28+
self::$post_id = $factory->post->create();
29+
self::$comment = $factory->comment->create_and_get(
30+
array(
31+
'comment_post_ID' => self::$post_id,
32+
'comment_content' => 'Short comment excerpt text.',
33+
)
34+
);
35+
}
36+
37+
public function tear_down() {
38+
unset( $GLOBALS['comment'] );
39+
parent::tear_down();
40+
}
41+
42+
/**
43+
* @ticket 65819
44+
*/
45+
public function test_comment_excerpt_echoes_excerpt() {
46+
$this->expectOutputString( 'Short comment excerpt text.' );
47+
comment_excerpt( self::$comment->comment_ID );
48+
}
49+
50+
/**
51+
* @ticket 65819
52+
*/
53+
public function test_comment_excerpt_accepts_comment_object() {
54+
$this->expectOutputString( 'Short comment excerpt text.' );
55+
comment_excerpt( self::$comment );
56+
}
57+
58+
/**
59+
* @ticket 65819
60+
*/
61+
public function test_comment_excerpt_uses_global_comment_when_unspecified() {
62+
$GLOBALS['comment'] = self::$comment;
63+
64+
$this->expectOutputString( 'Short comment excerpt text.' );
65+
comment_excerpt();
66+
}
67+
68+
/**
69+
* @ticket 65819
70+
*/
71+
public function test_comment_excerpt_filter_can_modify_output() {
72+
add_filter(
73+
'comment_excerpt',
74+
static function () {
75+
return 'Filtered excerpt.';
76+
}
77+
);
78+
79+
$this->expectOutputString( 'Filtered excerpt.' );
80+
comment_excerpt( self::$comment->comment_ID );
81+
}
82+
}

0 commit comments

Comments
 (0)