Make WordPress Core

Ticket #27246: 27246.3.diff

File 27246.3.diff, 2.5 KB (added by swissspidy, 9 years ago)
  • src/wp-includes/post-template.php

    diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php
    index 8a2989b..4b15de6 100644
    function the_excerpt() { 
    357357 * Retrieve the post excerpt.
    358358 *
    359359 * @since 0.71
     360 * @since 4.5.0 Introduced the `$post` parameter.
    360361 *
    361  * @param mixed $deprecated Not used.
    362  * @return string
     362 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
     363 * @return string Post excerpt.
    363364 */
    364 function get_the_excerpt( $deprecated = '' ) {
    365         if ( !empty( $deprecated ) )
     365function get_the_excerpt( $post = '' ) {
     366        if ( is_bool( $post ) ) {
    366367                _deprecated_argument( __FUNCTION__, '2.3' );
     368        }
    367369
    368         $post = get_post();
     370        $post = get_post( $post );
    369371        if ( empty( $post ) ) {
    370372                return '';
    371373        }
  • tests/phpunit/tests/post/output.php

    diff --git tests/phpunit/tests/post/output.php tests/phpunit/tests/post/output.php
    index 52c3eff..63b9aad 100644
    EOF; 
    171171                kses_remove_filters();
    172172        }
    173173
     174        /**
     175         * @ticket 27246
     176         */
     177        public function test_the_excerpt_invalid_post() {
     178                $this->assertSame( '', get_echo( 'the_excerpt' ) );
     179                $this->assertSame( '', get_the_excerpt() );
     180        }
     181
     182        /**
     183         * @ticket 27246
     184         * @expectedDeprecated get_the_excerpt
     185         */
     186        public function test_the_excerpt_deprecated() {
     187                $this->assertSame( '', get_the_excerpt( true ) );
     188                $this->assertSame( '', get_the_excerpt( false ) );
     189        }
     190
     191        /**
     192         * @ticket 27246
     193         */
     194        public function test_the_excerpt() {
     195                $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt' ) );
     196                $this->assertSame( "<p>Post excerpt</p>\n", get_echo( 'the_excerpt' ) );
     197                $this->assertSame( 'Post excerpt', get_the_excerpt() );
     198        }
     199
     200        /**
     201         * @ticket 27246
     202         */
     203        public function test_the_excerpt_password_protected_post() {
     204                $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Post excerpt', 'post_password' => '1234' ) );
     205                $this->assertSame( "<p>There is no excerpt because this is a protected post.</p>\n", get_echo( 'the_excerpt' ) );
     206                $this->assertSame( 'There is no excerpt because this is a protected post.', get_the_excerpt() );
     207        }
     208
     209        /**
     210         * @ticket 27246
     211         */
     212        public function test_the_excerpt_specific_post() {
     213                $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Foo' ) );
     214                $post_id = self::factory()->post->create( array( 'post_excerpt' => 'Bar' ) );
     215                $this->assertSame( 'Bar', get_the_excerpt( $post_id ) );
     216        }
    174217}