Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions tests/phpunit/tests/comment/commentExcerpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/**
* Tests for comment_excerpt().
*
* @group comment
*
* @covers ::comment_excerpt
* @covers ::get_comment_excerpt
*/
class Tests_Comment_CommentExcerpt extends WP_UnitTestCase {

/**
* Post fixture.
*
* @var int
*/
private static $post_id;

/**
* Comment fixture.
*
* @var WP_Comment
*/
private static $comment;

public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$post_id = $factory->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() {
$this->expectOutputString( 'Short comment excerpt text.' );
comment_excerpt( self::$comment->comment_ID );
}

/**
* @ticket 65819
*/
public function test_comment_excerpt_accepts_comment_object() {
$this->expectOutputString( 'Short comment excerpt text.' );
comment_excerpt( self::$comment );
}

/**
* @ticket 65819
*/
public function test_comment_excerpt_uses_global_comment_when_unspecified() {
$GLOBALS['comment'] = self::$comment;

$this->expectOutputString( 'Short comment excerpt text.' );
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 );
}
}
Loading