WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/10/2016 01:53:08 AM (4 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Re-use a bunch of fixtures in test classes for user and XMLRPC tests.

Shaves a couple of seconds off of the tests.

See #30017, #38716

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/getComment.php

    r35242 r39189  
    55 */
    66class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase {
    7     var $post_id;
    8     var $parent_comment_id;
    9     var $parent_comment_data;
    10     var $child_comment_id;
    11     var $child_comment_data;
     7    protected static $post_id;
     8    protected static $parent_comment_id;
     9    protected static $parent_comment_data;
     10    protected static $child_comment_id;
     11    protected static $child_comment_data;
    1212
    13     function setUp() {
    14         parent::setUp();
     13    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     14        self::$post_id = $factory->post->create();
    1515
    16         $this->post_id = self::factory()->post->create();
    17 
    18         $this->parent_comment_data = array(
    19             'comment_post_ID' => $this->post_id,
     16        self::$parent_comment_data = array(
     17            'comment_post_ID' => self::$post_id,
    2018            'comment_author' => 'Test commenter',
    2119            'comment_author_url' => 'http://example.com/',
     
    2321            'comment_content' => rand_str( 100 ),
    2422        );
    25         $this->parent_comment_id = wp_insert_comment( $this->parent_comment_data );
     23        self::$parent_comment_id = wp_insert_comment( self::$parent_comment_data );
    2624
    27         $this->child_comment_data = array(
    28             'comment_post_ID' => $this->post_id,
     25        self::$child_comment_data = array(
     26            'comment_post_ID' => self::$post_id,
    2927            'comment_author' => 'Test commenter 2',
    3028            'comment_author_url' => 'http://example.org/',
    3129            'comment_author_email' => 'example@example.org',
    32             'comment_parent' => $this->parent_comment_id,
     30            'comment_parent' => self::$parent_comment_id,
    3331            'comment_content' => rand_str( 100 )
    3432        );
    35         $this->child_comment_id = wp_insert_comment( $this->child_comment_data );
     33        self::$child_comment_id = wp_insert_comment( self::$child_comment_data );
    3634    }
    3735
    3836    function test_invalid_username_password() {
    39         $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', $this->parent_comment_id ) );
     37        $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', self::$parent_comment_id ) );
    4038        $this->assertInstanceOf( 'IXR_Error', $result );
    4139        $this->assertEquals( 403, $result->code );
     
    4543        $this->make_user_by_role( 'contributor' );
    4644
    47         $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', $this->parent_comment_id ) );
     45        $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', self::$parent_comment_id ) );
    4846        $this->assertInstanceOf( 'IXR_Error', $result );
    4947        $this->assertEquals( 403, $result->code );
     
    5351        $this->make_user_by_role( 'editor' );
    5452
    55         $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->parent_comment_id ) );
     53        $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$parent_comment_id ) );
    5654        $this->assertNotInstanceOf( 'IXR_Error', $result );
    5755
     
    7775        $this->assertStringMatchesFormat( '%d', $result['parent'] );
    7876        $this->assertStringMatchesFormat( '%d', $result['post_id'] );
    79         $this->assertEquals( $this->parent_comment_id, $result['comment_id'] );
     77        $this->assertEquals( self::$parent_comment_id, $result['comment_id'] );
    8078        $this->assertEquals( 0, $result['parent'] );
    81         $this->assertEquals( $this->parent_comment_data['comment_content'], $result['content'] );
    82         $this->assertEquals( $this->post_id, $result['post_id'] );
    83         $this->assertEquals( $this->parent_comment_data['comment_author'], $result['author'] );
    84         $this->assertEquals( $this->parent_comment_data['comment_author_url'], $result['author_url'] );
    85         $this->assertEquals( $this->parent_comment_data['comment_author_email'], $result['author_email'] );
     79        $this->assertEquals( self::$parent_comment_data['comment_content'], $result['content'] );
     80        $this->assertEquals( self::$post_id, $result['post_id'] );
     81        $this->assertEquals( self::$parent_comment_data['comment_author'], $result['author'] );
     82        $this->assertEquals( self::$parent_comment_data['comment_author_url'], $result['author_url'] );
     83        $this->assertEquals( self::$parent_comment_data['comment_author_email'], $result['author_email'] );
    8684    }
    8785
     
    8987        $this->make_user_by_role( 'editor' );
    9088
    91         $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->child_comment_id ) );
     89        $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$child_comment_id ) );
    9290        $this->assertNotInstanceOf( 'IXR_Error', $result );
    9391
    94         $this->assertEquals( $this->child_comment_id, $result['comment_id'] );
    95         $this->assertEquals( $this->parent_comment_id, $result['parent'] );
     92        $this->assertEquals( self::$child_comment_id, $result['comment_id'] );
     93        $this->assertEquals( self::$parent_comment_id, $result['parent'] );
    9694    }
    9795
Note: See TracChangeset for help on using the changeset viewer.