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-posts-controller.php

    r46648 r46657  
    2020
    2121        protected static $supported_formats;
     22        protected static $post_ids    = array();
     23        protected static $total_posts = 30;
     24        protected static $per_page    = 50;
    2225
    2326        protected $forbidden_cat;
     
    6265                self::$supported_formats = get_theme_support( 'post-formats' );
    6366                add_theme_support( 'post-formats', array( 'post', 'gallery' ) );
     67
     68                // Set up posts for pagination tests.
     69                for ( $i = 0; $i < self::$total_posts - 1; $i++ ) {
     70                        self::$post_ids[] = $factory->post->create(
     71                                array(
     72                                        'post_title' => "Post {$i}",
     73                                )
     74                        );
     75                }
    6476        }
    6577
     
    7082                } else {
    7183                        remove_theme_support( 'post-formats' );
     84                }
     85
     86                // Remove posts for pagination tests.
     87                foreach ( self::$post_ids as $post_id ) {
     88                        wp_delete_post( $post_id, true );
    7289                }
    7390
     
    204221
    205222                wp_set_current_user( self::$editor_id );
     223
    206224                $request  = new WP_REST_Request( 'OPTIONS', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    207225                $response = rest_get_server()->dispatch( $request );
     
    241259                $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
    242260                $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    243                 // All 3 posts
    244                 $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     261
     262                $total_posts = self::$total_posts + 2;
     263
     264                // All posts in the database.
     265                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     266                $request->set_param( 'per_page', self::$per_page );
    245267                $response = rest_get_server()->dispatch( $request );
    246268                $this->assertEquals( 200, $response->get_status() );
    247                 $this->assertEquals( 3, count( $response->get_data() ) );
    248                 // 2 of 3 posts
     269                $this->assertEquals( $total_posts, count( $response->get_data() ) );
     270
     271                // Limit to editor and author.
    249272                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    250273                $request->set_param( 'author', array( self::$editor_id, self::$author_id ) );
     
    254277                $this->assertEquals( 2, count( $data ) );
    255278                $this->assertEqualSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) );
    256                 // 1 of 3 posts
     279
     280                // Limit to editor.
    257281                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    258282                $request->set_param( 'author', self::$editor_id );
     
    267291                $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
    268292                $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    269                 // All 3 posts
    270                 $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     293
     294                $total_posts = self::$total_posts + 2;
     295
     296                // All posts in the database.
     297                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     298                $request->set_param( 'per_page', self::$per_page );
    271299                $response = rest_get_server()->dispatch( $request );
    272300                $this->assertEquals( 200, $response->get_status() );
    273                 $this->assertEquals( 3, count( $response->get_data() ) );
    274                 // 1 of 3 posts
    275                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     301                $this->assertEquals( $total_posts, count( $response->get_data() ) );
     302
     303                // Exclude editor and author.
     304                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     305                $request->set_param( 'per_page', self::$per_page );
    276306                $request->set_param( 'author_exclude', array( self::$editor_id, self::$author_id ) );
    277307                $response = rest_get_server()->dispatch( $request );
    278308                $this->assertEquals( 200, $response->get_status() );
    279309                $data = $response->get_data();
    280                 $this->assertEquals( 1, count( $data ) );
     310                $this->assertEquals( $total_posts - 2, count( $data ) );
    281311                $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
    282312                $this->assertNotEquals( self::$author_id, $data[0]['author'] );
    283                 // 2 of 3 posts
    284                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     313
     314                // Exclude editor.
     315                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     316                $request->set_param( 'per_page', self::$per_page );
    285317                $request->set_param( 'author_exclude', self::$editor_id );
    286318                $response = rest_get_server()->dispatch( $request );
    287319                $this->assertEquals( 200, $response->get_status() );
    288320                $data = $response->get_data();
    289                 $this->assertEquals( 2, count( $data ) );
     321                $this->assertEquals( $total_posts - 1, count( $data ) );
    290322                $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
    291323                $this->assertNotEquals( self::$editor_id, $data[1]['author'] );
    292                 // invalid author_exclude errors
     324
     325                // Invalid 'author_exclude' should error.
    293326                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    294327                $request->set_param( 'author_exclude', 'invalid' );
     
    299332        public function test_get_items_include_query() {
    300333                $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    301                 $this->factory->post->create( array( 'post_status' => 'publish' ) );
    302                 $id3     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    303                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    304                 // Orderby=>desc
    305                 $request->set_param( 'include', array( $id1, $id3 ) );
     334                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     335
     336                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     337
     338                // Order defaults to 'desc'.
     339                $request->set_param( 'include', array( $id1, $id2 ) );
    306340                $response = rest_get_server()->dispatch( $request );
    307341                $data     = $response->get_data();
    308342                $this->assertEquals( 2, count( $data ) );
    309                 $this->assertEquals( $id3, $data[0]['id'] );
     343                $this->assertEquals( $id2, $data[0]['id'] );
    310344                $this->assertPostsOrderedBy( '{posts}.post_date DESC' );
    311                 // Orderby=>include
     345
     346                // 'orderby' => 'include'
    312347                $request->set_param( 'orderby', 'include' );
    313348                $response = rest_get_server()->dispatch( $request );
     
    315350                $this->assertEquals( 2, count( $data ) );
    316351                $this->assertEquals( $id1, $data[0]['id'] );
    317                 $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id3)" );
    318                 // Invalid include should error
     352                $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id2)" );
     353
     354                // Invalid 'include' should error.
    319355                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    320356                $request->set_param( 'include', 'invalid' );
     
    421457
    422458        public function test_get_items_exclude_query() {
    423                 $id1      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    424                 $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     459                $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     460                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     461
    425462                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    426463                $response = rest_get_server()->dispatch( $request );
    427464                $data     = $response->get_data();
    428                 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    429                 $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     465                $ids      = wp_list_pluck( $data, 'id' );
     466                $this->assertTrue( in_array( $id1, $ids, true ) );
     467                $this->assertTrue( in_array( $id2, $ids, true ) );
    430468
    431469                $request->set_param( 'exclude', array( $id2 ) );
    432470                $response = rest_get_server()->dispatch( $request );
    433471                $data     = $response->get_data();
    434                 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    435                 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     472                $ids      = wp_list_pluck( $data, 'id' );
     473                $this->assertTrue( in_array( $id1, $ids, true ) );
     474                $this->assertFalse( in_array( $id2, $ids, true ) );
    436475
    437476                $request->set_param( 'exclude', "$id2" );
    438477                $response = rest_get_server()->dispatch( $request );
    439478                $data     = $response->get_data();
    440                 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    441                 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     479                $ids      = wp_list_pluck( $data, 'id' );
     480                $this->assertTrue( in_array( $id1, $ids, true ) );
     481                $this->assertFalse( in_array( $id2, $ids, true ) );
    442482
    443483                $request->set_param( 'exclude', 'invalid' );
     
    447487
    448488        public function test_get_items_search_query() {
    449                 for ( $i = 0;  $i < 5;  $i++ ) {
    450                         $this->factory->post->create( array( 'post_status' => 'publish' ) );
    451                 }
    452489                $this->factory->post->create(
    453490                        array(
     
    456493                        )
    457494                );
    458                 $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    459                 $response = rest_get_server()->dispatch( $request );
    460                 $this->assertEquals( 7, count( $response->get_data() ) );
     495                $total_posts = self::$total_posts + 1;
     496
     497                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     498                $request->set_param( 'per_page', self::$per_page );
     499                $response = rest_get_server()->dispatch( $request );
     500                $this->assertEquals( $total_posts, count( $response->get_data() ) );
     501
    461502                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    462503                $request->set_param( 'search', 'Search Result' );
     
    480521                        )
    481522                );
     523
    482524                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    483525                $request->set_param( 'slug', 'apple' );
     
    508550                        )
    509551                );
     552
    510553                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    511554                $request->set_param( 'slug', array( 'banana', 'peach' ) );
     
    541584                        )
    542585                );
     586
    543587                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    544588                $request->set_param( 'slug', 'apple,banana' );
     
    557601        public function test_get_items_status_query() {
    558602                wp_set_current_user( 0 );
     603
    559604                $this->factory->post->create( array( 'post_status' => 'draft' ) );
    560                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     605
     606                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     607                $request->set_param( 'per_page', self::$per_page );
    561608                $request->set_param( 'status', 'publish' );
    562609                $response = rest_get_server()->dispatch( $request );
    563610                $this->assertEquals( 200, $response->get_status() );
    564                 $this->assertEquals( 1, count( $response->get_data() ) );
     611                $this->assertEquals( self::$total_posts, count( $response->get_data() ) );
     612
    565613                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    566614                $request->set_param( 'status', 'draft' );
    567615                $response = rest_get_server()->dispatch( $request );
    568616                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    569                 wp_set_current_user( self::$editor_id );
     617
     618                wp_set_current_user( self::$editor_id );
     619
    570620                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    571621                $request->set_param( 'status', 'draft' );
     
    636686
    637687                wp_set_current_user( self::$private_reader_id );
     688
    638689                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    639690                $request->set_param( 'status', array( 'private', 'future' ) );
     
    645696        public function test_get_items_invalid_status_query() {
    646697                wp_set_current_user( 0 );
     698
    647699                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    648700                $request->set_param( 'status', 'invalid' );
     
    657709                        )
    658710                );
     711
    659712                wp_set_current_user( 0 );
    660713
     
    695748                        )
    696749                );
     750
    697751                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    698752                $request->set_param( 'search', 'Apple' );
    699                 // order defaults to 'desc'
     753
     754                // Order defaults to 'desc'.
    700755                $request->set_param( 'orderby', 'title' );
    701756                $response = rest_get_server()->dispatch( $request );
     
    703758                $this->assertEquals( 'Apple Sauce', $data[0]['title']['rendered'] );
    704759                $this->assertPostsOrderedBy( '{posts}.post_title DESC' );
    705                 // order=>asc
     760
     761                // 'order' => 'asc'.
    706762                $request->set_param( 'order', 'asc' );
    707763                $response = rest_get_server()->dispatch( $request );
     
    709765                $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] );
    710766                $this->assertPostsOrderedBy( '{posts}.post_title ASC' );
    711                 // order=>asc,id should fail
     767
     768                // 'order' => 'asc,id' should error.
    712769                $request->set_param( 'order', 'asc,id' );
    713770                $response = rest_get_server()->dispatch( $request );
    714771                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    715                 // orderby=>content should fail (invalid param test)
     772
     773                // 'orderby' => 'content' should error (invalid param test).
    716774                $request->set_param( 'order', 'asc' );
    717775                $request->set_param( 'orderby', 'content' );
     
    722780        public function test_get_items_with_orderby_include_without_include_param() {
    723781                $this->factory->post->create( array( 'post_status' => 'publish' ) );
     782
    724783                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    725784                $request->set_param( 'orderby', 'include' );
     
    818877
    819878        public function test_get_items_with_orderby_relevance() {
    820                 $id1     = $this->factory->post->create(
     879                $id1 = $this->factory->post->create(
    821880                        array(
    822881                                'post_title'   => 'Title is more relevant',
     
    825884                        )
    826885                );
    827                 $id2     = $this->factory->post->create(
     886                $id2 = $this->factory->post->create(
    828887                        array(
    829888                                'post_title'   => 'Title is',
     
    832891                        )
    833892                );
     893
    834894                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    835895                $request->set_param( 'orderby', 'relevance' );
     
    845905
    846906        public function test_get_items_with_orderby_relevance_two_terms() {
    847                 $id1     = $this->factory->post->create(
     907                $id1 = $this->factory->post->create(
    848908                        array(
    849909                                'post_title'   => 'Title is more relevant',
     
    852912                        )
    853913                );
    854                 $id2     = $this->factory->post->create(
     914                $id2 = $this->factory->post->create(
    855915                        array(
    856916                                'post_title'   => 'Title is',
     
    859919                        )
    860920                );
     921
    861922                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    862923                $request->set_param( 'orderby', 'relevance' );
     
    879940
    880941        public function test_get_items_offset_query() {
    881                 $id1     = self::$post_id;
    882                 $id2     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    883                 $id3     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    884                 $id4     = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    885                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     942                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     943                $request->set_param( 'per_page', self::$per_page );
    886944                $request->set_param( 'offset', 1 );
    887945                $response = rest_get_server()->dispatch( $request );
    888                 $this->assertCount( 3, $response->get_data() );
    889                 // 'offset' works with 'per_page'
     946                $this->assertCount( self::$total_posts - 1, $response->get_data() );
     947
     948                // 'offset' works with 'per_page'.
    890949                $request->set_param( 'per_page', 2 );
    891950                $response = rest_get_server()->dispatch( $request );
    892951                $this->assertCount( 2, $response->get_data() );
    893                 // 'offset' takes priority over 'page'
     952
     953                // 'offset' takes priority over 'page'.
    894954                $request->set_param( 'page', 2 );
    895955                $response = rest_get_server()->dispatch( $request );
    896956                $this->assertCount( 2, $response->get_data() );
    897                 // Invalid 'offset' should error
     957
     958                // Invalid 'offset' should error.
    898959                $request->set_param( 'offset', 'moreplease' );
    899960                $response = rest_get_server()->dispatch( $request );
     
    903964        public function test_get_items_tags_query() {
    904965                $id1 = self::$post_id;
    905                 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    906                 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    907                 $id4 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    908966                $tag = wp_insert_term( 'My Tag', 'post_tag' );
    909967
    910968                wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' );
     969
    911970                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    912971                $request->set_param( 'tags', array( $tag['term_id'] ) );
     
    925984                $tag = wp_insert_term( 'My Tag', 'post_tag' );
    926985
     986                $total_posts = self::$total_posts + 3;
     987
    927988                wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' );
    928                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     989
     990                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     991                $request->set_param( 'per_page', self::$per_page );
    929992                $request->set_param( 'tags_exclude', array( $tag['term_id'] ) );
    930993
    931994                $response = rest_get_server()->dispatch( $request );
    932995                $data     = $response->get_data();
    933                 $this->assertCount( 3, $data );
     996                $this->assertCount( $total_posts - 1, $data );
    934997                $this->assertEquals( $id4, $data[0]['id'] );
    935998                $this->assertEquals( $id3, $data[1]['id'] );
     
    9401003                $id1      = self::$post_id;
    9411004                $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    942                 $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    943                 $id4      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    9441005                $tag      = wp_insert_term( 'My Tag', 'post_tag' );
    9451006                $category = wp_insert_term( 'My Category', 'category' );
     
    9671028                $id1      = self::$post_id;
    9681029                $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    969                 $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    970                 $id4      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    9711030                $tag      = wp_insert_term( 'My Tag', 'post_tag' );
    9721031                $category = wp_insert_term( 'My Category', 'category' );
     
    9901049        public function test_get_items_tags_and_categories_exclude_query() {
    9911050                $id1      = self::$post_id;
     1051                $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     1052                $tag      = wp_insert_term( 'My Tag', 'post_tag' );
     1053                $category = wp_insert_term( 'My Category', 'category' );
     1054
     1055                wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' );
     1056                wp_set_object_terms( $id2, array( $tag['term_id'] ), 'post_tag' );
     1057                wp_set_object_terms( $id1, array( $category['term_id'] ), 'category' );
     1058
     1059                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1060                $request->set_param( 'tags', array( $tag['term_id'] ) );
     1061                $request->set_param( 'categories_exclude', array( $category['term_id'] ) );
     1062
     1063                $response = rest_get_server()->dispatch( $request );
     1064                $data     = $response->get_data();
     1065                $this->assertCount( 1, $data );
     1066                $this->assertEquals( $id2, $data[0]['id'] );
     1067
     1068                $request->set_param( 'tags_exclude', array( 'my-tag' ) );
     1069                $response = rest_get_server()->dispatch( $request );
     1070                $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     1071        }
     1072
     1073        /**
     1074         * @ticket 44326
     1075         */
     1076        public function test_get_items_tags_or_categories_exclude_query() {
     1077                $id1      = end( self::$post_ids );
    9921078                $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    9931079                $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    9961082                $category = wp_insert_term( 'My Category', 'category' );
    9971083
    998                 wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' );
    999                 wp_set_object_terms( $id2, array( $tag['term_id'] ), 'post_tag' );
    1000                 wp_set_object_terms( $id1, array( $category['term_id'] ), 'category' );
    1001 
    1002                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1003                 $request->set_param( 'tags', array( $tag['term_id'] ) );
    1004                 $request->set_param( 'categories_exclude', array( $category['term_id'] ) );
    1005 
    1006                 $response = rest_get_server()->dispatch( $request );
    1007                 $data     = $response->get_data();
    1008                 $this->assertCount( 1, $data );
    1009                 $this->assertEquals( $id2, $data[0]['id'] );
    1010 
    1011                 $request->set_param( 'tags_exclude', array( 'my-tag' ) );
    1012                 $response = rest_get_server()->dispatch( $request );
    1013                 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    1014         }
    1015 
    1016         /**
    1017          * @ticket 44326
    1018          */
    1019         public function test_get_items_tags_or_categories_exclude_query() {
    1020                 $id1      = self::$post_id;
    1021                 $id2      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    1022                 $id3      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    1023                 $id4      = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    1024                 $tag      = wp_insert_term( 'My Tag', 'post_tag' );
    1025                 $category = wp_insert_term( 'My Category', 'category' );
     1084                $total_posts = self::$total_posts + 3;
    10261085
    10271086                wp_set_object_terms( $id1, array( $tag['term_id'] ), 'post_tag' );
     
    10311090
    10321091                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1092                $request->set_param( 'per_page', self::$per_page );
    10331093                $request->set_param( 'tags', array( $tag['term_id'] ) );
    10341094                $request->set_param( 'categories_exclude', array( $category['term_id'] ) );
     
    10381098                $response = rest_get_server()->dispatch( $request );
    10391099                $data     = $response->get_data();
    1040                 $this->assertCount( 3, $data );
     1100                $this->assertCount( $total_posts - 1, $data );
    10411101                $this->assertEquals( $id4, $data[0]['id'] );
    10421102                $this->assertEquals( $id2, $data[1]['id'] );
     
    10821142                $id1 = self::$post_id;
    10831143                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    1084                 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    10851144
    10861145                update_option( 'sticky_posts', array( $id2 ) );
     
    11171176
    11181177        public function test_get_items_sticky_no_sticky_posts() {
    1119                 $id1 = self::$post_id;
    1120 
    11211178                update_option( 'sticky_posts', array() );
    11221179
     
    11541211
    11551212        public function test_get_items_not_sticky() {
    1156                 $id1 = self::$post_id;
     1213                $id1 = end( self::$post_ids );
    11571214                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    11581215
     1216                $total_posts = self::$total_posts + 1;
     1217
    11591218                update_option( 'sticky_posts', array( $id2 ) );
    11601219
    11611220                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1221                $request->set_param( 'per_page', self::$per_page );
    11621222                $request->set_param( 'sticky', false );
    11631223
    11641224                $response = rest_get_server()->dispatch( $request );
    1165                 $this->assertCount( 1, $response->get_data() );
     1225                $this->assertCount( $total_posts - 1, $response->get_data() );
    11661226
    11671227                $posts = $response->get_data();
     
    11731233
    11741234        public function test_get_items_not_sticky_with_exclude() {
    1175                 $id1 = self::$post_id;
     1235                $id1 = end( self::$post_ids );
    11761236                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    11771237                $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    11781238
     1239                $total_posts = self::$total_posts + 2;
     1240
    11791241                update_option( 'sticky_posts', array( $id2 ) );
    11801242
    11811243                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1244                $request->set_param( 'per_page', self::$per_page );
    11821245                $request->set_param( 'sticky', false );
    11831246                $request->set_param( 'exclude', array( $id3 ) );
    11841247
    11851248                $response = rest_get_server()->dispatch( $request );
    1186                 $this->assertCount( 1, $response->get_data() );
     1249                $this->assertCount( $total_posts - 2, $response->get_data() );
    11871250
    11881251                $posts = $response->get_data();
    1189                 $post  = $posts[0];
    1190                 $this->assertEquals( $id1, $post['id'] );
     1252                $ids   = wp_list_pluck( $posts, 'id' );
     1253                $this->assertTrue( in_array( $id1, $ids, true ) );
     1254                $this->assertFalse( in_array( $id2, $ids, true ) );
     1255                $this->assertFalse( in_array( $id3, $ids, true ) );
    11911256
    11921257                $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3,$id2) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" );
     
    11981263                $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    11991264
     1265                $total_posts = self::$total_posts + 2;
     1266
    12001267                update_option( 'sticky_posts', array() );
    12011268
    12021269                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1270                $request->set_param( 'per_page', self::$per_page );
    12031271                $request->set_param( 'sticky', false );
    12041272                $request->set_param( 'exclude', array( $id3 ) );
    12051273
    12061274                $response = rest_get_server()->dispatch( $request );
    1207                 $this->assertCount( 2, $response->get_data() );
     1275                $this->assertCount( $total_posts - 1, $response->get_data() );
    12081276
    12091277                $posts = $response->get_data();
    12101278                $ids   = wp_list_pluck( $posts, 'id' );
    1211                 sort( $ids );
    1212                 $this->assertEquals( array( $id1, $id2 ), $ids );
     1279                $this->assertTrue( in_array( $id1, $ids, true ) );
     1280                $this->assertTrue( in_array( $id2, $ids, true ) );
     1281                $this->assertFalse( in_array( $id3, $ids, true ) );
    12131282
    12141283                $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" );
     
    12161285
    12171286        public function test_get_items_pagination_headers() {
    1218                 // Start of the index
    1219                 for ( $i = 0; $i < 49; $i++ ) {
    1220                         $this->factory->post->create(
    1221                                 array(
    1222                                         'post_title' => "Post {$i}",
    1223                                 )
    1224                         );
    1225                 }
     1287                $total_posts = self::$total_posts;
     1288                $total_pages = (int) ceil( $total_posts / 10 );
     1289
     1290                // Start of the index.
    12261291                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12271292                $response = rest_get_server()->dispatch( $request );
    12281293                $headers  = $response->get_headers();
    1229                 $this->assertEquals( 50, $headers['X-WP-Total'] );
    1230                 $this->assertEquals( 5, $headers['X-WP-TotalPages'] );
     1294                $this->assertEquals( $total_posts, $headers['X-WP-Total'] );
     1295                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    12311296                $next_link = add_query_arg(
    12321297                        array(
     
    12371302                $this->assertFalse( stripos( $headers['Link'], 'rel="prev"' ) );
    12381303                $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    1239                 // 3rd page
    1240                 $this->factory->post->create(
    1241                         array(
    1242                                 'post_title' => 'Post 51',
    1243                         )
    1244                 );
     1304
     1305                // 3rd page.
     1306                $this->factory->post->create();
     1307                $total_posts++;
     1308                $total_pages++;
    12451309                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12461310                $request->set_param( 'page', 3 );
    12471311                $response = rest_get_server()->dispatch( $request );
    12481312                $headers  = $response->get_headers();
    1249                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    1250                 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
     1313                $this->assertEquals( $total_posts, $headers['X-WP-Total'] );
     1314                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    12511315                $prev_link = add_query_arg(
    12521316                        array(
     
    12631327                );
    12641328                $this->assertContains( '<' . $next_link . '>; rel="next"', $headers['Link'] );
    1265                 // Last page
    1266                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1267                 $request->set_param( 'page', 6 );
     1329
     1330                // Last page.
     1331                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1332                $request->set_param( 'page', $total_pages );
    12681333                $response = rest_get_server()->dispatch( $request );
    12691334                $headers  = $response->get_headers();
    1270                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    1271                 $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
     1335                $this->assertEquals( $total_posts, $headers['X-WP-Total'] );
     1336                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    12721337                $prev_link = add_query_arg(
    12731338                        array(
    1274                                 'page' => 5,
     1339                                'page' => $total_pages - 1,
    12751340                        ),
    12761341                        rest_url( '/wp/v2/posts' )
     
    12791344                $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
    12801345
    1281                 // Out of bounds
    1282                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    1283                 $request->set_param( 'page', 8 );
     1346                // Out of bounds.
     1347                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1348                $request->set_param( 'page', 100 );
    12841349                $response = rest_get_server()->dispatch( $request );
    12851350                $headers  = $response->get_headers();
     
    12871352
    12881353                // With query params.
    1289                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     1354                $total_pages = (int) ceil( $total_posts / 5 );
     1355                $request     = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    12901356                $request->set_query_params(
    12911357                        array(
     
    12961362                $response = rest_get_server()->dispatch( $request );
    12971363                $headers  = $response->get_headers();
    1298                 $this->assertEquals( 51, $headers['X-WP-Total'] );
    1299                 $this->assertEquals( 11, $headers['X-WP-TotalPages'] );
     1364                $this->assertEquals( $total_posts, $headers['X-WP-Total'] );
     1365                $this->assertEquals( $total_pages, $headers['X-WP-TotalPages'] );
    13001366                $prev_link = add_query_arg(
    13011367                        array(
     
    13211387                // Drafts status query var inaccessible to unauthorized users.
    13221388                wp_set_current_user( 0 );
     1389
    13231390                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    13241391                $request->set_param( 'status', 'draft' );
     
    13281395                // Users with 'read_private_posts' cap shouldn't also be able to view drafts.
    13291396                wp_set_current_user( self::$private_reader_id );
     1397
    13301398                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    13311399                $request->set_param( 'status', 'draft' );
     
    13351403                // But drafts are accessible to authorized users.
    13361404                wp_set_current_user( self::$editor_id );
    1337                 $response = rest_get_server()->dispatch( $request );
    1338                 $data     = $response->get_data();
    1339 
     1405
     1406                $response = rest_get_server()->dispatch( $request );
     1407                $data     = $response->get_data();
    13401408                $this->assertEquals( $draft_id, $data[0]['id'] );
    13411409        }
     
    13481416
    13491417                wp_set_current_user( 0 );
     1418
    13501419                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    13511420                $request->set_param( 'status', 'private' );
     
    13541423
    13551424                wp_set_current_user( self::$private_reader_id );
     1425
    13561426                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    13571427                $request->set_param( 'status', 'private' );
     
    15211591                        )
    15221592                );
     1593
    15231594                wp_set_current_user( 0 );
    15241595
     
    15531624        public function test_get_post_list_context_without_permission() {
    15541625                wp_set_current_user( 0 );
     1626
    15551627                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    15561628                $request->set_query_params(
     
    15661638        public function test_get_post_context_without_permission() {
    15671639                wp_set_current_user( 0 );
     1640
    15681641                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15691642                $request->set_query_params(
     
    16051678                );
    16061679
    1607                 $post    = get_post( $post_id );
     1680                $post = get_post( $post_id );
     1681
    16081682                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    16091683                $request->set_param( 'password', '$inthebananastand' );
     
    16261700                );
    16271701
    1628                 $post    = get_post( $post_id );
     1702                $post = get_post( $post_id );
     1703
    16291704                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    16301705                $request->set_param( 'password', 'wrongpassword' );
     
    16351710
    16361711        public function test_get_post_with_password_without_permission() {
    1637                 $post_id  = $this->factory->post->create(
     1712                $post_id = $this->factory->post->create(
    16381713                        array(
    16391714                                'post_password' => '$inthebananastand',
     
    16421717                        )
    16431718                );
     1719
    16441720                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    16451721                $response = rest_get_server()->dispatch( $request );
     
    17041780                        )
    17051781                );
     1782
    17061783                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
    17071784                $request->set_param( 'context', 'edit' );
     
    17141791                register_post_status( 'testpubstatus', array( 'public' => true ) );
    17151792                register_post_status( 'testprivtatus', array( 'public' => false ) );
    1716                 // Public status
     1793
     1794                // Public status.
    17171795                wp_update_post(
    17181796                        array(
     
    17211799                        )
    17221800                );
     1801
    17231802                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    17241803                $response = rest_get_server()->dispatch( $request );
    17251804                $this->assertEquals( 200, $response->get_status() );
    1726                 // Private status
     1805
     1806                // Private status.
    17271807                wp_update_post(
    17281808                        array(
     
    17311811                        )
    17321812                );
     1813
    17331814                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    17341815                $response = rest_get_server()->dispatch( $request );
     
    17481829        public function test_prepare_item_limit_fields() {
    17491830                wp_set_current_user( self::$editor_id );
     1831
    17501832                $endpoint = new WP_REST_Posts_Controller( 'post' );
    17511833                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     
    17751857
    17761858                wp_set_current_user( self::$editor_id );
     1859
    17771860                $endpoint = new WP_REST_Posts_Controller( 'post' );
    1778                 $request  = new WP_REST_REQUEST( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1861                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    17791862
    17801863                $request->set_param( 'context', 'edit' );
     
    18101893
    18111894                wp_set_current_user( self::$editor_id );
     1895
    18121896                $endpoint = new WP_REST_Posts_Controller( 'post' );
    1813                 $request  = new WP_REST_REQUEST( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1897                $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    18141898
    18151899                $request->set_param( 'context', 'edit' );
     
    19202004        public function test_create_post_date( $status, $params, $results ) {
    19212005                wp_set_current_user( self::$editor_id );
     2006
    19222007                update_option( 'timezone_string', $params['timezone_string'] );
    19232008
     
    19532038        public function test_create_item_with_template() {
    19542039                wp_set_current_user( self::$editor_id );
     2040
    19552041                add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
    19562042
     
    20022088        public function test_create_item_with_template_none() {
    20032089                wp_set_current_user( self::$editor_id );
     2090
    20042091                add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
    20052092                update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' );
     
    20502137        public function test_create_post_as_contributor() {
    20512138                wp_set_current_user( self::$contributor_id );
     2139
    20522140                update_option( 'timezone_string', 'America/Chicago' );
    20532141
     
    21832271        public function test_create_post_private_without_permission() {
    21842272                wp_set_current_user( self::$author_id );
     2273
    21852274                $user = wp_get_current_user();
    21862275                $user->add_cap( 'publish_posts', false );
     
    22042293        public function test_create_post_publish_without_permission() {
    22052294                wp_set_current_user( self::$author_id );
     2295
    22062296                $user = wp_get_current_user();
    22072297                $user->add_cap( 'publish_posts', false );
     
    24092499
    24102500                $data = $response->get_data();
    2411 
    24122501                $this->assertEquals( '0', $data['password'] );
    24132502        }
     
    25522641                $request->set_body_params( $params );
    25532642                $response = rest_get_server()->dispatch( $request );
    2554                 $new_data = $response->get_data();
    2555                 $this->assertEquals( "Rob O'Rourke's Diary", $new_data['title']['raw'] );
     2643
     2644                $data = $response->get_data();
     2645                $this->assertEquals( "Rob O'Rourke's Diary", $data['title']['raw'] );
    25562646        }
    25572647
    25582648        public function test_create_post_with_categories() {
    25592649                wp_set_current_user( self::$editor_id );
     2650
    25602651                $category = wp_insert_term( 'Test Category', 'category' );
    2561                 $request  = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    2562                 $params   = $this->set_post_data(
     2652
     2653                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     2654                $params  = $this->set_post_data(
    25632655                        array(
    25642656                                'password'   => 'testing',
     
    25772669        public function test_create_post_with_categories_as_csv() {
    25782670                wp_set_current_user( self::$editor_id );
     2671
    25792672                $category  = wp_insert_term( 'Chicken', 'category' );
    25802673                $category2 = wp_insert_term( 'Ribs', 'category' );
    2581                 $request   = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    2582                 $params    = $this->set_post_data(
     2674
     2675                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     2676                $params  = $this->set_post_data(
    25832677                        array(
    25842678                                'categories' => $category['term_id'] . ',' . $category2['term_id'],
     
    25942688        public function test_create_post_with_invalid_categories() {
    25952689                wp_set_current_user( self::$editor_id );
     2690
    25962691                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    25972692                $params  = $this->set_post_data(
     
    26182713
    26192714                wp_set_current_user( self::$editor_id );
     2715
    26202716                $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    26212717                $params  = $this->set_post_data(
     
    26642760        public function test_update_item_no_change() {
    26652761                wp_set_current_user( self::$editor_id );
     2762
    26662763                $post = get_post( self::$post_id );
    26672764
     
    27092806                // Create a new test post.
    27102807                $post_id = $this->factory->post->create();
     2808
    27112809                wp_set_current_user( self::$editor_id );
    27122810
    27132811                // Set the post date to the future.
    27142812                $future_date = '2919-07-29T18:00:00';
    2715                 $request     = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
     2813
     2814                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $post_id ) );
    27162815                $request->add_header( 'content-type', 'application/json' );
    27172816                $params = $this->set_post_data(
     
    27972896        public function test_update_post_without_permission() {
    27982897                wp_set_current_user( self::$editor_id );
     2898
    27992899                $user = wp_get_current_user();
    28002900                $user->add_cap( 'edit_published_posts', false );
     
    29513051        public function test_update_post_date( $status, $params, $results ) {
    29523052                wp_set_current_user( self::$editor_id );
     3053
    29533054                update_option( 'timezone_string', $params['timezone_string'] );
    29543055
     
    30133114
    30143115                wp_set_current_user( self::$editor_id );
     3116
    30153117                update_option( 'timezone_string', 'America/Chicago' );
    30163118
     
    31913293        public function test_update_post_with_empty_password() {
    31923294                wp_set_current_user( self::$editor_id );
     3295
    31933296                wp_update_post(
    31943297                        array(
     
    32813384
    32823385        public function test_update_post_with_categories() {
    3283 
    3284                 wp_set_current_user( self::$editor_id );
     3386                wp_set_current_user( self::$editor_id );
     3387
    32853388                $category = wp_insert_term( 'Test Category', 'category' );
    32863389
     
    33073410                $query = parse_url( $categories_path, PHP_URL_QUERY );
    33083411                parse_str( $query, $args );
     3412
    33093413                $request = new WP_REST_Request( 'GET', $args['rest_route'] );
    33103414                unset( $args['rest_route'] );
     
    33173421
    33183422        public function test_update_post_with_empty_categories() {
    3319 
    3320                 wp_set_current_user( self::$editor_id );
     3423                wp_set_current_user( self::$editor_id );
     3424
    33213425                $category = wp_insert_term( 'Test Category', 'category' );
    33223426                wp_set_object_terms( self::$post_id, $category['term_id'], 'category' );
     
    33433447
    33443448                wp_set_current_user( self::$editor_id );
     3449
    33453450                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    33463451                $params  = $this->set_post_data(
     
    33643469        public function test_update_item_with_template() {
    33653470                wp_set_current_user( self::$editor_id );
     3471
    33663472                add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
    33673473
     
    33933499        public function test_update_item_with_template_none() {
    33943500                wp_set_current_user( self::$editor_id );
     3501
    33953502                add_filter( 'theme_post_templates', array( $this, 'filter_theme_post_templates' ) );
    33963503                update_post_meta( self::$post_id, '_wp_page_template', 'post-my-test-template.php' );
     
    34253532         */
    34263533        public function test_update_item_with_same_template_that_no_longer_exists() {
    3427 
    34283534                wp_set_current_user( self::$editor_id );
    34293535
     
    35983704        public function test_post_roundtrip_as_author( $raw, $expected ) {
    35993705                wp_set_current_user( self::$author_id );
     3706
    36003707                $this->assertFalse( current_user_can( 'unfiltered_html' ) );
    36013708                $this->verify_post_roundtrip( $raw, $expected );
     
    36043711        public function test_post_roundtrip_as_editor_unfiltered_html() {
    36053712                wp_set_current_user( self::$editor_id );
     3713
    36063714                if ( is_multisite() ) {
    36073715                        $this->assertFalse( current_user_can( 'unfiltered_html' ) );
     
    36553763        public function test_post_roundtrip_as_superadmin_unfiltered_html() {
    36563764                wp_set_current_user( self::$superadmin_id );
     3765
    36573766                $this->assertTrue( current_user_can( 'unfiltered_html' ) );
    36583767                $this->verify_post_roundtrip(
     
    36813790        public function test_delete_item() {
    36823791                $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
     3792
    36833793                wp_set_current_user( self::$editor_id );
    36843794
     
    36953805        public function test_delete_item_skip_trash() {
    36963806                $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
     3807
    36973808                wp_set_current_user( self::$editor_id );
    36983809
     
    37093820        public function test_delete_item_already_trashed() {
    37103821                $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
    3711                 wp_set_current_user( self::$editor_id );
     3822
     3823                wp_set_current_user( self::$editor_id );
     3824
    37123825                $request  = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    37133826                $response = rest_get_server()->dispatch( $request );
     
    37283841        public function test_delete_post_invalid_post_type() {
    37293842                $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     3843
    37303844                wp_set_current_user( self::$editor_id );
    37313845
     
    39464060                );
    39474061
    3948                 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    3949 
     4062                $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
    39504063                $response = rest_get_server()->dispatch( $request );
    39514064                $data     = $response->get_data();
     
    39584071                $post_id = $this->factory->post->create();
    39594072
    3960                 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    3961 
     4073                $request  = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    39624074                $response = rest_get_server()->dispatch( $request );
    39634075                $this->assertArrayHasKey( 'my_custom_int', $response->data );
     
    40444156
    40454157                wp_set_current_user( self::$editor_id );
     4158
    40464159                // Check for error on update.
    40474160                $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     
    40724185
    40734186        public function test_publish_action_ldo_registered() {
    4074 
    40754187                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
    40764188                $data     = $response->get_data();
     
    40844196
    40854197        public function test_sticky_action_ldo_registered_for_posts() {
    4086 
    40874198                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
    40884199                $data     = $response->get_data();
     
    40964207
    40974208        public function test_sticky_action_ldo_not_registered_for_non_posts() {
    4098 
    40994209                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ) );
    41004210                $data     = $response->get_data();
     
    41084218
    41094219        public function test_author_action_ldo_registered_for_post_types_with_author_support() {
    4110 
    41114220                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
    41124221                $data     = $response->get_data();
     
    41204229
    41214230        public function test_author_action_ldo_not_registered_for_post_types_without_author_support() {
    4122 
    41234231                remove_post_type_support( 'post', 'author' );
    41244232
     
    41404248
    41414249        public function test_term_action_ldos_registered() {
    4142 
    41434250                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
    41444251                $data     = $response->get_data();
     
    41604267
    41614268        public function test_action_links_only_available_in_edit_context() {
    4162 
    41634269                wp_set_current_user( self::$author_id );
    41644270
     
    41764282
    41774283        public function test_publish_action_link_exists_for_author() {
    4178 
    41794284                wp_set_current_user( self::$author_id );
    41804285
     
    41924297
    41934298        public function test_publish_action_link_does_not_exist_for_contributor() {
    4194 
    41954299                wp_set_current_user( self::$contributor_id );
    41964300
     
    42084312
    42094313        public function test_sticky_action_exists_for_editor() {
    4210 
    42114314                wp_set_current_user( self::$editor_id );
    42124315
     
    42244327
    42254328        public function test_sticky_action_does_not_exist_for_author() {
    4226 
    42274329                wp_set_current_user( self::$author_id );
    42284330
     
    42404342
    42414343        public function test_sticky_action_does_not_exist_for_non_post_posts() {
    4242 
    42434344                wp_set_current_user( self::$editor_id );
    42444345
     
    42624363
    42634364        public function test_assign_author_action_exists_for_editor() {
    4264 
    42654365                wp_set_current_user( self::$editor_id );
    42664366
     
    42784378
    42794379        public function test_assign_author_action_does_not_exist_for_author() {
    4280 
    42814380                wp_set_current_user( self::$author_id );
    42824381
     
    42944393
    42954394        public function test_assign_author_action_does_not_exist_for_post_types_without_author_support() {
    4296 
    42974395                remove_post_type_support( 'post', 'author' );
    42984396
     
    43124410
    43134411        public function test_create_term_action_exists_for_editor() {
    4314 
    43154412                wp_set_current_user( self::$editor_id );
    43164413
     
    43304427
    43314428        public function test_create_term_action_non_hierarchical_exists_for_author() {
    4332 
    43334429                wp_set_current_user( self::$author_id );
    43344430
     
    43464442
    43474443        public function test_create_term_action_hierarchical_does_not_exists_for_author() {
    4348 
    43494444                wp_set_current_user( self::$author_id );
    43504445
     
    43624457
    43634458        public function test_assign_term_action_exists_for_contributor() {
    4364 
    43654459                wp_set_current_user( self::$contributor_id );
    43664460
     
    43854479        public function test_assign_unfiltered_html_action_superadmin() {
    43864480                $post_id = self::factory()->post->create();
     4481
    43874482                wp_set_current_user( self::$superadmin_id );
     4483
    43884484                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    43894485                $request->set_param( 'context', 'edit' );
     
    43954491        public function test_assign_unfiltered_html_action_editor() {
    43964492                $post_id = self::factory()->post->create();
    4397                 wp_set_current_user( self::$editor_id );
     4493
     4494                wp_set_current_user( self::$editor_id );
     4495
    43984496                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    43994497                $request->set_param( 'context', 'edit' );
     
    44104508        public function test_assign_unfiltered_html_action_author() {
    44114509                $post_id = self::factory()->post->create();
     4510
    44124511                wp_set_current_user( self::$author_id );
     4512
    44134513                $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id );
    44144514                $request->set_param( 'context', 'edit' );
     
    44914591         */
    44924592        public function test_putting_same_publish_date_does_not_remove_floating_date() {
    4493 
    44944593                wp_set_current_user( self::$superadmin_id );
    44954594
     
    45274626         */
    45284627        public function test_putting_different_publish_date_removes_floating_date() {
    4529 
    45304628                wp_set_current_user( self::$superadmin_id );
    45314629
     
    45704668         */
    45714669        public function test_publishing_post_with_same_date_removes_floating_date() {
    4572 
    45734670                wp_set_current_user( self::$superadmin_id );
    45744671
Note: See TracChangeset for help on using the changeset viewer.