Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/multisite/getBlogDetails.php

    r40317 r42343  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * @ticket 29845
    7  * @group ms-site
    8  * @group multisite
    9  */
    10 class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase {
    11     protected static $network_ids;
    12     protected static $site_ids;
    13 
    14     public static function wpSetUpBeforeClass( $factory ) {
    15         self::$site_ids = array(
    16             WP_TESTS_DOMAIN . '/foo/'      => array( 'domain' => WP_TESTS_DOMAIN,          'path' => '/foo/'),
    17             'foo.' . WP_TESTS_DOMAIN . '/' => array( 'domain' => 'foo.' . WP_TESTS_DOMAIN, 'path' => '/' ),
    18             'wordpress.org/'               => array( 'domain' => 'wordpress.org',          'path' => '/' ),
    19         );
    20 
    21         foreach ( self::$site_ids as &$id ) {
    22             $id = $factory->blog->create( $id );
    23         }
    24         unset( $id );
     5    /**
     6     * @ticket 29845
     7     * @group ms-site
     8     * @group multisite
     9     */
     10    class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase {
     11        protected static $network_ids;
     12        protected static $site_ids;
     13
     14        public static function wpSetUpBeforeClass( $factory ) {
     15            self::$site_ids = array(
     16                WP_TESTS_DOMAIN . '/foo/'      => array(
     17                    'domain' => WP_TESTS_DOMAIN,
     18                    'path'   => '/foo/',
     19                ),
     20                'foo.' . WP_TESTS_DOMAIN . '/' => array(
     21                    'domain' => 'foo.' . WP_TESTS_DOMAIN,
     22                    'path'   => '/',
     23                ),
     24                'wordpress.org/'               => array(
     25                    'domain' => 'wordpress.org',
     26                    'path'   => '/',
     27                ),
     28            );
     29
     30            foreach ( self::$site_ids as &$id ) {
     31                $id = $factory->blog->create( $id );
     32            }
     33            unset( $id );
     34        }
     35
     36        public static function wpTearDownAfterClass() {
     37            foreach ( self::$site_ids as $id ) {
     38                wpmu_delete_blog( $id, true );
     39            }
     40
     41            wp_update_network_site_counts();
     42        }
     43
     44        public function test_get_blog_details_with_no_arguments_returns_current_site() {
     45            $site = get_blog_details();
     46            $this->assertEquals( get_current_blog_id(), $site->blog_id );
     47        }
     48
     49        public function test_get_blog_details_with_site_name_string_subdirectory() {
     50            if ( is_subdomain_install() ) {
     51                $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
     52            }
     53
     54            $site = get_blog_details( 'foo' );
     55            $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/' ], $site->blog_id );
     56        }
     57
     58        public function test_get_blog_details_with_site_name_string_subdomain() {
     59            if ( ! is_subdomain_install() ) {
     60                $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
     61            }
     62
     63            $site = get_blog_details( 'foo' );
     64            $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
     65        }
     66
     67        public function test_get_blog_details_with_invalid_site_name_string() {
     68            $site = get_blog_details( 'invalid' );
     69            $this->assertFalse( $site );
     70        }
     71
     72        public function test_get_blog_details_with_site_id_int() {
     73            $site = get_blog_details( self::$site_ids['wordpress.org/'] );
     74            $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     75        }
     76
     77        public function test_get_blog_details_with_invalid_site_id_int() {
     78            $site = get_blog_details( 99999 );
     79            $this->assertFalse( $site );
     80        }
     81
     82        public function test_get_blog_details_with_blog_id_in_fields() {
     83            $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
     84            $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     85        }
     86
     87        public function test_get_blog_details_with_invalid_blog_id_in_fields() {
     88            $site = get_blog_details( array( 'blog_id' => 88888 ) );
     89            $this->assertFalse( $site );
     90        }
     91
     92        public function test_get_blog_details_with_domain_and_path_in_fields() {
     93            $site = get_blog_details(
     94                array(
     95                    'domain' => 'wordpress.org',
     96                    'path'   => '/',
     97                )
     98            );
     99            $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     100        }
     101
     102        public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
     103            $site = get_blog_details(
     104                array(
     105                    'domain' => 'wordpress.org',
     106                    'path'   => '/zxy/',
     107                )
     108            );
     109            $this->assertFalse( $site );
     110        }
     111
     112        public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
     113            $site = get_blog_details(
     114                array(
     115                    'domain' => 'invalid.org',
     116                    'path'   => '/foo/',
     117                )
     118            );
     119            $this->assertFalse( $site );
     120        }
     121
     122        public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
     123            if ( ! is_subdomain_install() ) {
     124                $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
     125            }
     126
     127            $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
     128            $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     129        }
     130
     131        public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
     132            if ( is_subdomain_install() ) {
     133                $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
     134            }
     135
     136            $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
     137            $this->assertFalse( $site );
     138        }
     139
     140        public function test_get_blog_details_with_only_path_in_fields() {
     141            $site = get_blog_details( array( 'path' => '/foo/' ) );
     142            $this->assertFalse( $site );
     143        }
     144
     145        /**
     146         * @dataProvider data_get_all
     147         *
     148         * @ticket 40228
     149         */
     150        public function test_get_blog_details_get_object_vars( $get_all ) {
     151            $site = get_blog_details(
     152                array(
     153                    'domain' => 'wordpress.org',
     154                    'path'   => '/',
     155                ), $get_all
     156            );
     157
     158            $result = array_keys( get_object_vars( $site ) );
     159
     160            $this->assertEqualSets( $this->get_fields( $get_all ), $result );
     161        }
     162
     163        /**
     164         * @dataProvider data_get_all
     165         *
     166         * @ticket 40228
     167         */
     168        public function test_get_blog_details_iterate_over_result( $get_all ) {
     169            $site = get_blog_details(
     170                array(
     171                    'domain' => 'wordpress.org',
     172                    'path'   => '/',
     173                ), $get_all
     174            );
     175
     176            $result = array();
     177            foreach ( $site as $key => $value ) {
     178                $result[] = $key;
     179            }
     180
     181            $this->assertEqualSets( $this->get_fields( $get_all ), $result );
     182        }
     183
     184        public function data_get_all() {
     185            return array(
     186                array( false ),
     187                array( true ),
     188            );
     189        }
     190
     191        protected function get_fields( $all = false ) {
     192            $fields = array(
     193                'blog_id',
     194                'domain',
     195                'path',
     196                'site_id',
     197                'registered',
     198                'last_updated',
     199                'public',
     200                'archived',
     201                'mature',
     202                'spam',
     203                'deleted',
     204                'lang_id',
     205            );
     206
     207            if ( $all ) {
     208                $fields = array_merge(
     209                    $fields, array(
     210                        'blogname',
     211                        'siteurl',
     212                        'post_count',
     213                        'home',
     214                    )
     215                );
     216            }
     217
     218            return $fields;
     219        }
    25220    }
    26221
    27     public static function wpTearDownAfterClass() {
    28         foreach( self::$site_ids as $id ) {
    29             wpmu_delete_blog( $id, true );
    30         }
    31 
    32         wp_update_network_site_counts();
    33     }
    34 
    35     public function test_get_blog_details_with_no_arguments_returns_current_site() {
    36         $site = get_blog_details();
    37         $this->assertEquals( get_current_blog_id(), $site->blog_id );
    38     }
    39 
    40     public function test_get_blog_details_with_site_name_string_subdirectory() {
    41         if ( is_subdomain_install() ) {
    42             $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
    43         }
    44 
    45         $site = get_blog_details( 'foo' );
    46         $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/'], $site->blog_id );
    47     }
    48 
    49     public function test_get_blog_details_with_site_name_string_subdomain() {
    50         if ( ! is_subdomain_install() ) {
    51             $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
    52         }
    53 
    54         $site = get_blog_details( 'foo' );
    55         $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
    56     }
    57 
    58     public function test_get_blog_details_with_invalid_site_name_string() {
    59         $site = get_blog_details( 'invalid' );
    60         $this->assertFalse( $site );
    61     }
    62 
    63     public function test_get_blog_details_with_site_id_int() {
    64         $site = get_blog_details( self::$site_ids['wordpress.org/'] );
    65         $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
    66     }
    67 
    68     public function test_get_blog_details_with_invalid_site_id_int() {
    69         $site = get_blog_details( 99999 );
    70         $this->assertFalse( $site );
    71     }
    72 
    73     public function test_get_blog_details_with_blog_id_in_fields() {
    74         $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
    75         $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
    76     }
    77 
    78     public function test_get_blog_details_with_invalid_blog_id_in_fields() {
    79         $site = get_blog_details( array( 'blog_id' => 88888 ) );
    80         $this->assertFalse( $site );
    81     }
    82 
    83     public function test_get_blog_details_with_domain_and_path_in_fields() {
    84         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
    85         $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
    86     }
    87 
    88     public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
    89         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) );
    90         $this->assertFalse( $site );
    91     }
    92 
    93     public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
    94         $site = get_blog_details( array( 'domain' => 'invalid.org', 'path' => '/foo/' ) );
    95         $this->assertFalse( $site );
    96     }
    97 
    98     public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
    99         if ( ! is_subdomain_install() ) {
    100             $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
    101         }
    102 
    103         $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
    104         $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
    105     }
    106 
    107     public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
    108         if ( is_subdomain_install() ) {
    109             $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
    110         }
    111 
    112         $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
    113         $this->assertFalse( $site );
    114     }
    115 
    116     public function test_get_blog_details_with_only_path_in_fields() {
    117         $site = get_blog_details( array( 'path' => '/foo/' ) );
    118         $this->assertFalse( $site );
    119     }
    120 
    121     /**
    122      * @dataProvider data_get_all
    123      *
    124      * @ticket 40228
    125      */
    126     public function test_get_blog_details_get_object_vars( $get_all ) {
    127         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all );
    128 
    129         $result = array_keys( get_object_vars( $site ) );
    130 
    131         $this->assertEqualSets( $this->get_fields( $get_all ), $result );
    132     }
    133 
    134     /**
    135      * @dataProvider data_get_all
    136      *
    137      * @ticket 40228
    138      */
    139     public function test_get_blog_details_iterate_over_result( $get_all ) {
    140         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ), $get_all );
    141 
    142         $result = array();
    143         foreach ( $site as $key => $value ) {
    144             $result[] = $key;
    145         }
    146 
    147         $this->assertEqualSets( $this->get_fields( $get_all ), $result );
    148     }
    149 
    150     public function data_get_all() {
    151         return array(
    152             array( false ),
    153             array( true ),
    154         );
    155     }
    156 
    157     protected function get_fields( $all = false ) {
    158         $fields = array(
    159             'blog_id',
    160             'domain',
    161             'path',
    162             'site_id',
    163             'registered',
    164             'last_updated',
    165             'public',
    166             'archived',
    167             'mature',
    168             'spam',
    169             'deleted',
    170             'lang_id',
    171         );
    172 
    173         if ( $all ) {
    174             $fields = array_merge( $fields, array(
    175                 'blogname',
    176                 'siteurl',
    177                 'post_count',
    178                 'home',
    179             ) );
    180         }
    181 
    182         return $fields;
    183     }
    184 }
    185 
    186222endif;
Note: See TracChangeset for help on using the changeset viewer.