Make WordPress Core


Ignore:
Timestamp:
08/04/2017 01:55:04 PM (7 years ago)
Author:
johnbillion
Message:

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

See #41463

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php

    r39343 r41228  
    3636
    3737    public function test_register_routes() {
    38 
     38        $routes = $this->server->get_routes();
     39        $this->assertArrayHasKey( '/wp/v2/pages', $routes );
     40        $this->assertCount( 2, $routes['/wp/v2/pages'] );
     41        $this->assertArrayHasKey( '/wp/v2/pages/(?P<id>[\d]+)', $routes );
     42        $this->assertCount( 3, $routes['/wp/v2/pages/(?P<id>[\d]+)'] );
    3943    }
    4044
     
    8488
    8589    public function test_get_items() {
    86 
     90        $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) );
     91        $id2 = $this->factory->post->create( array( 'post_status' => 'draft', 'post_type' => 'page' ) );
     92        $request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
     93        $response = $this->server->dispatch( $request );
     94        $data = $response->get_data();
     95        $this->assertEquals( 1, count( $data ) );
     96        $this->assertEquals( $id1, $data[0]['id'] );
    8797    }
    8898
     
    306316
    307317    public function test_delete_item() {
    308 
     318        $page_id = $this->factory->post->create( array(
     319            'post_type'  => 'page',
     320            'post_title' => 'Deleted page',
     321        ) );
     322        wp_set_current_user( self::$editor_id );
     323
     324        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/pages/%d', $page_id ) );
     325        $request->set_param( 'force', 'false' );
     326        $response = $this->server->dispatch( $request );
     327
     328        $this->assertEquals( 200, $response->get_status() );
     329        $data = $response->get_data();
     330        $this->assertEquals( 'Deleted page', $data['title']['raw'] );
     331        $this->assertEquals( 'trash', $data['status'] );
    309332    }
    310333
Note: See TracChangeset for help on using the changeset viewer.