WordPress.org

Make WordPress Core

Ticket #34954: 34954.1.patch

File 34954.1.patch, 1.5 KB (added by rachelbaker, 4 years ago)

Added unit tests

  • src/wp-includes/comment.php

     
    19041904        }
    19051905
    19061906        // Make sure that the comment post ID is valid (if specified).
    1907         if ( isset( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
     1907        if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
    19081908                return 0;
    19091909        }
    19101910
  • tests/phpunit/tests/comment.php

     
    7070                $this->assertEquals( 1, $comment->user_id );
    7171        }
    7272
     73        /**
     74         * @ticket 34954
     75         */
     76        function test_wp_update_comment_with_no_post_id() {
     77                $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => 0 ) );
     78
     79                $updated_comment_text = 'I should be able to update a comment with a Post ID of zero';
     80
     81                $update = wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_content' => $updated_comment_text, 'comment_post_ID' => 0 ) );
     82
     83                $this->assertEquals( 1, $update );
     84
     85                $comment = get_comment( $comment_id );
     86                $this->assertEquals( $updated_comment_text, $comment->comment_content );
     87        }
     88
    7389        public function test_get_approved_comments() {
    7490                $ca1 = self::factory()->comment->create( array(
    7591                        'comment_post_ID' => self::$post_id, 'comment_approved' => '1'