WordPress.org

Make WordPress Core

Changeset 39189


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

Location:
trunk/tests/phpunit/tests
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/author.php

    r37306 r39189  
    88 */
    99class Tests_User_Author_Template extends WP_UnitTestCase {
    10     protected $author_id = 0;
    11     protected $post_id = 0;
     10    protected static $author_id = 0;
     11    protected static $post_id = 0;
    1212
    1313    private $permalink_structure;
     14
     15    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     16        self::$author_id = $factory->user->create( array(
     17            'role' => 'author',
     18            'user_login' => 'test_author',
     19            'description' => 'test_author',
     20        ) );
     21
     22        self::$post_id = $factory->post->create( array(
     23            'post_author' => self::$author_id,
     24            'post_status' => 'publish',
     25            'post_content' => rand_str(),
     26            'post_title' => rand_str(),
     27            'post_type' => 'post'
     28        ) );
     29    }
    1430
    1531    function setUp() {
    1632        parent::setUp();
    1733
    18         $this->author_id = self::factory()->user->create( array(
    19             'role' => 'author',
    20             'user_login' => 'test_author',
    21             'description' => 'test_author',
    22         ) );
    23         $user = new WP_User( $this->author_id );
    24 
    25         $post = array(
    26             'post_author' => $this->author_id,
    27             'post_status' => 'publish',
    28             'post_content' => rand_str(),
    29             'post_title' => rand_str(),
    30             'post_type' => 'post'
    31         );
    32 
    33         // insert a post and make sure the ID is ok
    34         $this->post_id = self::factory()->post->create( $post );
    35 
    36         setup_postdata( get_post( $this->post_id ) );
     34        setup_postdata( get_post( self::$post_id ) );
    3735    }
    3836
     
    4442    function test_get_the_author() {
    4543        $author_name = get_the_author();
    46         $user = new WP_User( $this->author_id );
     44        $user = new WP_User( self::$author_id );
    4745
    4846        $this->assertEquals( $user->display_name, $author_name );
     
    5755        $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
    5856        $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
    59         add_user_meta( $this->author_id, 'user_description', 'user description' );
    60         $this->assertEquals( 'user description', get_user_meta( $this->author_id, 'user_description', true ) );
     57        add_user_meta( self::$author_id, 'user_description', 'user description' );
     58        $this->assertEquals( 'user description', get_user_meta( self::$author_id, 'user_description', true ) );
    6159        // user_description in meta is ignored. The content of description is returned instead.
    6260        // See #20285
    6361        $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
    6462        $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
    65         update_user_meta( $this->author_id, 'user_description', '' );
    66         $this->assertEquals( '', get_user_meta( $this->author_id, 'user_description', true ) );
     63        update_user_meta( self::$author_id, 'user_description', '' );
     64        $this->assertEquals( '', get_user_meta( self::$author_id, 'user_description', true ) );
    6765        $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) );
    6866        $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) );
     
    8179        // Test with no global post, result should be 0 because no author is found
    8280        $this->assertEquals( 0, get_the_author_posts() );
    83         $GLOBALS['post'] = $this->post_id;
     81        $GLOBALS['post'] = self::$post_id;
    8482        $this->assertEquals( 1, get_the_author_posts() );
    8583    }
     
    9290
    9391        $cpt_ids = self::factory()->post->create_many( 2, array(
    94             'post_author' => $this->author_id,
     92            'post_author' => self::$author_id,
    9593            'post_type'   => 'wptests_pt',
    9694        ) );
  • trunk/tests/phpunit/tests/user/mapMetaCap.php

    r38378 r39189  
    66 */
    77class Tests_User_MapMetaCap extends WP_UnitTestCase {
    8     var $super_admins = null;
    9 
    10     function setUp() {
    11         parent::setUp();
    12 
    13         $this->user_ids = array();
    14 
    15         $this->user_id   = self::factory()->user->create( array( 'role' => 'administrator' ) );
    16         $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    17 
    18         if ( isset( $GLOBALS['super_admins'] ) )
    19             $this->super_admins = $GLOBALS['super_admins'];
    20         $user = new WP_User( $this->user_id );
     8
     9    protected static $post_type    = 'mapmetacap';
     10    protected static $super_admins = null;
     11    protected static $user_id      = null;
     12    protected static $author_id    = null;
     13    protected static $post_id      = null;
     14
     15    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     16        self::$user_id   = self::factory()->user->create( array( 'role' => 'administrator' ) );
     17        self::$author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     18
     19        if ( isset( $GLOBALS['super_admins'] ) ) {
     20            self::$super_admins = $GLOBALS['super_admins'];
     21        }
     22        $user = new WP_User( self::$user_id );
    2123        $GLOBALS['super_admins'] = array( $user->user_login );
    2224
    23         $this->post_type = rand_str( 20 );
    24         register_post_type( $this->post_type );
    25 
    26         $this->post_id = wp_insert_post( array(
    27             'post_title' => rand_str(),
    28             'post_type' => $this->post_type,
     25        register_post_type( self::$post_type );
     26
     27        self::$post_id = $factory->post->create( array(
     28            'post_type'   => self::$post_type,
    2929            'post_status' => 'private',
    30             'post_author' => $this->author_id,
    31         ) );
    32     }
    33 
    34     function tearDown() {
    35         $GLOBALS['super_admins'] = $this->super_admins;
    36         unset( $GLOBALS['wp_post_types'][ $this->post_type ] );
    37         parent::tearDown();
     30            'post_author' => self::$author_id,
     31        ) );
     32    }
     33
     34    public static function wpTearDownAfterClass() {
     35        $GLOBALS['super_admins'] = self::$super_admins;
     36        unset( $GLOBALS['wp_post_types'][ self::$post_type ] );
    3837    }
    3938
     
    4443        $this->assertEquals(
    4544            array( 'do_not_allow' ),
    46             map_meta_cap( 'edit_post', $this->user_id, $this->post_id + 1 )
     45            map_meta_cap( 'edit_post', self::$user_id, self::$post_id + 1 )
    4746        );
    4847    }
     
    5049    function test_capability_type_post_with_no_extra_caps() {
    5150
    52         register_post_type( $this->post_type, array(
    53             'capability_type' => 'post',
    54         ) );
    55         $post_type_object = get_post_type_object( $this->post_type );
     51        register_post_type( self::$post_type, array(
     52            'capability_type' => 'post',
     53        ) );
     54        $post_type_object = get_post_type_object( self::$post_type );
    5655
    5756        $this->assertTrue( $post_type_object->map_meta_cap );
    5857
    5958        $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
    60             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
    61         $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
    62             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
    63 
    64         $this->assertEquals( array( 'read_private_posts' ),
    65             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
    66         $this->assertEquals( array( 'read_private_posts' ),
    67             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
    68 
    69         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    70             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
    71         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    72             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     59            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
     60        $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
     61            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
     62
     63        $this->assertEquals( array( 'read_private_posts' ),
     64            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
     65        $this->assertEquals( array( 'read_private_posts' ),
     66            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
     67
     68        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     69            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
     70        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     71            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    7372    }
    7473
    7574    function test_custom_capability_type_with_map_meta_cap() {
    76         register_post_type( $this->post_type, array(
     75        register_post_type( self::$post_type, array(
    7776            'capability_type' => 'book',
    7877            'map_meta_cap' => true,
    7978        ) );
    8079
    81         $post_type_object = get_post_type_object( $this->post_type );
     80        $post_type_object = get_post_type_object( self::$post_type );
    8281
    8382        $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ),
    84             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
     83            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
    8584        $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ),
    86             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
     85            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
    8786
    8887        $this->assertEquals( array( 'read_private_books' ),
    89             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
     88            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
    9089        $this->assertEquals( array( 'read_private_books' ),
    91             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
     90            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
    9291
    9392        $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ),
    94             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
     93            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
    9594        $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ),
    96             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     95            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    9796    }
    9897
    9998    function test_capability_type_post_with_one_renamed_cap() {
    100         register_post_type( $this->post_type, array(
     99        register_post_type( self::$post_type, array(
    101100            'capability_type' => 'post',
    102101            'capabilities' => array( 'edit_posts' => 'edit_books' ),
    103102        ) );
    104103
    105         $post_type_object = get_post_type_object( $this->post_type );
     104        $post_type_object = get_post_type_object( self::$post_type );
    106105
    107106        $this->assertFalse( $post_type_object->map_meta_cap );
    108107
    109108        $this->assertEquals( array( 'edit_post' ),
    110             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
     109            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
    111110        $this->assertEquals( array( 'edit_post' ),
    112             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
     111            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
    113112
    114113        $this->assertEquals( array( 'read_post' ),
    115             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
     114            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
    116115        $this->assertEquals( array( 'read_post' ),
    117             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
     116            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
    118117
    119118        $this->assertEquals( array( 'delete_post' ),
    120             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
     119            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
    121120        $this->assertEquals( array( 'delete_post' ),
    122             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     121            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    123122    }
    124123
    125124    function test_capability_type_post_map_meta_cap_true_with_renamed_cap() {
    126         register_post_type( $this->post_type, array(
     125        register_post_type( self::$post_type, array(
    127126            'capability_type' => 'post',
    128127            'map_meta_cap' => true,
     
    133132        ) );
    134133
    135         $post_type_object = get_post_type_object( $this->post_type );
     134        $post_type_object = get_post_type_object( self::$post_type );
    136135
    137136        $this->assertTrue( $post_type_object->map_meta_cap );
    138137
    139138        $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ),
    140             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
     139            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
    141140        $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ),
    142             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
    143 
    144         $this->assertEquals( array( 'read_private_posts' ),
    145             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
    146         $this->assertEquals( array( 'read_private_posts' ),
    147             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
    148 
    149         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    150             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
    151         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    152             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     141            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
     142
     143        $this->assertEquals( array( 'read_private_posts' ),
     144            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
     145        $this->assertEquals( array( 'read_private_posts' ),
     146            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
     147
     148        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     149            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
     150        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     151            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    153152    }
    154153
    155154    function test_capability_type_post_with_all_meta_caps_renamed() {
    156         register_post_type( $this->post_type, array(
     155        register_post_type( self::$post_type, array(
    157156            'capability_type' => 'post',
    158157            'capabilities' => array(
     
    163162        ) );
    164163
    165         $post_type_object = get_post_type_object( $this->post_type );
     164        $post_type_object = get_post_type_object( self::$post_type );
    166165
    167166        $this->assertFalse( $post_type_object->map_meta_cap );
    168167
    169168        $this->assertEquals( array( 'edit_book' ),
    170             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
     169            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
    171170        $this->assertEquals( array( 'edit_book' ),
    172             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
     171            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
    173172
    174173        $this->assertEquals( array( 'read_book' ),
    175             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
     174            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
    176175        $this->assertEquals( array( 'read_book' ),
    177             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
     176            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
    178177
    179178        $this->assertEquals( array( 'delete_book' ),
    180             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
     179            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
    181180        $this->assertEquals( array( 'delete_book' ),
    182             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     181            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    183182    }
    184183
    185184    function test_capability_type_post_with_all_meta_caps_renamed_mapped() {
    186         register_post_type( $this->post_type, array(
     185        register_post_type( self::$post_type, array(
    187186            'capability_type' => 'post',
    188187            'map_meta_cap' => true,
     
    194193        ) );
    195194
    196         $post_type_object = get_post_type_object( $this->post_type );
     195        $post_type_object = get_post_type_object( self::$post_type );
    197196
    198197        $this->assertTrue( $post_type_object->map_meta_cap );
    199198
    200199        $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
    201             map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );
    202         $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
    203             map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );
    204 
    205         $this->assertEquals( array( 'read_private_posts' ),
    206             map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );
    207         $this->assertEquals( array( 'read_private_posts' ),
    208             map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );
    209 
    210         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    211             map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );
    212         $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
    213             map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );
     200            map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) );
     201        $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ),
     202            map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) );
     203
     204        $this->assertEquals( array( 'read_private_posts' ),
     205            map_meta_cap( 'read_post', self::$user_id, self::$post_id ) );
     206        $this->assertEquals( array( 'read_private_posts' ),
     207            map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) );
     208
     209        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     210            map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) );
     211        $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ),
     212            map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) );
    214213    }
    215214
     
    219218        if ( is_multisite() ) {
    220219            $this->assertEquals( array( 'do_not_allow' ), map_meta_cap( 'unfiltered_html', 0 ) );
    221             $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', $this->user_id ) );
     220            $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', self::$user_id ) );
    222221        } else {
    223             $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', $this->user_id ) );
     222            $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', self::$user_id ) );
    224223        }
    225224    }
     
    239238        }
    240239
    241         $this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', $this->user_id ) );
    242         $this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', $this->user_id ) );
     240        $this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', self::$user_id ) );
     241        $this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', self::$user_id ) );
    243242    }
    244243
     
    269268
    270269        update_option( 'page_on_front', $post_id );
    271         $caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );
     270        $caps = map_meta_cap( 'delete_page', self::$user_id, $post_id );
    272271        delete_option( 'page_on_front' );
    273272
     
    287286
    288287        update_option( 'page_for_posts', $post_id );
    289         $caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );
     288        $caps = map_meta_cap( 'delete_page', self::$user_id, $post_id );
    290289        delete_option( 'page_for_posts' );
    291290
  • trunk/tests/phpunit/tests/xmlrpc/mw/getPost.php

    r35242 r39189  
    55 */
    66class Tests_XMLRPC_mw_getPost 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_author' => $factory->user->create( array(
     12                'user_login' => 'author',
     13                'user_pass'  => 'author',
     14                'role'       => 'author'
     15            ) ),
     16            'post_date'   => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ),
     17        ) );
    2418    }
    2519
    2620    function test_invalid_username_password() {
    27         $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'username', 'password' ) );
     21        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'username', 'password' ) );
    2822        $this->assertInstanceOf( 'IXR_Error', $result );
    2923        $this->assertEquals( 403, $result->code );
     
    3327        $this->make_user_by_role( 'subscriber' );
    3428
    35         $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'subscriber', 'subscriber' ) );
     29        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'subscriber', 'subscriber' ) );
    3630        $this->assertInstanceOf( 'IXR_Error', $result );
    3731        $this->assertEquals( 401, $result->code );
     
    5145
    5246        $fields = array( 'post' );
    53         $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );
     47        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
    5448        $this->assertNotInstanceOf( 'IXR_Error', $result );
    5549
     
    7771        $this->assertInternalType( 'bool',   $result['sticky'] );
    7872
     73        $post_data = get_post( self::$post_id );
    7974
    8075        // Check expected values
    8176        $this->assertStringMatchesFormat( '%d', $result['userid'] );
    82         $this->assertEquals( $this->post_data['post_title'], $result['title'] );
    83         $this->assertEquals( 'draft', $result['post_status'] );
     77        $this->assertEquals( $post_data->post_title, $result['title'] );
     78        $this->assertEquals( 'publish', $result['post_status'] );
    8479        $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
    85         $this->assertEquals( $this->post_data['post_excerpt'], $result['mt_excerpt'] );
    86         $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id );
     80        $this->assertEquals( $post_data->post_excerpt, $result['mt_excerpt'] );
     81        $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id );
    8782
    8883        $this->assertEquals( '', $result['wp_post_thumbnail'] );
     
    9893        $attachment_id = self::factory()->attachment->create_upload_object( $filename );
    9994
    100         set_post_thumbnail( $this->post_id, $attachment_id );
     95        set_post_thumbnail( self::$post_id, $attachment_id );
    10196
    10297        $fields = array( 'post' );
    103         $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );
     98        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
    10499        $this->assertNotInstanceOf( 'IXR_Error', $result );
    105100
     
    113108    function test_date() {
    114109        $fields = array( 'post' );
    115         $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );
     110        $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) );
    116111        $this->assertNotInstanceOf( 'IXR_Error', $result );
    117112
     
    121116        $this->assertInstanceOf( 'IXR_Date', $result['date_modified_gmt'] );
    122117
    123         $this->assertEquals( $this->post_date_ts, $result['dateCreated']->getTimestamp() );
    124         $this->assertEquals( $this->post_date_ts, $result['date_modified']->getTimestamp() );
     118        $post_data = get_post( self::$post_id );
    125119
    126         $post_date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) );
    127         $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) );
     120        $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
     121        $this->assertEquals( strtotime( $post_data->post_date ), $result['date_modified']->getTimestamp() );
     122
     123        $post_date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
     124        $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
    128125
    129126        $this->assertEquals( $post_date_gmt, $result['date_created_gmt']->getTimestamp() );
  • 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
  • trunk/tests/phpunit/tests/xmlrpc/wp/deleteTerm.php

    r38698 r39189  
    55 */
    66class Tests_XMLRPC_wp_deleteTerm extends WP_XMLRPC_UnitTestCase {
    7     var $term;
     7    protected static $term_id;
    88
    9     function setUp() {
    10         parent::setUp();
    11 
    12         $this->term = wp_insert_term( 'term' . rand_str() , 'category' );
    13         $this->assertInternalType( 'array', $this->term );
     9    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     10        self::$term_id = $factory->term->create( array(
     11            'taxonomy' => 'category',
     12        ) );
    1413    }
    1514
     
    4140        $this->make_user_by_role( 'subscriber' );
    4241
    43         $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) );
     42        $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) );
    4443        $this->assertInstanceOf( 'IXR_Error', $result );
    4544        $this->assertEquals( 401, $result->code );
     
    6867        $this->make_user_by_role( 'editor' );
    6968
    70         $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) );
     69        $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) );
    7170        $this->assertNotInstanceOf( 'IXR_Error', $result );
    7271        $this->assertInternalType( 'boolean', $result );
  • 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 );
  • 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
  • trunk/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php

    r35309 r39189  
    55 */
    66class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
    7     var $post_id;
     7    protected static $post_id;
     8
    89    var $attachment_data;
    910    var $attachment_id;
     11
     12    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     13        self::$post_id = $factory->post->create();
     14    }
    1015
    1116    function setUp() {
     
    1419        add_theme_support( 'post-thumbnails' );
    1520
    16         $this->post_id = wp_insert_post( array(
    17             'post_title' => rand_str(),
    18             'post_content' => rand_str(),
    19             'post_status' => 'publish'
    20         ));
    21 
    2221        $filename = ( DIR_TESTDATA.'/images/waffles.jpg' );
    2322        $contents = file_get_contents( $filename );
    2423        $upload = wp_upload_bits(basename($filename), null, $contents);
    2524
    26         $this->attachment_id = $this->_make_attachment( $upload, $this->post_id );
     25        $this->attachment_id = $this->_make_attachment( $upload, self::$post_id );
    2726        $this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
    2827
    29         set_post_thumbnail( $this->post_id, $this->attachment_id );
     28        set_post_thumbnail( self::$post_id, $this->attachment_id );
    3029    }
    3130
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPage.php

    r35244 r39189  
    55 */
    66class Tests_XMLRPC_wp_getPage 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         $this->post_date_ts = strtotime( '+1 day' );
    15         $this->post_data = array(
    16             'post_type' => 'page',
    17             'post_title' => rand_str(),
    18             'post_content' => rand_str( 2000 ),
    19             'post_excerpt' => rand_str( 100 ),
    20             'post_author' => $this->make_user_by_role( 'author' ),
    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
    2621    function test_invalid_username_password() {
    27         $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'username', 'password' ) );
     22        $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'username', 'password' ) );
    2823        $this->assertInstanceOf( 'IXR_Error', $result );
    2924        $this->assertEquals( 403, $result->code );
     
    4439        $this->make_user_by_role( 'editor' );
    4540
    46         $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );
     41        $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'editor', 'editor' ) );
    4742        $this->assertNotInstanceOf( 'IXR_Error', $result );
    4843
     
    7166        $this->assertInternalType( 'string', $result['wp_page_template'] );
    7267
     68        $post_data = get_post( self::$post_id );
     69
    7370        // Check expected values
    7471        $this->assertStringMatchesFormat( '%d', $result['userid'] );
    75         $this->assertEquals( 'draft', $result['page_status'] );
    76         $this->assertEquals( $this->post_data['post_title'], $result['title'] );
    77         $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id );
    78         $this->assertEquals( $this->post_data['post_excerpt'], $result['excerpt'] );
     72        $this->assertEquals( 'future', $result['page_status'] );
     73        $this->assertEquals( $post_data->post_title, $result['title'] );
     74        $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id );
     75        $this->assertEquals( $post_data->post_excerpt, $result['excerpt'] );
    7976        $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] );
    8077    }
     
    8380        $this->make_user_by_role( 'editor' );
    8481
    85         $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );
     82        $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'editor', 'editor' ) );
    8683        $this->assertNotInstanceOf( 'IXR_Error', $result );
    8784
     
    8986        $this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] );
    9087
    91         $date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) );
     88        $post_data = get_post( self::$post_id );
    9289
    93         $this->assertEquals( $this->post_date_ts, $result['dateCreated']->getTimestamp() );
     90        $date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) );
     91
     92        $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() );
    9493        $this->assertEquals( $date_gmt, $result['date_created_gmt']->getTimestamp() );
    9594    }
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPageList.php

    r25002 r39189  
    55 */
    66class Tests_XMLRPC_wp_getPageList 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         $this->post_date_ts = strtotime( '+1 day' );
    15         $this->post_data = array(
    16             'post_type' => 'page',
    17             'post_title' => rand_str(),
    18             'post_content' => rand_str( 2000 ),
    19             'post_excerpt' => rand_str( 100 ),
    20             'post_author' => $this->make_user_by_role( 'author' ),
    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
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPages.php

    r25002 r39189  
    55 */
    66class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase {
    7     var $post_data;
    8     var $post_id;
    9     var $post_date_ts;
    10     var $editor_id;
     7    protected static $post_id;
     8    protected static $editor_id;
    119
    12     function setUp() {
    13         parent::setUp();
     10    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     11        self::$post_id = $factory->post->create( array(
     12            'post_type'   => 'page',
     13            'post_author' => $factory->user->create( array(
     14                'user_login' => 'administrator',
     15                'user_pass'  => 'administrator',
     16                'role'       => 'administrator'
     17            ) ),
     18            'post_date'   => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ),
     19        ) );
     20        self::$editor_id = $factory->user->create( array(
     21            'user_login' => 'editor',
     22            'user_pass'  => 'editor',
     23            'role'       => 'editor'
     24        ) );
     25    }
    1426
    15         $this->post_date_ts = strtotime( '+1 day' );
    16         $this->post_data = array(
    17             'post_type' => 'page',
    18             'post_title' => rand_str(),
    19             'post_content' => rand_str( 2000 ),
    20             'post_excerpt' => rand_str( 100 ),
    21             'post_author' => $this->make_user_by_role( 'administrator' ),
    22             'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    23         );
    24         $this->post_id = wp_insert_post( $this->post_data );
    25         $this->editor_id = $this->make_user_by_role( 'editor' );
    26     }
     27    function test_invalid_username_password() {
     28        $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) );
     29        $this->assertInstanceOf( 'IXR_Error', $result );
     30        $this->assertEquals( 403, $result->code );
     31    }
    2732
    28     function test_invalid_username_password() {
    29         $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) );
    30         $this->assertInstanceOf( 'IXR_Error', $result );
    31         $this->assertEquals( 403, $result->code );
    32     }
    33 
    34     function test_incapable_user() {
     33    function test_incapable_user() {
    3534        $this->make_user_by_role( 'contributor' );
    3635
    37         $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) );
    38         $this->assertInstanceOf( 'IXR_Error', $result );
    39         $this->assertEquals( 401, $result->code );
    40     }
     36        $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) );
     37        $this->assertInstanceOf( 'IXR_Error', $result );
     38        $this->assertEquals( 401, $result->code );
     39    }
    4140
    42     function test_capable_user() {
    43         $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'administrator', 'administrator' ) );
    44         $this->assertNotInstanceOf( 'IXR_Error', $results );
     41    function test_capable_user() {
     42        $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'administrator', 'administrator' ) );
     43        $this->assertNotInstanceOf( 'IXR_Error', $results );
    4544
    46         foreach( $results as $result ) {
    47             $page = get_post( $result['page_id'] );
    48             $this->assertEquals( $page->post_type, 'page' );
    49         }
    50     }
     45        foreach( $results as $result ) {
     46            $page = get_post( $result['page_id'] );
     47            $this->assertEquals( $page->post_type, 'page' );
     48        }
     49    }
    5150
    52     function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) {
    53         if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) {
    54             if ( $user_id == $this->editor_id && $args[0] == $this->post_id ) {
    55                 return array( false );
    56             }
    57         }
     51    function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) {
     52        if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) {
     53            if ( $user_id == self::$editor_id && $args[0] == self::$post_id ) {
     54                return array( false );
     55            }
     56        }
    5857
    59         return $caps;
    60     }
     58        return $caps;
     59    }
    6160
    6261    /**
     
    6463     */
    6564    function test_semi_capable_user() {
    66         add_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap') , 10, 4 );
     65        add_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap') , 10, 4 );
    6766
    68         $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'editor', 'editor' ) );
    69         $this->assertNotInstanceOf( 'IXR_Error', $results );
     67        $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'editor', 'editor' ) );
     68        $this->assertNotInstanceOf( 'IXR_Error', $results );
    7069
    71         $found_incapable = false;
    72         foreach( $results as $result ) {
    73             // WP#20629
    74             $this->assertNotInstanceOf( 'IXR_Error', $result );
     70        $found_incapable = false;
     71        foreach( $results as $result ) {
     72            // WP#20629
     73            $this->assertNotInstanceOf( 'IXR_Error', $result );
    7574
    76             if ( $result['page_id'] == $this->post_id ) {
    77                 $found_incapable = true;
    78                 break;
    79             }
    80         }
    81         $this->assertFalse( $found_incapable );
     75            if ( $result['page_id'] == self::$post_id ) {
     76                $found_incapable = true;
     77                break;
     78            }
     79        }
     80        $this->assertFalse( $found_incapable );
    8281
    83         remove_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 );
    84     }
     82        remove_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 );
     83    }
    8584
    8685}
  • trunk/tests/phpunit/tests/xmlrpc/wp/getTerm.php

    r38698 r39189  
    55 */
    66class Tests_XMLRPC_wp_getTerm extends WP_XMLRPC_UnitTestCase {
    7     var $term;
    87
    9     function setUp() {
    10         parent::setUp();
     8    protected static $term_id;
    119
    12         $this->term = wp_insert_term( 'term' . rand_str() , 'category' );
    13         $this->assertInternalType( 'array', $this->term );
     10    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     11        self::$term_id = $factory->term->create( array(
     12            'taxonomy' => 'category',
     13        ) );
    1414    }
    1515
     
    4141        $this->make_user_by_role( 'subscriber' );
    4242
    43         $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) );
     43        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) );
    4444        $this->assertInstanceOf( 'IXR_Error', $result );
    4545        $this->assertEquals( 401, $result->code );
     
    6969        $this->make_user_by_role( 'editor' );
    7070
    71         $term = get_term( $this->term['term_id'], 'category', ARRAY_A );
     71        $term = get_term( self::$term_id, 'category', ARRAY_A );
    7272
    73         $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) );
     73        $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) );
    7474
    7575        $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/tests/phpunit/tests/xmlrpc/wp/newTerm.php

    r38078 r39189  
    55 */
    66class Tests_XMLRPC_wp_newTerm extends WP_XMLRPC_UnitTestCase {
    7     var $parent_term;
    87
    9     function setUp() {
    10         parent::setUp();
     8    protected static $parent_term_id;
    119
    12         $this->parent_term = wp_insert_term( 'parent' . rand_str(), 'category' );
    13         $this->assertInternalType( 'array', $this->parent_term );
    14         $this->parent_term = $this->parent_term['term_id'];
     10    public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
     11        self::$parent_term_id = $factory->term->create( array(
     12            'taxonomy' => 'category',
     13        ) );
    1514    }
    1615
     
    6059        $this->make_user_by_role( 'editor' );
    6160
    62         $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term, 'name' => 'test' ) ) );
     61        $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => self::$parent_term_id, 'name' => 'test' ) ) );
    6362        $this->assertInstanceOf( 'IXR_Error', $result );
    6463        $this->assertEquals( 403, $result->code );
     
    9594        $this->make_user_by_role( 'editor' );
    9695
    97         $result  = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test' ) ) );
     96        $result  = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => self::$parent_term_id, 'name' => 'test' ) ) );
    9897        $this->assertNotInstanceOf( 'IXR_Error', $result );
    9998        $this->assertStringMatchesFormat( '%d', $result );
     
    103102        $this->make_user_by_role( 'editor' );
    104103
    105         $taxonomy = array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' );
     104        $taxonomy = array( 'taxonomy' => 'category', 'parent' => self::$parent_term_id, 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' );
    106105        $result  = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', $taxonomy ) );
    107106        $this->assertNotInstanceOf( 'IXR_Error', $result );
Note: See TracChangeset for help on using the changeset viewer.