Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:04:59 PM (9 years ago)
Author:
rachelbaker
Message:

REST API: Modify the structure of our DELETE responses to be more explicit.

Add the deleted property to the root of the Response object to communicate if the delete action was successful. Move the state of the resource prior to the delete request under a new previous property. As a result DELETE responses are now structured like so:

{ deleted: true, previous: { ... } }

Also includes helpful information to DELETE requests for resources that are not trashable.

Props timmydcrawford, rmccue, jnylen0.
Fixes #38494.

File:
1 edited

Legend:

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

    r39105 r39126  
    18891889            'user_id'          => self::$subscriber_id,
    18901890        ));
     1891
    18911892        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    1892 
    1893         $response = $this->server->dispatch( $request );
    1894         $this->assertEquals( 200, $response->get_status() );
    1895         $data = $response->get_data();
    1896         $this->assertEquals( self::$post_id, $data['post'] );
     1893        $request->set_param( 'force', 'false' );
     1894        $response = $this->server->dispatch( $request );
     1895        $this->assertEquals( 200, $response->get_status() );
     1896
     1897        $data = $response->get_data();
     1898        $this->assertEquals( 'trash', $data['status'] );
    18971899    }
    18981900
     
    19111913        $this->assertEquals( 200, $response->get_status() );
    19121914        $data = $response->get_data();
    1913         $this->assertEquals( self::$post_id, $data['post'] );
     1915        $this->assertTrue( $data['deleted'] );
     1916        $this->assertNotEmpty( $data['previous']['post'] );
    19141917    }
    19151918
Note: See TracChangeset for help on using the changeset viewer.