WordPress.org

Make WordPress Core

Changeset 38941


Ignore:
Timestamp:
10/26/16 01:59:00 (7 months ago)
Author:
boonebgorges
Message:

Tests: Share fixtures in term endpoint tests.

See #30017.

File:
1 edited

Legend:

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

    r38834 r38941  
    1111 */ 
    1212class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 
    13  
    14     public function setUp() { 
    15         parent::setUp(); 
    16         $this->administrator = $this->factory->user->create( array( 
     13    protected static $administrator; 
     14    protected static $subscriber; 
     15 
     16    public static function wpSetUpBeforeClass( $factory ) { 
     17        self::$administrator = $factory->user->create( array( 
    1718            'role' => 'administrator', 
    1819        ) ); 
    19         $this->subscriber = $this->factory->user->create( array( 
     20        self::$subscriber = $factory->user->create( array( 
    2021            'role' => 'subscriber', 
    2122        ) ); 
     23    } 
     24 
     25    public static function wpTearDownAfterClass() { 
     26        self::delete_user( self::$administrator ); 
     27        self::delete_user( self::$subscriber ); 
    2228    } 
    2329 
     
    451457 
    452458    public function test_create_item() { 
    453         wp_set_current_user( $this->administrator ); 
     459        wp_set_current_user( self::$administrator ); 
    454460        $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 
    455461        $request->set_param( 'name', 'My Awesome Term' ); 
     
    467473 
    468474    public function test_create_item_incorrect_permissions() { 
    469         wp_set_current_user( $this->subscriber ); 
     475        wp_set_current_user( self::$subscriber ); 
    470476        $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 
    471477        $request->set_param( 'name', 'Incorrect permissions' ); 
     
    475481 
    476482    public function test_create_item_missing_arguments() { 
    477         wp_set_current_user( $this->administrator ); 
     483        wp_set_current_user( self::$administrator ); 
    478484        $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 
    479485        $response = $this->server->dispatch( $request ); 
     
    482488 
    483489    public function test_create_item_parent_non_hierarchical_taxonomy() { 
    484         wp_set_current_user( $this->administrator ); 
     490        wp_set_current_user( self::$administrator ); 
    485491 
    486492        $request = new WP_REST_Request( 'POST', '/wp/v2/tags' ); 
     
    492498 
    493499    public function test_update_item() { 
    494         wp_set_current_user( $this->administrator ); 
     500        wp_set_current_user( self::$administrator ); 
    495501        $orig_args = array( 
    496502            'name'        => 'Original Name', 
     
    512518 
    513519    public function test_update_item_invalid_term() { 
    514         wp_set_current_user( $this->administrator ); 
     520        wp_set_current_user( self::$administrator ); 
    515521        $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 
    516522        $request->set_param( 'name', 'Invalid Term' ); 
     
    520526 
    521527    public function test_update_item_incorrect_permissions() { 
    522         wp_set_current_user( $this->subscriber ); 
     528        wp_set_current_user( self::$subscriber ); 
    523529        $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 
    524530        $request = new WP_REST_Request( 'POST', '/wp/v2/tags/' . $term->term_id ); 
     
    529535 
    530536    public function test_update_item_parent_non_hierarchical_taxonomy() { 
    531         wp_set_current_user( $this->administrator ); 
     537        wp_set_current_user( self::$administrator ); 
    532538        $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 
    533539 
     
    539545 
    540546    public function test_delete_item() { 
    541         wp_set_current_user( $this->administrator ); 
     547        wp_set_current_user( self::$administrator ); 
    542548        $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 
    543549        $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 
     
    550556 
    551557    public function test_delete_item_force_false() { 
    552         wp_set_current_user( $this->administrator ); 
     558        wp_set_current_user( self::$administrator ); 
    553559        $term = get_term_by( 'id', $this->factory->tag->create( array( 'name' => 'Deleted Tag' ) ), 'post_tag' ); 
    554560        $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 
     
    559565 
    560566    public function test_delete_item_invalid_term() { 
    561         wp_set_current_user( $this->administrator ); 
     567        wp_set_current_user( self::$administrator ); 
    562568        $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER ); 
    563569        $response = $this->server->dispatch( $request ); 
     
    566572 
    567573    public function test_delete_item_incorrect_permissions() { 
    568         wp_set_current_user( $this->subscriber ); 
     574        wp_set_current_user( self::$subscriber ); 
    569575        $term = get_term_by( 'id', $this->factory->tag->create(), 'post_tag' ); 
    570576        $request = new WP_REST_Request( 'DELETE', '/wp/v2/tags/' . $term->term_id ); 
     
    653659        ) ); 
    654660 
    655         wp_set_current_user( $this->administrator ); 
     661        wp_set_current_user( self::$administrator ); 
    656662        $tag_id = $this->factory->tag->create(); 
    657663        // Check for error on update. 
Note: See TracChangeset for help on using the changeset viewer.