Make WordPress Core

Changeset 47626


Ignore:
Timestamp:
04/26/2020 01:42:03 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Comments: Ensure that inserting a comment with an empty type results in correct comment type.

Add unit tests for wp_handle_comment_submission() and wp_insert_comment() receiving an empty type.

Follow-up to [47597].

Props ocean90, imath.
Fixes #49236.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r47617 r47626  
    19131913    $comment_approved = ! isset( $data['comment_approved'] ) ? 1 : $data['comment_approved'];
    19141914    $comment_agent    = ! isset( $data['comment_agent'] ) ? '' : $data['comment_agent'];
    1915     $comment_type     = ! isset( $data['comment_type'] ) ? 'comment' : $data['comment_type'];
     1915    $comment_type     = empty( $data['comment_type'] ) ? 'comment' : $data['comment_type'];
    19161916    $comment_parent   = ! isset( $data['comment_parent'] ) ? 0 : $data['comment_parent'];
    19171917
  • trunk/tests/phpunit/tests/comment-submission.php

    r47597 r47626  
    714714        $this->assertWPError( $comment );
    715715        $this->assertSame( $error, $comment->get_error_code() );
     716    }
     717
     718    /**
     719     * @ticket 49236
     720     */
     721    public function test_submitting_comment_with_empty_type_results_in_correct_type() {
     722        $data    = array(
     723            'comment_post_ID' => self::$post->ID,
     724            'comment'         => 'Comment',
     725            'author'          => 'Comment Author',
     726            'email'           => 'comment@example.org',
     727            'comment_type'    => '',
     728        );
     729        $comment = wp_handle_comment_submission( $data );
     730
     731        $this->assertNotWPError( $comment );
     732        $this->assertInstanceOf( 'WP_Comment', $comment );
     733
     734        $this->assertSame( 'comment', $comment->comment_type );
     735    }
     736
     737    /**
     738     * @ticket 49236
     739     */
     740    public function test_inserting_comment_with_empty_type_results_in_correct_type() {
     741        $data       = array(
     742            'comment_post_ID' => self::$post->ID,
     743            'comment'         => 'Comment',
     744            'author'          => 'Comment Author',
     745            'email'           => 'comment@example.org',
     746            'comment_type'    => '',
     747        );
     748        $comment_id = wp_insert_comment( $data );
     749        $comment    = get_comment( $comment_id );
     750
     751        $this->assertNotWPError( $comment );
     752        $this->assertInstanceOf( 'WP_Comment', $comment );
     753
     754        $this->assertSame( 'comment', $comment->comment_type );
    716755    }
    717756
Note: See TracChangeset for help on using the changeset viewer.