WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (3 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r38913 r42343  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * Tests specific to users in multisite.
    7  *
    8  * @group user
    9  * @group ms-user
    10  * @group multisite
    11  */
    12 class Tests_Multisite_getActiveBlogForUser extends WP_UnitTestCase {
    13     static $user_id = false;
     5    /**
     6    * Tests specific to users in multisite.
     7    *
     8    * @group user
     9    * @group ms-user
     10    * @group multisite
     11    */
     12    class Tests_Multisite_getActiveBlogForUser extends WP_UnitTestCase {
     13        static $user_id = false;
    1414
    15     public static function wpSetUpBeforeClass( $factory ) {
    16         self::$user_id = $factory->user->create();
     15        public static function wpSetUpBeforeClass( $factory ) {
     16            self::$user_id = $factory->user->create();
     17        }
     18
     19        public static function wpTearDownAfterClass() {
     20            wpmu_delete_user( self::$user_id );
     21
     22            global $wp_rewrite;
     23            $wp_rewrite->init();
     24        }
     25
     26        /**
     27         * @ticket 38355
     28         */
     29        public function test_get_active_blog_for_user_with_no_sites() {
     30            $current_site_id = get_current_blog_id();
     31
     32            remove_user_from_blog( self::$user_id, $current_site_id );
     33
     34            $result = get_active_blog_for_user( self::$user_id );
     35
     36            $this->assertNull( $result );
     37        }
     38
     39        /**
     40         * @ticket 38355
     41         */
     42        public function test_get_active_blog_for_user_with_primary_site() {
     43            $site_id_one = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
     44            $site_id_two = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
     45
     46            $sites           = get_blogs_of_user( self::$user_id );
     47            $site_ids        = array_keys( $sites );
     48            $primary_site_id = $site_ids[1];
     49
     50            update_user_meta( self::$user_id, 'primary_blog', $primary_site_id );
     51
     52            $result = get_active_blog_for_user( self::$user_id );
     53
     54            wpmu_delete_blog( $site_id_one, true );
     55            wpmu_delete_blog( $site_id_two, true );
     56
     57            $this->assertEquals( $primary_site_id, $result->id );
     58        }
     59
     60        /**
     61         * @ticket 38355
     62         */
     63        public function test_get_active_blog_for_user_without_primary_site() {
     64            $sites           = get_blogs_of_user( self::$user_id );
     65            $site_ids        = array_keys( $sites );
     66            $primary_site_id = $site_ids[0];
     67
     68            delete_user_meta( self::$user_id, 'primary_blog' );
     69
     70            $result = get_active_blog_for_user( self::$user_id );
     71
     72            wpmu_delete_blog( $primary_site_id, true );
     73
     74            $this->assertEquals( $primary_site_id, $result->id );
     75        }
     76
     77        /**
     78         * @ticket 38355
     79         */
     80        public function test_get_active_blog_for_user_with_spam_site() {
     81            $current_site_id = get_current_blog_id();
     82
     83            $site_id = self::factory()->blog->create(
     84                array(
     85                    'user_id' => self::$user_id,
     86                    'meta'    => array( 'spam' => 1 ),
     87                )
     88            );
     89
     90            add_user_to_blog( $site_id, self::$user_id, 'subscriber' );
     91            update_user_meta( self::$user_id, 'primary_blog', $site_id );
     92
     93            $result = get_active_blog_for_user( self::$user_id );
     94
     95            wpmu_delete_blog( $site_id, true );
     96
     97            $this->assertEquals( $current_site_id, $result->id );
     98        }
    1799    }
    18100
    19     public static function wpTearDownAfterClass() {
    20         wpmu_delete_user( self::$user_id );
    21 
    22         global $wp_rewrite;
    23         $wp_rewrite->init();
    24     }
    25 
    26     /**
    27      * @ticket 38355
    28      */
    29     public function test_get_active_blog_for_user_with_no_sites() {
    30         $current_site_id = get_current_blog_id();
    31 
    32         remove_user_from_blog( self::$user_id, $current_site_id );
    33 
    34         $result = get_active_blog_for_user( self::$user_id );
    35 
    36         $this->assertNull( $result );
    37     }
    38 
    39     /**
    40      * @ticket 38355
    41      */
    42     public function test_get_active_blog_for_user_with_primary_site() {
    43         $site_id_one = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
    44         $site_id_two = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
    45 
    46         $sites = get_blogs_of_user( self::$user_id );
    47         $site_ids = array_keys( $sites );
    48         $primary_site_id = $site_ids[1];
    49 
    50         update_user_meta( self::$user_id, 'primary_blog', $primary_site_id );
    51 
    52         $result = get_active_blog_for_user( self::$user_id );
    53 
    54         wpmu_delete_blog( $site_id_one, true );
    55         wpmu_delete_blog( $site_id_two, true );
    56 
    57         $this->assertEquals( $primary_site_id, $result->id );
    58     }
    59 
    60     /**
    61      * @ticket 38355
    62      */
    63     public function test_get_active_blog_for_user_without_primary_site() {
    64         $sites = get_blogs_of_user( self::$user_id );
    65         $site_ids = array_keys( $sites );
    66         $primary_site_id = $site_ids[0];
    67 
    68         delete_user_meta( self::$user_id, 'primary_blog' );
    69 
    70         $result = get_active_blog_for_user( self::$user_id );
    71 
    72         wpmu_delete_blog( $primary_site_id, true );
    73 
    74         $this->assertEquals( $primary_site_id, $result->id );
    75     }
    76 
    77     /**
    78      * @ticket 38355
    79      */
    80     public function test_get_active_blog_for_user_with_spam_site() {
    81         $current_site_id = get_current_blog_id();
    82 
    83         $site_id = self::factory()->blog->create( array(
    84             'user_id' => self::$user_id,
    85             'meta'    => array( 'spam' => 1 ),
    86         ) );
    87 
    88         add_user_to_blog( $site_id, self::$user_id, 'subscriber' );
    89         update_user_meta( self::$user_id, 'primary_blog', $site_id );
    90 
    91         $result = get_active_blog_for_user( self::$user_id );
    92 
    93         wpmu_delete_blog( $site_id, true );
    94 
    95         $this->assertEquals( $current_site_id, $result->id );
    96     }
    97 }
    98 
    99 endif ;
     101endif;
Note: See TracChangeset for help on using the changeset viewer.