Make WordPress Core

Changeset 48113


Ignore:
Timestamp:
06/21/2020 10:28:52 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Simplify test_setup_postdata_loop().

The important part here is calling the_content() after setting up post data for another post without updating global $post.

The foreach() loop is not necessary.

Follow-up to [UT1289].

See #47824, #24330.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/setupPostdata.php

    r46586 r48113  
    399399         * @ticket 24330
    400400         *
    401          * setup_postdata( $a_post ) followed by the_content() in a loop that does not update
    402          * global $post should use the content of $a_post rather then the global post.
    403          */
    404         function test_setup_postdata_loop() {
     401         * setup_postdata( $a_post ) followed by the_content() without updating global $post
     402         * should use the content of $a_post rather then the global post.
     403         */
     404        function test_setup_postdata_with_the_content() {
    405405                $post_id                   = self::factory()->post->create( array( 'post_content' => 'global post' ) );
    406406                $GLOBALS['post']           = get_post( $post_id );
    407407                $GLOBALS['wp_query']->post = $GLOBALS['post'];
    408408
    409                 $ids = self::factory()->post->create_many( 5 );
    410                 foreach ( $ids as $id ) {
    411                         $page = get_post( $id );
    412                         if ( $page ) {
    413                                 setup_postdata( $page );
    414                                 $content = get_echo( 'the_content', array() );
    415                                 $this->assertEquals( $post_id, $GLOBALS['post']->ID );
    416                                 $this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
    417                                 wp_reset_postdata();
    418                         }
    419                 }
     409                $a_post_id = self::factory()->post->create();
     410                $a_post    = get_post( $a_post_id );
     411
     412                setup_postdata( $a_post );
     413                $content = get_echo( 'the_content' );
     414                $this->assertEquals( $post_id, $GLOBALS['post']->ID );
     415                $this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
     416                wp_reset_postdata();
    420417        }
    421418
Note: See TracChangeset for help on using the changeset viewer.