mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
REST API: Add support for searching resources by id.
This brings support for the `include` and `exclude` collection parameters to the Search Controller. This can be used to find an item by id when it's subtype is unknown. Props kadamwhite. Fixes #56546. git-svn-id: https://develop.svn.wordpress.org/trunk@54123 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -819,4 +819,78 @@ class WP_Test_REST_Search_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56546
|
||||
*/
|
||||
public function test_get_items_search_posts_include_ids() {
|
||||
$response = $this->do_request_with_params(
|
||||
array(
|
||||
'include' => array_slice( self::$my_title_post_ids, 1, 2 ),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array( self::$my_title_post_ids[1], self::$my_title_post_ids[2] ),
|
||||
wp_list_pluck( $response->get_data(), 'id' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56546
|
||||
*/
|
||||
public function test_get_items_search_posts_exclude_ids() {
|
||||
$response = $this->do_request_with_params(
|
||||
array(
|
||||
'exclude' => self::$my_title_page_ids,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array_merge(
|
||||
self::$my_title_post_ids,
|
||||
self::$my_content_post_ids
|
||||
),
|
||||
wp_list_pluck( $response->get_data(), 'id' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56546
|
||||
*/
|
||||
public function test_get_items_search_terms_include_ids() {
|
||||
$response = $this->do_request_with_params(
|
||||
array(
|
||||
'include' => self::$my_tag_id,
|
||||
'type' => 'term',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array( self::$my_tag_id ),
|
||||
wp_list_pluck( $response->get_data(), 'id' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56546
|
||||
*/
|
||||
public function test_get_items_search_terms_exclude_ids() {
|
||||
$response = $this->do_request_with_params(
|
||||
array(
|
||||
// "1" is the default category.
|
||||
'exclude' => array( 1, self::$my_tag_id ),
|
||||
'type' => 'term',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( 200, $response->get_status() );
|
||||
$this->assertSameSets(
|
||||
array( self::$my_category_id ),
|
||||
wp_list_pluck( $response->get_data(), 'id' )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user