- Timestamp:
- 02/10/2025 10:21:51 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r59766 r59801 198 198 'exclude', 199 199 'format', 200 'ignore_sticky', 200 201 'include', 201 202 'modified_after', … … 5717 5718 5718 5719 /** 5720 * Test the REST API support for `ignore_sticky_posts`. 5721 * 5722 * @ticket 35907 5723 * 5724 * @covers WP_REST_Posts_Controller::get_items 5725 */ 5726 public function test_get_posts_ignore_sticky_default_prepends_sticky_posts() { 5727 $id1 = self::$post_id; 5728 // Create more recent post to avoid automatically placing other at the top. 5729 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5730 5731 update_option( 'sticky_posts', array( $id1 ) ); 5732 5733 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5734 $response = rest_get_server()->dispatch( $request ); 5735 $data = $response->get_data(); 5736 5737 $this->assertSame( $data[0]['id'], $id1, 'Response has sticky post at the top.' ); 5738 $this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post.' ); 5739 } 5740 5741 /** 5742 * Test the REST API support for `ignore_sticky_posts`. 5743 * 5744 * @ticket 35907 5745 * 5746 * @covers WP_REST_Posts_Controller::get_items 5747 */ 5748 public function test_get_posts_ignore_sticky_ignores_post_stickiness() { 5749 $id1 = self::$post_id; 5750 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5751 5752 update_option( 'sticky_posts', array( $id1 ) ); 5753 5754 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5755 $request->set_param( 'ignore_sticky', true ); 5756 $response = rest_get_server()->dispatch( $request ); 5757 $data = $response->get_data(); 5758 5759 $this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top.' ); 5760 } 5761 5762 /** 5763 * Test the REST API support for `ignore_sticky_posts`. 5764 * 5765 * @ticket 35907 5766 * 5767 * @covers WP_REST_Posts_Controller::get_items 5768 */ 5769 public function test_get_posts_ignore_sticky_honors_include() { 5770 $id1 = self::$post_id; 5771 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5772 5773 update_option( 'sticky_posts', array( $id1 ) ); 5774 5775 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5776 $request->set_param( 'include', array( $id2 ) ); 5777 $response = rest_get_server()->dispatch( $request ); 5778 $data = $response->get_data(); 5779 5780 $this->assertCount( 1, $data, 'Only one post is expected to be returned.' ); 5781 $this->assertSame( $data[0]['id'], $id2, 'Returns the included post.' ); 5782 } 5783 5784 /** 5719 5785 * Internal function used to disable an insert query which 5720 5786 * will trigger a wpdb error for testing purposes.
Note: See TracChangeset
for help on using the changeset viewer.