Changeset 39628
- Timestamp:
- 12/21/2016 05:12:06 AM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39566 r39628 665 665 } 666 666 667 if ( ! empty( $prepared_args['comment_post_ID'] ) ) { 668 $post = get_post( $prepared_args['comment_post_ID'] ); 669 if ( empty( $post ) ) { 670 return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) ); 671 } 672 } 673 667 674 if ( empty( $prepared_args ) && isset( $request['status'] ) ) { 668 675 // Only the comment status is being changed. … … 691 698 $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); 692 699 693 if ( 0=== $updated ) {700 if ( false === $updated ) { 694 701 return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); 695 702 } -
branches/4.7/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39566 r39628 1962 1962 } 1963 1963 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 1964 1980 public function test_update_comment_status() { 1965 1981 wp_set_current_user( self::$admin_id ); … … 2205 2221 $response = $this->server->dispatch( $request ); 2206 2222 $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 ); 2207 2233 } 2208 2234
Note: See TracChangeset
for help on using the changeset viewer.