mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
REST API: Clean-up our validation callbacks and add missing array items properties in our endpoint schemas.
Props joehoyle, jnylen0. Fixes #38617. git-svn-id: https://develop.svn.wordpress.org/trunk@39105 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -363,6 +363,20 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 );
|
||||
}
|
||||
|
||||
public function test_get_items_invalid_order() {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'order', 'asc,id' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_get_items_invalid_orderby() {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/users' );
|
||||
$request->set_param( 'orderby', 'invalid' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_get_items_offset() {
|
||||
wp_set_current_user( self::$user );
|
||||
// 2 users created in __construct(), plus default user
|
||||
@@ -379,6 +393,10 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$request->set_param( 'page', 3 );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertCount( 2, $response->get_data() );
|
||||
// 'offset' invalid value should error
|
||||
$request->set_param( 'offset', 'moreplease' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_get_items_include_query() {
|
||||
@@ -399,7 +417,12 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals( 2, count( $data ) );
|
||||
$this->assertEquals( $id3, $data[0]['id'] );
|
||||
// Invalid include should fail
|
||||
$request->set_param( 'include', 'invalid' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
// No privileges
|
||||
$request->set_param( 'include', array( $id3, $id1 ) );
|
||||
wp_set_current_user( 0 );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
@@ -421,6 +444,10 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$data = $response->get_data();
|
||||
$this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
|
||||
$this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
|
||||
// Invalid exlude value should error.
|
||||
$request->set_param( 'exclude', 'none-of-those-please' );
|
||||
$response = $this->server->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
public function test_get_items_search() {
|
||||
|
||||
Reference in New Issue
Block a user