WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2016 03:27:22 AM (3 years ago)
Author:
pento
Message:

REST API: Add tests for empty or "no-op" updates.

The API should allow updates that don't actually change anything. This allows clients to, for example, accidentally send the same request twice without encountering unexpected errors. This currently works for posts, terms, and users, so this commit adds test cases accordingly.

See #38700 for issues preventing this from working for comments.

Merge of [39371] to the 4.7 branch.

Props jnylen0.
See #38975.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/tests/phpunit/tests/rest-api/rest-users-controller.php

    r39293 r39372  
    10861086        // as per https://core.trac.wordpress.org/ticket/21429
    10871087        $this->assertEquals( $pw_before, $user->user_pass );
     1088    }
     1089
     1090    public function test_update_item_no_change() {
     1091        $this->allow_user_to_manage_multisite();
     1092        wp_set_current_user( self::$user );
     1093        $user = get_userdata( self::$editor );
     1094
     1095        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) );
     1096        $request->set_param( 'slug', $user->user_nicename );
     1097
     1098        // Run twice to make sure that the update still succeeds even if no DB
     1099        // rows are updated.
     1100        $response = $this->server->dispatch( $request );
     1101        $this->assertEquals( 200, $response->get_status() );
     1102
     1103        $response = $this->server->dispatch( $request );
     1104        $this->assertEquals( 200, $response->get_status() );
    10881105    }
    10891106
Note: See TracChangeset for help on using the changeset viewer.