diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index 2b7057c..32d5004 100644
a
|
b
|
class WP_REST_Comments_Controller extends WP_REST_Controller { |
624 | 624 | return $prepared_args; |
625 | 625 | } |
626 | 626 | |
| 627 | if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
| 628 | $post = $this->get_post( $prepared_args['comment_post_ID'] ); |
| 629 | if ( empty( $post ) ) { |
| 630 | return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid comment post id.' ), array( 'status' => 404 ) ); |
| 631 | } |
| 632 | } |
| 633 | |
627 | 634 | if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
628 | 635 | // Only the comment status is being changed. |
629 | 636 | $change = $this->handle_status_param( $request['status'], $comment ); |
… |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller { |
644 | 651 | return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); |
645 | 652 | } |
646 | 653 | |
647 | | $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
648 | | |
649 | | if ( 0 === $updated ) { |
650 | | return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); |
651 | | } |
| 654 | wp_update_comment( wp_slash( (array) $prepared_args ) ); |
652 | 655 | |
653 | 656 | if ( isset( $request['status'] ) ) { |
654 | 657 | $this->handle_status_param( $request['status'], $comment ); |
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index e225cbc..4571f88 100644
a
|
b
|
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase |
1618 | 1618 | $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] ); |
1619 | 1619 | } |
1620 | 1620 | |
| 1621 | public function test_update_item_no_change() { |
| 1622 | wp_set_current_user( self::$admin_id ); |
| 1623 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| 1624 | $response = $this->server->dispatch( $request ); |
| 1625 | $this->assertEquals( 200, $response->get_status() ); |
| 1626 | } |
| 1627 | |
1621 | 1628 | public function test_update_comment_status() { |
1622 | 1629 | wp_set_current_user( self::$admin_id ); |
1623 | 1630 | |
… |
… |
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase |
1769 | 1776 | $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 ); |
1770 | 1777 | } |
1771 | 1778 | |
| 1779 | public function test_update_comment_invalid_post_id() { |
| 1780 | wp_set_current_user( self::$admin_id ); |
| 1781 | |
| 1782 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| 1783 | $request->set_param( 'post', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
| 1784 | $request->set_param( 'content', 'avoid rest_comment_content_required error' ); |
| 1785 | |
| 1786 | $response = $this->server->dispatch( $request ); |
| 1787 | $this->assertErrorResponse( 'rest_comment_invalid_post_id', $response, 404 ); |
| 1788 | } |
| 1789 | |
1772 | 1790 | public function test_update_comment_invalid_permission() { |
1773 | 1791 | wp_set_current_user( 0 ); |
1774 | 1792 | |
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
index 57d5deb..342deae 100644
a
|
b
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
1565 | 1565 | $this->assertEquals( $params['excerpt'], $post->post_excerpt ); |
1566 | 1566 | } |
1567 | 1567 | |
| 1568 | public function test_update_item_no_change() { |
| 1569 | wp_set_current_user( self::$editor_id ); |
| 1570 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1571 | $response = $this->server->dispatch( $request ); |
| 1572 | $this->check_update_post_response( $response ); |
| 1573 | } |
| 1574 | |
1568 | 1575 | public function test_rest_update_post() { |
1569 | 1576 | wp_set_current_user( self::$editor_id ); |
1570 | 1577 | |
diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php
index df2c030..702f6f8 100644
a
|
b
|
class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { |
542 | 542 | $this->assertEquals( 'new-slug', $data['slug'] ); |
543 | 543 | } |
544 | 544 | |
| 545 | public function test_update_item_no_change() { |
| 546 | wp_set_current_user( self::$administrator ); |
| 547 | $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); |
| 548 | $request = new WP_REST_Request( 'PUT', '/wp/v2/tags/' . $term->term_id ); |
| 549 | $response = $this->server->dispatch( $request ); |
| 550 | $this->assertEquals( 200, $response->get_status() ); |
| 551 | } |
| 552 | |
545 | 553 | public function test_update_item_invalid_term() { |
546 | 554 | wp_set_current_user( self::$administrator ); |
547 | 555 | $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); |
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php
index 09e11a6..6108a7b 100644
a
|
b
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
840 | 840 | $this->assertEquals( $pw_before, $user->user_pass ); |
841 | 841 | } |
842 | 842 | |
| 843 | public function test_update_item_no_change() { |
| 844 | $this->allow_user_to_manage_multisite(); |
| 845 | wp_set_current_user( self::$user ); |
| 846 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/users/%d', self::$editor ) ); |
| 847 | $response = $this->server->dispatch( $request ); |
| 848 | $this->assertEquals( 200, $response->get_status() ); |
| 849 | } |
| 850 | |
843 | 851 | public function test_update_item_existing_email() { |
844 | 852 | $user1 = $this->factory->user->create( array( 'user_login' => 'test_json_user', 'user_email' => 'testjson@example.com' ) ); |
845 | 853 | $user2 = $this->factory->user->create( array( 'user_login' => 'test_json_user2', 'user_email' => 'testjson2@example.com' ) ); |