Make WordPress Core


Ignore:
Timestamp:
11/05/2019 08:41:12 PM (7 years ago)
Author:
SergeyBiryukov
Message:

REST API: Speed up pagination unit tests by creating less fixtures and reusing them where possible.

Includes minor documentation and code layout fixes for better readability.

See #30017, #48145.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php

    r46586 r46657  
    2626        protected static $hold_id;
    2727
     28        protected static $comment_ids    = array();
     29        protected static $total_comments = 30;
     30        protected static $per_page       = 50;
     31
    2832        protected $endpoint;
    2933
     
    111115                        )
    112116                );
     117
     118                // Set up comments for pagination tests.
     119                for ( $i = 0; $i < self::$total_comments - 1; $i++ ) {
     120                        $comment_ids[] = $factory->comment->create(
     121                                array(
     122                                        'comment_content' => "Comment {$i}",
     123                                        'comment_post_ID' => self::$post_id,
     124                                )
     125                        );
     126                }
    113127        }
    114128
     
    130144                wp_delete_post( self::$approved_id, true );
    131145                wp_delete_post( self::$hold_id, true );
     146
     147                // Remove comments for pagination tests.
     148                foreach ( self::$comment_ids as $comment_id ) {
     149                        wp_delete_comment( $comment_id, true );
     150                }
    132151        }
    133152
     
    198217
    199218        public function test_get_items() {
    200                 $this->factory->comment->create_post_comments( self::$post_id, 6 );
    201 
    202219                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     220                $request->set_param( 'per_page', self::$per_page );
    203221
    204222                $response = rest_get_server()->dispatch( $request );
     
    206224
    207225                $comments = $response->get_data();
    208                 // We created 6 comments in this method, plus self::$approved_id.
    209                 $this->assertCount( 7, $comments );
     226                $this->assertCount( self::$total_comments, $comments );
    210227        }
    211228
     
    216233                wp_set_current_user( 0 );
    217234
    218                 $args             = array(
     235                $args = array(
    219236                        'comment_approved' => 1,
    220237                        'comment_post_ID'  => self::$password_id,
    221238                );
     239
    222240                $password_comment = $this->factory->comment->create( $args );
    223241
     
    238256        public function test_get_items_with_password_without_post() {
    239257                wp_set_current_user( 0 );
    240                 $args             = array(
     258
     259                $args = array(
    241260                        'comment_approved' => 1,
    242261                        'comment_post_ID'  => self::$password_id,
    243262                );
     263
    244264                $password_comment = $this->factory->comment->create( $args );
    245265
     
    259279        public function test_get_items_with_password_with_multiple_post() {
    260280                wp_set_current_user( 0 );
    261                 $args             = array(
     281
     282                $args = array(
    262283                        'comment_approved' => 1,
    263284                        'comment_post_ID'  => self::$password_id,
    264285                );
     286
    265287                $password_comment = $this->factory->comment->create( $args );
    266288
     
    276298                wp_set_current_user( 0 );
    277299
    278                 $args             = array(
     300                $args = array(
    279301                        'comment_approved' => 1,
    280302                        'comment_post_ID'  => self::$password_id,
    281303                );
     304
    282305                $password_comment = $this->factory->comment->create( $args );
    283306
     
    294317                wp_set_current_user( self::$admin_id );
    295318
    296                 $args             = array(
     319                $args = array(
    297320                        'comment_approved' => 1,
    298321                        'comment_post_ID'  => self::$password_id,
    299322                );
     323
    300324                $password_comment = $this->factory->comment->create( $args );
    301325
     
    312336                wp_set_current_user( 0 );
    313337
    314                 $args            = array(
     338                $args = array(
    315339                        'comment_approved' => 1,
    316340                        'comment_post_ID'  => self::$private_id,
    317341                );
     342
    318343                $private_comment = $this->factory->comment->create( $args );
    319344
     
    330355                wp_set_current_user( self::$admin_id );
    331356
    332                 $args            = array(
     357                $args = array(
    333358                        'comment_approved' => 1,
    334359                        'comment_post_ID'  => self::$private_id,
    335360                );
     361
    336362                $private_comment = $this->factory->comment->create( $args );
    337363
     
    389415        public function test_get_items_no_permission_for_context() {
    390416                wp_set_current_user( 0 );
     417
    391418                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    392419                $request->set_param( 'context', 'edit' );
     
    396423
    397424        public function test_get_items_no_post() {
     425                wp_set_current_user( self::$admin_id );
     426
    398427                $this->factory->comment->create_post_comments( 0, 2 );
    399                 wp_set_current_user( self::$admin_id );
     428
    400429                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    401430                $request->set_param( 'post', 0 );
     
    408437        public function test_get_items_no_permission_for_no_post() {
    409438                wp_set_current_user( 0 );
     439
    410440                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    411441                $request->set_param( 'post', 0 );
     
    416446        public function test_get_items_edit_context() {
    417447                wp_set_current_user( self::$admin_id );
     448
    418449                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    419450                $request->set_param( 'context', 'edit' );
     
    442473        public function test_get_items_include_query() {
    443474                wp_set_current_user( self::$admin_id );
     475
    444476                $args = array(
    445477                        'comment_approved' => 1,
    446478                        'comment_post_ID'  => self::$post_id,
    447479                );
    448                 $id1  = $this->factory->comment->create( $args );
    449                 $this->factory->comment->create( $args );
    450                 $id3     = $this->factory->comment->create( $args );
     480
     481                $id1 = $this->factory->comment->create( $args );
     482                $id2 = $this->factory->comment->create( $args );
     483
    451484                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    452                 // Order=>asc
     485
     486                // 'order' => 'asc'.
    453487                $request->set_param( 'order', 'asc' );
    454                 $request->set_param( 'include', array( $id3, $id1 ) );
     488                $request->set_param( 'include', array( $id2, $id1 ) );
    455489                $response = rest_get_server()->dispatch( $request );
    456490                $data     = $response->get_data();
    457491                $this->assertEquals( 2, count( $data ) );
    458492                $this->assertEquals( $id1, $data[0]['id'] );
    459                 // Orderby=>include
     493
     494                // 'orderby' => 'include'.
    460495                $request->set_param( 'orderby', 'include' );
    461496                $response = rest_get_server()->dispatch( $request );
    462497                $data     = $response->get_data();
    463498                $this->assertEquals( 2, count( $data ) );
    464                 $this->assertEquals( $id3, $data[0]['id'] );
    465                 // Orderby=>invalid should fail.
     499                $this->assertEquals( $id2, $data[0]['id'] );
     500
     501                // Invalid 'orderby' should error.
    466502                $request->set_param( 'orderby', 'invalid' );
    467503                $response = rest_get_server()->dispatch( $request );
    468504                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    469                 // fails on invalid id.
     505
     506                // Invalid 'include' should error.
    470507                $request->set_param( 'orderby', array( 'include' ) );
    471508                $request->set_param( 'include', array( 'invalid' ) );
     
    476513        public function test_get_items_exclude_query() {
    477514                wp_set_current_user( self::$admin_id );
    478                 $args     = array(
    479                         'comment_approved' => 1,
    480                         'comment_post_ID'  => self::$post_id,
    481                 );
    482                 $id1      = $this->factory->comment->create( $args );
    483                 $id2      = $this->factory->comment->create( $args );
    484                 $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    485                 $response = rest_get_server()->dispatch( $request );
    486                 $data     = $response->get_data();
    487                 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    488                 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    489                 $request->set_param( 'exclude', array( $id2 ) );
    490                 $response = rest_get_server()->dispatch( $request );
    491                 $data     = $response->get_data();
    492                 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    493                 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
    494 
    495                 // fails on invalid id.
    496                 $request->set_param( 'exclude', array( 'invalid' ) );
    497                 $response = rest_get_server()->dispatch( $request );
    498                 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    499         }
    500 
    501         public function test_get_items_offset_query() {
    502                 wp_set_current_user( self::$admin_id );
     515
    503516                $args = array(
    504517                        'comment_approved' => 1,
    505518                        'comment_post_ID'  => self::$post_id,
    506519                );
    507                 $this->factory->comment->create( $args );
    508                 $this->factory->comment->create( $args );
    509                 $this->factory->comment->create( $args );
     520
     521                $id1 = $this->factory->comment->create( $args );
     522                $id2 = $this->factory->comment->create( $args );
     523
     524                $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     525                $response = rest_get_server()->dispatch( $request );
     526                $data     = $response->get_data();
     527                $ids      = wp_list_pluck( $data, 'id' );
     528                $this->assertTrue( in_array( $id1, $ids, true ) );
     529                $this->assertTrue( in_array( $id2, $ids, true ) );
     530
     531                $request->set_param( 'exclude', array( $id2 ) );
     532                $response = rest_get_server()->dispatch( $request );
     533                $data     = $response->get_data();
     534                $ids      = wp_list_pluck( $data, 'id' );
     535                $this->assertTrue( in_array( $id1, $ids, true ) );
     536                $this->assertFalse( in_array( $id2, $ids, true ) );
     537
     538                // Invalid 'exclude' should error.
     539                $request->set_param( 'exclude', array( 'invalid' ) );
     540                $response = rest_get_server()->dispatch( $request );
     541                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     542        }
     543
     544        public function test_get_items_offset_query() {
     545                wp_set_current_user( self::$admin_id );
     546
    510547                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     548                $request->set_param( 'per_page', self::$per_page );
    511549                $request->set_param( 'offset', 1 );
    512550                $response = rest_get_server()->dispatch( $request );
    513                 $this->assertCount( 3, $response->get_data() );
    514                 // 'offset' works with 'per_page'
     551                $this->assertCount( self::$total_comments - 1, $response->get_data() );
     552
     553                // 'offset' works with 'per_page'.
    515554                $request->set_param( 'per_page', 2 );
    516555                $response = rest_get_server()->dispatch( $request );
    517556                $this->assertCount( 2, $response->get_data() );
    518                 // 'offset' takes priority over 'page'
     557
     558                // 'offset' takes priority over 'page'.
    519559                $request->set_param( 'page', 3 );
    520560                $response = rest_get_server()->dispatch( $request );
    521561                $this->assertCount( 2, $response->get_data() );
    522                 // 'offset' with invalid value errors.
     562
     563                // Invalid 'offset' should error.
    523564                $request->set_param( 'offset', 'moreplease' );
    524565                $response = rest_get_server()->dispatch( $request );
     
    528569        public function test_get_items_order_query() {
    529570                wp_set_current_user( self::$admin_id );
     571
    530572                $args = array(
    531573                        'comment_approved' => 1,
    532574                        'comment_post_ID'  => self::$post_id,
    533575                );
    534                 $this->factory->comment->create( $args );
    535                 $this->factory->comment->create( $args );
    536                 $id3     = $this->factory->comment->create( $args );
     576
     577                $id = $this->factory->comment->create( $args );
     578
    537579                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    538                 // order defaults to 'desc'
     580
     581                // Order defaults to 'desc'.
    539582                $response = rest_get_server()->dispatch( $request );
    540583                $data     = $response->get_data();
    541                 $this->assertEquals( $id3, $data[0]['id'] );
    542                 // order=>asc
     584                $this->assertEquals( $id, $data[0]['id'] );
     585
     586                // 'order' => 'asc'.
    543587                $request->set_param( 'order', 'asc' );
    544588                $response = rest_get_server()->dispatch( $request );
    545589                $data     = $response->get_data();
    546590                $this->assertEquals( self::$approved_id, $data[0]['id'] );
    547                 // order=>asc,id should fail
     591
     592                // 'order' => 'asc,id' should error.
    548593                $request->set_param( 'order', 'asc,id' );
    549594                $response = rest_get_server()->dispatch( $request );
     
    553598        public function test_get_items_private_post_no_permissions() {
    554599                wp_set_current_user( 0 );
     600
    555601                $post_id = $this->factory->post->create( array( 'post_status' => 'private' ) );
     602
    556603                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    557604                $request->set_param( 'post', $post_id );
     
    561608
    562609        public function test_get_items_author_arg() {
    563                 // Authorized
    564                 wp_set_current_user( self::$admin_id );
     610                // Authorized.
     611                wp_set_current_user( self::$admin_id );
     612
    565613                $args = array(
    566614                        'comment_approved' => 1,
     
    568616                        'user_id'          => self::$author_id,
    569617                );
     618
    570619                $this->factory->comment->create( $args );
    571620                $args['user_id'] = self::$subscriber_id;
     
    574623                $this->factory->comment->create( $args );
    575624
    576                 // 'author' limits result to 1 of 3
     625                // Limit to comment author.
    577626                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    578627                $request->set_param( 'author', self::$author_id );
     
    581630                $comments = $response->get_data();
    582631                $this->assertCount( 1, $comments );
    583                 // Multiple authors are supported
     632
     633                // Multiple authors are supported.
    584634                $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
    585635                $response = rest_get_server()->dispatch( $request );
     
    587637                $comments = $response->get_data();
    588638                $this->assertCount( 2, $comments );
    589                 // Invalid author param errors
     639
     640                // Invalid 'author' should error.
    590641                $request->set_param( 'author', 'skippy' );
    591642                $response = rest_get_server()->dispatch( $request );
    592643                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    593                 // Unavailable to unauthenticated; defaults to error
     644
     645                // Unavailable to unauthenticated; defaults to error.
    594646                wp_set_current_user( 0 );
    595647                $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
     
    599651
    600652        public function test_get_items_author_exclude_arg() {
    601                 // Authorized
    602                 wp_set_current_user( self::$admin_id );
     653                // Authorized.
     654                wp_set_current_user( self::$admin_id );
     655
    603656                $args = array(
    604657                        'comment_approved' => 1,
     
    606659                        'user_id'          => self::$author_id,
    607660                );
     661
    608662                $this->factory->comment->create( $args );
    609663                $args['user_id'] = self::$subscriber_id;
     
    612666                $this->factory->comment->create( $args );
    613667
    614                 $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     668                $total_comments = self::$total_comments + 3;
     669
     670                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     671                $request->set_param( 'per_page', self::$per_page );
    615672                $response = rest_get_server()->dispatch( $request );
    616673                $comments = $response->get_data();
    617                 $this->assertCount( 4, $comments );
    618 
    619                 // 'author_exclude' limits result to 3 of 4
     674                $this->assertCount( $total_comments, $comments );
     675
     676                // Exclude comment author.
    620677                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     678                $request->set_param( 'per_page', self::$per_page );
    621679                $request->set_param( 'author_exclude', self::$author_id );
    622680                $response = rest_get_server()->dispatch( $request );
    623681                $this->assertEquals( 200, $response->get_status() );
    624682                $comments = $response->get_data();
    625                 $this->assertCount( 3, $comments );
    626                 // 'author_exclude' for both comment authors (2 of 4)
     683                $this->assertCount( $total_comments - 1, $comments );
     684
     685                // Exclude both comment authors.
    627686                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     687                $request->set_param( 'per_page', self::$per_page );
    628688                $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
    629689                $response = rest_get_server()->dispatch( $request );
    630690                $this->assertEquals( 200, $response->get_status() );
    631691                $comments = $response->get_data();
    632                 $this->assertCount( 2, $comments );
    633                 // 'author_exclude' for both invalid author
     692                $this->assertCount( $total_comments - 2, $comments );
     693
     694                // 'author_exclude' for invalid author.
    634695                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    635696                $request->set_param( 'author_exclude', 'skippy' );
    636697                $response = rest_get_server()->dispatch( $request );
    637698                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    638                 // Unavailable to unauthenticated; defaults to error
     699
     700                // Unavailable to unauthenticated; defaults to error.
    639701                wp_set_current_user( 0 );
    640702                $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
     
    654716                $args['comment_parent'] = $parent_id2;
    655717                $this->factory->comment->create( $args );
    656                 // All comments in the database
    657                 $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    658                 $response = rest_get_server()->dispatch( $request );
    659                 $this->assertCount( 5, $response->get_data() );
    660                 // Limit to the parent
     718
     719                $total_comments = self::$total_comments + 4;
     720
     721                // All comments in the database.
     722                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     723                $request->set_param( 'per_page', self::$per_page );
     724                $response = rest_get_server()->dispatch( $request );
     725                $this->assertCount( $total_comments, $response->get_data() );
     726
     727                // Limit to the parent.
    661728                $request->set_param( 'parent', $parent_id );
    662729                $response = rest_get_server()->dispatch( $request );
    663730                $this->assertCount( 1, $response->get_data() );
    664                 // Limit to two parents
     731
     732                // Limit to two parents.
    665733                $request->set_param( 'parent', array( $parent_id, $parent_id2 ) );
    666734                $response = rest_get_server()->dispatch( $request );
    667735                $this->assertCount( 2, $response->get_data() );
    668                 // Invalid parent should error
     736
     737                // Invalid 'parent' should error.
    669738                $request->set_param( 'parent', 'invalid' );
    670739                $response = rest_get_server()->dispatch( $request );
     
    683752                $args['comment_parent'] = $parent_id2;
    684753                $this->factory->comment->create( $args );
    685                 // All comments in the database
    686                 $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    687                 $response = rest_get_server()->dispatch( $request );
    688                 $this->assertCount( 5, $response->get_data() );
    689                 // Exclude this particular parent
     754
     755                $total_comments = self::$total_comments + 4;
     756
     757                // All comments in the database.
     758                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     759                $request->set_param( 'per_page', self::$per_page );
     760                $response = rest_get_server()->dispatch( $request );
     761                $this->assertCount( $total_comments, $response->get_data() );
     762
     763                // Exclude this particular parent.
    690764                $request->set_param( 'parent_exclude', $parent_id );
    691765                $response = rest_get_server()->dispatch( $request );
    692                 $this->assertCount( 4, $response->get_data() );
    693                 // Exclude both comment parents
     766                $this->assertCount( $total_comments - 1, $response->get_data() );
     767
     768                // Exclude both comment parents.
    694769                $request->set_param( 'parent_exclude', array( $parent_id, $parent_id2 ) );
    695770                $response = rest_get_server()->dispatch( $request );
    696                 $this->assertCount( 3, $response->get_data() );
    697                 // Invalid parent id should error
     771                $this->assertCount( $total_comments - 2, $response->get_data() );
     772
     773                // Invalid 'parent_exclude' should error.
    698774                $request->set_param( 'parent_exclude', 'invalid' );
    699775                $response = rest_get_server()->dispatch( $request );
     
    703779        public function test_get_items_search_query() {
    704780                wp_set_current_user( self::$admin_id );
    705                 $args                    = array(
     781
     782                $args = array(
    706783                        'comment_approved' => 1,
    707784                        'comment_post_ID'  => self::$post_id,
     
    709786                        'comment_author'   => 'Homer J Simpson',
    710787                );
    711                 $id1                     = $this->factory->comment->create( $args );
    712                 $args['comment_content'] = 'bar';
    713                 $this->factory->comment->create( $args );
    714                 $args['comment_content'] = 'burrito';
    715                 $this->factory->comment->create( $args );
    716                 // 3 comments, plus 1 created in construct
    717                 $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    718                 $response = rest_get_server()->dispatch( $request );
    719                 $this->assertCount( 4, $response->get_data() );
    720                 // One matching comments
     788
     789                $id = $this->factory->comment->create( $args );
     790
     791                $total_comments = self::$total_comments + 1;
     792
     793                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     794                $request->set_param( 'per_page', self::$per_page );
     795                $response = rest_get_server()->dispatch( $request );
     796                $this->assertCount( $total_comments, $response->get_data() );
     797
     798                // One matching comment.
    721799                $request->set_param( 'search', 'foo' );
    722800                $response = rest_get_server()->dispatch( $request );
    723801                $data     = $response->get_data();
    724802                $this->assertCount( 1, $data );
    725                 $this->assertEquals( $id1, $data[0]['id'] );
     803                $this->assertEquals( $id, $data[0]['id'] );
    726804        }
    727805
    728806        public function test_get_comments_pagination_headers() {
    729                 wp_set_current_user( self::$admin_id );
    730                 // Start of the index
    731                 for ( $i = 0; $i < 49; $i++ ) {
    732                         $this->factory->comment->create(
    733                                 array(
    734                                         'comment_content' => "Comment {$i}",
    735                                         'comment_post_ID' => self::$post_id,
    736                                 )
    737                         );
    738                 }
     807                $total_comments = self::$total_comments;
     808                $total_pages    = (int) ceil( $total_comments / 10 );
     809
     810                wp_set_current_user( self::$admin_id );
     811
     812                // Start of the index.
    739813                $request  = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    740814                $response = rest_get_server()->dispatch( $request );
    741815                $headers  = $response->get_headers();
    742                 $this->assertEquals( 50, $headers['X-WP-Total'] );
    743                 $this->assertEquals( 5, $headers['X-WP-TotalPages'] );
     816                $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
     817                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    744818                $next_link = add_query_arg(
    745819                        array(
     
    750824                $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) );
    751825                $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    752                 // 3rd page
     826
     827                // 3rd page.
    753828                $this->factory->comment->create(
    754829                        array(
    755                                 'comment_content' => 'Comment 51',
    756830                                'comment_post_ID' => self::$post_id,
    757831                        )
    758832                );
     833                $total_comments++;
     834                $total_pages++;
    759835                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    760836                $request->set_param( 'page', 3 );
    761837                $response = rest_get_server()->dispatch( $request );
    762838                $headers  = $response->get_headers();
    763                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    764                 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
     839                $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
     840                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    765841                $prev_link = add_query_arg(
    766842                        array(
     
    777853                );
    778854                $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    779                 // Last page
     855
     856                // Last page.
    780857                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    781                 $request->set_param( 'page', 6 );
     858                $request->set_param( 'page', $total_pages );
    782859                $response = rest_get_server()->dispatch( $request );
    783860                $headers  = $response->get_headers();
    784                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    785                 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
     861                $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
     862                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    786863                $prev_link = add_query_arg(
    787864                        array(
    788                                 'page' => 5,
     865                                'page' => $total_pages - 1,
    789866                        ),
    790867                        rest_url( '/wp/v2/comments' )
     
    792869                $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    793870                $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
    794                 // Out of bounds
     871
     872                // Out of bounds.
    795873                $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    796                 $request->set_param( 'page', 8 );
     874                $request->set_param( 'page', 100 );
    797875                $response = rest_get_server()->dispatch( $request );
    798876                $headers  = $response->get_headers();
    799                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    800                 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
     877                $this->assertEquals( $total_comments, $headers['X-WP-Total'] );
     878                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    801879                $prev_link = add_query_arg(
    802880                        array(
    803                                 'page' => 6,
     881                                'page' => $total_pages,
    804882                        ),
    805883                        rest_url( '/wp/v2/comments' )
     
    858936        public function test_prepare_item() {
    859937                wp_set_current_user( self::$admin_id );
     938
    860939                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    861940                $request->set_query_params(
     
    874953        public function test_prepare_item_limit_fields() {
    875954                wp_set_current_user( self::$admin_id );
     955
    876956                $endpoint = new WP_REST_Comments_Controller;
    877957                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
     
    916996        public function test_get_comment_invalid_context() {
    917997                wp_set_current_user( 0 );
     998
    918999                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) );
    9191000                $request->set_param( 'context', 'edit' );
     
    9241005        public function test_get_comment_invalid_post_id() {
    9251006                wp_set_current_user( 0 );
     1007
    9261008                $comment_id = $this->factory->comment->create(
    9271009                        array(
     
    9301012                        )
    9311013                );
    932                 $request    = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    933 
     1014
     1015                $request  = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    9341016                $response = rest_get_server()->dispatch( $request );
    9351017                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    9381020        public function test_get_comment_invalid_post_id_as_admin() {
    9391021                wp_set_current_user( self::$admin_id );
     1022
    9401023                $comment_id = $this->factory->comment->create(
    9411024                        array(
     
    9441027                        )
    9451028                );
    946                 $request    = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    947 
     1029
     1030                $request  = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $comment_id );
    9481031                $response = rest_get_server()->dispatch( $request );
    9491032                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     
    9531036                wp_set_current_user( 0 );
    9541037
    955                 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    956 
     1038                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    9571039                $response = rest_get_server()->dispatch( $request );
    9581040                $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
     
    9621044                wp_set_current_user( self::$admin_id );
    9631045
    964                 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    965 
     1046                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    9661047                $response = rest_get_server()->dispatch( $request );
    9671048                $this->assertEquals( 200, $response->get_status() );
     
    10091090        public function test_get_comment_with_password_without_edit_post_permission() {
    10101091                wp_set_current_user( self::$subscriber_id );
    1011                 $args             = array(
     1092
     1093                $args = array(
    10121094                        'comment_approved' => 1,
    10131095                        'comment_post_ID'  => self::$password_id,
    10141096                );
     1097
    10151098                $password_comment = $this->factory->comment->create( $args );
    1016                 $request          = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) );
    1017                 $response         = rest_get_server()->dispatch( $request );
     1099
     1100                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $password_comment ) );
     1101                $response = rest_get_server()->dispatch( $request );
    10181102                $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    10191103        }
     
    10251109                wp_set_current_user( self::$subscriber_id );
    10261110
    1027                 $args             = array(
     1111                $args = array(
    10281112                        'comment_approved' => 1,
    10291113                        'comment_post_ID'  => self::$password_id,
    10301114                );
     1115
    10311116                $password_comment = $this->factory->comment->create( $args );
    10321117
     
    11141199        public function test_create_comment_date( $params, $results ) {
    11151200                wp_set_current_user( self::$admin_id );
     1201
    11161202                update_option( 'timezone_string', $params['timezone_string'] );
    11171203
     
    12341320        public function test_create_comment_missing_required_author_email() {
    12351321                wp_set_current_user( self::$admin_id );
     1322
    12361323                update_option( 'require_name_email', 1 );
    12371324
     
    12521339        public function test_create_comment_empty_required_author_email() {
    12531340                wp_set_current_user( self::$admin_id );
     1341
    12541342                update_option( 'require_name_email', 1 );
    12551343
     
    13431431
    13441432                wp_set_current_user( self::$admin_id );
    1345                 $params  = array(
     1433
     1434                $params = array(
    13461435                        'post'         => self::$post_id,
    13471436                        'author_name'  => 'Comic Book Guy',
     
    13521441                        'date'         => '2014-11-07T10:14:25',
    13531442                );
     1443
    13541444                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    13551445                $request->add_header( 'content-type', 'application/json' );
     
    13651455        public function test_create_comment_without_type() {
    13661456                $post_id = $this->factory->post->create();
     1457
    13671458                wp_set_current_user( self::$admin_id );
    13681459
     
    14021493        public function test_create_comment_with_invalid_type() {
    14031494                $post_id = $this->factory->post->create();
     1495
    14041496                wp_set_current_user( self::$admin_id );
    14051497
     
    14251517        public function test_create_comment_invalid_email() {
    14261518                $post_id = $this->factory->post->create();
     1519
    14271520                wp_set_current_user( self::$admin_id );
    14281521
     
    15691662        public function test_create_comment_with_status_IP_and_user_agent() {
    15701663                $post_id = $this->factory->post->create();
     1664
    15711665                wp_set_current_user( self::$admin_id );
    15721666
     
    16631757        public function test_create_comment_author_ip_no_permission() {
    16641758                wp_set_current_user( self::$subscriber_id );
    1665                 $params  = array(
     1759
     1760                $params = array(
    16661761                        'author_name'  => 'Comic Book Guy',
    16671762                        'author_email' => 'cbg@androidsdungeon.com',
     
    16711766                        'status'       => 'approved',
    16721767                );
     1768
    16731769                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    16741770                $request->add_header( 'content-type', 'application/json' );
     
    16801776        public function test_create_comment_author_ip_defaults_to_remote_addr() {
    16811777                wp_set_current_user( self::$admin_id );
     1778
    16821779                $_SERVER['REMOTE_ADDR'] = '127.0.0.2';
    1683                 $params                 = array(
     1780
     1781                $params = array(
    16841782                        'post'         => self::$post_id,
    16851783                        'author_name'  => 'Comic Book Guy',
     
    16881786                        'content'      => 'Worst Comment Ever!',
    16891787                );
    1690                 $request                = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     1788
     1789                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    16911790                $request->add_header( 'content-type', 'application/json' );
    16921791                $request->set_body( wp_json_encode( $params ) );
     
    17001799                wp_set_current_user( self::$admin_id );
    17011800
    1702                 $params  = array(
     1801                $params = array(
    17031802                        'author_name'  => 'Comic Book Guy',
    17041803                        'author_email' => 'cbg@androidsdungeon.com',
     
    17071806                        'status'       => 'approved',
    17081807                );
     1808
    17091809                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    17101810                $request->add_header( 'content-type', 'application/json' );
     
    17191819                wp_set_current_user( self::$subscriber_id );
    17201820
    1721                 $params  = array(
     1821                $params = array(
    17221822                        'author_name'  => 'Homer Jay Simpson',
    17231823                        'author_email' => 'chunkylover53@aol.com',
     
    17261826                        'author'       => self::$subscriber_id,
    17271827                );
     1828
    17281829                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    17291830                $request->add_header( 'content-type', 'application/json' );
     
    17571858                wp_set_current_user( self::$subscriber_id );
    17581859
    1759                 $params  = array(
     1860                $params = array(
    17601861                        'post'         => self::$draft_id,
    17611862                        'author_name'  => 'Ishmael',
     
    17651866                        'author'       => self::$subscriber_id,
    17661867                );
    1767                 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1768                 $request->add_header( 'content-type', 'application/json' );
    1769                 $request->set_body( wp_json_encode( $params ) );
    1770 
    1771                 $response = rest_get_server()->dispatch( $request );
    1772 
     1868
     1869                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     1870                $request->add_header( 'content-type', 'application/json' );
     1871                $request->set_body( wp_json_encode( $params ) );
     1872
     1873                $response = rest_get_server()->dispatch( $request );
    17731874                $this->assertErrorResponse( 'rest_comment_draft_post', $response, 403 );
    17741875        }
     
    17771878                wp_set_current_user( self::$subscriber_id );
    17781879
    1779                 $params  = array(
     1880                $params = array(
    17801881                        'post'         => self::$trash_id,
    17811882                        'author_name'  => 'Ishmael',
     
    17851886                        'author'       => self::$subscriber_id,
    17861887                );
     1888
    17871889                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    17881890                $request->add_header( 'content-type', 'application/json' );
     
    17971899                wp_set_current_user( self::$subscriber_id );
    17981900
    1799                 $params  = array(
     1901                $params = array(
    18001902                        'post'         => self::$private_id,
    18011903                        'author_name'  => 'Homer Jay Simpson',
     
    18051907                        'author'       => self::$subscriber_id,
    18061908                );
    1807                 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1808                 $request->add_header( 'content-type', 'application/json' );
    1809                 $request->set_body( wp_json_encode( $params ) );
    1810 
    1811                 $response = rest_get_server()->dispatch( $request );
    1812 
     1909
     1910                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     1911                $request->add_header( 'content-type', 'application/json' );
     1912                $request->set_body( wp_json_encode( $params ) );
     1913
     1914                $response = rest_get_server()->dispatch( $request );
    18131915                $this->assertErrorResponse( 'rest_cannot_read_post', $response, 403 );
    18141916        }
     
    18171919                wp_set_current_user( self::$subscriber_id );
    18181920
    1819                 $params  = array(
     1921                $params = array(
    18201922                        'post'         => self::$password_id,
    18211923                        'author_name'  => 'Homer Jay Simpson',
     
    18251927                        'author'       => self::$subscriber_id,
    18261928                );
     1929
    18271930                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    18281931                $request->add_header( 'content-type', 'application/json' );
     
    18351938        public function test_create_item_duplicate() {
    18361939                wp_set_current_user( self::$subscriber_id );
     1940
    18371941                $this->factory->comment->create(
    18381942                        array(
     
    18651969                        )
    18661970                );
     1971
    18671972                wp_set_current_user( self::$subscriber_id );
    18681973
     
    18811986        public function test_create_comment_require_login() {
    18821987                wp_set_current_user( 0 );
     1988
    18831989                update_option( 'comment_registration', 1 );
    18841990                add_filter( 'rest_allow_anonymous_comments', '__return_true' );
     1991
    18851992                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    18861993                $request->set_param( 'post', self::$post_id );
     
    19982105                wp_set_current_user( self::$subscriber_id );
    19992106
    2000                 $params  = array(
     2107                $params = array(
    20012108                        'post'         => self::$post_id,
    20022109                        'author_name'  => rand_long_str( 246 ),
     
    20062113                        'date'         => '1995-04-30T10:22:00',
    20072114                );
     2115
    20082116                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    20092117
     
    20212129                wp_set_current_user( self::$subscriber_id );
    20222130
    2023                 $params  = array(
     2131                $params = array(
    20242132                        'post'         => self::$post_id,
    20252133                        'author_name'  => 'Bleeding Gums Murphy',
     
    20292137                        'date'         => '1995-04-30T10:22:00',
    20302138                );
     2139
    20312140                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    20322141
     
    20442153                wp_set_current_user( self::$subscriber_id );
    20452154
    2046                 $params  = array(
     2155                $params = array(
    20472156                        'post'         => self::$post_id,
    20482157                        'author_name'  => 'Bleeding Gums Murphy',
     
    20522161                        'date'         => '1995-04-30T10:22:00',
    20532162                );
     2163
    20542164                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    20552165
     
    20672177                wp_set_current_user( self::$subscriber_id );
    20682178
    2069                 $params  = array(
     2179                $params = array(
    20702180                        'post'         => self::$post_id,
    20712181                        'author_name'  => 'Bleeding Gums Murphy',
     
    20752185                        'date'         => '1995-04-30T10:22:00',
    20762186                );
     2187
    20772188                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    20782189
     
    20872198                wp_set_current_user( self::$subscriber_id );
    20882199
    2089                 $params  = array(
     2200                $params = array(
    20902201                        'post'         => self::$password_id,
    20912202                        'author_name'  => 'Bleeding Gums Murphy',
     
    20942205                        'content'      => 'This isn\'t a saxophone. It\'s an umbrella.',
    20952206                );
     2207
    20962208                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    20972209
     
    21062218                add_filter( 'rest_allow_anonymous_comments', '__return_true' );
    21072219
    2108                 $params  = array(
     2220                $params = array(
    21092221                        'post'         => self::$password_id,
    21102222                        'author_name'  => 'Bleeding Gums Murphy',
     
    21142226                        'password'     => 'toomanysecrets',
    21152227                );
     2228
    21162229                $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    21172230
     
    21272240                wp_set_current_user( self::$admin_id );
    21282241
    2129                 $params  = array(
     2242                $params = array(
    21302243                        'author'       => self::$subscriber_id,
    21312244                        'author_name'  => 'Disco Stu',
     
    21372250                        'post'         => $post_id,
    21382251                );
     2252
    21392253                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    21402254                $request->add_header( 'content-type', 'application/json' );
     
    21632277        public function test_update_comment_date( $params, $results ) {
    21642278                wp_set_current_user( self::$editor_id );
     2279
    21652280                update_option( 'timezone_string', $params['timezone_string'] );
    21662281
     
    22142329
    22152330                wp_set_current_user( self::$admin_id );
     2331
    22162332                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    22172333                $request->set_param( 'post', $comment->comment_post_ID );
     
    22362352                );
    22372353
    2238                 $params  = array(
     2354                $params = array(
    22392355                        'status' => 'approve',
    22402356                );
     2357
    22412358                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    22422359                $request->add_header( 'content-type', 'application/json' );
     
    22632380                );
    22642381
    2265                 $params  = array(
     2382                $params = array(
    22662383                        'status' => 'approve',
    22672384                );
     2385
    22682386                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    22692387                $request->add_header( 'content-type', 'application/json' );
     
    22832401                wp_set_current_user( self::$admin_id );
    22842402
    2285                 $params  = array(
     2403                $params = array(
    22862404                        'date_gmt' => '2015-05-07T10:14:25',
    22872405                        'content'  => 'I\'ll be deep in the cold, cold ground before I recognize Missouri.',
    22882406                );
     2407
    22892408                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    22902409                $request->add_header( 'content-type', 'application/json' );
     
    23022421        public function test_update_comment_author_email_only() {
    23032422                wp_set_current_user( self::$editor_id );
     2423
    23042424                update_option( 'require_name_email', 1 );
    23052425
     
    23202440        public function test_update_comment_empty_author_name() {
    23212441                wp_set_current_user( self::$editor_id );
     2442
    23222443                update_option( 'require_name_email', 1 );
    23232444
     
    23392460        public function test_update_comment_author_name_only() {
    23402461                wp_set_current_user( self::$admin_id );
     2462
    23412463                update_option( 'require_name_email', 1 );
    23422464
     
    23572479        public function test_update_comment_empty_author_email() {
    23582480                wp_set_current_user( self::$admin_id );
     2481
    23592482                update_option( 'require_name_email', 1 );
    23602483
     
    23972520                wp_set_current_user( self::$admin_id );
    23982521
    2399                 $params  = array(
     2522                $params = array(
    24002523                        'type' => 'trackback',
    24012524                );
     2525
    24022526                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    24032527                $request->add_header( 'content-type', 'application/json' );
     
    24112535                wp_set_current_user( self::$admin_id );
    24122536
    2413                 $params  = array(
     2537                $params = array(
    24142538                        'content' => array(
    24152539                                'raw' => 'What the heck kind of name is Persephone?',
    24162540                        ),
    24172541                );
     2542
    24182543                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    24192544                $request->add_header( 'content-type', 'application/json' );
     
    24642589                wp_set_current_user( self::$subscriber_id );
    24652590
    2466                 $params  = array(
     2591                $params = array(
    24672592                        'content' => 'Oh, they have the internet on computers now!',
    24682593                );
     2594
    24692595                $request = new WP_REST_Request( 'PUT', '/wp/v2/comments/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
    24702596                $request->add_header( 'content-type', 'application/json' );
     
    24882614                add_filter( 'rest_allow_anonymous_comments', '__return_true' );
    24892615
    2490                 $params  = array(
     2616                $params = array(
    24912617                        'content' => 'Disco Stu likes disco music.',
    24922618                );
     2619
    24932620                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    24942621                $request->add_header( 'content-type', 'application/json' );
     
    25052632                wp_set_current_user( self::$moderator_id );
    25062633
    2507                 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    2508                 $params  = array(
     2634                $params = array(
    25092635                        'content' => 'Updated comment.',
    25102636                        'date'    => '2019-10-07T23:14:25',
    25112637                );
     2638
     2639                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    25122640                $request->add_header( 'content-type', 'application/json' );
    25132641                $request->set_body( wp_json_encode( $params ) );
     
    25352663                wp_set_current_user( self::$subscriber_id );
    25362664
    2537                 $params  = array(
     2665                $params = array(
    25382666                        'content' => 'Disco Stu likes disco music.',
    25392667                );
     2668
    25402669                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $private_comment_id ) );
    25412670                $request->add_header( 'content-type', 'application/json' );
     
    25482677        public function test_update_comment_with_children_link() {
    25492678                wp_set_current_user( self::$admin_id );
     2679
    25502680                $comment_id_1 = $this->factory->comment->create(
    25512681                        array(
     
    25902720                wp_set_current_user( self::$admin_id );
    25912721
    2592                 $params  = array(
     2722                $params = array(
    25932723                        'author_name' => rand_long_str( 246 ),
    25942724                        'content'     => 'This isn\'t a saxophone. It\'s an umbrella.',
    25952725                );
     2726
    25962727                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    25972728
     
    26092740                wp_set_current_user( self::$admin_id );
    26102741
    2611                 $params  = array(
     2742                $params = array(
    26122743                        'author_email' => 'murphy@' . rand_long_str( 190 ) . '.com',
    26132744                        'content'      => 'This isn\'t a saxophone. It\'s an umbrella.',
    26142745                );
     2746
    26152747                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    26162748
     
    26282760                wp_set_current_user( self::$admin_id );
    26292761
    2630                 $params  = array(
     2762                $params = array(
    26312763                        'author_url' => 'http://jazz.' . rand_long_str( 185 ) . '.com',
    26322764                        'content'    => 'This isn\'t a saxophone. It\'s an umbrella.',
    26332765                );
     2766
    26342767                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    26352768
     
    26472780                wp_set_current_user( self::$admin_id );
    26482781
    2649                 $params  = array(
     2782                $params = array(
    26502783                        'content' => rand_long_str( 66525 ),
    26512784                );
     2785
    26522786                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    26532787
     
    27122846        public function test_comment_roundtrip_as_editor() {
    27132847                wp_set_current_user( self::$editor_id );
     2848
    27142849                $this->assertEquals( ! is_multisite(), current_user_can( 'unfiltered_html' ) );
    27152850                $this->verify_comment_roundtrip(
     
    27322867        public function test_comment_roundtrip_as_editor_unfiltered_html() {
    27332868                wp_set_current_user( self::$editor_id );
     2869
    27342870                if ( is_multisite() ) {
    27352871                        $this->assertFalse( current_user_can( 'unfiltered_html' ) );
     
    27712907        public function test_comment_roundtrip_as_superadmin() {
    27722908                wp_set_current_user( self::$superadmin_id );
     2909
    27732910                $this->assertTrue( current_user_can( 'unfiltered_html' ) );
    27742911                $this->verify_comment_roundtrip(
     
    27912928        public function test_comment_roundtrip_as_superadmin_unfiltered_html() {
    27922929                wp_set_current_user( self::$superadmin_id );
     2930
    27932931                $this->assertTrue( current_user_can( 'unfiltered_html' ) );
    27942932                $this->verify_comment_roundtrip(
     
    28322970                wp_set_current_user( self::$admin_id );
    28332971
    2834                 $comment_id       = $this->factory->comment->create(
     2972                $comment_id = $this->factory->comment->create(
    28352973                        array(
    28362974                                'comment_approved' => 1,
     
    28392977                        )
    28402978                );
     2979
    28412980                $request          = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    28422981                $request['force'] = true;
     
    28592998                        )
    28602999                );
    2861                 $request    = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
    2862                 $response   = rest_get_server()->dispatch( $request );
     3000
     3001                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
     3002                $response = rest_get_server()->dispatch( $request );
    28633003                $this->assertEquals( 200, $response->get_status() );
    28643004                $data     = $response->get_data();
     
    28703010                wp_set_current_user( self::$admin_id );
    28713011
    2872                 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    2873 
     3012                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
    28743013                $response = rest_get_server()->dispatch( $request );
    28753014                $this->assertErrorResponse( 'rest_comment_invalid_id', $response, 404 );
     
    28793018                wp_set_current_user( self::$subscriber_id );
    28803019
    2881                 $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    2882 
     3020                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    28833021                $response = rest_get_server()->dispatch( $request );
    28843022                $this->assertErrorResponse( 'rest_cannot_delete', $response, 403 );
     
    28873025        public function test_delete_child_comment_link() {
    28883026                wp_set_current_user( self::$admin_id );
     3027
    28893028                $comment_id_1 = $this->factory->comment->create(
    28903029                        array(
     
    29483087        public function test_get_item_schema_show_avatar() {
    29493088                update_option( 'show_avatars', false );
     3089
    29503090                $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    29513091                $response   = rest_get_server()->dispatch( $request );
     
    29753115                );
    29763116
    2977                 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    2978 
     3117                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments' );
    29793118                $response = rest_get_server()->dispatch( $request );
    29803119                $data     = $response->get_data();
     
    29833122                $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
    29843123
    2985                 $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id );
    2986 
     3124                $request  = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id );
    29873125                $response = rest_get_server()->dispatch( $request );
    29883126                $this->assertArrayHasKey( 'my_custom_int', $response->data );
Note: See TracChangeset for help on using the changeset viewer.