Make WordPress Core


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

    r38698 r39189  
    55 */
    66class Tests_XMLRPC_wp_editTerm extends WP_XMLRPC_UnitTestCase {
    7     var $parent_term;
    8     var $child_term;
    9     var $post_tag;
     7    protected static $parent_term;
     8    protected static $child_term;
     9    protected static $post_tag;
    1010
    11     function setUp() {
    12         parent::setUp();
    13 
    14         $this->parent_term = wp_insert_term( 'parent' . rand_str() , 'category' );
    15         $this->assertInternalType( 'array', $this->parent_term );
    16         $this->child_term = wp_insert_term( 'child' . rand_str() , 'category' );
    17         $this->assertInternalType( 'array', $this->child_term );
    18         $this->post_tag = wp_insert_term( 'test' . rand_str() , 'post_tag' );
    19         $this->assertInternalType( 'array', $this->post_tag );
     11    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     12        self::$parent_term = $factory->term->create( array(
     13            'taxonomy' => 'category',
     14        ) );
     15        self::$child_term = $factory->term->create( array(
     16            'taxonomy' => 'category',
     17        ) );
     18        self::$post_tag = $factory->term->create( array(
     19            'taxonomy' => 'post_tag',
     20        ) );
    2021    }
    2122
     
    3839        $this->make_user_by_role( 'subscriber' );
    3940
    40         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'not_existing' ) ) );
     41        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'not_existing' ) ) );
    4142        $this->assertInstanceOf( 'IXR_Error', $result );
    4243        $this->assertEquals( 403, $result->code );
     
    4748        $this->make_user_by_role( 'subscriber' );
    4849
    49         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'category' ) ) );
     50        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'category' ) ) );
    5051        $this->assertInstanceOf( 'IXR_Error', $result );
    5152        $this->assertEquals( 401, $result->code );
     
    7475        $this->make_user_by_role( 'editor' );
    7576
    76         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->parent_term['term_id'], array( 'taxonomy' => 'category', 'name' => '' ) ) );
     77        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$parent_term, array( 'taxonomy' => 'category', 'name' => '' ) ) );
    7778        $this->assertInstanceOf( 'IXR_Error', $result );
    7879        $this->assertEquals( 403, $result->code );
     
    8384        $this->make_user_by_role( 'editor' );
    8485
    85         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->post_tag['term_id'], array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term['term_id'] ) ) );
     86        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$post_tag, array( 'taxonomy' => 'post_tag', 'parent' => self::$parent_term ) ) );
    8687        $this->assertInstanceOf( 'IXR_Error', $result );
    8788        $this->assertEquals( 403, $result->code );
     
    9293        $this->make_user_by_role( 'editor' );
    9394
    94         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) );
     95        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) );
    9596        $this->assertNotInstanceOf( 'IXR_Error', $result );
    9697        $this->assertTrue( $result );
     
    100101        $this->make_user_by_role( 'editor' );
    101102
    102         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => NULL, 'name' => 'test' ) ) );
     103        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => NULL, 'name' => 'test' ) ) );
    103104
    104105        $this->assertNotInstanceOf( 'IXR_Error', $result );
    105106        $this->assertInternalType( 'boolean', $result );
    106107
    107         $term = get_term( $this->child_term['term_id'], 'category' );
     108        $term = get_term( self::$child_term, 'category' );
    108109        $this->assertEquals( '0', $term->parent );
    109110    }
     
    112113        $this->make_user_by_role( 'editor' );
    113114
    114         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) );
     115        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) );
    115116        $this->assertInstanceOf( 'IXR_Error', $result );
    116117        $this->assertEquals( 500, $result->code );
     
    120121        $this->make_user_by_role( 'editor' );
    121122
    122         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) );
     123        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) );
    123124        $this->assertInstanceOf( 'IXR_Error', $result );
    124125        $this->assertEquals( 403, $result->code );
     
    129130        $this->make_user_by_role( 'editor' );
    130131
    131         $parent_term = get_term_by( 'id', $this->parent_term['term_id'], 'category' );
    132         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'slug' => $parent_term->slug ) ) );
     132        $parent_term = get_term_by( 'id', self::$parent_term, 'category' );
     133        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'slug' => $parent_term->slug ) ) );
    133134        $this->assertInstanceOf( 'IXR_Error', $result );
    134135        $this->assertEquals( 500, $result->code );
     
    139140        $this->make_user_by_role( 'editor' );
    140141
    141         $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => $this->parent_term['term_id'], 'description' => 'Child term', 'slug' => 'child_2' );
    142         $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], $fields ) );
     142        $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => self::$parent_term, 'description' => 'Child term', 'slug' => 'child_2' );
     143        $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, $fields ) );
    143144
    144145        $this->assertNotInstanceOf( 'IXR_Error', $result );
Note: See TracChangeset for help on using the changeset viewer.