Make WordPress Core

Ticket #46471: 46471-2.diff

File 46471-2.diff, 5.8 KB (added by birgire, 7 years ago)
  • src/wp-includes/post-template.php

    diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php
    index b817ede..164e549 100644
    function get_the_content( $more_link_text = null, $strip_teaser = false, $post = 
    315315        $content = $elements['pages'][ $page_no - 1 ];
    316316        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    317317                $content = explode( $matches[0], $content, 2 );
     318
     319                // Remove the core/more block tags now that it has been split up.
     320                $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
     321
    318322                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
    319323                        $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
    320324                }
  • tests/phpunit/tests/post/output.php

    diff --git tests/phpunit/tests/post/output.php tests/phpunit/tests/post/output.php
    index b6c402b..02be7ff 100644
    EOF; 
    175175
    176176                kses_remove_filters();
    177177        }
     178
     179        /**
     180         * Ensure the_content handles a More block on a singular page.
     181         *
     182         * @ticket 46471
     183         *
     184         * @group blocks
     185         */
     186        public function test_the_content_should_handle_more_block_on_singular() {
     187                $post_content = <<<EOF
     188<!-- wp:paragraph -->
     189<p>Teaser part.</p>
     190<!-- /wp:paragraph -->
     191
     192<!-- wp:more {"customText":"Read More"} -->
     193<!--more Read More-->
     194<!-- /wp:more -->
     195
     196<!-- wp:paragraph -->
     197<p>Second block.</p>
     198<!-- /wp:paragraph -->
     199EOF;
     200
     201                $post_id = self::factory()->post->create( compact( 'post_content' ) );
     202
     203                $expected_without_teaser = <<<EOF
     204<span id="more-{$post_id}"></span>
     205<p>Second block.</p>
     206EOF;
     207
     208                $expected_with_teaser = <<<EOF
     209<p>Teaser part.</p>
     210<span id="more-{$post_id}"></span>
     211<p>Second block.</p>
     212EOF;
     213
     214                $this->go_to( get_permalink( $post_id ) );
     215                $this->assertTrue( is_singular() );
     216                $this->assertTrue( have_posts() );
     217                $this->assertNull( the_post() );
     218
     219                // Without the teaser.
     220                $actual = get_echo( 'the_content', array( null, true ) );
     221                $this->assertSame( strip_ws( $expected_without_teaser ), strip_ws( $actual ) );
     222
     223                // With the teaser.
     224                $actual = get_echo( 'the_content', array( null, false ) );
     225                $this->assertSame( strip_ws( $expected_with_teaser ), strip_ws( $actual ) );
     226        }
     227
     228        /**
     229         * Ensure the_content handles a More block when using the noteaser text tag on a singular page.
     230         *
     231         * @ticket 46471
     232         *
     233         * @group blocks
     234         */
     235        public function test_the_content_should_handle_more_block_when_noteaser_on_singular() {
     236                $post_content = <<<EOF
     237<!-- wp:paragraph -->
     238<p>Teaser part.</p>
     239<!-- /wp:paragraph -->
     240
     241<!-- wp:more -->
     242<!--more-->
     243<!--noteaser-->
     244<!-- /wp:more -->
     245
     246<!-- wp:paragraph -->
     247<p>Second block.</p>
     248<!-- /wp:paragraph -->
     249EOF;
     250
     251                $post_id = self::factory()->post->create( compact( 'post_content' ) );
     252
     253                $expected = <<<EOF
     254<span id="more-{$post_id}"></span>
     255<!--noteaser-->
     256<p>Second block.</p>
     257EOF;
     258
     259                $this->go_to( get_permalink( $post_id ) );
     260                $this->assertTrue( is_singular() );
     261                $this->assertTrue( have_posts() );
     262                $this->assertNull( the_post() );
     263
     264                $actual = get_echo( 'the_content', array( null, true ) );
     265                $this->assertSame( strip_ws( $expected ), strip_ws( $actual ) );
     266
     267                $actual = get_echo( 'the_content', array( null, false ) );
     268                $this->assertSame( strip_ws( $expected ), strip_ws( $actual ) );
     269        }
     270
     271        /**
     272         * Ensure the_content displays the teaser part with a read more link
     273         * for a More block on a non-singular page.
     274         *
     275         * @ticket 46471
     276         *
     277         * @group blocks
     278         */
     279        public function test_the_content_should_handle_more_block_when_non_singular() {
     280                $post_content = <<<EOF
     281<!-- wp:paragraph -->
     282<p>Teaser part.</p>
     283<!-- /wp:paragraph -->
     284
     285<!-- wp:more {"customText":"Read More"} -->
     286<!--more Read More-->
     287<!-- /wp:more -->
     288
     289<!-- wp:paragraph -->
     290<p>Second block.</p>
     291<!-- /wp:paragraph -->
     292EOF;
     293
     294                $post_id = self::factory()->post->create( compact( 'post_content' ) );
     295
     296                $expected = <<<EOF
     297<span id="more-{$post_id}"></span>
     298<p>Second block.</p>
     299EOF;
     300
     301                $this->go_to( home_url() );
     302                $this->assertFalse( is_singular() );
     303                $this->assertTrue( have_posts() );
     304                $this->assertNull( the_post() );
     305
     306                foreach ( array( true, false ) as $strip_teaser ) {
     307                        $actual = get_echo( 'the_content', array( null, $strip_teaser ) );
     308                        $this->assertContains( 'Teaser part', $actual );
     309                        $this->assertContains( 'Read More</a>', $actual );
     310                        $this->assertNotContains( '<!--more-->', $actual );
     311                        $this->assertNotContains( 'wp:more', $actual );
     312                        $this->assertNotContains( 'wp:paragraph', $actual );
     313                }
     314        }
     315
     316        /**
     317         * Ensure the_content displays the teaser part with a read more link for a More block
     318         * when using the noteaser text tag on a non-singular page.
     319         *
     320         * @ticket 46471
     321         *
     322         * @group blocks
     323         */
     324        public function test_the_content_should_handle_more_block_when_noteaser_on_non_singular() {
     325                $post_content = <<<EOF
     326<!-- wp:paragraph -->
     327<p>Teaser part.</p>
     328<!-- /wp:paragraph -->
     329
     330<!-- wp:more -->
     331<!--more-->
     332<!--noteaser-->
     333<!-- /wp:more -->
     334
     335<!-- wp:paragraph -->
     336<p>Second block.</p>
     337<!-- /wp:paragraph -->
     338EOF;
     339
     340                $post_id = self::factory()->post->create( compact( 'post_content' ) );
     341
     342                $this->go_to( home_url() );
     343                $this->assertFalse( is_singular() );
     344                $this->assertTrue( have_posts() );
     345                $this->assertNull( the_post() );
     346
     347                foreach ( array( true, false ) as $strip_teaser ) {
     348                        $actual = get_echo( 'the_content', array( null, $strip_teaser ) );
     349                        $this->assertContains( 'Teaser part', $actual );
     350                        $this->assertContains( '(more&hellip;)</span></a>', $actual );
     351                        $this->assertNotContains( '<!--more-->', $actual );
     352                        $this->assertNotContains( '<!--noteaser-->', $actual ); // We placed the noteaser tag below the more tag.
     353                        $this->assertNotContains( 'wp:more', $actual );
     354                        $this->assertNotContains( 'wp:paragraph', $actual );
     355                }
     356        }
    178357}