Make WordPress Core

Ticket #38466: 38466.diff

File 38466.diff, 2.3 KB (added by markoheijnen, 9 years ago)
  • src/wp-includes/class-wp-xmlrpc-server.php

     
    35533553                        return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) );
    35543554                }
    35553555
    3556                 $comment = array();
    3557                 $comment['comment_post_ID'] = $post_id;
     3556                if ( empty( $content_struct['content'] ) ) {
     3557                        return new IXR_Error( 403, __( 'Comment is required.' ) );
     3558                }
     3559
     3560                $comment = array(
     3561                        'comment_post_ID' => $post_id,
     3562                        'comment_content' => $content_struct['content'],
     3563                );
    35583564
    35593565                if ( $logged_in ) {
    35603566                        $display_name = $user->display_name;
     
    35903596
    35913597                $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0;
    35923598
    3593                 $comment['comment_content'] =  isset($content_struct['content']) ? $content_struct['content'] : null;
    3594 
    35953599                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    35963600                do_action( 'xmlrpc_call', 'wp.newComment' );
    35973601
  • tests/phpunit/tests/xmlrpc/wp/newComment.php

     
    44 * @group xmlrpc
    55 */
    66class Tests_XMLRPC_wp_newComment extends WP_XMLRPC_UnitTestCase {
     7
     8        function test_valid_comment() {
     9                $this->make_user_by_role( 'administrator' );
     10                $post = self::factory()->post->create_and_get();
     11
     12                $result = $this->myxmlrpcserver->wp_newComment( array( 1, 'administrator', 'administrator', $post->ID, array(
     13                        'content' => rand_str( 100 )
     14                ) ) );
     15
     16                $this->assertNotInstanceOf( 'IXR_Error', $result );
     17        }
     18
     19        function test_empty_comment() {
     20                $this->make_user_by_role( 'administrator' );
     21                $post = self::factory()->post->create_and_get();
     22
     23                $result = $this->myxmlrpcserver->wp_newComment( array( 1, 'administrator', 'administrator', $post->ID, array(
     24                        'comment_content' => ''
     25                ) ) );
     26
     27                $this->assertInstanceOf( 'IXR_Error', $result );
     28                $this->assertEquals( 403, $result->code );
     29        }
     30
    731        function test_new_comment_post_closed() {
    832                $this->make_user_by_role( 'administrator' );
    933                $post = self::factory()->post->create_and_get( array(