REST API: Populate some missing tests from test cases which extend the controller test case.

See #41463


git-svn-id: https://develop.svn.wordpress.org/trunk@41228 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-08-04 13:55:04 +00:00
parent babec6d399
commit 14ff8eb16b
2 changed files with 36 additions and 4 deletions

View File

@ -35,7 +35,11 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
} }
public function test_register_routes() { public function test_register_routes() {
$routes = $this->server->get_routes();
$this->assertArrayHasKey( '/wp/v2/pages', $routes );
$this->assertCount( 2, $routes['/wp/v2/pages'] );
$this->assertArrayHasKey( '/wp/v2/pages/(?P<id>[\d]+)', $routes );
$this->assertCount( 3, $routes['/wp/v2/pages/(?P<id>[\d]+)'] );
} }
public function test_context_param() { public function test_context_param() {
@ -83,7 +87,13 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
} }
public function test_get_items() { public function test_get_items() {
$id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) );
$id2 = $this->factory->post->create( array( 'post_status' => 'draft', 'post_type' => 'page' ) );
$request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$this->assertEquals( 1, count( $data ) );
$this->assertEquals( $id1, $data[0]['id'] );
} }
public function test_get_items_parent_query() { public function test_get_items_parent_query() {
@ -305,7 +315,20 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
} }
public function test_delete_item() { public function test_delete_item() {
$page_id = $this->factory->post->create( array(
'post_type' => 'page',
'post_title' => 'Deleted page',
) );
wp_set_current_user( self::$editor_id );
$request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/pages/%d', $page_id ) );
$request->set_param( 'force', 'false' );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$data = $response->get_data();
$this->assertEquals( 'Deleted page', $data['title']['raw'] );
$this->assertEquals( 'trash', $data['status'] );
} }
public function test_prepare_item() { public function test_prepare_item() {

View File

@ -32,7 +32,12 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
$this->assertArrayHasKey( '/wp/v2/settings', $routes ); $this->assertArrayHasKey( '/wp/v2/settings', $routes );
} }
public function test_get_items() { public function test_get_item() {
/** Individual settings can't be gotten **/
wp_set_current_user( self::$administrator );
$request = new WP_REST_Request( 'GET', '/wp/v2/settings/title' );
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
} }
public function test_context_param() { public function test_context_param() {
@ -44,7 +49,7 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
$this->assertEquals( 403, $response->get_status() ); $this->assertEquals( 403, $response->get_status() );
} }
public function test_get_item() { public function test_get_items() {
wp_set_current_user( self::$administrator ); wp_set_current_user( self::$administrator );
$request = new WP_REST_Request( 'GET', '/wp/v2/settings' ); $request = new WP_REST_Request( 'GET', '/wp/v2/settings' );
$response = $this->server->dispatch( $request ); $response = $this->server->dispatch( $request );
@ -336,6 +341,10 @@ class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase
} }
public function test_delete_item() { public function test_delete_item() {
/** Settings can't be deleted **/
$request = new WP_REST_Request( 'DELETE', '/wp/v2/settings/title' );
$response = $this->server->dispatch( $request );
$this->assertEquals( 404, $response->get_status() );
} }
public function test_prepare_item() { public function test_prepare_item() {