Build/Test tools: Switch to PHPUnit's `expectOutputString()` method instead of manually using output buffers for output assertions.
Props birgire Fixes #42098 git-svn-id: https://develop.svn.wordpress.org/trunk@42382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
07be59d34b
commit
a7488c9441
|
@ -127,11 +127,9 @@ EOF;
|
|||
}
|
||||
|
||||
function test_wp_get_archives_echo() {
|
||||
$expected['echo'] = "<li><a href='" . $this->month_url . "'>" . date( 'F Y' ) . '</a></li>';
|
||||
ob_start();
|
||||
$expected['echo'] = "\t<li><a href='" . $this->month_url . "'>" . date( 'F Y' ) . '</a></li>' . "\n";
|
||||
$this->expectOutputString( $expected['echo'] );
|
||||
wp_get_archives( array( 'echo' => true ) );
|
||||
$actual = ob_get_clean();
|
||||
$this->assertEquals( $expected['echo'], trim( $actual ) );
|
||||
}
|
||||
|
||||
function test_wp_get_archives_order() {
|
||||
|
|
|
@ -238,10 +238,8 @@ class Tests_List_Pages extends WP_UnitTestCase {
|
|||
<li class="page_item page-item-2 page_item_has_children"><a href="' . get_permalink( 2 ) . '">Parent 2</a></li>
|
||||
<li class="page_item page-item-3 page_item_has_children"><a href="' . get_permalink( 3 ) . '">Parent 3</a></li>
|
||||
</ul></li>';
|
||||
ob_start();
|
||||
$this->expectOutputString( $expected['echo'] );
|
||||
wp_list_pages( $args );
|
||||
$actual = ob_get_clean();
|
||||
$this->AssertEquals( $expected['echo'], $actual );
|
||||
}
|
||||
|
||||
function test_wp_list_pages_authors() {
|
||||
|
|
|
@ -141,10 +141,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
|
||||
set_post_thumbnail( $post_id, $attachment_id );
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( $caption );
|
||||
the_post_thumbnail_caption( $post_id );
|
||||
|
||||
$this->assertEquals( $caption, ob_get_clean() );
|
||||
}
|
||||
|
||||
function test_get_the_post_thumbnail() {
|
||||
|
@ -166,19 +164,14 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
function test_the_post_thumbnail() {
|
||||
ob_start();
|
||||
the_post_thumbnail();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEquals( '', $actual );
|
||||
$this->expectOutputString( '' );
|
||||
the_post_thumbnail();
|
||||
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( '' );
|
||||
the_post_thumbnail();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEquals( '', $actual );
|
||||
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
|
@ -188,11 +181,8 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( $expected );
|
||||
the_post_thumbnail();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,25 +223,13 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
function test_the_post_thumbnail_url() {
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( '' );
|
||||
the_post_thumbnail_url();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEmpty( $actual );
|
||||
|
||||
ob_start();
|
||||
the_post_thumbnail_url();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEmpty( $actual );
|
||||
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( wp_get_attachment_url( self::$attachment_id ) );
|
||||
the_post_thumbnail_url();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,13 +66,11 @@ class Tests_Taxonomy extends WP_UnitTestCase {
|
|||
function test_the_taxonomies() {
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
ob_start();
|
||||
$this->expectOutputString( sprintf(
|
||||
'Categories: <a href="%s">Uncategorized</a>.',
|
||||
get_category_link( 1 )
|
||||
) );
|
||||
the_taxonomies( array( 'post' => $post_id ) );
|
||||
$output = ob_get_clean();
|
||||
|
||||
$link = get_category_link( 1 );
|
||||
$expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.';
|
||||
$this->assertEquals( $expected, $output );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -161,10 +161,8 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
|
|||
|
||||
function test_wp_list_authors_echo() {
|
||||
$expected['echo'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
|
||||
ob_start();
|
||||
$this->expectOutputString( $expected['echo'] );
|
||||
wp_list_authors( array( 'echo' => true ) );
|
||||
$actual = ob_get_clean();
|
||||
$this->AssertEquals( $expected['echo'], $actual );
|
||||
}
|
||||
|
||||
function test_wp_list_authors_feed() {
|
||||
|
|
Loading…
Reference in New Issue