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

    r38864 r38975  
    1212class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase {
    1313
    14     protected $admin_id;
    15     protected $subscriber_id;
    16 
    17     protected $post_id;
    18     protected $private_id;
    19     protected $draft_id;
    20     protected $trash_id;
    21 
    22     protected $approved_id;
    23     protected $hold_id;
     14    protected static $admin_id;
     15    protected static $subscriber_id;
     16    protected static $author_id;
     17
     18    protected static $post_id;
     19    protected static $private_id;
     20    protected static $draft_id;
     21    protected static $trash_id;
     22    protected static $approved_id;
     23    protected static $hold_id;
    2424
    2525    protected $endpoint;
    2626
    27     public function setUp() {
    28         parent::setUp();
    29 
    30         $this->admin_id = $this->factory->user->create( array(
     27    public static function wpSetUpBeforeClass( $factory ) {
     28        self::$admin_id = $factory->user->create( array(
    3129            'role' => 'administrator',
    32         ));
    33         $this->subscriber_id = $this->factory->user->create( array(
     30        ) );
     31        self::$subscriber_id = $factory->user->create( array(
    3432            'role' => 'subscriber',
    35         ));
    36         $this->author_id = $this->factory->user->create( array(
     33        ) );
     34        self::$author_id = $factory->user->create( array(
    3735            'role'         => 'author',
    3836            'display_name' => 'Sea Captain',
     
    4139            'user_email'   => 'captain@thefryingdutchman.com',
    4240            'user_url'     => 'http://thefryingdutchman.com',
    43         ));
    44 
    45         $this->post_id = $this->factory->post->create();
    46         $this->private_id = $this->factory->post->create( array(
     41        ) );
     42
     43        self::$post_id = $factory->post->create();
     44        self::$private_id = $factory->post->create( array(
    4745            'post_status' => 'private',
    48         ));
    49         $this->draft_id = $this->factory->post->create( array(
     46        ) );
     47        self::$draft_id = $factory->post->create( array(
    5048            'post_status' => 'draft',
    51         ));
    52         $this->trash_id = $this->factory->post->create( array(
     49        ) );
     50        self::$trash_id = $factory->post->create( array(
    5351            'post_status' => 'trash',
    54         ));
    55 
    56         $this->approved_id = $this->factory->comment->create( array(
    57             'comment_approved' => 1,
    58             'comment_post_ID'  => $this->post_id,
     52        ) );
     53
     54        self::$approved_id = $factory->comment->create( array(
     55            'comment_approved' => 1,
     56            'comment_post_ID'  => self::$post_id,
    5957            'user_id'          => 0,
    60         ));
    61         $this->hold_id = $this->factory->comment->create( array(
     58        ) );
     59        self::$hold_id = $factory->comment->create( array(
    6260            'comment_approved' => 0,
    63             'comment_post_ID'  => $this->post_id,
    64             'user_id'          => $this->subscriber_id,
    65         ));
    66 
     61            'comment_post_ID'  => self::$post_id,
     62            'user_id'          => self::$subscriber_id,
     63        ) );
     64    }
     65
     66    public static function wpTearDownAfterClass() {
     67        self::delete_user( self::$admin_id );
     68        self::delete_user( self::$subscriber_id );
     69        self::delete_user( self::$author_id );
     70
     71        wp_delete_post( self::$post_id, true );
     72        wp_delete_post( self::$private_id, true );
     73        wp_delete_post( self::$draft_id, true );
     74        wp_delete_post( self::$trash_id, true );
     75        wp_delete_post( self::$approved_id, true );
     76        wp_delete_post( self::$hold_id, true );
     77    }
     78
     79    public function setUp() {
     80        parent::setUp();
    6781        $this->endpoint = new WP_REST_Comments_Controller;
    6882    }
     
    89103        $this->assertEquals( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
    90104        // Single
    91         $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . $this->approved_id );
     105        $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/comments/' . self::$approved_id );
    92106        $response = $this->server->dispatch( $request );
    93107        $data = $response->get_data();
     
    127141
    128142    public function test_get_items() {
    129         $this->factory->comment->create_post_comments( $this->post_id, 6 );
     143        $this->factory->comment->create_post_comments( self::$post_id, 6 );
    130144
    131145        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    135149
    136150        $comments = $response->get_data();
    137         // We created 6 comments in this method, plus $this->approved_id.
     151        // We created 6 comments in this method, plus self::$approved_id.
    138152        $this->assertCount( 7, $comments );
    139153    }
     
    144158        $args = array(
    145159            'comment_approved' => 1,
    146             'comment_post_ID'  => $this->private_id,
     160            'comment_post_ID'  => self::$private_id,
    147161        );
    148162        $private_comment = $this->factory->comment->create( $args );
     
    158172
    159173    public function test_get_items_with_private_post_permission() {
    160         wp_set_current_user( $this->admin_id );
     174        wp_set_current_user( self::$admin_id );
    161175
    162176        $args = array(
    163177            'comment_approved' => 1,
    164             'comment_post_ID'  => $this->private_id,
     178            'comment_post_ID'  => self::$private_id,
    165179        );
    166180        $private_comment = $this->factory->comment->create( $args );
     
    195209
    196210    public function test_get_items_with_invalid_post_permission() {
    197         wp_set_current_user( $this->admin_id );
     211        wp_set_current_user( self::$admin_id );
    198212
    199213        $comment_id = $this->factory->comment->create( array(
     
    223237    public function test_get_items_no_post() {
    224238        $this->factory->comment->create_post_comments( 0, 2 );
    225         wp_set_current_user( $this->admin_id );
     239        wp_set_current_user( self::$admin_id );
    226240        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    227241        $request->set_param( 'post', 0 );
     
    241255
    242256    public function test_get_items_edit_context() {
    243         wp_set_current_user( $this->admin_id );
     257        wp_set_current_user( self::$admin_id );
    244258        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    245259        $request->set_param( 'context', 'edit' );
     
    265279
    266280    public function test_get_items_include_query() {
    267         wp_set_current_user( $this->admin_id );
     281        wp_set_current_user( self::$admin_id );
    268282        $args = array(
    269283            'comment_approved' => 1,
    270             'comment_post_ID'  => $this->post_id,
     284            'comment_post_ID'  => self::$post_id,
    271285        );
    272286        $id1 = $this->factory->comment->create( $args );
     
    290304
    291305    public function test_get_items_exclude_query() {
    292         wp_set_current_user( $this->admin_id );
     306        wp_set_current_user( self::$admin_id );
    293307        $args = array(
    294308            'comment_approved' => 1,
    295             'comment_post_ID'  => $this->post_id,
     309            'comment_post_ID'  => self::$post_id,
    296310        );
    297311        $id1 = $this->factory->comment->create( $args );
     
    310324
    311325    public function test_get_items_offset_query() {
    312         wp_set_current_user( $this->admin_id );
     326        wp_set_current_user( self::$admin_id );
    313327        $args = array(
    314328            'comment_approved' => 1,
    315             'comment_post_ID'  => $this->post_id,
     329            'comment_post_ID'  => self::$post_id,
    316330        );
    317331        $this->factory->comment->create( $args );
     
    333347
    334348    public function test_get_items_order_query() {
    335         wp_set_current_user( $this->admin_id );
     349        wp_set_current_user( self::$admin_id );
    336350        $args = array(
    337351            'comment_approved' => 1,
    338             'comment_post_ID'  => $this->post_id,
     352            'comment_post_ID'  => self::$post_id,
    339353        );
    340354        $this->factory->comment->create( $args );
     
    350364        $response = $this->server->dispatch( $request );
    351365        $data = $response->get_data();
    352         $this->assertEquals( $this->approved_id, $data[0]['id'] );
     366        $this->assertEquals( self::$approved_id, $data[0]['id'] );
    353367    }
    354368
     
    364378    public function test_get_items_author_arg() {
    365379        // Authorized
    366         wp_set_current_user( $this->admin_id );
     380        wp_set_current_user( self::$admin_id );
    367381        $args = array(
    368382            'comment_approved' => 1,
    369             'comment_post_ID'  => $this->post_id,
    370             'user_id'          => $this->author_id,
     383            'comment_post_ID'  => self::$post_id,
     384            'user_id'          => self::$author_id,
    371385        );
    372386        $this->factory->comment->create( $args );
    373         $args['user_id'] = $this->subscriber_id;
     387        $args['user_id'] = self::$subscriber_id;
    374388        $this->factory->comment->create( $args );
    375389        unset( $args['user_id'] );
     
    378392        // 'author' limits result to 1 of 3
    379393        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    380         $request->set_param( 'author', $this->author_id );
     394        $request->set_param( 'author', self::$author_id );
    381395        $response = $this->server->dispatch( $request );
    382396        $this->assertEquals( 200, $response->get_status() );
     
    384398        $this->assertCount( 1, $comments );
    385399        // Multiple authors are supported
    386         $request->set_param( 'author', array( $this->author_id, $this->subscriber_id ) );
     400        $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) );
    387401        $response = $this->server->dispatch( $request );
    388402        $this->assertEquals( 200, $response->get_status() );
     
    397411    public function test_get_items_author_exclude_arg() {
    398412        // Authorized
    399         wp_set_current_user( $this->admin_id );
     413        wp_set_current_user( self::$admin_id );
    400414        $args = array(
    401415            'comment_approved' => 1,
    402             'comment_post_ID'  => $this->post_id,
    403             'user_id'          => $this->author_id,
     416            'comment_post_ID'  => self::$post_id,
     417            'user_id'          => self::$author_id,
    404418        );
    405419        $this->factory->comment->create( $args );
    406         $args['user_id'] = $this->subscriber_id;
     420        $args['user_id'] = self::$subscriber_id;
    407421        $this->factory->comment->create( $args );
    408422        unset( $args['user_id'] );
     
    416430        // 'author_exclude' limits result to 3 of 4
    417431        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    418         $request->set_param( 'author_exclude', $this->author_id );
     432        $request->set_param( 'author_exclude', self::$author_id );
    419433        $response = $this->server->dispatch( $request );
    420434        $this->assertEquals( 200, $response->get_status() );
     
    423437        // 'author_exclude' for both comment authors (2 of 4)
    424438        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
    425         $request->set_param( 'author_exclude', array( $this->author_id, $this->subscriber_id ) );
     439        $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) );
    426440        $response = $this->server->dispatch( $request );
    427441        $this->assertEquals( 200, $response->get_status() );
     
    437451        $args = array(
    438452            'comment_approved'  => 1,
    439             'comment_post_ID'   => $this->post_id,
     453            'comment_post_ID'   => self::$post_id,
    440454        );
    441455        $parent_id = $this->factory->comment->create( $args );
     
    462476        $args = array(
    463477            'comment_approved'  => 1,
    464             'comment_post_ID'   => $this->post_id,
     478            'comment_post_ID'   => self::$post_id,
    465479        );
    466480        $parent_id = $this->factory->comment->create( $args );
     
    485499
    486500    public function test_get_items_search_query() {
    487         wp_set_current_user( $this->admin_id );
     501        wp_set_current_user( self::$admin_id );
    488502        $args = array(
    489503            'comment_approved' => 1,
    490             'comment_post_ID'  => $this->post_id,
     504            'comment_post_ID'  => self::$post_id,
    491505            'comment_content'  => 'foo',
    492506            'comment_author'   => 'Homer J Simpson',
     
    510524
    511525    public function test_get_comments_pagination_headers() {
    512         wp_set_current_user( $this->admin_id );
     526        wp_set_current_user( self::$admin_id );
    513527        // Start of the index
    514528        for ( $i = 0; $i < 49; $i++ ) {
    515529            $this->factory->comment->create( array(
    516530                'comment_content'   => "Comment {$i}",
    517                 'comment_post_ID'   => $this->post_id,
     531                'comment_post_ID'   => self::$post_id,
    518532                ) );
    519533        }
     
    531545        $this->factory->comment->create( array(
    532546                'comment_content'   => 'Comment 51',
    533                 'comment_post_ID'   => $this->post_id,
     547                'comment_post_ID'   => self::$post_id,
    534548                ) );
    535549        $request = new WP_REST_Request( 'GET', '/wp/v2/comments' );
     
    584598        $comment1 = $this->factory->comment->create( array(
    585599            'comment_date'    => '2016-01-15T00:00:00Z',
    586             'comment_post_ID' => $this->post_id,
     600            'comment_post_ID' => self::$post_id,
    587601        ) );
    588602        $comment2 = $this->factory->comment->create( array(
    589603            'comment_date'    => '2016-01-16T00:00:00Z',
    590             'comment_post_ID' => $this->post_id,
     604            'comment_post_ID' => self::$post_id,
    591605        ) );
    592606        $comment3 = $this->factory->comment->create( array(
    593607            'comment_date'    => '2016-01-17T00:00:00Z',
    594             'comment_post_ID' => $this->post_id,
     608            'comment_post_ID' => self::$post_id,
    595609        ) );
    596610
     
    605619
    606620    public function test_get_item() {
    607         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     621        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    608622
    609623        $response = $this->server->dispatch( $request );
     
    615629
    616630    public function test_prepare_item() {
    617         wp_set_current_user( $this->admin_id );
    618         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     631        wp_set_current_user( self::$admin_id );
     632        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    619633        $request->set_query_params( array(
    620634            'context' => 'edit',
     
    629643
    630644    public function test_get_comment_author_avatar_urls() {
    631         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     645        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    632646
    633647        $response = $this->server->dispatch( $request );
     
    638652        $this->assertArrayHasKey( 96,  $data['author_avatar_urls'] );
    639653
    640         $comment = get_comment( $this->approved_id );
     654        $comment = get_comment( self::$approved_id );
    641655        /**
    642656         * Ignore the subdomain, since 'get_avatar_url randomly sets the Gravatar
     
    655669    public function test_get_comment_invalid_context() {
    656670        wp_set_current_user( 0 );
    657         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $this->approved_id ) );
     671        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', self::$approved_id ) );
    658672        $request->set_param( 'context', 'edit' );
    659673        $response = $this->server->dispatch( $request );
     
    674688
    675689    public function test_get_comment_invalid_post_id_as_admin() {
    676         wp_set_current_user( $this->admin_id );
     690        wp_set_current_user( self::$admin_id );
    677691        $comment_id = $this->factory->comment->create( array(
    678692            'comment_approved' => 1,
     
    688702        wp_set_current_user( 0 );
    689703
    690         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );
     704        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    691705
    692706        $response = $this->server->dispatch( $request );
     
    695709
    696710    public function test_get_comment_not_approved_same_user() {
    697         wp_set_current_user( $this->subscriber_id );
    698 
    699         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );
     711        wp_set_current_user( self::$subscriber_id );
     712
     713        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    700714
    701715        $response = $this->server->dispatch( $request );
     
    706720        $comment_id_1 = $this->factory->comment->create( array(
    707721            'comment_approved' => 1,
    708             'comment_post_ID'  => $this->post_id,
    709             'user_id'          => $this->subscriber_id,
     722            'comment_post_ID'  => self::$post_id,
     723            'user_id'          => self::$subscriber_id,
    710724        ) );
    711725
     
    713727            'comment_approved' => 1,
    714728            'comment_parent'   => $comment_id_1,
    715             'comment_post_ID'  => $this->post_id,
    716             'user_id'          => $this->subscriber_id,
     729            'comment_post_ID'  => self::$post_id,
     730            'user_id'          => self::$subscriber_id,
    717731        ) );
    718732
     
    726740        $comment_id_1 = $this->factory->comment->create( array(
    727741            'comment_approved' => 1,
    728             'comment_post_ID'  => $this->post_id,
    729             'user_id'          => $this->subscriber_id,
     742            'comment_post_ID'  => self::$post_id,
     743            'user_id'          => self::$subscriber_id,
    730744        ) );
    731745
     
    740754
    741755        $params = array(
    742             'post'    => $this->post_id,
     756            'post'    => self::$post_id,
    743757            'author_name'  => 'Comic Book Guy',
    744758            'author_email' => 'cbg@androidsdungeon.com',
     
    759773        $this->assertEquals( 'hold', $data['status'] );
    760774        $this->assertEquals( '2014-11-07T10:14:25', $data['date'] );
    761         $this->assertEquals( $this->post_id, $data['post'] );
     775        $this->assertEquals( self::$post_id, $data['post'] );
    762776    }
    763777
     
    766780
    767781        $params = array(
    768             'post'         => $this->post_id,
     782            'post'         => self::$post_id,
    769783            'author_name'  => 'Reverend Lovejoy',
    770784            'author_email' => 'lovejoy@example.com',
     
    791805
    792806        $params = array(
    793             'post'    => $this->post_id,
     807            'post'    => self::$post_id,
    794808            'content' => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.',
    795809        );
     
    809823
    810824        $params = array(
    811             'post'         => $this->post_id,
     825            'post'         => self::$post_id,
    812826            'author_email' => 'ekrabappel@springfield-elementary.edu',
    813827            'content'      => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.',
     
    828842
    829843        $params = array(
    830             'post'        => $this->post_id,
     844            'post'        => self::$post_id,
    831845            'author_name' => 'Edna Krabappel',
    832846            'content'     => 'Now, I don\'t want you to worry class. These tests will have no affect on your grades. They merely determine your future social status and financial success. If any.',
     
    847861
    848862        $params = array(
    849             'post'         => $this->post_id,
     863            'post'         => self::$post_id,
    850864            'author_name'  => 'Reverend Lovejoy',
    851865            'author_email' => 'lovejoy@example.com',
     
    866880
    867881        $params = array(
    868             'post'         => $this->post_id,
     882            'post'         => self::$post_id,
    869883            'author_name'  => 'Reverend Lovejoy',
    870884            'author_email' => 'lovejoy@example.com',
     
    889903        ));
    890904
    891         wp_set_current_user( $this->admin_id );
    892         $params = array(
    893             'post'    => $this->post_id,
     905        wp_set_current_user( self::$admin_id );
     906        $params = array(
     907            'post'    => self::$post_id,
    894908            'author_name'  => 'Comic Book Guy',
    895909            'author_email' => 'cbg@androidsdungeon.com',
     
    912926    public function test_create_comment_without_type() {
    913927        $post_id = $this->factory->post->create();
    914         wp_set_current_user( $this->admin_id );
     928        wp_set_current_user( self::$admin_id );
    915929
    916930        $params = array(
    917931            'post'    => $post_id,
    918             'author'       => $this->admin_id,
     932            'author'       => self::$admin_id,
    919933            'author_name'  => 'Comic Book Guy',
    920934            'author_email' => 'cbg@androidsdungeon.com',
     
    957971
    958972        $params = array(
    959             'post' => $this->post_id,
     973            'post' => self::$post_id,
    960974            'content' => "Well sir, there's nothing on earth like a genuine, bona fide, electrified, six-car Monorail!",
    961975        );
     
    979993
    980994    public function test_create_comment_other_user() {
    981         wp_set_current_user( $this->admin_id );
    982 
    983         $params = array(
    984             'post'    => $this->post_id,
     995        wp_set_current_user( self::$admin_id );
     996
     997        $params = array(
     998            'post'    => self::$post_id,
    985999            'author_name'  => 'Homer Jay Simpson',
    9861000            'author_email' => 'chunkylover53@aol.com',
    9871001            'author_url'   => 'http://compuglobalhypermeganet.com',
    9881002            'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    989             'author'    => $this->subscriber_id,
     1003            'author'    => self::$subscriber_id,
    9901004        );
    9911005
     
    9971011        $this->assertEquals( 201, $response->get_status() );
    9981012        $data = $response->get_data();
    999         $this->assertEquals( $this->subscriber_id, $data['author'] );
     1013        $this->assertEquals( self::$subscriber_id, $data['author'] );
    10001014        $this->assertEquals( 'Homer Jay Simpson', $data['author_name'] );
    10011015        $this->assertEquals( 'chunkylover53@aol.com', $data['author_email'] );
     
    10041018
    10051019    public function test_create_comment_other_user_without_permission() {
    1006         wp_set_current_user( $this->subscriber_id );
    1007 
    1008         $params = array(
    1009             'post'         => $this->post_id,
     1020        wp_set_current_user( self::$subscriber_id );
     1021
     1022        $params = array(
     1023            'post'         => self::$post_id,
    10101024            'author_name'  => 'Homer Jay Simpson',
    10111025            'author_email' => 'chunkylover53@aol.com',
    10121026            'author_url'   => 'http://compuglobalhypermeganet.com',
    10131027            'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1014             'author'       => $this->admin_id,
     1028            'author'       => self::$admin_id,
    10151029        );
    10161030
     
    10241038
    10251039    public function test_create_comment_karma_without_permission() {
    1026         wp_set_current_user( $this->subscriber_id );
    1027 
    1028         $params = array(
    1029             'post'         => $this->post_id,
     1040        wp_set_current_user( self::$subscriber_id );
     1041
     1042        $params = array(
     1043            'post'         => self::$post_id,
    10301044            'author_name'  => 'Homer Jay Simpson',
    10311045            'author_email' => 'chunkylover53@aol.com',
    10321046            'author_url'   => 'http://compuglobalhypermeganet.com',
    10331047            'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1034             'author'       => $this->subscriber_id,
     1048            'author'       => self::$subscriber_id,
    10351049            'karma'        => 100,
    10361050        );
     
    10451059
    10461060    public function test_create_comment_status_without_permission() {
    1047         wp_set_current_user( $this->subscriber_id );
    1048 
    1049         $params = array(
    1050             'post'         => $this->post_id,
     1061        wp_set_current_user( self::$subscriber_id );
     1062
     1063        $params = array(
     1064            'post'         => self::$post_id,
    10511065            'author_name'  => 'Homer Jay Simpson',
    10521066            'author_email' => 'chunkylover53@aol.com',
    10531067            'author_url'   => 'http://compuglobalhypermeganet.com',
    10541068            'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1055             'author'       => $this->subscriber_id,
     1069            'author'       => self::$subscriber_id,
    10561070            'status'        => 'approved',
    10571071        );
     
    10671081    public function test_create_comment_with_status_IP_and_user_agent() {
    10681082        $post_id = $this->factory->post->create();
    1069         wp_set_current_user( $this->admin_id );
     1083        wp_set_current_user( self::$admin_id );
    10701084
    10711085        $params = array(
     
    10941108
    10951109    public function test_create_comment_invalid_author_IP() {
    1096         wp_set_current_user( $this->admin_id );
     1110        wp_set_current_user( self::$admin_id );
    10971111
    10981112        $params = array(
     
    11141128
    11151129    public function test_create_comment_no_post_id() {
    1116         wp_set_current_user( $this->admin_id );
     1130        wp_set_current_user( self::$admin_id );
    11171131
    11181132        $params = array(
     
    11321146
    11331147    public function test_create_comment_no_post_id_no_permission() {
    1134         wp_set_current_user( $this->subscriber_id );
     1148        wp_set_current_user( self::$subscriber_id );
    11351149
    11361150        $params = array(
     
    11391153            'author_url'   => 'http://compuglobalhypermeganet.com',
    11401154            'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1141             'author'       => $this->subscriber_id,
     1155            'author'       => self::$subscriber_id,
    11421156        );
    11431157        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     
    11511165
    11521166    public function test_create_comment_draft_post() {
    1153         wp_set_current_user( $this->subscriber_id );
    1154 
    1155         $params = array(
    1156             'post'         => $this->draft_id,
     1167        wp_set_current_user( self::$subscriber_id );
     1168
     1169        $params = array(
     1170            'post'         => self::$draft_id,
    11571171            'author_name'  => 'Ishmael',
    11581172            'author_email' => 'herman-melville@earthlink.net',
    11591173            'author_url'   => 'https://en.wikipedia.org/wiki/Herman_Melville',
    11601174            'content'      => 'Call me Ishmael.',
    1161             'author'       => $this->subscriber_id,
     1175            'author'       => self::$subscriber_id,
    11621176        );
    11631177        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     
    11711185
    11721186    public function test_create_comment_trash_post() {
    1173         wp_set_current_user( $this->subscriber_id );
    1174 
    1175         $params = array(
    1176             'post'         => $this->trash_id,
     1187        wp_set_current_user( self::$subscriber_id );
     1188
     1189        $params = array(
     1190            'post'         => self::$trash_id,
    11771191            'author_name'  => 'Ishmael',
    11781192            'author_email' => 'herman-melville@earthlink.net',
    11791193            'author_url'   => 'https://en.wikipedia.org/wiki/Herman_Melville',
    11801194            'content'      => 'Call me Ishmael.',
    1181             'author'       => $this->subscriber_id,
     1195            'author'       => self::$subscriber_id,
    11821196        );
    11831197        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     
    11911205
    11921206    public function test_create_comment_private_post_invalid_permission() {
    1193         wp_set_current_user( $this->subscriber_id );
    1194 
    1195         $params = array(
    1196             'post'         => $this->private_id,
     1207        wp_set_current_user( self::$subscriber_id );
     1208
     1209        $params = array(
     1210            'post'         => self::$private_id,
    11971211            'author_name'  => 'Homer Jay Simpson',
    11981212            'author_email' => 'chunkylover53@aol.com',
    11991213            'author_url'   => 'http://compuglobalhypermeganet.com',
    12001214            'content'      => 'I\’d be a vegetarian if bacon grew on trees.',
    1201             'author'       => $this->subscriber_id,
     1215            'author'       => self::$subscriber_id,
    12021216        );
    12031217        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     
    12131227        $this->factory->comment->create(
    12141228            array(
    1215                 'comment_post_ID'      => $this->post_id,
     1229                'comment_post_ID'      => self::$post_id,
    12161230                'comment_author'       => 'Guy N. Cognito',
    12171231                'comment_author_email' => 'chunkylover53@aol.co.uk',
     
    12221236
    12231237        $params = array(
    1224             'post'    => $this->post_id,
     1238            'post'    => self::$post_id,
    12251239            'author_name'  => 'Guy N. Cognito',
    12261240            'author_email' => 'chunkylover53@aol.co.uk',
     
    12581272        update_option( 'comment_registration', 1 );
    12591273        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1260         $request->set_param( 'post', $this->post_id );
     1274        $request->set_param( 'post', self::$post_id );
    12611275        $response = $this->server->dispatch( $request );
    12621276        $this->assertEquals( 401, $response->get_status() );
     
    12661280
    12671281    public function test_create_item_invalid_author() {
    1268         wp_set_current_user( $this->admin_id );
    1269 
    1270         $params = array(
    1271             'post'         => $this->post_id,
     1282        wp_set_current_user( self::$admin_id );
     1283
     1284        $params = array(
     1285            'post'         => self::$post_id,
    12721286            'author'       => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER,
    12731287            'content'      => 'It\'s all over\, people! We don\'t have a prayer!',
     
    12831297
    12841298    public function test_create_item_pull_author_info() {
    1285         wp_set_current_user( $this->admin_id );
    1286 
    1287         $author = new WP_User( $this->author_id );
    1288         $params = array(
    1289             'post'         => $this->post_id,
    1290             'author'       => $this->author_id,
     1299        wp_set_current_user( self::$admin_id );
     1300
     1301        $author = new WP_User( self::$author_id );
     1302        $params = array(
     1303            'post'         => self::$post_id,
     1304            'author'       => self::$author_id,
    12911305            'content'      => 'It\'s all over\, people! We don\'t have a prayer!',
    12921306        );
     
    12991313
    13001314        $result = $response->get_data();
    1301         $this->assertSame( $this->author_id, $result['author'] );
     1315        $this->assertSame( self::$author_id, $result['author'] );
    13021316        $this->assertSame( 'Sea Captain', $result['author_name'] );
    13031317        $this->assertSame( 'captain@thefryingdutchman.com', $result['author_email'] );
     
    13091323
    13101324        $params = array(
    1311             'post'    => $this->post_id,
     1325            'post'    => self::$post_id,
    13121326            'author_name'  => 'Comic Book Guy',
    13131327            'author_email' => 'cbg@androidsdungeon.com',
     
    13241338
    13251339        $params = array(
    1326             'post'    => $this->post_id,
     1340            'post'    => self::$post_id,
    13271341            'author_name'  => 'Comic Book Guy',
    13281342            'author_email' => 'cbg@androidsdungeon.com',
     
    13421356        $post_id = $this->factory->post->create();
    13431357
    1344         wp_set_current_user( $this->admin_id );
    1345 
    1346         $params = array(
    1347             'author'       => $this->subscriber_id,
     1358        wp_set_current_user( self::$admin_id );
     1359
     1360        $params = array(
     1361            'author'       => self::$subscriber_id,
    13481362            'author_name'  => 'Disco Stu',
    13491363            'author_url'   => 'http://stusdisco.com',
     
    13551369            'post'         => $post_id,
    13561370        );
    1357         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1371        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    13581372        $request->add_header( 'content-type', 'application/json' );
    13591373        $request->set_body( wp_json_encode( $params ) );
     
    13631377
    13641378        $comment = $response->get_data();
    1365         $updated = get_comment( $this->approved_id );
     1379        $updated = get_comment( self::$approved_id );
    13661380        $this->assertEquals( $params['content'], $comment['content']['raw'] );
    13671381        $this->assertEquals( $params['author'], $comment['author'] );
     
    13781392
    13791393    public function test_update_comment_status() {
    1380         wp_set_current_user( $this->admin_id );
     1394        wp_set_current_user( self::$admin_id );
    13811395
    13821396        $comment_id = $this->factory->comment->create( array(
    13831397            'comment_approved' => 0,
    1384             'comment_post_ID'  => $this->post_id,
     1398            'comment_post_ID'  => self::$post_id,
    13851399        ));
    13861400
     
    14021416
    14031417    public function test_update_comment_field_does_not_use_default_values() {
    1404         wp_set_current_user( $this->admin_id );
     1418        wp_set_current_user( self::$admin_id );
    14051419
    14061420        $comment_id = $this->factory->comment->create( array(
    14071421            'comment_approved' => 0,
    1408             'comment_post_ID'  => $this->post_id,
     1422            'comment_post_ID'  => self::$post_id,
    14091423            'comment_content'  => 'some content',
    14101424        ));
     
    14281442
    14291443    public function test_update_comment_date_gmt() {
    1430         wp_set_current_user( $this->admin_id );
     1444        wp_set_current_user( self::$admin_id );
    14311445
    14321446        $params = array(
     
    14341448            'content'  => 'I\'ll be deep in the cold, cold ground before I recognize Missouri.',
    14351449        );
    1436         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1450        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    14371451        $request->add_header( 'content-type', 'application/json' );
    14381452        $request->set_body( wp_json_encode( $params ) );
     
    14421456
    14431457        $comment = $response->get_data();
    1444         $updated = get_comment( $this->approved_id );
     1458        $updated = get_comment( self::$approved_id );
    14451459        $this->assertEquals( $params['date_gmt'], $comment['date_gmt'] );
    14461460        $this->assertEquals( $params['date_gmt'], mysql_to_rfc3339( $updated->comment_date_gmt ) );
     
    14481462
    14491463    public function test_update_comment_invalid_type() {
    1450         wp_set_current_user( $this->admin_id );
     1464        wp_set_current_user( self::$admin_id );
    14511465
    14521466        $params = array(
    14531467            'type' => 'trackback',
    14541468        );
    1455         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1469        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    14561470        $request->add_header( 'content-type', 'application/json' );
    14571471        $request->set_body( wp_json_encode( $params ) );
     
    14621476
    14631477    public function test_update_comment_with_raw_property() {
    1464         wp_set_current_user( $this->admin_id );
     1478        wp_set_current_user( self::$admin_id );
    14651479
    14661480        $params = array(
     
    14691483            ),
    14701484        );
    1471         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1485        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    14721486        $request->add_header( 'content-type', 'application/json' );
    14731487        $request->set_body( wp_json_encode( $params ) );
     
    14781492
    14791493        $comment = $response->get_data();
    1480         $updated = get_comment( $this->approved_id );
     1494        $updated = get_comment( self::$approved_id );
    14811495        $this->assertEquals( $params['content']['raw'], $updated->comment_content );
    14821496    }
    14831497
    14841498    public function test_update_item_invalid_date() {
    1485         wp_set_current_user( $this->admin_id );
     1499        wp_set_current_user( self::$admin_id );
    14861500
    14871501        $params = array(
     
    14901504        );
    14911505
    1492         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1506        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    14931507        $request->add_header( 'content-type', 'application/json' );
    14941508        $request->set_body( wp_json_encode( $params ) );
     
    14991513
    15001514    public function test_update_item_invalid_date_gmt() {
    1501         wp_set_current_user( $this->admin_id );
     1515        wp_set_current_user( self::$admin_id );
    15021516
    15031517        $params = array(
     
    15061520        );
    15071521
    1508         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1522        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    15091523        $request->add_header( 'content-type', 'application/json' );
    15101524        $request->set_body( wp_json_encode( $params ) );
     
    15341548            'content' => 'Disco Stu likes disco music.',
    15351549        );
    1536         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', $this->hold_id ) );
     1550        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$hold_id ) );
    15371551        $request->add_header( 'content-type', 'application/json' );
    15381552        $request->set_body( wp_json_encode( $params ) );
     
    15451559        $private_comment_id = $this->factory->comment->create( array(
    15461560            'comment_approved' => 1,
    1547             'comment_post_ID'  => $this->private_id,
     1561            'comment_post_ID'  => self::$private_id,
    15481562            'user_id'          => 0,
    15491563        ));
    15501564
    1551         wp_set_current_user( $this->subscriber_id );
     1565        wp_set_current_user( self::$subscriber_id );
    15521566
    15531567        $params = array(
     
    15631577
    15641578    public function test_update_comment_with_children_link() {
    1565         wp_set_current_user( $this->admin_id );
     1579        wp_set_current_user( self::$admin_id );
    15661580        $comment_id_1 = $this->factory->comment->create( array(
    15671581            'comment_approved' => 1,
    1568             'comment_post_ID'  => $this->post_id,
    1569             'user_id'          => $this->subscriber_id,
     1582            'comment_post_ID'  => self::$post_id,
     1583            'user_id'          => self::$subscriber_id,
    15701584        ) );
    15711585
    15721586        $child_comment = $this->factory->comment->create( array(
    15731587            'comment_approved' => 1,
    1574             'comment_post_ID'  => $this->post_id,
    1575             'user_id'          => $this->subscriber_id,
     1588            'comment_post_ID'  => self::$post_id,
     1589            'user_id'          => self::$subscriber_id,
    15761590        ) );
    15771591
     
    15971611
    15981612    public function test_delete_item() {
    1599         wp_set_current_user( $this->admin_id );
     1613        wp_set_current_user( self::$admin_id );
    16001614
    16011615        $comment_id = $this->factory->comment->create( array(
    16021616            'comment_approved' => 1,
    1603             'comment_post_ID'  => $this->post_id,
    1604             'user_id'          => $this->subscriber_id,
     1617            'comment_post_ID'  => self::$post_id,
     1618            'user_id'          => self::$subscriber_id,
    16051619        ));
    16061620        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
     
    16091623        $this->assertEquals( 200, $response->get_status() );
    16101624        $data = $response->get_data();
    1611         $this->assertEquals( $this->post_id, $data['post'] );
     1625        $this->assertEquals( self::$post_id, $data['post'] );
    16121626    }
    16131627
    16141628    public function test_delete_item_skip_trash() {
    1615         wp_set_current_user( $this->admin_id );
     1629        wp_set_current_user( self::$admin_id );
    16161630
    16171631        $comment_id = $this->factory->comment->create( array(
    16181632            'comment_approved' => 1,
    1619             'comment_post_ID'  => $this->post_id,
    1620             'user_id'          => $this->subscriber_id,
     1633            'comment_post_ID'  => self::$post_id,
     1634            'user_id'          => self::$subscriber_id,
    16211635        ));
    16221636        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
     
    16261640        $this->assertEquals( 200, $response->get_status() );
    16271641        $data = $response->get_data();
    1628         $this->assertEquals( $this->post_id, $data['post'] );
     1642        $this->assertEquals( self::$post_id, $data['post'] );
    16291643    }
    16301644
    16311645    public function test_delete_item_already_trashed() {
    1632         wp_set_current_user( $this->admin_id );
     1646        wp_set_current_user( self::$admin_id );
    16331647
    16341648        $comment_id = $this->factory->comment->create( array(
    16351649            'comment_approved' => 1,
    1636             'comment_post_ID'  => $this->post_id,
    1637             'user_id'          => $this->subscriber_id,
     1650            'comment_post_ID'  => self::$post_id,
     1651            'user_id'          => self::$subscriber_id,
    16381652        ));
    16391653        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $comment_id ) );
     
    16461660
    16471661    public function test_delete_comment_invalid_id() {
    1648         wp_set_current_user( $this->admin_id );
     1662        wp_set_current_user( self::$admin_id );
    16491663
    16501664        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ) );
     
    16551669
    16561670    public function test_delete_comment_without_permission() {
    1657         wp_set_current_user( $this->subscriber_id );
    1658 
    1659         $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1671        wp_set_current_user( self::$subscriber_id );
     1672
     1673        $request = new WP_REST_Request( 'DELETE', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    16601674
    16611675        $response = $this->server->dispatch( $request );
     
    16641678
    16651679    public function test_delete_child_comment_link() {
    1666         wp_set_current_user( $this->admin_id );
     1680        wp_set_current_user( self::$admin_id );
    16671681        $comment_id_1 = $this->factory->comment->create( array(
    16681682            'comment_approved' => 1,
    1669             'comment_post_ID'  => $this->post_id,
    1670             'user_id'          => $this->subscriber_id,
     1683            'comment_post_ID'  => self::$post_id,
     1684            'user_id'          => self::$subscriber_id,
    16711685        ) );
    16721686
     
    16741688            'comment_approved' => 1,
    16751689            'comment_parent'   => $comment_id_1,
    1676             'comment_post_ID'  => $this->post_id,
    1677             'user_id'          => $this->subscriber_id,
     1690            'comment_post_ID'  => self::$post_id,
     1691            'user_id'          => self::$subscriber_id,
    16781692        ) );
    16791693
     
    17481762        $this->assertEquals( $schema, $data['schema']['properties']['my_custom_int'] );
    17491763
    1750         $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . $this->approved_id );
     1764        $request = new WP_REST_Request( 'GET', '/wp/v2/comments/' . self::$approved_id );
    17511765
    17521766        $response = $this->server->dispatch( $request );
    17531767        $this->assertArrayHasKey( 'my_custom_int', $response->data );
    17541768
    1755         $request = new WP_REST_Request( 'POST', '/wp/v2/comments/' . $this->approved_id );
     1769        $request = new WP_REST_Request( 'POST', '/wp/v2/comments/' . self::$approved_id );
    17561770        $request->set_body_params(array(
    17571771            'my_custom_int' => 123,
     
    17611775        wp_set_current_user( 1 );
    17621776        $this->server->dispatch( $request );
    1763         $this->assertEquals( 123, get_comment_meta( $this->approved_id, 'my_custom_int', true ) );
     1777        $this->assertEquals( 123, get_comment_meta( self::$approved_id, 'my_custom_int', true ) );
    17641778
    17651779        $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
     
    17681782            'title'         => 'hello',
    17691783            'content'       => 'goodbye',
    1770             'post'          => $this->post_id,
     1784            'post'          => self::$post_id,
    17711785        ));
    17721786
     
    17931807        ) );
    17941808
    1795         wp_set_current_user( $this->admin_id );
     1809        wp_set_current_user( self::$admin_id );
    17961810
    17971811        // Check for error on update.
    1798         $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/comments/%d', $this->approved_id ) );
     1812        $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/comments/%d', self::$approved_id ) );
    17991813        $request->set_body_params(array(
    18001814            'my_custom_int' => 'returnError',
Note: See TracChangeset for help on using the changeset viewer.