Make WordPress Core


Ignore:
Timestamp:
12/13/2016 01:52:49 PM (8 years ago)
Author:
jnylen0
Message:

REST API: Allow sending an empty or no-op comment update.

In general, updates that don't actually change anything should succeed.
[39371] added tests for other object types, and this commit fixes empty updates
for comments and adds the missing test.

Fixes #38700.

File:
1 edited

Legend:

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

    r39487 r39597  
    19621962    }
    19631963
     1964    public function test_update_item_no_change() {
     1965        $comment = get_comment( self::$approved_id );
     1966
     1967        wp_set_current_user( self::$admin_id );
     1968        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
     1969        $request->set_param( 'post', $comment->comment_post_ID );
     1970
     1971        // Run twice to make sure that the update still succeeds even if no DB
     1972        // rows are updated.
     1973        $response = $this->server->dispatch( $request );
     1974        $this->assertEquals( 200, $response->get_status() );
     1975
     1976        $response = $this->server->dispatch( $request );
     1977        $this->assertEquals( 200, $response->get_status() );
     1978    }
     1979
    19641980    public function test_update_comment_status() {
    19651981        wp_set_current_user( self::$admin_id );
     
    22052221        $response = $this->server->dispatch( $request );
    22062222        $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
     2223    }
     2224
     2225    public function test_update_comment_invalid_post_id() {
     2226        wp_set_current_user( self::$admin_id );
     2227
     2228        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
     2229        $request->set_param( 'post', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     2230
     2231        $response = $this->server->dispatch( $request );
     2232        $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 403 );
    22072233    }
    22082234
Note: See TracChangeset for help on using the changeset viewer.