WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2016 03:02:01 AM (4 years ago)
Author:
jnylen0
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.

Fixes #38975.

File:
1 edited

Legend:

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

    r39193 r39371  
    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.