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/post/getPostsByAuthorSql.php

    r32524 r35225  
    6060    public function test_public_only_true_should_not_allow_any_private_posts_for_loggedin_user(){
    6161        $current_user = get_current_user_id();
    62         $u = $this->factory->user->create();
     62        $u = self::$factory->user->create();
    6363        wp_set_current_user( $u );
    6464
     
    7171    public function test_public_only_should_default_to_false(){
    7272        $current_user = get_current_user_id();
    73         $u = $this->factory->user->create();
     73        $u = self::$factory->user->create();
    7474        wp_set_current_user( $u );
    7575
     
    8181    public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_current_user_matches_post_author(){
    8282        $current_user = get_current_user_id();
    83         $u = $this->factory->user->create();
     83        $u = self::$factory->user->create();
    8484        wp_set_current_user( $u );
    8585
     
    9292    public function test_public_only_false_should_not_allow_access_to_private_posts_if_current_user_is_not_post_author(){
    9393        $current_user = get_current_user_id();
    94         $u1 = $this->factory->user->create();
    95         $u2 = $this->factory->user->create();
     94        $u1 = self::$factory->user->create();
     95        $u2 = self::$factory->user->create();
    9696        wp_set_current_user( $u1 );
    9797
     
    104104    public function test_public_only_false_should_allow_current_user_access_to_own_private_posts_when_post_author_is_not_provided(){
    105105        $current_user = get_current_user_id();
    106         $u = $this->factory->user->create();
     106        $u = self::$factory->user->create();
    107107        wp_set_current_user( $u );
    108108
     
    116116    public function test_administrator_should_have_access_to_private_posts_when_public_only_is_false(){
    117117        $current_user = get_current_user_id();
    118         $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     118        $u = self::$factory->user->create( array( 'role' => 'administrator' ) );
    119119        wp_set_current_user( $u );
    120120
     
    131131        register_post_type( 'baz', array( 'capabilities' => array( 'read_private_posts' => 'read_private_baz' ) ) );
    132132        $current_user = get_current_user_id();
    133         $u = $this->factory->user->create( array( 'role' => 'editor' ) );
     133        $u = self::$factory->user->create( array( 'role' => 'editor' ) );
    134134        $editor_role = get_role('editor');
    135135        $editor_role->add_cap( 'read_private_baz' );
Note: See TracChangeset for help on using the changeset viewer.