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

    r39193 r39372  
    553553        $this->assertEquals( 'New Description', $data['description'] );
    554554        $this->assertEquals( 'new-slug', $data['slug'] );
     555    }
     556
     557    public function test_update_item_no_change() {
     558        wp_set_current_user( self::$administrator );
     559        $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' );
     560
     561        $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id );
     562
     563        $response = $this->server->dispatch( $request );
     564        $this->assertEquals( 200, $response->get_status() );
     565        $request->set_param( 'slug', $term->slug );
     566
     567        // Run twice to make sure that the update still succeeds even if no DB
     568        // rows are updated.
     569        $response = $this->server->dispatch( $request );
     570        $this->assertEquals( 200, $response->get_status() );
     571
     572        $response = $this->server->dispatch( $request );
     573        $this->assertEquals( 200, $response->get_status() );
    555574    }
    556575
Note: See TracChangeset for help on using the changeset viewer.