WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/22/2015 04:14:15 AM (4 years ago)
Author:
wonderboymusic
Message:

Media: Add new functions, get_the_post_thumbnail_url() and the_post_thumbnail_url().

Adds unit tests.

Props dipesh.kakadiya, swissspidy, atomicjack.
Fixes #33070.

File:
1 edited

Legend:

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

    r34167 r34373  
    111111        $this->assertEquals( $expected, $actual );
    112112    }
     113
     114    /**
     115     * @ticket 33070
     116     */
     117    function test_get_the_post_thumbnail_url() {
     118        $this->assertEquals( '', get_the_post_thumbnail_url() );
     119        $this->assertEquals( '', get_the_post_thumbnail_url( $this->post ) );
     120
     121        set_post_thumbnail( $this->post, $this->attachment_id );
     122
     123        var_dump( get_the_post_thumbnail_url( $this->post ) );
     124
     125        $this->assertEquals( '', get_the_post_thumbnail_url() );
     126        $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url( $this->post ) );
     127
     128        $GLOBALS['post'] = $this->post;
     129
     130        $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), get_the_post_thumbnail_url() );
     131    }
     132
     133    /**
     134     * @ticket 33070
     135     */
     136    function test_the_post_thumbnail_url() {
     137        $GLOBALS['post'] = $this->post;
     138
     139        ob_start();
     140        the_post_thumbnail_url();
     141        $actual = ob_get_clean();
     142
     143        $this->assertEmpty( $actual );
     144
     145        ob_start();
     146        the_post_thumbnail_url();
     147        $actual = ob_get_clean();
     148
     149        $this->assertEmpty( $actual );
     150
     151        set_post_thumbnail( $this->post, $this->attachment_id );
     152
     153        ob_start();
     154        the_post_thumbnail_url();
     155        $actual = ob_get_clean();
     156
     157        $this->assertEquals( wp_get_attachment_url( $this->attachment_id ), $actual );
     158    }
    113159}
Note: See TracChangeset for help on using the changeset viewer.