REST API: Unify object access handling for simplicity.

Rather than repeating ourselves, unifying the access into a single method keeps everything tidy. While we're at it, add in additional schema handling for common parameters.

See #38792.

git-svn-id: https://develop.svn.wordpress.org/trunk@39954 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Hoyle
2017-01-26 13:38:27 +00:00
parent d2374614c2
commit 0a82ee0a31
13 changed files with 356 additions and 158 deletions

View File

@@ -182,7 +182,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$data = $response->get_data();
$keys = array_keys( $data['endpoints'][0]['args'] );
sort( $keys );
$this->assertEquals( array( 'context' ), $keys );
$this->assertEquals( array( 'context', 'id' ), $keys );
}
public function test_get_items() {

View File

@@ -837,7 +837,7 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
$request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
$response = $this->server->dispatch( $request );
$this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
$this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
}
public function test_get_comment_invalid_post_id_as_admin() {

View File

@@ -128,7 +128,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
$data = $response->get_data();
$keys = array_keys( $data['endpoints'][0]['args'] );
sort( $keys );
$this->assertEquals( array( 'context', 'password' ), $keys );
$this->assertEquals( array( 'context', 'id', 'password' ), $keys );
}
public function test_get_items() {

View File

@@ -1887,12 +1887,6 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$request->set_param( 'reassign', false );
$response = $this->server->dispatch( $request );
// Not implemented in multisite.
if ( is_multisite() ) {
$this->assertErrorResponse( 'rest_cannot_delete', $response, 501 );
return;
}
$this->assertErrorResponse( 'rest_user_invalid_id', $response, 404 );
}