Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (9 years ago)
Author:
wonderboymusic
Message:

Unit Tests: one $factory to rule them all, and it shall be static.

Using more than one instance of WP_UnitTest_Factory causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use setUpBeforeClass, we were creating ad hoc instances. To avoid that, we were injecting one static instance via Dependency Injection in wpSetUpBeforeClass. All tests should really use the static instance, so we will remove the instance prop $factory.

Replace $this->factory with self::$factory over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.

#YOLOFriday

File:
1 edited

Legend:

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

    r34113 r35225  
    1313        $this->user_ids = array();
    1414
    15         $this->user_id   = $this->factory->user->create( array( 'role' => 'administrator' ) );
    16         $this->author_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     15        $this->user_id   = self::$factory->user->create( array( 'role' => 'administrator' ) );
     16        $this->author_id = self::$factory->user->create( array( 'role' => 'administrator' ) );
    1717
    1818        if ( isset( $GLOBALS['super_admins'] ) )
     
    249249     */
    250250    function test_authorless_posts_capabilties() {
    251         $post_id = $this->factory->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => 'publish' ) );
    252         $editor = $this->factory->user->create( array( 'role' => 'editor' ) );
     251        $post_id = self::$factory->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => 'publish' ) );
     252        $editor = self::$factory->user->create( array( 'role' => 'editor' ) );
    253253
    254254        $this->assertEquals( array( 'edit_others_posts', 'edit_published_posts' ), map_meta_cap( 'edit_post', $editor, $post_id ) );
Note: See TracChangeset for help on using the changeset viewer.