Make WordPress Core


Ignore:
Timestamp:
10/27/2016 02:56:28 AM (10 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-pages-controller.php

    r38968 r38975  
    1212  */
    1313class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Testcase {
     14        protected static $editor_id;
     15
     16        public static function wpSetUpBeforeClass( $factory ) {
     17                self::$editor_id = $factory->user->create( array(
     18                        'role' => 'editor',
     19                ) );
     20        }
     21
     22        public static function wpTearDownAfterClass() {
     23                self::delete_user( self::$editor_id );
     24        }
    1425
    1526        public function setUp() {
    1627                parent::setUp();
    17 
    18                 $this->editor_id = $this->factory->user->create( array(
    19                         'role' => 'editor',
    20                 ) );
    21                 $this->author_id = $this->factory->user->create( array(
    22                         'role' => 'author',
    23                 ) );
    24 
    2528                $this->has_setup_template = false;
    2629                add_filter( 'theme_page_templates', array( $this, 'filter_theme_page_templates' ) );
     
    184187
    185188                // But they are accessible to authorized users
    186                 wp_set_current_user( $this->editor_id );
     189                wp_set_current_user( self::$editor_id );
    187190                $response = $this->server->dispatch( $request );
    188191                $data = $response->get_data();
     
    228231
    229232        public function test_create_item_with_template() {
    230                 wp_set_current_user( $this->editor_id );
     233                wp_set_current_user( self::$editor_id );
    231234
    232235                $request = new WP_REST_Request( 'POST', '/wp/v2/pages' );
     
    247250                        'type' => 'page',
    248251                ) );
    249                 wp_set_current_user( $this->editor_id );
     252                wp_set_current_user( self::$editor_id );
    250253
    251254                $request = new WP_REST_Request( 'POST', '/wp/v2/pages' );
     
    268271
    269272        public function test_create_page_with_invalid_parent() {
    270                 wp_set_current_user( $this->editor_id );
     273                wp_set_current_user( self::$editor_id );
    271274
    272275                $request = new WP_REST_Request( 'POST', '/wp/v2/pages' );
     
    323326                ) );
    324327
    325                 wp_set_current_user( $this->editor_id );
     328                wp_set_current_user( self::$editor_id );
    326329
    327330                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', $page_id ) );
     
    343346                ) );
    344347
    345                 wp_set_current_user( $this->editor_id );
     348                wp_set_current_user( self::$editor_id );
    346349
    347350                $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', $page_id ) );
Note: See TracChangeset for help on using the changeset viewer.