Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:04:59 PM (8 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-revisions-controller.php

    r38975 r39126  
    185185        wp_set_current_user( self::$editor_id );
    186186        $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     187        $request->set_param( 'force', true );
    187188        $response = $this->server->dispatch( $request );
    188189        $this->assertEquals( 200, $response->get_status() );
    189190        $this->assertNull( get_post( $this->revision_id1 ) );
     191    }
     192
     193    public function test_delete_item_no_trash() {
     194        wp_set_current_user( self::$editor_id );
     195
     196        $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . self::$post_id . '/revisions/' . $this->revision_id1 );
     197        $response = $this->server->dispatch( $request );
     198        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     199
     200        $request->set_param( 'force', 'false' );
     201        $response = $this->server->dispatch( $request );
     202        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     203
     204        // Ensure the revision still exists
     205        $this->assertNotNull( get_post( $this->revision_id1 ) );
    190206    }
    191207
Note: See TracChangeset for help on using the changeset viewer.