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. git-svn-id: https://develop.svn.wordpress.org/trunk@48113 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0c1a49c728
commit
a7264f196d
@ -398,25 +398,22 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
||||
/**
|
||||
* @ticket 24330
|
||||
*
|
||||
* setup_postdata( $a_post ) followed by the_content() in a loop that does not update
|
||||
* global $post should use the content of $a_post rather then the global post.
|
||||
* setup_postdata( $a_post ) followed by the_content() without updating global $post
|
||||
* should use the content of $a_post rather then the global post.
|
||||
*/
|
||||
function test_setup_postdata_loop() {
|
||||
function test_setup_postdata_with_the_content() {
|
||||
$post_id = self::factory()->post->create( array( 'post_content' => 'global post' ) );
|
||||
$GLOBALS['post'] = get_post( $post_id );
|
||||
$GLOBALS['wp_query']->post = $GLOBALS['post'];
|
||||
|
||||
$ids = self::factory()->post->create_many( 5 );
|
||||
foreach ( $ids as $id ) {
|
||||
$page = get_post( $id );
|
||||
if ( $page ) {
|
||||
setup_postdata( $page );
|
||||
$content = get_echo( 'the_content', array() );
|
||||
$this->assertEquals( $post_id, $GLOBALS['post']->ID );
|
||||
$this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
|
||||
wp_reset_postdata();
|
||||
}
|
||||
}
|
||||
$a_post_id = self::factory()->post->create();
|
||||
$a_post = get_post( $a_post_id );
|
||||
|
||||
setup_postdata( $a_post );
|
||||
$content = get_echo( 'the_content' );
|
||||
$this->assertEquals( $post_id, $GLOBALS['post']->ID );
|
||||
$this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
|
||||
wp_reset_postdata();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user