WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/27/2016 02:56:28 AM (5 years ago)
Author:
boonebgorges
Message:

Share fixtures in REST API endpoint tests.

As sparrows' tears shed steadily
Make widest rivers filled,

setUp() routines run prodig'ly
Add minutes to a build.

So cull ye fixtures profligate!
Direct thine frugal gaze!

Our savings here - a half-minute -
When multiplied: Amaze!

See #30017.

File:
1 edited

Legend:

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

    r38968 r38975  
    1111 */
    1212class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Testcase {
     13    protected static $post_id;
     14
     15    protected static $editor_id;
     16    protected static $author_id;
     17    protected static $contributor_id;
     18
     19    public static function wpSetUpBeforeClass( $factory ) {
     20        self::$post_id = $factory->post->create();
     21
     22        self::$editor_id = $factory->user->create( array(
     23            'role' => 'editor',
     24        ) );
     25        self::$author_id = $factory->user->create( array(
     26            'role' => 'author',
     27        ) );
     28        self::$contributor_id = $factory->user->create( array(
     29            'role' => 'contributor',
     30        ) );
     31    }
     32
     33    public static function wpTearDownAfterClass() {
     34        wp_delete_post( self::$post_id, true );
     35
     36        self::delete_user( self::$editor_id );
     37        self::delete_user( self::$author_id );
     38        self::delete_user( self::$contributor_id );
     39    }
    1340
    1441    public function setUp() {
    1542        parent::setUp();
    16 
    17         $this->post_id = $this->factory->post->create();
    18 
    19         $this->editor_id = $this->factory->user->create( array(
    20             'role' => 'editor',
    21         ) );
    22         $this->author_id = $this->factory->user->create( array(
    23             'role' => 'author',
    24         ) );
    25         $this->contributor_id = $this->factory->user->create( array(
    26             'role' => 'contributor',
    27         ) );
    28 
    2943        register_post_type( 'youseeme', array( 'supports' => array(), 'show_in_rest' => true ) );
    3044    }
     
    4761        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    4862        // Single
    49         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . $this->post_id );
     63        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts/' . self::$post_id );
    5064        $response = $this->server->dispatch( $request );
    5165        $data = $response->get_data();
     
    106120
    107121    public function test_get_items_author_query() {
    108         $this->factory->post->create( array( 'post_author' => $this->editor_id ) );
    109         $this->factory->post->create( array( 'post_author' => $this->author_id ) );
     122        $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
     123        $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    110124        // All 3 posts
    111125        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    115129        // 2 of 3 posts
    116130        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    117         $request->set_param( 'author', array( $this->editor_id, $this->author_id ) );
     131        $request->set_param( 'author', array( self::$editor_id, self::$author_id ) );
    118132        $response = $this->server->dispatch( $request );
    119133        $this->assertEquals( 200, $response->get_status() );
    120134        $data = $response->get_data();
    121135        $this->assertEquals( 2, count( $data ) );
    122         $this->assertEqualSets( array( $this->editor_id, $this->author_id ), wp_list_pluck( $data, 'author' ) );
     136        $this->assertEqualSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) );
    123137        // 1 of 3 posts
    124138        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    125         $request->set_param( 'author', $this->editor_id );
     139        $request->set_param( 'author', self::$editor_id );
    126140        $response = $this->server->dispatch( $request );
    127141        $this->assertEquals( 200, $response->get_status() );
    128142        $data = $response->get_data();
    129143        $this->assertEquals( 1, count( $data ) );
    130         $this->assertEquals( $this->editor_id, $data[0]['author'] );
     144        $this->assertEquals( self::$editor_id, $data[0]['author'] );
    131145    }
    132146
    133147    public function test_get_items_author_exclude_query() {
    134         $this->factory->post->create( array( 'post_author' => $this->editor_id ) );
    135         $this->factory->post->create( array( 'post_author' => $this->author_id ) );
     148        $this->factory->post->create( array( 'post_author' => self::$editor_id ) );
     149        $this->factory->post->create( array( 'post_author' => self::$author_id ) );
    136150        // All 3 posts
    137151        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    141155        // 1 of 3 posts
    142156        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    143         $request->set_param( 'author_exclude', array( $this->editor_id, $this->author_id ) );
     157        $request->set_param( 'author_exclude', array( self::$editor_id, self::$author_id ) );
    144158        $response = $this->server->dispatch( $request );
    145159        $this->assertEquals( 200, $response->get_status() );
    146160        $data = $response->get_data();
    147161        $this->assertEquals( 1, count( $data ) );
    148         $this->assertNotEquals( $this->editor_id, $data[0]['author'] );
    149         $this->assertNotEquals( $this->author_id, $data[0]['author'] );
     162        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
     163        $this->assertNotEquals( self::$author_id, $data[0]['author'] );
    150164        // 2 of 3 posts
    151165        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    152         $request->set_param( 'author_exclude', $this->editor_id );
     166        $request->set_param( 'author_exclude', self::$editor_id );
    153167        $response = $this->server->dispatch( $request );
    154168        $this->assertEquals( 200, $response->get_status() );
    155169        $data = $response->get_data();
    156170        $this->assertEquals( 2, count( $data ) );
    157         $this->assertNotEquals( $this->editor_id, $data[0]['author'] );
    158         $this->assertNotEquals( $this->editor_id, $data[1]['author'] );
     171        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
     172        $this->assertNotEquals( self::$editor_id, $data[1]['author'] );
    159173    }
    160174
     
    233247        $response = $this->server->dispatch( $request );
    234248        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    235         wp_set_current_user( $this->editor_id );
     249        wp_set_current_user( self::$editor_id );
    236250        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
    237251        $request->set_param( 'status', 'draft' );
     
    306320        $response = $this->server->dispatch( $request );
    307321        $data = $response->get_data();
    308         $this->assertEquals( array( $this->post_id, $post_id3, $post_id2, $post_id1 ), wp_list_pluck( $data, 'id' ) );
     322        $this->assertEquals( array( self::$post_id, $post_id3, $post_id2, $post_id1 ), wp_list_pluck( $data, 'id' ) );
    309323
    310324        // Permit stickies
     
    313327        $response = $this->server->dispatch( $request );
    314328        $data = $response->get_data();
    315         $this->assertEquals( array( $post_id2, $this->post_id, $post_id3, $post_id1 ), wp_list_pluck( $data, 'id' ) );
     329        $this->assertEquals( array( $post_id2, self::$post_id, $post_id3, $post_id1 ), wp_list_pluck( $data, 'id' ) );
    316330    }
    317331
    318332    public function test_get_items_offset_query() {
    319         $id1 = $this->post_id;
     333        $id1 = self::$post_id;
    320334        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    321335        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    336350
    337351    public function test_get_items_tags_query() {
    338         $id1 = $this->post_id;
     352        $id1 = self::$post_id;
    339353        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    340354        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    353367
    354368    public function test_get_items_tags_exclude_query() {
    355         $id1 = $this->post_id;
     369        $id1 = self::$post_id;
    356370        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    357371        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    372386
    373387    public function test_get_items_tags_and_categories_query() {
    374         $id1 = $this->post_id;
     388        $id1 = self::$post_id;
    375389        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    376390        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    392406
    393407    public function test_get_items_tags_and_categories_exclude_query() {
    394         $id1 = $this->post_id;
     408        $id1 = self::$post_id;
    395409        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    396410        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    414428
    415429    public function test_get_items_sticky_query() {
    416         $id1 = $this->post_id;
     430        $id1 = self::$post_id;
    417431        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    418432
     
    431445
    432446    public function test_get_items_sticky_with_post__in_query() {
    433         $id1 = $this->post_id;
     447        $id1 = self::$post_id;
    434448        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    435449        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    460474
    461475    public function test_get_items_not_sticky_query() {
    462         $id1 = $this->post_id;
     476        $id1 = self::$post_id;
    463477        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    464478
     
    477491
    478492    public function test_get_items_sticky_with_post__not_in_query() {
    479         $id1 = $this->post_id;
     493        $id1 = self::$post_id;
    480494        $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
    481495        $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) );
     
    587601
    588602        // But they are accessible to authorized users
    589         wp_set_current_user( $this->editor_id );
     603        wp_set_current_user( self::$editor_id );
    590604        $response = $this->server->dispatch( $request );
    591605        $data = $response->get_data();
     
    631645
    632646    public function test_get_item() {
    633         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     647        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    634648        $response = $this->server->dispatch( $request );
    635649
     
    638652
    639653    public function test_get_item_links() {
    640         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     654        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    641655        $response = $this->server->dispatch( $request );
    642656
    643657        $links = $response->get_links();
    644658
    645         $this->assertEquals( rest_url( '/wp/v2/posts/' . $this->post_id ), $links['self'][0]['href'] );
     659        $this->assertEquals( rest_url( '/wp/v2/posts/' . self::$post_id ), $links['self'][0]['href'] );
    646660        $this->assertEquals( rest_url( '/wp/v2/posts' ), $links['collection'][0]['href'] );
    647661
    648         $this->assertEquals( rest_url( '/wp/v2/types/' . get_post_type( $this->post_id ) ), $links['about'][0]['href'] );
     662        $this->assertEquals( rest_url( '/wp/v2/types/' . get_post_type( self::$post_id ) ), $links['about'][0]['href'] );
    649663
    650664        $replies_url = rest_url( '/wp/v2/comments' );
    651         $replies_url = add_query_arg( 'post', $this->post_id, $replies_url );
     665        $replies_url = add_query_arg( 'post', self::$post_id, $replies_url );
    652666        $this->assertEquals( $replies_url, $links['replies'][0]['href'] );
    653667
    654         $this->assertEquals( rest_url( '/wp/v2/posts/' . $this->post_id . '/revisions' ), $links['version-history'][0]['href'] );
     668        $this->assertEquals( rest_url( '/wp/v2/posts/' . self::$post_id . '/revisions' ), $links['version-history'][0]['href'] );
    655669
    656670        $attachments_url = rest_url( '/wp/v2/media' );
    657         $attachments_url = add_query_arg( 'parent', $this->post_id, $attachments_url );
     671        $attachments_url = add_query_arg( 'parent', self::$post_id, $attachments_url );
    658672        $this->assertEquals( $attachments_url, $links['https://api.w.org/attachment'][0]['href'] );
    659673
     
    673687        $this->assertNull( $format_link );
    674688
    675         $tags_url = add_query_arg( 'post', $this->post_id, rest_url( '/wp/v2/tags' ) );
     689        $tags_url = add_query_arg( 'post', self::$post_id, rest_url( '/wp/v2/tags' ) );
    676690        $this->assertEquals( $tags_url, $tag_link['href'] );
    677691
    678         $category_url = add_query_arg( 'post', $this->post_id, rest_url( '/wp/v2/categories' ) );
     692        $category_url = add_query_arg( 'post', self::$post_id, rest_url( '/wp/v2/categories' ) );
    679693        $this->assertEquals( $category_url, $cat_link['href'] );
    680694    }
    681695
    682696    public function test_get_item_links_no_author() {
    683         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     697        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    684698        $response = $this->server->dispatch( $request );
    685699        $links = $response->get_links();
    686700        $this->assertFalse( isset( $links['author'] ) );
    687         wp_update_post( array( 'ID' => $this->post_id, 'post_author' => $this->author_id ) );
    688         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     701        wp_update_post( array( 'ID' => self::$post_id, 'post_author' => self::$author_id ) );
     702        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    689703        $response = $this->server->dispatch( $request );
    690704        $links = $response->get_links();
    691         $this->assertEquals( rest_url( '/wp/v2/users/' . $this->author_id ), $links['author'][0]['href'] );
     705        $this->assertEquals( rest_url( '/wp/v2/users/' . self::$author_id ), $links['author'][0]['href'] );
    692706    }
    693707
     
    717731        ) );
    718732
    719         wp_set_current_user( $this->editor_id );
     733        wp_set_current_user( self::$editor_id );
    720734
    721735        $response = $this->server->dispatch( $request );
     
    737751    public function test_get_post_context_without_permission() {
    738752        wp_set_current_user( 0 );
    739         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     753        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    740754        $request->set_query_params( array(
    741755            'context' => 'edit',
     
    812826        register_post_status( 'testprivtatus', array( 'public' => false ) );
    813827        // Public status
    814         wp_update_post( array( 'ID' => $this->post_id, 'post_status' => 'testpubstatus' ) );
    815         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     828        wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testpubstatus' ) );
     829        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    816830        $response = $this->server->dispatch( $request );
    817831        $this->assertEquals( 200, $response->get_status() );
    818832        // Private status
    819         wp_update_post( array( 'ID' => $this->post_id, 'post_status' => 'testprivtatus' ) );
    820         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     833        wp_update_post( array( 'ID' => self::$post_id, 'post_status' => 'testprivtatus' ) );
     834        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    821835        $response = $this->server->dispatch( $request );
    822836        $this->assertEquals( 403, $response->get_status() );
     
    824838
    825839    public function test_prepare_item() {
    826         wp_set_current_user( $this->editor_id );
    827 
    828         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     840        wp_set_current_user( self::$editor_id );
     841
     842        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    829843        $request->set_query_params( array( 'context' => 'edit' ) );
    830844        $response = $this->server->dispatch( $request );
     
    834848
    835849    public function test_create_item() {
    836         wp_set_current_user( $this->editor_id );
     850        wp_set_current_user( self::$editor_id );
    837851
    838852        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    846860
    847861    public function test_rest_create_item() {
    848         wp_set_current_user( $this->editor_id );
     862        wp_set_current_user( self::$editor_id );
    849863
    850864        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    858872
    859873    public function test_create_post_invalid_id() {
    860         wp_set_current_user( $this->editor_id );
     874        wp_set_current_user( self::$editor_id );
    861875
    862876        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    871885
    872886    public function test_create_post_as_contributor() {
    873         wp_set_current_user( $this->contributor_id );
     887        wp_set_current_user( self::$contributor_id );
    874888
    875889        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    884898
    885899    public function test_create_post_sticky() {
    886         wp_set_current_user( $this->editor_id );
     900        wp_set_current_user( self::$editor_id );
    887901
    888902        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    900914
    901915    public function test_create_post_sticky_as_contributor() {
    902         wp_set_current_user( $this->contributor_id );
     916        wp_set_current_user( self::$contributor_id );
    903917
    904918        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    914928
    915929    public function test_create_post_other_author_without_permission() {
    916         wp_set_current_user( $this->author_id );
     930        wp_set_current_user( self::$author_id );
    917931
    918932        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    919933        $params = $this->set_post_data(array(
    920             'author' => $this->editor_id,
     934            'author' => self::$editor_id,
    921935        ));
    922936        $request->set_body_params( $params );
     
    940954
    941955    public function test_create_post_draft() {
    942         wp_set_current_user( $this->editor_id );
     956        wp_set_current_user( self::$editor_id );
    943957
    944958        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    959973
    960974    public function test_create_post_private() {
    961         wp_set_current_user( $this->editor_id );
     975        wp_set_current_user( self::$editor_id );
    962976
    963977        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    975989
    976990    public function test_create_post_private_without_permission() {
    977         wp_set_current_user( $this->author_id );
     991        wp_set_current_user( self::$author_id );
    978992        $user = wp_get_current_user();
    979993        $user->add_cap( 'publish_posts', false );
     
    985999        $params = $this->set_post_data( array(
    9861000            'status' => 'private',
    987             'author' => $this->author_id,
     1001            'author' => self::$author_id,
    9881002        ) );
    9891003        $request->set_body_params( $params );
     
    9941008
    9951009    public function test_create_post_publish_without_permission() {
    996         wp_set_current_user( $this->author_id );
     1010        wp_set_current_user( self::$author_id );
    9971011        $user = wp_get_current_user();
    9981012        $user->add_cap( 'publish_posts', false );
     
    10121026
    10131027    public function test_create_post_invalid_status() {
    1014         wp_set_current_user( $this->editor_id );
     1028        wp_set_current_user( self::$editor_id );
    10151029
    10161030        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    10251039
    10261040    public function test_create_post_with_format() {
    1027         wp_set_current_user( $this->editor_id );
     1041        wp_set_current_user( self::$editor_id );
    10281042
    10291043        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    10411055
    10421056    public function test_create_post_with_invalid_format() {
    1043         wp_set_current_user( $this->editor_id );
     1057        wp_set_current_user( self::$editor_id );
    10441058
    10451059        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    10611075        ) );
    10621076
    1063         wp_set_current_user( $this->editor_id );
     1077        wp_set_current_user( self::$editor_id );
    10641078
    10651079        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    10861100
    10871101    public function test_create_post_invalid_author() {
    1088         wp_set_current_user( $this->editor_id );
     1102        wp_set_current_user( self::$editor_id );
    10891103
    10901104        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    10991113
    11001114    public function test_create_post_invalid_author_without_permission() {
    1101         wp_set_current_user( $this->author_id );
    1102 
    1103         $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    1104         $params = $this->set_post_data( array(
    1105             'author' => $this->editor_id,
     1115        wp_set_current_user( self::$author_id );
     1116
     1117        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     1118        $params = $this->set_post_data( array(
     1119            'author' => self::$editor_id,
    11061120        ) );
    11071121        $request->set_body_params( $params );
     
    11121126
    11131127    public function test_create_post_with_password() {
    1114         wp_set_current_user( $this->editor_id );
     1128        wp_set_current_user( self::$editor_id );
    11151129
    11161130        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    11261140
    11271141    public function test_create_post_with_falsy_password() {
    1128         wp_set_current_user( $this->editor_id );
     1142        wp_set_current_user( self::$editor_id );
    11291143
    11301144        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    11411155
    11421156    public function test_create_post_with_empty_string_password_and_sticky() {
    1143         wp_set_current_user( $this->editor_id );
     1157        wp_set_current_user( self::$editor_id );
    11441158
    11451159        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    11571171
    11581172    public function test_create_post_with_password_and_sticky_fails() {
    1159         wp_set_current_user( $this->editor_id );
     1173        wp_set_current_user( self::$editor_id );
    11601174
    11611175        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    11711185
    11721186    public function test_create_post_custom_date() {
    1173         wp_set_current_user( $this->editor_id );
     1187        wp_set_current_user( self::$editor_id );
    11741188
    11751189        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    11881202
    11891203    public function test_create_post_custom_date_with_timezone() {
    1190         wp_set_current_user( $this->editor_id );
     1204        wp_set_current_user( self::$editor_id );
    11911205
    11921206        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12091223
    12101224    public function test_create_post_with_db_error() {
    1211         wp_set_current_user( $this->editor_id );
     1225        wp_set_current_user( self::$editor_id );
    12121226
    12131227        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12311245
    12321246    public function test_create_post_with_invalid_date() {
    1233         wp_set_current_user( $this->editor_id );
     1247        wp_set_current_user( self::$editor_id );
    12341248
    12351249        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12441258
    12451259    public function test_create_post_with_invalid_date_gmt() {
    1246         wp_set_current_user( $this->editor_id );
     1260        wp_set_current_user( self::$editor_id );
    12471261
    12481262        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12571271
    12581272    public function test_create_post_with_quotes_in_title() {
    1259         wp_set_current_user( $this->editor_id );
     1273        wp_set_current_user( self::$editor_id );
    12601274
    12611275        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12701284
    12711285    public function test_create_post_with_categories() {
    1272         wp_set_current_user( $this->editor_id );
     1286        wp_set_current_user( self::$editor_id );
    12731287        $category = wp_insert_term( 'Test Category', 'category' );
    12741288        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     
    12871301
    12881302    public function test_create_post_with_invalid_categories() {
    1289         wp_set_current_user( $this->editor_id );
     1303        wp_set_current_user( self::$editor_id );
    12901304        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
    12911305        $params = $this->set_post_data( array(
     
    13031317
    13041318    public function test_update_item() {
    1305         wp_set_current_user( $this->editor_id );
    1306 
    1307         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1319        wp_set_current_user( self::$editor_id );
     1320
     1321        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    13081322        $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    13091323        $params = $this->set_post_data();
     
    13131327        $this->check_update_post_response( $response );
    13141328        $new_data = $response->get_data();
    1315         $this->assertEquals( $this->post_id, $new_data['id'] );
     1329        $this->assertEquals( self::$post_id, $new_data['id'] );
    13161330        $this->assertEquals( $params['title'], $new_data['title']['raw'] );
    13171331        $this->assertEquals( $params['content'], $new_data['content']['raw'] );
    13181332        $this->assertEquals( $params['excerpt'], $new_data['excerpt']['raw'] );
    1319         $post = get_post( $this->post_id );
     1333        $post = get_post( self::$post_id );
    13201334        $this->assertEquals( $params['title'], $post->post_title );
    13211335        $this->assertEquals( $params['content'], $post->post_content );
     
    13241338
    13251339    public function test_rest_update_post() {
    1326         wp_set_current_user( $this->editor_id );
    1327 
    1328         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1340        wp_set_current_user( self::$editor_id );
     1341
     1342        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    13291343        $request->add_header( 'content-type', 'application/json' );
    13301344        $params = $this->set_post_data();
     
    13341348        $this->check_update_post_response( $response );
    13351349        $new_data = $response->get_data();
    1336         $this->assertEquals( $this->post_id, $new_data['id'] );
     1350        $this->assertEquals( self::$post_id, $new_data['id'] );
    13371351        $this->assertEquals( $params['title'], $new_data['title']['raw'] );
    13381352        $this->assertEquals( $params['content'], $new_data['content']['raw'] );
    13391353        $this->assertEquals( $params['excerpt'], $new_data['excerpt']['raw'] );
    1340         $post = get_post( $this->post_id );
     1354        $post = get_post( self::$post_id );
    13411355        $this->assertEquals( $params['title'], $post->post_title );
    13421356        $this->assertEquals( $params['content'], $post->post_content );
     
    13451359
    13461360    public function test_rest_update_post_raw() {
    1347         wp_set_current_user( $this->editor_id );
    1348 
    1349         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1361        wp_set_current_user( self::$editor_id );
     1362
     1363        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    13501364        $request->add_header( 'content-type', 'application/json' );
    13511365        $params = $this->set_raw_post_data();
     
    13551369        $this->check_update_post_response( $response );
    13561370        $new_data = $response->get_data();
    1357         $this->assertEquals( $this->post_id, $new_data['id'] );
     1371        $this->assertEquals( self::$post_id, $new_data['id'] );
    13581372        $this->assertEquals( $params['title']['raw'], $new_data['title']['raw'] );
    13591373        $this->assertEquals( $params['content']['raw'], $new_data['content']['raw'] );
    13601374        $this->assertEquals( $params['excerpt']['raw'], $new_data['excerpt']['raw'] );
    1361         $post = get_post( $this->post_id );
     1375        $post = get_post( self::$post_id );
    13621376        $this->assertEquals( $params['title']['raw'], $post->post_title );
    13631377        $this->assertEquals( $params['content']['raw'], $post->post_content );
     
    13661380
    13671381    public function test_update_post_without_extra_params() {
    1368         wp_set_current_user( $this->editor_id );
    1369 
    1370         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1382        wp_set_current_user( self::$editor_id );
     1383
     1384        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    13711385        $params = $this->set_post_data();
    13721386        unset( $params['type'] );
     
    13811395
    13821396    public function test_update_post_without_permission() {
    1383         wp_set_current_user( $this->editor_id );
     1397        wp_set_current_user( self::$editor_id );
    13841398        $user = wp_get_current_user();
    13851399        $user->add_cap( 'edit_published_posts', false );
     
    13881402        $user->update_user_level_from_caps();
    13891403
    1390         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1404        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    13911405        $params = $this->set_post_data();
    13921406        $request->set_body_params( $params );
     
    13971411
    13981412    public function test_update_post_sticky_as_contributor() {
    1399         wp_set_current_user( $this->contributor_id );
    1400 
    1401         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1413        wp_set_current_user( self::$contributor_id );
     1414
     1415        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14021416        $params = $this->set_post_data( array(
    14031417            'sticky' => true,
     
    14111425
    14121426    public function test_update_post_invalid_id() {
    1413         wp_set_current_user( $this->editor_id );
     1427        wp_set_current_user( self::$editor_id );
    14141428
    14151429        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
     
    14201434
    14211435    public function test_update_post_invalid_route() {
    1422         wp_set_current_user( $this->editor_id );
    1423 
    1424         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', $this->post_id ) );
     1436        wp_set_current_user( self::$editor_id );
     1437
     1438        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', self::$post_id ) );
    14251439        $response = $this->server->dispatch( $request );
    14261440
     
    14291443
    14301444    public function test_update_post_with_format() {
    1431         wp_set_current_user( $this->editor_id );
    1432 
    1433         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1445        wp_set_current_user( self::$editor_id );
     1446
     1447        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14341448        $params = $this->set_post_data( array(
    14351449            'format' => 'gallery',
     
    14451459
    14461460    public function test_update_post_with_invalid_format() {
    1447         wp_set_current_user( $this->editor_id );
    1448 
    1449         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1461        wp_set_current_user( self::$editor_id );
     1462
     1463        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14501464        $params = $this->set_post_data( array(
    14511465            'format' => 'testformat',
     
    14581472
    14591473    public function test_update_post_ignore_readonly() {
    1460         wp_set_current_user( $this->editor_id );
     1474        wp_set_current_user( self::$editor_id );
    14611475
    14621476        $new_content = rand_str();
    14631477        $expected_modified = current_time( 'mysql' );
    14641478
    1465         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1479        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14661480        $params = $this->set_post_data( array(
    14671481            'modified' => '2010-06-01T02:00:00Z',
     
    14841498
    14851499    public function test_update_post_with_invalid_date() {
    1486         wp_set_current_user( $this->editor_id );
    1487 
    1488         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1500        wp_set_current_user( self::$editor_id );
     1501
     1502        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    14891503        $params = $this->set_post_data( array(
    14901504            'date' => rand_str(),
     
    14971511
    14981512    public function test_update_post_with_invalid_date_gmt() {
    1499         wp_set_current_user( $this->editor_id );
    1500 
    1501         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1513        wp_set_current_user( self::$editor_id );
     1514
     1515        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15021516        $params = $this->set_post_data( array(
    15031517            'date_gmt' => rand_str(),
     
    15101524
    15111525    public function test_update_post_slug() {
    1512         wp_set_current_user( $this->editor_id );
    1513 
    1514         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1526        wp_set_current_user( self::$editor_id );
     1527
     1528        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15151529        $params = $this->set_post_data( array(
    15161530            'slug' => 'sample-slug',
     
    15261540
    15271541    public function test_update_post_slug_accented_chars() {
    1528         wp_set_current_user( $this->editor_id );
    1529 
    1530         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1542        wp_set_current_user( self::$editor_id );
     1543
     1544        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15311545        $params = $this->set_post_data( array(
    15321546            'slug' => 'tęst-acceńted-chäræcters',
     
    15421556
    15431557    public function test_update_post_sticky() {
    1544         wp_set_current_user( $this->editor_id );
    1545 
    1546         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1558        wp_set_current_user( self::$editor_id );
     1559
     1560        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15471561        $params = $this->set_post_data( array(
    15481562            'sticky' => true,
     
    15571571
    15581572        // Updating another field shouldn't change sticky status
    1559         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1573        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15601574        $params = $this->set_post_data( array(
    15611575            'title'       => 'This should not reset sticky',
     
    15711585
    15721586    public function test_update_post_excerpt() {
    1573         wp_set_current_user( $this->editor_id );
    1574 
    1575         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1587        wp_set_current_user( self::$editor_id );
     1588
     1589        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15761590        $request->set_body_params( array(
    15771591            'excerpt' => 'An Excerpt',
     
    15841598
    15851599    public function test_update_post_empty_excerpt() {
    1586         wp_set_current_user( $this->editor_id );
    1587 
    1588         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1600        wp_set_current_user( self::$editor_id );
     1601
     1602        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    15891603        $request->set_body_params( array(
    15901604            'excerpt' => '',
     
    15971611
    15981612    public function test_update_post_content() {
    1599         wp_set_current_user( $this->editor_id );
    1600 
    1601         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1613        wp_set_current_user( self::$editor_id );
     1614
     1615        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16021616        $request->set_body_params( array(
    16031617            'content' => 'Some Content',
     
    16101624
    16111625    public function test_update_post_empty_content() {
    1612         wp_set_current_user( $this->editor_id );
    1613 
    1614         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1626        wp_set_current_user( self::$editor_id );
     1627
     1628        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16151629        $request->set_body_params( array(
    16161630            'content' => '',
     
    16231637
    16241638    public function test_update_post_with_password_and_sticky_fails() {
    1625         wp_set_current_user( $this->editor_id );
    1626 
    1627         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1639        wp_set_current_user( self::$editor_id );
     1640
     1641        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16281642        $params = $this->set_post_data( array(
    16291643            'password' => '123',
     
    16371651
    16381652    public function test_update_stick_post_with_password_fails() {
    1639         wp_set_current_user( $this->editor_id );
    1640 
    1641         stick_post( $this->post_id );
    1642 
    1643         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1653        wp_set_current_user( self::$editor_id );
     1654
     1655        stick_post( self::$post_id );
     1656
     1657        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16441658        $params = $this->set_post_data( array(
    16451659            'password' => '123',
     
    16521666
    16531667    public function test_update_password_protected_post_with_sticky_fails() {
    1654         wp_set_current_user( $this->editor_id );
    1655 
    1656         wp_update_post( array( 'ID' => $this->post_id, 'post_password' => '123' ) );
    1657 
    1658         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1668        wp_set_current_user( self::$editor_id );
     1669
     1670        wp_update_post( array( 'ID' => self::$post_id, 'post_password' => '123' ) );
     1671
     1672        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16591673        $params = $this->set_post_data( array(
    16601674            'sticky' => true,
     
    16671681
    16681682    public function test_update_post_with_quotes_in_title() {
    1669         wp_set_current_user( $this->editor_id );
    1670 
    1671         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1683        wp_set_current_user( self::$editor_id );
     1684
     1685        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16721686        $params = $this->set_post_data( array(
    16731687            'title' => "Rob O'Rourke's Diary",
     
    16811695    public function test_update_post_with_categories() {
    16821696
    1683         wp_set_current_user( $this->editor_id );
     1697        wp_set_current_user( self::$editor_id );
    16841698        $category = wp_insert_term( 'Test Category', 'category' );
    16851699
    1686         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1700        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    16871701        $params = $this->set_post_data( array(
    16881702            'title' => 'Tester',
     
    17151729    public function test_update_post_with_empty_categories() {
    17161730
    1717         wp_set_current_user( $this->editor_id );
     1731        wp_set_current_user( self::$editor_id );
    17181732        $category = wp_insert_term( 'Test Category', 'category' );
    1719         wp_set_object_terms( $this->post_id, $category['term_id'], 'category' );
    1720 
    1721         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1733        wp_set_object_terms( self::$post_id, $category['term_id'], 'category' );
     1734
     1735        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    17221736        $params = $this->set_post_data( array(
    17231737            'title' => 'Tester',
     
    17321746    public function test_delete_item() {
    17331747        $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
    1734         wp_set_current_user( $this->editor_id );
     1748        wp_set_current_user( self::$editor_id );
    17351749
    17361750        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
     
    17451759    public function test_delete_item_skip_trash() {
    17461760        $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
    1747         wp_set_current_user( $this->editor_id );
     1761        wp_set_current_user( self::$editor_id );
    17481762
    17491763        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
     
    17591773    public function test_delete_item_already_trashed() {
    17601774        $post_id = $this->factory->post->create( array( 'post_title' => 'Deleted post' ) );
    1761         wp_set_current_user( $this->editor_id );
     1775        wp_set_current_user( self::$editor_id );
    17621776        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $post_id ) );
    17631777        $response = $this->server->dispatch( $request );
     
    17681782
    17691783    public function test_delete_post_invalid_id() {
    1770         wp_set_current_user( $this->editor_id );
     1784        wp_set_current_user( self::$editor_id );
    17711785
    17721786        $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER );
     
    17781792    public function test_delete_post_invalid_post_type() {
    17791793        $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
    1780         wp_set_current_user( $this->editor_id );
     1794        wp_set_current_user( self::$editor_id );
    17811795
    17821796        $request = new WP_REST_Request( 'DELETE', '/wp/v2/posts/' . $page_id );
     
    17871801
    17881802    public function test_delete_post_without_permission() {
    1789         wp_set_current_user( $this->author_id );
    1790 
    1791         $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1803        wp_set_current_user( self::$author_id );
     1804
     1805        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    17921806        $response = $this->server->dispatch( $request );
    17931807
     
    19061920        ) );
    19071921
    1908         wp_set_current_user( $this->editor_id );
     1922        wp_set_current_user( self::$editor_id );
    19091923        // Check for error on update.
    1910         $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', $this->post_id ) );
     1924        $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    19111925        $request->set_body_params( array(
    19121926            'my_custom_int' => 'returnError',
Note: See TracChangeset for help on using the changeset viewer.