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

    r39105 r39126  
    726726        $this->assertEquals( 200, $response->get_status() );
    727727        $data = $response->get_data();
    728         $this->assertEquals( 'Deleted Category', $data['name'] );
    729     }
    730 
    731     public function test_delete_item_force_false() {
     728        $this->assertTrue( $data['deleted'] );
     729        $this->assertEquals( 'Deleted Category', $data['previous']['name'] );
     730    }
     731
     732    public function test_delete_item_no_trash() {
    732733        wp_set_current_user( self::$administrator );
    733734        $term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
     735
    734736        $request = new WP_REST_Request( 'DELETE', '/wp/v2/categories/' . $term->term_id );
    735         // force defaults to false
    736         $response = $this->server->dispatch( $request );
    737         $this->assertEquals( 501, $response->get_status() );
     737        $response = $this->server->dispatch( $request );
     738        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     739
     740        $request->set_param( 'force', 'false' );
     741        $response = $this->server->dispatch( $request );
     742        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    738743    }
    739744
Note: See TracChangeset for help on using the changeset viewer.