Make WordPress Core

Ticket #30307: 30307.3.patch

File 30307.3.patch, 3.2 KB (added by rachelbaker, 10 years ago)

Updated unit test to confirm user_id is not the current user.

  • src/wp-admin/includes/comment.php

     
    3737        if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) )
    3838                wp_die ( __( 'You are not allowed to edit comments on this post.' ) );
    3939
     40        $comment_data = array();
     41
    4042        if ( isset( $_POST['newcomment_author'] ) )
    41                 $_POST['comment_author'] = $_POST['newcomment_author'];
     43                $comment_data['comment_author'] = $_POST['newcomment_author'];
    4244        if ( isset( $_POST['newcomment_author_email'] ) )
    43                 $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
     45                $comment_data['comment_author_email'] = $_POST['newcomment_author_email'];
    4446        if ( isset( $_POST['newcomment_author_url'] ) )
    45                 $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
     47                $comment_data['comment_author_url'] = $_POST['newcomment_author_url'];
    4648        if ( isset( $_POST['comment_status'] ) )
    47                 $_POST['comment_approved'] = $_POST['comment_status'];
     49                $comment_data['comment_approved'] = $_POST['comment_status'];
    4850        if ( isset( $_POST['content'] ) )
    49                 $_POST['comment_content'] = $_POST['content'];
     51                $comment_data['comment_content'] = $_POST['content'];
    5052        if ( isset( $_POST['comment_ID'] ) )
    51                 $_POST['comment_ID'] = (int) $_POST['comment_ID'];
     53                $comment_data['comment_ID'] = (int) $_POST['comment_ID'];
    5254
    53         foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
    54                 if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
    55                         $_POST['edit_date'] = '1';
     55        foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
     56                if ( ! empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
     57                        $comment_data['edit_date'] = '1';
    5658                        break;
    5759                }
    5860        }
    5961
    60         if ( !empty ( $_POST['edit_date'] ) ) {
     62        if ( ! empty( $comment_data['edit_date'] ) ) {
    6163                $aa = $_POST['aa'];
    6264                $mm = $_POST['mm'];
    6365                $jj = $_POST['jj'];
     
    6870                $hh = ($hh > 23 ) ? $hh -24 : $hh;
    6971                $mn = ($mn > 59 ) ? $mn -60 : $mn;
    7072                $ss = ($ss > 59 ) ? $ss -60 : $ss;
    71                 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
     73                $comment_data['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    7274        }
    7375
    74         wp_update_comment( $_POST );
     76        wp_update_comment( $comment_data );
    7577}
    7678
    7779/**
  • tests/phpunit/tests/comment.php

     
    3636         * @ticket 30307
    3737         */
    3838        function test_wp_update_comment_updates_user_id() {
     39                wp_set_current_user( 1 );
    3940                $post_id = $this->factory->post->create();
    40                 $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id ) );
     41                $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $post_id, 'user_id' => 1 ) );
    4142
    42                 wp_update_comment( array( 'comment_ID' => $comment_id, 'user_id' => 1 ) );
     43                wp_update_comment( array( 'comment_ID' => $comment_id, 'user_id' => 0 ) );
    4344
    4445                $comment = get_comment( $comment_id );
    45                 $this->assertEquals( 1, $comment->user_id );
     46                $this->assertEquals( 0, $comment->user_id );
    4647        }
    4748
    4849        public function test_get_approved_comments() {