Skip to content

Commit

Permalink
add additional test case
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Wilson <[email protected]>
  • Loading branch information
Juzar10 and peterwilsoncc authored Feb 6, 2025
1 parent e271243 commit 049861e
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions tests/phpunit/tests/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ public function test_the_loop_when_querying_post_parents_only() {
)
);

$child = self::factory()->post->create(
$children = self::factory()->post->create_many(
2,
array(
'post_type' => 'page',
'post_parent' => $parent,
Expand All @@ -764,17 +765,58 @@ public function test_the_loop_when_querying_post_parents_only() {

$query = new WP_Query(
array(
'fields' => 'id=>parent',
'fields' => 'id=>parent',
'post_type' => 'page',
'post_parent' => $parent,
)
);

$query->the_post();
$global_post = get_post( null, ARRAY_A );
$specific_post = get_post( $children[0], ARRAY_A );

$this->assertEqualSetsWithIndex( $specific_post, $global_post, 'Global post is expected to match the first child page.' );

$next_post = $query->next_post();
$this->assertInstanceOf( 'WP_Post', $next_post, 'WP_Query::next_post() should always return a WP_Post object' );
$this->assertSame( $children[1], $next_post->ID, 'The next post is expected to be the second child page.' );
}

/**
* @ticket 56992
*/
public function test_the_loop_when_querying_post_ids_only() {
$parent = self::factory()->post->create(
array(
'post_type' => 'page',
'page_id' => $child,
)
);

$children = self::factory()->post->create_many(
2,
array(
'post_type' => 'page',
'post_parent' => $parent,
)
);

$query = new WP_Query(
array(
'fields' => 'id',
'post_type' => 'page',
'post_parent' => $parent,
)
);

$query->the_post();
$global_post = get_post( null, ARRAY_A );
$specific_post = get_post( $child, ARRAY_A );
$specific_post = get_post( $children[0], ARRAY_A );

$this->assertEqualSetsWithIndex( $specific_post, $global_post, 'Global post is expected to match the first child page.' );

$this->assertEqualSetsWithIndex( $global_post, $specific_post );
$next_post = $query->next_post();
$this->assertInstanceOf( 'WP_Post', $next_post, 'WP_Query::next_post() should always return a WP_Post object' );
$this->assertSame( $children[1], $next_post->ID, 'The next post is expected to be the second child page.' );
}

/**
Expand Down

0 comments on commit 049861e

Please sign in to comment.