WordPress.org

Make WordPress Core

Ticket #48027: 48027.1.diff

File 48027.1.diff, 4.0 KB (added by donmhico, 2 months ago)
  • src/wp-includes/class-wp-comment.php

    diff --git src/wp-includes/class-wp-comment.php src/wp-includes/class-wp-comment.php
    index f631444f8f..628aaf3082 100644
    final class WP_Comment { 
    162162         * Retrieves a WP_Comment instance.
    163163         *
    164164         * @since 4.4.0
     165         * @since 5.3.0 Convert WP_Comment::$user_id to int.
    165166         *
    166167         * @global wpdb $wpdb WordPress database abstraction object.
    167168         *
    final class WP_Comment { 
    188189                        wp_cache_add( $_comment->comment_ID, $_comment, 'comment' );
    189190                }
    190191
     192                $_comment->user_id = ( int ) $_comment->user_id;
     193
    191194                return new WP_Comment( $_comment );
    192195        }
    193196
  • tests/phpunit/tests/comment-submission.php

    diff --git tests/phpunit/tests/comment-submission.php tests/phpunit/tests/comment-submission.php
    index 2ad7f49bf5..760747ab8f 100644
    class Tests_Comment_Submission extends WP_UnitTestCase { 
    246246                $this->assertSame( 'Comment Author', $comment->comment_author );
    247247                $this->assertSame( 'comment@example.org', $comment->comment_author_email );
    248248                $this->assertSame( 'http://user.example.org', $comment->comment_author_url );
    249                 $this->assertSame( '0', $comment->user_id );
     249                $this->assertSame( 0, $comment->user_id );
    250250
    251251        }
    252252
  • tests/phpunit/tests/comment.php

    diff --git tests/phpunit/tests/comment.php tests/phpunit/tests/comment.php
    index 720a805062..bb21adfe88 100644
    class Tests_Comment extends WP_UnitTestCase { 
    855855
    856856                $expected = array(
    857857                        'comment_ID'           => (string) $comment_id,
    858                         'user_id'              => '0', // Anonymized.
     858                        'user_id'              => 0, // Anonymized.
    859859                        'comment_author'       => 'Anonymous', // Anonymized.
    860860                        'comment_author_email' => '', // Anonymized.
    861861                        'comment_author_url'   => '', // Anonymized.
    class Tests_Comment extends WP_UnitTestCase { 
    12411241                // Number of exported comments.
    12421242                $this->assertSame( 0, count( $actual['data'] ) );
    12431243        }
     1244
     1245        /**
     1246         * @ticket 48027
     1247         */
     1248        public function test_user_id_from_get_comment_should_be_int() {
     1249                $args = array(
     1250                        'user_id'                          => self::$user_id,
     1251                        'comment_post_ID'      => self::$post_id,
     1252                        'comment_author'       => 'Comment Author',
     1253                        'comment_author_email' => 'personal@local.host',
     1254                        'comment_author_url'   => 'https://local.host/',
     1255                        'comment_author_IP'    => '192.168.0.1',
     1256                        'comment_date'         => '2018-03-28 20:05:00',
     1257                        'comment_agent'        => 'SOME_AGENT',
     1258                        'comment_content'      => 'Comment',
     1259                );
     1260
     1261                $c = self::factory()->comment->create( $args );
     1262
     1263                $comment = get_comment( $c );
     1264                $this->assertSame( $comment->user_id, self::$user_id );
     1265
     1266                // Test for get_comments().
     1267                $user_id_1 = self::factory()->user->create();
     1268                $user_id_2 = self::factory()->user->create();
     1269                $user_id_3 = self::factory()->user->create();
     1270                self::factory()->comment->create( array( 'user_id' => $user_id_1, 'comment_post_ID' => self::$post_id ) );
     1271                self::factory()->comment->create( array( 'user_id' => $user_id_2, 'comment_post_ID' => self::$post_id ) );
     1272                self::factory()->comment->create( array( 'user_id' => $user_id_3, 'comment_post_ID' => self::$post_id ) );
     1273
     1274                $comments = get_comments( array( 'post_id' => self::$post_id ) );
     1275
     1276                foreach( $comments as $comm ) {
     1277                        $this->assertInternalType( 'int', $comm->user_id );
     1278                }
     1279        }
    12441280}
  • tests/phpunit/tests/xmlrpc/wp/getComment.php

    diff --git tests/phpunit/tests/xmlrpc/wp/getComment.php tests/phpunit/tests/xmlrpc/wp/getComment.php
    index 200f71ec53..ad2f6aa079 100644
    class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase { 
    5454                $this->assertNotIXRError( $result );
    5555
    5656                // Check data types
    57                 $this->assertInternalType( 'string', $result['user_id'] );
     57                $this->assertInternalType( 'int', $result['user_id'] );
    5858                $this->assertInternalType( 'string', $result['comment_id'] );
    5959                $this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] );
    6060                $this->assertInternalType( 'string', $result['parent'] );