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/wpGetSites.php

    r37667 r42343  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * @group wp-get-site
    7  * @group ms-site
    8  * @group multisite
    9  */
    10 class Tests_Multisite_WP_Get_Sites extends WP_UnitTestCase {
    11     protected static $site_ids;
     5    /**
     6    * @group wp-get-site
     7    * @group ms-site
     8    * @group multisite
     9    */
     10    class Tests_Multisite_WP_Get_Sites extends WP_UnitTestCase {
     11        protected static $site_ids;
    1212
    13     public static function wpSetUpBeforeClass( $factory ) {
    14         self::$site_ids = array(
    15             'w.org/'      => array( 'domain' => 'w.org',  'path' => '/',     'site_id' => 2 ),
    16             'wp.org/'     => array( 'domain' => 'wp.org', 'path' => '/',     'site_id' => 2, 'meta' => array( 'public' => 0 ) ),
    17             'wp.org/foo/' => array( 'domain' => 'wp.org', 'path' => '/foo/', 'site_id' => 1, 'meta' => array( 'public' => 0 ) ),
    18             'wp.org/oof/' => array( 'domain' => 'wp.org', 'path' => '/oof/' ),
    19         );
     13        public static function wpSetUpBeforeClass( $factory ) {
     14            self::$site_ids = array(
     15                'w.org/'      => array(
     16                    'domain'  => 'w.org',
     17                    'path'    => '/',
     18                    'site_id' => 2,
     19                ),
     20                'wp.org/'     => array(
     21                    'domain'  => 'wp.org',
     22                    'path'    => '/',
     23                    'site_id' => 2,
     24                    'meta'    => array( 'public' => 0 ),
     25                ),
     26                'wp.org/foo/' => array(
     27                    'domain'  => 'wp.org',
     28                    'path'    => '/foo/',
     29                    'site_id' => 1,
     30                    'meta'    => array( 'public' => 0 ),
     31                ),
     32                'wp.org/oof/' => array(
     33                    'domain' => 'wp.org',
     34                    'path'   => '/oof/',
     35                ),
     36            );
    2037
    21         foreach ( self::$site_ids as &$id ) {
    22             $id = $factory->blog->create( $id );
     38            foreach ( self::$site_ids as &$id ) {
     39                $id = $factory->blog->create( $id );
     40            }
     41            unset( $id );
    2342        }
    24         unset( $id );
     43
     44        public static function wpTearDownAfterClass() {
     45            foreach ( self::$site_ids as $id ) {
     46                wpmu_delete_blog( $id, true );
     47            }
     48
     49            wp_update_network_site_counts();
     50        }
     51
     52        /**
     53         * @expectedDeprecated wp_get_sites
     54         */
     55        public function test_wp_get_sites_site_is_expected_array() {
     56
     57            $keys  = array(
     58                'blog_id',
     59                'site_id',
     60                'domain',
     61                'path',
     62                'registered',
     63                'last_updated',
     64                'public',
     65                'archived',
     66                'mature',
     67                'spam',
     68                'deleted',
     69                'lang_id',
     70            );
     71            $sites = wp_get_sites();
     72
     73            $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] );
     74
     75            $this->assertEquals( array(), $missing_keys, 'Keys are missing from site arrays.' );
     76        }
     77
     78        /**
     79         * @expectedDeprecated wp_get_sites
     80         * @dataProvider data_wp_get_sites
     81         *
     82         * @param $expected
     83         * @param $args
     84         * @param $error
     85         */
     86        public function test_wp_get_sites( $expected, $args, $error ) {
     87            $this->assertCount( $expected, wp_get_sites( $args ), $error );
     88        }
     89
     90        /**
     91         * @return array
     92         */
     93        public function data_wp_get_sites() {
     94            return array(
     95                array( 3, array(), 'Default arguments should return all sites from the current network.' ),
     96                array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ),
     97                array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ),
     98                array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ),
     99                array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ),
     100                array(
     101                    3,
     102                    array(
     103                        'public'     => 1,
     104                        'network_id' => null,
     105                    ),
     106                    'Public sites on all networks.',
     107                ),
     108                array(
     109                    2,
     110                    array(
     111                        'public'     => 0,
     112                        'network_id' => null,
     113                    ),
     114                    'Non public sites on all networks.',
     115                ),
     116                array(
     117                    2,
     118                    array(
     119                        'public'     => 1,
     120                        'network_id' => 1,
     121                    ),
     122                    'Public sites on a single network.',
     123                ),
     124                array(
     125                    1,
     126                    array(
     127                        'public'     => 1,
     128                        'network_id' => 2,
     129                    ),
     130                    'Public sites on a second network.',
     131                ),
     132                array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ),
     133                array(
     134                    1,
     135                    array(
     136                        'limit'  => 2,
     137                        'offset' => 2,
     138                    ),
     139                    'Provide both limit and offset arguments.',
     140                ),
     141                array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ),
     142                array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ),
     143            );
     144        }
    25145    }
    26146
    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     /**
    36      * @expectedDeprecated wp_get_sites
    37      */
    38     public function test_wp_get_sites_site_is_expected_array() {
    39 
    40         $keys = array(
    41             'blog_id',
    42             'site_id',
    43             'domain',
    44             'path',
    45             'registered',
    46             'last_updated',
    47             'public',
    48             'archived',
    49             'mature',
    50             'spam',
    51             'deleted',
    52             'lang_id'
    53         );
    54         $sites = wp_get_sites();
    55 
    56         $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] );
    57 
    58         $this->assertEquals( array(), $missing_keys, 'Keys are missing from site arrays.' );
    59     }
    60 
    61     /**
    62      * @expectedDeprecated wp_get_sites
    63      * @dataProvider data_wp_get_sites
    64      *
    65      * @param $expected
    66      * @param $args
    67      * @param $error
    68      */
    69     public function test_wp_get_sites( $expected, $args, $error ) {
    70         $this->assertCount( $expected, wp_get_sites( $args ), $error );
    71     }
    72 
    73     /**
    74      * @return array
    75      */
    76     public function data_wp_get_sites() {
    77         return array(
    78             array( 3, array(), 'Default arguments should return all sites from the current network.' ),
    79             array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ),
    80             array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ),
    81             array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ),
    82             array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ),
    83             array( 3, array( 'public' => 1, 'network_id' => null ), 'Public sites on all networks.' ),
    84             array( 2, array( 'public' => 0, 'network_id' => null ), 'Non public sites on all networks.' ),
    85             array( 2, array( 'public' => 1, 'network_id' => 1 ), 'Public sites on a single network.' ),
    86             array( 1, array( 'public' => 1, 'network_id' => 2 ), 'Public sites on a second network.' ),
    87             array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ),
    88             array( 1, array( 'limit' => 2, 'offset' => 2 ), 'Provide both limit and offset arguments.' ),
    89             array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ),
    90             array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ),
    91         );
    92     }
    93 }
    94 
    95147endif;
Note: See TracChangeset for help on using the changeset viewer.