Unit Tests: upgrade the fixtures in `Tests_Post_Thumbnail_Template`.
See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35194 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a65f390db6
commit
0cf7a91d3a
|
@ -5,62 +5,65 @@
|
|||
* @group media
|
||||
*/
|
||||
class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
||||
protected $post;
|
||||
protected $attachment_id;
|
||||
protected static $post;
|
||||
protected static $attachment_id;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->post = $this->factory->post->create_and_get();
|
||||
$file = DIR_TESTDATA . '/images/canola.jpg';
|
||||
$this->attachment_id = $this->factory->attachment->create_upload_object( $file, $this->post->ID, array(
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$post = $factory->post->create_and_get();
|
||||
$file = DIR_TESTDATA . '/images/canola.jpg';
|
||||
self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array(
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
) );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
wp_delete_post( self::$post->ID );
|
||||
wp_delete_attachment( self::$attachment_id );
|
||||
}
|
||||
|
||||
function test_has_post_thumbnail() {
|
||||
$this->assertFalse( has_post_thumbnail( $this->post ) );
|
||||
$this->assertFalse( has_post_thumbnail( $this->post->ID ) );
|
||||
$this->assertFalse( has_post_thumbnail( self::$post ) );
|
||||
$this->assertFalse( has_post_thumbnail( self::$post->ID ) );
|
||||
$this->assertFalse( has_post_thumbnail() );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
$this->assertFalse( has_post_thumbnail() );
|
||||
|
||||
unset( $GLOBALS['post'] );
|
||||
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$this->assertTrue( has_post_thumbnail( $this->post ) );
|
||||
$this->assertTrue( has_post_thumbnail( $this->post->ID ) );
|
||||
$this->assertTrue( has_post_thumbnail( self::$post ) );
|
||||
$this->assertTrue( has_post_thumbnail( self::$post->ID ) );
|
||||
$this->assertFalse( has_post_thumbnail() );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
$this->assertTrue( has_post_thumbnail() );
|
||||
}
|
||||
|
||||
function test_get_post_thumbnail_id() {
|
||||
$this->assertEmpty( get_post_thumbnail_id( $this->post ) );
|
||||
$this->assertEmpty( get_post_thumbnail_id( $this->post->ID ) );
|
||||
$this->assertEmpty( get_post_thumbnail_id( self::$post ) );
|
||||
$this->assertEmpty( get_post_thumbnail_id( self::$post->ID ) );
|
||||
$this->assertEmpty( get_post_thumbnail_id() );
|
||||
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post ) );
|
||||
$this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post->ID ) );
|
||||
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post ) );
|
||||
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
$this->assertEquals( $this->attachment_id, get_post_thumbnail_id() );
|
||||
$this->assertEquals( self::$attachment_id, get_post_thumbnail_id() );
|
||||
}
|
||||
|
||||
function test_update_post_thumbnail_cache() {
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$WP_Query = new WP_Query( array(
|
||||
'post_type' => 'any',
|
||||
'post__in' => array( $this->post->ID ),
|
||||
'post__in' => array( self::$post->ID ),
|
||||
'orderby' => 'post__in',
|
||||
) );
|
||||
|
||||
|
@ -73,16 +76,16 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
|
||||
function test_get_the_post_thumbnail() {
|
||||
$this->assertEquals( '', get_the_post_thumbnail() );
|
||||
$this->assertEquals( '', get_the_post_thumbnail( $this->post ) );
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
$this->assertEquals( '', get_the_post_thumbnail( self::$post ) );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(
|
||||
$expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
|
||||
'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
|
||||
) );
|
||||
|
||||
$this->assertEquals( $expected, get_the_post_thumbnail( $this->post ) );
|
||||
$this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
$this->assertEquals( $expected, get_the_post_thumbnail() );
|
||||
}
|
||||
|
@ -94,7 +97,7 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
|
||||
$this->assertEquals( '', $actual );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
ob_start();
|
||||
the_post_thumbnail();
|
||||
|
@ -102,9 +105,9 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
|
||||
$this->assertEquals( '', $actual );
|
||||
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(
|
||||
$expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
|
||||
'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
|
||||
) );
|
||||
|
||||
|
@ -119,41 +122,39 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
* @ticket 33070
|
||||
*/
|
||||
function test_get_the_post_thumbnail_url() {
|
||||
$this->assertFalse( has_post_thumbnail( $this->post ) );
|
||||
$this->assertFalse( has_post_thumbnail( self::$post ) );
|
||||
$this->assertFalse( get_the_post_thumbnail_url() );
|
||||
$this->assertFalse( get_the_post_thumbnail_url( $this->post ) );
|
||||
$this->assertFalse( get_the_post_thumbnail_url( self::$post ) );
|
||||
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
$this->assertFalse( get_the_post_thumbnail_url() );
|
||||
$this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url( $this->post ) );
|
||||
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) );
|
||||
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
$this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url() );
|
||||
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33070
|
||||
*/
|
||||
function test_get_the_post_thumbnail_url_with_invalid_post() {
|
||||
$post = $this->factory->post->create_and_get();
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
set_post_thumbnail( $post, $this->attachment_id );
|
||||
$this->assertTrue( false !== get_the_post_thumbnail_url( self::$post->ID ) );
|
||||
|
||||
$this->assertTrue( false !== get_the_post_thumbnail_url( $post->ID ) );
|
||||
|
||||
$deleted = wp_delete_post( $post->ID, true );
|
||||
$deleted = wp_delete_post( self::$post->ID, true );
|
||||
$this->assertNotEmpty( $deleted );
|
||||
|
||||
$this->assertFalse( get_the_post_thumbnail_url( $post->ID ) );
|
||||
$this->assertFalse( get_the_post_thumbnail_url( self::$post->ID ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 33070
|
||||
*/
|
||||
function test_the_post_thumbnail_url() {
|
||||
$GLOBALS['post'] = $this->post;
|
||||
$GLOBALS['post'] = self::$post;
|
||||
|
||||
ob_start();
|
||||
the_post_thumbnail_url();
|
||||
|
@ -167,12 +168,12 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
|||
|
||||
$this->assertEmpty( $actual );
|
||||
|
||||
set_post_thumbnail( $this->post, $this->attachment_id );
|
||||
set_post_thumbnail( self::$post, self::$attachment_id );
|
||||
|
||||
ob_start();
|
||||
the_post_thumbnail_url();
|
||||
$actual = ob_get_clean();
|
||||
|
||||
$this->assertEquals( wp_get_attachment_url( $this->attachment_id ), $actual );
|
||||
$this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue