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-posts-controller.php

    r39108 r39126  
    20092009
    20102010        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
     2011        $request->set_param( 'force', 'false' );
    20112012        $response = $this->server->dispatch( $request );
    20122013
     
    20152016        $data = $response->get_data();
    20162017        $this->assertEquals( 'Deleted post', $data['title']['raw'] );
     2018        $this->assertEquals( 'trash', $data['status'] );
    20172019    }
    20182020
     
    20282030        $this->assertEquals( 200, $response->get_status() );
    20292031        $data = $response->get_data();
    2030         $this->assertEquals( 'Deleted post', $data['title']['raw'] );
     2032        $this->assertTrue( $data['deleted'] );
     2033        $this->assertNotEmpty( $data['previous'] );
    20312034    }
    20322035
Note: See TracChangeset for help on using the changeset viewer.