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

    r39105 r39126  
    626626        $this->assertEquals( 200, $response->get_status() );
    627627        $data = $response->get_data();
    628         $this->assertEquals( 'Deleted Tag', $data['name'] );
    629     }
    630 
    631     public function test_delete_item_force_false() {
     628        $this->assertTrue( $data['deleted'] );
     629        $this->assertEquals( 'Deleted Tag', $data['previous']['name'] );
     630    }
     631
     632    public function test_delete_item_no_trash() {
    632633        wp_set_current_user( self::$administrator );
    633634        $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' );
     635
    634636        $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id );
    635         // force defaults to false
    636         $response = $this->server->dispatch( $request );
    637         $this->assertEquals( 501, $response->get_status() );
     637        $response = $this->server->dispatch( $request );
     638        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
     639
     640        $request->set_param( 'force', 'false' );
     641        $response = $this->server->dispatch( $request );
     642        $this->assertErrorResponse( 'rest_trash_not_supported', $response, 501 );
    638643    }
    639644
     
    668673        $this->assertEquals( 200, $response->get_status() );
    669674        $data = $response->get_data();
    670         $this->assertEquals( 'Deleted Tag', $data['name'] );
     675        $this->assertTrue( $data['deleted'] );
     676        $this->assertEquals( 'Deleted Tag', $data['previous']['name'] );
    671677    }
    672678
Note: See TracChangeset for help on using the changeset viewer.