Make WordPress Core

Changeset 35194


Ignore:
Timestamp:
10/15/2015 06:39:43 AM (9 years ago)
Author:
wonderboymusic
Message:

Unit Tests: upgrade the fixtures in Tests_Post_Thumbnail_Template.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r34855 r35194  
    66 */
    77class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
    8     protected $post;
    9     protected $attachment_id;
     8    protected static $post;
     9    protected static $attachment_id;
    1010
    11     function setUp() {
    12         parent::setUp();
    13 
    14         $this->post          = $this->factory->post->create_and_get();
    15         $file                = DIR_TESTDATA . '/images/canola.jpg';
    16         $this->attachment_id = $this->factory->attachment->create_upload_object( $file, $this->post->ID, array(
     11    public static function wpSetUpBeforeClass( $factory ) {
     12        self::$post = $factory->post->create_and_get();
     13        $file = DIR_TESTDATA . '/images/canola.jpg';
     14        self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array(
    1715            'post_mime_type' => 'image/jpeg',
    1816        ) );
    1917    }
    2018
     19    public static function wpTearDownAfterClass() {
     20        wp_delete_post( self::$post->ID );
     21        wp_delete_attachment( self::$attachment_id );
     22    }
     23
    2124    function test_has_post_thumbnail() {
    22         $this->assertFalse( has_post_thumbnail( $this->post ) );
    23         $this->assertFalse( has_post_thumbnail( $this->post->ID ) );
     25        $this->assertFalse( has_post_thumbnail( self::$post ) );
     26        $this->assertFalse( has_post_thumbnail( self::$post->ID ) );
    2427        $this->assertFalse( has_post_thumbnail() );
    2528
    26         $GLOBALS['post'] = $this->post;
     29        $GLOBALS['post'] = self::$post;
    2730
    2831        $this->assertFalse( has_post_thumbnail() );
     
    3033        unset( $GLOBALS['post'] );
    3134
    32         set_post_thumbnail( $this->post, $this->attachment_id );
     35        set_post_thumbnail( self::$post, self::$attachment_id );
    3336
    34         $this->assertTrue( has_post_thumbnail( $this->post ) );
    35         $this->assertTrue( has_post_thumbnail( $this->post->ID ) );
     37        $this->assertTrue( has_post_thumbnail( self::$post ) );
     38        $this->assertTrue( has_post_thumbnail( self::$post->ID ) );
    3639        $this->assertFalse( has_post_thumbnail() );
    3740
    38         $GLOBALS['post'] = $this->post;
     41        $GLOBALS['post'] = self::$post;
    3942
    4043        $this->assertTrue( has_post_thumbnail() );
     
    4245
    4346    function test_get_post_thumbnail_id() {
    44         $this->assertEmpty( get_post_thumbnail_id( $this->post ) );
    45         $this->assertEmpty( get_post_thumbnail_id( $this->post->ID ) );
     47        $this->assertEmpty( get_post_thumbnail_id( self::$post ) );
     48        $this->assertEmpty( get_post_thumbnail_id( self::$post->ID ) );
    4649        $this->assertEmpty( get_post_thumbnail_id() );
    4750
    48         set_post_thumbnail( $this->post, $this->attachment_id );
     51        set_post_thumbnail( self::$post, self::$attachment_id );
    4952
    50         $this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post ) );
    51         $this->assertEquals( $this->attachment_id, get_post_thumbnail_id( $this->post->ID ) );
     53        $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post ) );
     54        $this->assertEquals( self::$attachment_id, get_post_thumbnail_id( self::$post->ID ) );
    5255
    53         $GLOBALS['post'] = $this->post;
     56        $GLOBALS['post'] = self::$post;
    5457
    55         $this->assertEquals( $this->attachment_id, get_post_thumbnail_id() );
     58        $this->assertEquals( self::$attachment_id, get_post_thumbnail_id() );
    5659    }
    5760
    5861    function test_update_post_thumbnail_cache() {
    59         set_post_thumbnail( $this->post, $this->attachment_id );
     62        set_post_thumbnail( self::$post, self::$attachment_id );
    6063
    6164        $WP_Query = new WP_Query( array(
    6265            'post_type' => 'any',
    63             'post__in'  => array( $this->post->ID ),
     66            'post__in'  => array( self::$post->ID ),
    6467            'orderby'   => 'post__in',
    6568        ) );
     
    7477    function test_get_the_post_thumbnail() {
    7578        $this->assertEquals( '', get_the_post_thumbnail() );
    76         $this->assertEquals( '', get_the_post_thumbnail( $this->post ) );
    77         set_post_thumbnail( $this->post, $this->attachment_id );
     79        $this->assertEquals( '', get_the_post_thumbnail( self::$post ) );
     80        set_post_thumbnail( self::$post, self::$attachment_id );
    7881
    79         $expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(
     82        $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
    8083            'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
    8184        ) );
    8285
    83         $this->assertEquals( $expected, get_the_post_thumbnail( $this->post ) );
     86        $this->assertEquals( $expected, get_the_post_thumbnail( self::$post ) );
    8487
    85         $GLOBALS['post'] = $this->post;
     88        $GLOBALS['post'] = self::$post;
    8689
    8790        $this->assertEquals( $expected, get_the_post_thumbnail() );
     
    9598        $this->assertEquals( '', $actual );
    9699
    97         $GLOBALS['post'] = $this->post;
     100        $GLOBALS['post'] = self::$post;
    98101
    99102        ob_start();
     
    103106        $this->assertEquals( '', $actual );
    104107
    105         set_post_thumbnail( $this->post, $this->attachment_id );
     108        set_post_thumbnail( self::$post, self::$attachment_id );
    106109
    107         $expected = wp_get_attachment_image( $this->attachment_id, 'post-thumbnail', false, array(
     110        $expected = wp_get_attachment_image( self::$attachment_id, 'post-thumbnail', false, array(
    108111            'class' => 'attachment-post-thumbnail size-post-thumbnail wp-post-image'
    109112        ) );
     
    120123     */
    121124    function test_get_the_post_thumbnail_url() {
    122         $this->assertFalse( has_post_thumbnail( $this->post ) );
     125        $this->assertFalse( has_post_thumbnail( self::$post ) );
    123126        $this->assertFalse( get_the_post_thumbnail_url() );
    124         $this->assertFalse( get_the_post_thumbnail_url( $this->post ) );
     127        $this->assertFalse( get_the_post_thumbnail_url( self::$post ) );
    125128
    126         set_post_thumbnail( $this->post, $this->attachment_id );
     129        set_post_thumbnail( self::$post, self::$attachment_id );
    127130
    128131        $this->assertFalse( get_the_post_thumbnail_url() );
    129         $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url( $this->post ) );
     132        $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url( self::$post ) );
    130133
    131         $GLOBALS['post'] = $this->post;
     134        $GLOBALS['post'] = self::$post;
    132135
    133         $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url() );
     136        $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), get_the_post_thumbnail_url() );
    134137    }
    135138
     
    138141     */
    139142    function test_get_the_post_thumbnail_url_with_invalid_post() {
    140         $post = $this->factory->post->create_and_get();
     143        set_post_thumbnail( self::$post, self::$attachment_id );
    141144
    142         set_post_thumbnail( $post, $this->attachment_id );
     145        $this->assertTrue( false !== get_the_post_thumbnail_url( self::$post->ID ) );
    143146
    144         $this->assertTrue( false !== get_the_post_thumbnail_url( $post->ID ) );
    145 
    146         $deleted = wp_delete_post( $post->ID, true );
     147        $deleted = wp_delete_post( self::$post->ID, true );
    147148        $this->assertNotEmpty( $deleted );
    148149
    149         $this->assertFalse( get_the_post_thumbnail_url( $post->ID ) );
     150        $this->assertFalse( get_the_post_thumbnail_url( self::$post->ID ) );
    150151    }
    151152
     
    154155     */
    155156    function test_the_post_thumbnail_url() {
    156         $GLOBALS['post'] = $this->post;
     157        $GLOBALS['post'] = self::$post;
    157158
    158159        ob_start();
     
    168169        $this->assertEmpty( $actual );
    169170
    170         set_post_thumbnail( $this->post, $this->attachment_id );
     171        set_post_thumbnail( self::$post, self::$attachment_id );
    171172
    172173        ob_start();
     
    174175        $actual = ob_get_clean();
    175176
    176         $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), $actual );
     177        $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
    177178    }
    178179}
Note: See TracChangeset for help on using the changeset viewer.