Make WordPress Core


Ignore:
Timestamp:
11/10/2016 01:53:08 AM (7 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/mw/getRecentPosts.php

    r35244 r39189  
    55 */
    66class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
    7     var $post_data;
    8     var $post_id;
    9     var $post_date_ts;
     7    protected static $post_id;
    108
    11     function setUp() {
    12         parent::setUp();
    13 
    14         $author_id = $this->make_user_by_role( 'author' );
    15         $this->post_date_ts = strtotime( '+1 day' );
    16         $this->post_data = array(
    17             'post_title' => rand_str(),
    18             'post_content' => rand_str( 2000 ),
    19             'post_excerpt' => rand_str( 100 ),
    20             'post_author' => $author_id,
    21             'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    22         );
    23         $this->post_id = wp_insert_post( $this->post_data );
     9    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     10        self::$post_id = $factory->post->create( array(
     11            'post_type'   => 'page',
     12            'post_author' => $factory->user->create( array(
     13                'user_login' => 'author',
     14                'user_pass'  => 'author',
     15                'role'       => 'author'
     16            ) ),
     17            'post_date'   => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ),
     18        ) );
    2419    }
    2520
     
    4237
    4338    function test_no_editable_posts() {
    44         wp_delete_post( $this->post_id, true );
     39        wp_delete_post( self::$post_id, true );
    4540
    4641        $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) );
     
    10196        // create attachment
    10297        $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
    103         $attachment_id = self::factory()->attachment->create_upload_object( $filename, $this->post_id );
    104         set_post_thumbnail( $this->post_id, $attachment_id );
     98        $attachment_id = self::factory()->attachment->create_upload_object( $filename, self::$post_id );
     99        set_post_thumbnail( self::$post_id, $attachment_id );
    105100
    106         $results = $this->myxmlrpcserver->mw_getRecentPosts( array( $this->post_id, 'author', 'author' ) );
     101        $results = $this->myxmlrpcserver->mw_getRecentPosts( array( self::$post_id, 'author', 'author' ) );
    107102        $this->assertNotInstanceOf( 'IXR_Error', $results );
    108103
     
    111106            $this->assertStringMatchesFormat( '%d', $result['wp_post_thumbnail'] );
    112107
    113             if( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == $this->post_id ) {
     108            if( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == self::$post_id ) {
    114109                $attachment_id = get_post_meta( $result['postid'], '_thumbnail_id', true );
    115110
Note: See TracChangeset for help on using the changeset viewer.