Ticket #39732: 39732.3.patch
File 39732.3.patch, 7.9 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/comment.php
82 82 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 83 83 } 84 84 85 wp_update_comment( $_POST ); 85 $result = wp_update_comment( $_POST ); 86 87 if ( is_wp_error( $result ) ) { 88 wp_die ( $result->get_error_message() ); 89 } 86 90 } 87 91 88 92 /** -
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
730 730 return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); 731 731 } 732 732 733 if ( is_wp_error( $updated ) ) { 734 return $updated; 735 } 736 733 737 if ( isset( $request['status'] ) ) { 734 738 $this->handle_status_param( $request['status'], $id ); 735 739 } -
src/wp-includes/comment.php
2130 2130 * @global wpdb $wpdb WordPress database abstraction object. 2131 2131 * 2132 2132 * @param array $commentarr Contains information on the comment. 2133 * @return int Comment was updated if value is 1, or was not updated if value is 0.2133 * @return int|WP_Error Comment was updated if value is 1, or was not updated if value is 0 or WP_Error. 2134 2134 */ 2135 2135 function wp_update_comment($commentarr) { 2136 2136 global $wpdb; … … 2194 2194 */ 2195 2195 $data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr ); 2196 2196 2197 if ( is_wp_error( $data ) ) { 2198 return $data; 2199 } 2200 2197 2201 $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); 2198 2202 $data = wp_array_slice_assoc( $data, $keys ); 2199 2203 -
tests/phpunit/tests/comment.php
762 762 763 763 $this->assertSame( '1', $comment->comment_approved ); 764 764 } 765 766 /** 767 * @ticket 39732 768 */ 769 public function test_wp_update_comment_is_wp_error () { 770 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 771 772 add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 773 $result = wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_type' => 'pingback' ) ); 774 $this->assertInstanceOf( 'WP_Error', $result ); 775 remove_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 776 } 777 778 /** 779 * Block comments from being updated by returning WP_Error 780 */ 781 public function _wp_update_comment_data_filter ( $data, $comment, $commentarr ) { 782 return new WP_Error( 'comment_wrong', __( 'wp_update_comment_data filter fails for this comment.' ), 500 ); 783 } 765 784 } -
tests/phpunit/tests/xmlrpc/wp/editComment.php
69 69 70 70 $this->assertEquals( 'trash', get_comment( $comment_id )->comment_approved ); 71 71 } 72 73 /** 74 * @ticket 39732 75 */ 76 public function test__wp_update_comment_data_filter () { 77 $author_id = $this->make_user_by_role( 'author' ); 78 $post_id = self::factory()->post->create( array( 79 'post_title' => 'Post test by author', 80 'post_author' => $author_id 81 ) ); 82 83 $comment_id = wp_insert_comment(array( 84 'comment_post_ID' => $post_id, 85 'comment_author' => 'Commenter 1', 86 'comment_author_url' => "http://example.com/1/", 87 'comment_approved' => 1, 88 )); 89 90 add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 91 $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'author', 'author', $comment_id, array( 'status' => 'hold' ) ) ); 92 93 $this->assertInstanceOf( 'IXR_Error', $result ); 94 $this->assertEquals( 500, $result->code ); 95 $this->assertEquals( __( 'wp_update_comment_data filter fails for this comment.' ), $result->message ); 96 } 97 98 /** 99 * Block comments from being updated by returning WP_Error 100 */ 101 public function _wp_update_comment_data_filter ( $data, $comment, $commentarr ) { 102 return new WP_Error( 'comment_wrong', __( 'wp_update_comment_data filter fails for this comment.' ), 500 ); 103 } 72 104 } -
tests/phpunit/tests/ajax/EditComment.php
191 191 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 192 192 $this->_handleAjax( 'edit-comment' ); 193 193 } 194 195 /** 196 * @ticket 39732 197 */ 198 public function test_wp_update_comment_data_is_wp_error () { 199 200 // Become an administrator 201 $this->_setRole( 'administrator' ); 202 203 // Get a comment 204 $comments = get_comments( array( 205 'post_id' => $this->_comment_post->ID 206 ) ); 207 $comment = array_pop( $comments ); 208 209 // Set up a default request 210 $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' ); 211 $_POST['comment_ID'] = $comment->comment_ID; 212 $_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; 213 214 // Simulate filter check error 215 add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 216 217 // Make the request 218 $this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' ); 219 $this->_handleAjax( 'edit-comment' ); 220 221 remove_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 222 223 } 224 225 /** 226 * Block comments from being updated by returning WP_Error 227 */ 228 public function _wp_update_comment_data_filter ( $data, $comment, $commentarr ) { 229 return new WP_Error( 'comment_wrong', __( 'wp_update_comment_data filter fails for this comment.' ), 500 ); 230 } 194 231 } -
tests/phpunit/tests/rest-api/rest-comments-controller.php
2403 2403 $this->assertErrorResponse( 'comment_content_column_length', $response, 400 ); 2404 2404 } 2405 2405 2406 /** 2407 * @ticket 39732 2408 */ 2409 public function test_update_comment_is_wp_error() { 2410 wp_set_current_user( self::$admin_id ); 2411 2412 $params = array( 2413 'content' => 'This isn\'t a saxophone. It\'s an umbrella.', 2414 ); 2415 2416 add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 ); 2417 2418 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); 2419 2420 $request->add_header( 'content-type', 'application/json' ); 2421 $request->set_body( wp_json_encode( $params ) ); 2422 $response = $this->server->dispatch( $request ); 2423 2424 $this->assertErrorResponse( 'comment_wrong', $response, 500 ); 2425 } 2426 2427 /** 2428 * Block comments from being updated by returning WP_Error 2429 */ 2430 public function _wp_update_comment_data_filter ( $data, $comment, $commentarr ) { 2431 return new WP_Error( 'comment_wrong', __( 'wp_update_comment_data filter fails for this comment.' ), array( 'status' => 500 ) ); 2432 } 2433 2406 2434 public function verify_comment_roundtrip( $input = array(), $expected_output = array() ) { 2407 2435 // Create the comment 2408 2436 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );