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,26 +398,23 @@ class Tests_Query_SetupPostdata extends WP_UnitTestCase {
|
|||||||
/**
|
/**
|
||||||
* @ticket 24330
|
* @ticket 24330
|
||||||
*
|
*
|
||||||
* setup_postdata( $a_post ) followed by the_content() in a loop that does not update
|
* setup_postdata( $a_post ) followed by the_content() without updating global $post
|
||||||
* global $post should use the content of $a_post rather then the 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' ) );
|
$post_id = self::factory()->post->create( array( 'post_content' => 'global post' ) );
|
||||||
$GLOBALS['post'] = get_post( $post_id );
|
$GLOBALS['post'] = get_post( $post_id );
|
||||||
$GLOBALS['wp_query']->post = $GLOBALS['post'];
|
$GLOBALS['wp_query']->post = $GLOBALS['post'];
|
||||||
|
|
||||||
$ids = self::factory()->post->create_many( 5 );
|
$a_post_id = self::factory()->post->create();
|
||||||
foreach ( $ids as $id ) {
|
$a_post = get_post( $a_post_id );
|
||||||
$page = get_post( $id );
|
|
||||||
if ( $page ) {
|
setup_postdata( $a_post );
|
||||||
setup_postdata( $page );
|
$content = get_echo( 'the_content' );
|
||||||
$content = get_echo( 'the_content', array() );
|
|
||||||
$this->assertEquals( $post_id, $GLOBALS['post']->ID );
|
$this->assertEquals( $post_id, $GLOBALS['post']->ID );
|
||||||
$this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
|
$this->assertNotEquals( '<p>global post</p>', strip_ws( $content ) );
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ticket 47114
|
* @ticket 47114
|
||||||
|
Loading…
Reference in New Issue
Block a user