Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Feb 3, 2025
1 parent 06fe862 commit 5b7fb3c
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions tests/phpunit/tests/rest-api/rest-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5734,8 +5734,8 @@ public function test_get_posts_ignore_sticky_default_prepends_sticky_posts() {
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertSame( $data[0]['id'], $id1, 'Response has sticky post at the top' );
$this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post' );
$this->assertSame( $data[0]['id'], $id1, 'Response has sticky post at the top.' );
$this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post.' );
}

/**
Expand All @@ -5747,7 +5747,6 @@ public function test_get_posts_ignore_sticky_default_prepends_sticky_posts() {
*/
public function test_get_posts_ignore_sticky_ignores_post_stickiness() {
$id1 = self::$post_id;
// Create more recent post to avoid automatically placing other at the top.
$id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );

update_option( 'sticky_posts', array( $id1 ) );
Expand All @@ -5757,7 +5756,29 @@ public function test_get_posts_ignore_sticky_ignores_post_stickiness() {
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top' );
$this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top.' );
}

/**
* Test the REST API support for `ignore_sticky_posts`.
*
* @ticket 35907
*
* @covers WP_REST_Posts_Controller::get_items
*/
public function test_get_posts_ignore_sticky_honors_include() {
$id1 = self::$post_id;
$id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );

update_option( 'sticky_posts', array( $id1 ) );

$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
$request->set_param( 'include', array( $id2 ) );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();

$this->assertCount( 1, $data, 'Only one post is expected to be returned.' );
$this->assertSame( $data[0]['id'], $id2, 'Returns the included post.' );
}

/**
Expand Down

0 comments on commit 5b7fb3c

Please sign in to comment.