Changeset 60200
- Timestamp:
- 04/28/2025 04:47:40 PM (7 weeks ago)
- Location:
- branches/6.8
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.8
-
branches/6.8/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r59970 r60200 3076 3076 'description' => __( 'Whether to ignore sticky posts or not.' ), 3077 3077 'type' => 'boolean', 3078 'default' => false,3078 'default' => true, 3079 3079 ); 3080 3080 } -
branches/6.8/tests/phpunit/tests/rest-api/rest-posts-controller.php
r59985 r60200 662 662 } 663 663 664 /** 665 * @ticket 63307 666 */ 664 667 public function test_get_items_slug_query() { 665 self::factory()->post->create(668 $id1 = self::factory()->post->create( 666 669 array( 667 670 'post_title' => 'Apple', … … 669 672 ) 670 673 ); 671 self::factory()->post->create(674 $id2 = self::factory()->post->create( 672 675 array( 673 676 'post_title' => 'Banana', … … 675 678 ) 676 679 ); 680 681 update_option( 'sticky_posts', array( $id2 ) ); 677 682 678 683 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); … … 682 687 $data = $response->get_data(); 683 688 $this->assertCount( 1, $data ); 684 $this->assertSame( 'Apple', $data[0]['title']['rendered'] );689 $this->assertSame( 'Apple', $data[0]['title']['rendered'], 'Return the post with the given slug' ); 685 690 } 686 691 … … 5971 5976 5972 5977 /** 5978 * Test the REST API doesn't prioritize sticky posts by default. 5979 * 5980 * @ticket 35907 5981 * @ticket 63307 5982 * 5983 * @covers WP_REST_Posts_Controller::get_items 5984 */ 5985 public function test_get_posts_ignore_sticky_by_default() { 5986 $id1 = self::$post_id; 5987 // Create more recent post to avoid automatically placing other at the top. 5988 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5989 5990 update_option( 'sticky_posts', array( $id1 ) ); 5991 5992 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5993 $response = rest_get_server()->dispatch( $request ); 5994 $data = $response->get_data(); 5995 $rest_ids = wp_list_pluck( $data, 'id' ); 5996 5997 $this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top.' ); 5998 5999 $posts_query = new WP_Query( array( 'ignore_sticky_posts' => true ) ); 6000 $post_ids = wp_list_pluck( $posts_query->get_posts(), 'ID' ); 6001 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticky_posts=true.' ); 6002 } 6003 6004 /** 5973 6005 * Test the REST API support for `ignore_sticky_posts`. 5974 6006 * 5975 6007 * @ticket 35907 6008 * @ticket 63307 5976 6009 * 5977 6010 * @covers WP_REST_Posts_Controller::get_items 5978 6011 */ 5979 public function test_get_posts_ignore_sticky_ default_prepends_sticky_posts() {6012 public function test_get_posts_ignore_sticky_false_prepends_sticky_posts() { 5980 6013 $id1 = self::$post_id; 5981 6014 // Create more recent post to avoid automatically placing other at the top. … … 5984 6017 update_option( 'sticky_posts', array( $id1 ) ); 5985 6018 5986 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5987 $response = rest_get_server()->dispatch( $request ); 5988 $data = $response->get_data(); 6019 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 6020 $request->set_param( 'ignore_sticky', false ); 6021 $response = rest_get_server()->dispatch( $request ); 6022 $data = $response->get_data(); 6023 $rest_ids = wp_list_pluck( $data, 'id' ); 5989 6024 5990 6025 $this->assertSame( $data[0]['id'], $id1, 'Response has sticky post at the top.' ); 5991 6026 $this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post.' ); 6027 6028 $posts_query = new WP_Query(); 6029 $post_ids = wp_list_pluck( $posts_query->get_posts(), 'ID' ); 6030 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticky_posts=false.' ); 5992 6031 } 5993 6032 … … 5996 6035 * 5997 6036 * @ticket 35907 6037 * @ticket 63307 5998 6038 * 5999 6039 * @covers WP_REST_Posts_Controller::get_items 6000 6040 */ 6001 public function test_get_posts_ignore_sticky_ignores_post_stickiness() { 6041 public function test_get_posts_ignore_sticky_honors_include() { 6042 6002 6043 $id1 = self::$post_id; 6003 6044 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); … … 6006 6047 6007 6048 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 6008 $request->set_param( 'ignore_sticky', true );6009 $response = rest_get_server()->dispatch( $request );6010 $data = $response->get_data();6011 6012 $this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top.' );6013 }6014 6015 /**6016 * Test the REST API support for `ignore_sticky_posts`.6017 *6018 * @ticket 359076019 *6020 * @covers WP_REST_Posts_Controller::get_items6021 */6022 public function test_get_posts_ignore_sticky_honors_include() {6023 $id1 = self::$post_id;6024 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );6025 6026 update_option( 'sticky_posts', array( $id1 ) );6027 6028 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );6029 6049 $request->set_param( 'include', array( $id2 ) ); 6030 6050 $response = rest_get_server()->dispatch( $request ); 6031 6051 $data = $response->get_data(); 6052 $rest_ids = wp_list_pluck( $data, 'id' ); 6032 6053 6033 6054 $this->assertCount( 1, $data, 'Only one post is expected to be returned.' ); 6034 6055 $this->assertSame( $data[0]['id'], $id2, 'Returns the included post.' ); 6056 6057 $posts_query = new WP_Query( 6058 array( 6059 'post__in' => array( $id2 ), 6060 'ignore_sticky_posts' => true, 6061 ) 6062 ); 6063 $post_ids = wp_list_pluck( $posts_query->get_posts(), 'ID' ); 6064 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticky_posts=truehas no sticky post at the top.' ); 6035 6065 } 6036 6066 -
branches/6.8/tests/qunit/fixtures/wp-api-generated.js
r59892 r60200 634 634 "description": "Whether to ignore sticky posts or not.", 635 635 "type": "boolean", 636 "default": false,636 "default": true, 637 637 "required": false 638 638 },
Note: See TracChangeset
for help on using the changeset viewer.