From a7264f196d6a54aabf9f8f3b51cd6358c5dd04d4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 21 Jun 2020 10:28:52 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/query/setupPostdata.php | 25 +++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/tests/query/setupPostdata.php b/tests/phpunit/tests/query/setupPostdata.php index 38d473065f..6515e385eb 100644 --- a/tests/phpunit/tests/query/setupPostdata.php +++ b/tests/phpunit/tests/query/setupPostdata.php @@ -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( '

global post

', 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( '

global post

', strip_ws( $content ) ); + wp_reset_postdata(); } /**