Make WordPress Core


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

    r41063 r42343  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * Test network query functionality in multisite.
    7  *
    8  * @group ms-network
    9  * @group ms-network-query
    10  * @group multisite
    11  */
    12 class Tests_Multisite_Network_Query extends WP_UnitTestCase {
    13         protected static $network_ids;
    14 
    15         protected $suppress = false;
    16 
    17         function setUp() {
    18                 global $wpdb;
    19                 parent::setUp();
    20                 $this->suppress = $wpdb->suppress_errors();
     5        /**
     6         * Test network query functionality in multisite.
     7         *
     8         * @group ms-network
     9         * @group ms-network-query
     10         * @group multisite
     11         */
     12        class Tests_Multisite_Network_Query extends WP_UnitTestCase {
     13                protected static $network_ids;
     14
     15                protected $suppress = false;
     16
     17                function setUp() {
     18                        global $wpdb;
     19                        parent::setUp();
     20                        $this->suppress = $wpdb->suppress_errors();
     21                }
     22
     23                function tearDown() {
     24                        global $wpdb;
     25                        $wpdb->suppress_errors( $this->suppress );
     26                        parent::tearDown();
     27                }
     28
     29                public static function wpSetUpBeforeClass( $factory ) {
     30                        self::$network_ids = array(
     31                                'wordpress.org/'      => array(
     32                                        'domain' => 'wordpress.org',
     33                                        'path'   => '/',
     34                                ),
     35                                'make.wordpress.org/' => array(
     36                                        'domain' => 'make.wordpress.org',
     37                                        'path'   => '/',
     38                                ),
     39                                'www.wordpress.net/'  => array(
     40                                        'domain' => 'www.wordpress.net',
     41                                        'path'   => '/',
     42                                ),
     43                                'www.w.org/foo/'      => array(
     44                                        'domain' => 'www.w.org',
     45                                        'path'   => '/foo/',
     46                                ),
     47                        );
     48
     49                        foreach ( self::$network_ids as &$id ) {
     50                                $id = $factory->network->create( $id );
     51                        }
     52                        unset( $id );
     53                }
     54
     55                public static function wpTearDownAfterClass() {
     56                        global $wpdb;
     57
     58                        foreach ( self::$network_ids as $id ) {
     59                                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
     60                                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
     61                        }
     62                }
     63
     64                public function test_wp_network_query_by_number() {
     65                        $q     = new WP_Network_Query();
     66                        $found = $q->query(
     67                                array(
     68                                        'fields' => 'ids',
     69                                        'number' => 3,
     70                                )
     71                        );
     72
     73                        $this->assertEquals( 3, count( $found ) );
     74                }
     75
     76                public function test_wp_network_query_by_network__in_with_order() {
     77                        $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
     78
     79                        $q     = new WP_Network_Query();
     80                        $found = $q->query(
     81                                array(
     82                                        'fields'      => 'ids',
     83                                        'network__in' => $expected,
     84                                        'order'       => 'ASC',
     85                                )
     86                        );
     87
     88                        $this->assertEquals( $expected, $found );
     89
     90                        $found = $q->query(
     91                                array(
     92                                        'fields'      => 'ids',
     93                                        'network__in' => $expected,
     94                                        'order'       => 'DESC',
     95                                )
     96                        );
     97
     98                        $this->assertEquals( array_reverse( $expected ), $found );
     99                }
     100
     101                public function test_wp_network_query_by_network__in_with_single_id() {
     102                        $expected = array( self::$network_ids['wordpress.org/'] );
     103
     104                        $q     = new WP_Network_Query();
     105                        $found = $q->query(
     106                                array(
     107                                        'fields'      => 'ids',
     108                                        'network__in' => $expected,
     109                                )
     110                        );
     111
     112                        $this->assertEqualSets( $expected, $found );
     113                }
     114
     115                public function test_wp_network_query_by_network__in_with_multiple_ids() {
     116                        $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.wordpress.net/'] );
     117
     118                        $q     = new WP_Network_Query();
     119                        $found = $q->query(
     120                                array(
     121                                        'fields'      => 'ids',
     122                                        'network__in' => $expected,
     123                                )
     124                        );
     125
     126                        $this->assertEqualSets( $expected, $found );
     127                }
     128
     129                public function test_wp_network_query_by_network__in_and_count_with_multiple_ids() {
     130                        $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
     131
     132                        $q     = new WP_Network_Query();
     133                        $found = $q->query(
     134                                array(
     135                                        'fields'      => 'ids',
     136                                        'count'       => true,
     137                                        'network__in' => $expected,
     138                                )
     139                        );
     140
     141                        $this->assertEquals( 2, $found );
     142                }
     143
     144                public function test_wp_network_query_by_network__not_in_with_single_id() {
     145                        $excluded = array( self::$network_ids['wordpress.org/'] );
     146                        $expected = array_diff( self::$network_ids, $excluded );
     147
     148                        // Exclude main network since we don't have control over it here.
     149                        $excluded[] = 1;
     150
     151                        $q     = new WP_Network_Query();
     152                        $found = $q->query(
     153                                array(
     154                                        'fields'          => 'ids',
     155                                        'network__not_in' => $excluded,
     156                                )
     157                        );
     158
     159                        $this->assertEqualSets( $expected, $found );
     160                }
     161
     162                public function test_wp_network_query_by_network__not_in_with_multiple_ids() {
     163                        $excluded = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.w.org/foo/'] );
     164                        $expected = array_diff( self::$network_ids, $excluded );
     165
     166                        // Exclude main network since we don't have control over it here.
     167                        $excluded[] = 1;
     168
     169                        $q     = new WP_Network_Query();
     170                        $found = $q->query(
     171                                array(
     172                                        'fields'          => 'ids',
     173                                        'network__not_in' => $excluded,
     174                                )
     175                        );
     176
     177                        $this->assertEqualSets( $expected, $found );
     178                }
     179
     180                public function test_wp_network_query_by_domain() {
     181                        $q     = new WP_Network_Query();
     182                        $found = $q->query(
     183                                array(
     184                                        'fields' => 'ids',
     185                                        'domain' => 'www.w.org',
     186                                )
     187                        );
     188
     189                        $expected = array(
     190                                self::$network_ids['www.w.org/foo/'],
     191                        );
     192
     193                        $this->assertEqualSets( $expected, $found );
     194                }
     195
     196                public function test_wp_network_query_by_domain__in_with_single_domain() {
     197                        $q     = new WP_Network_Query();
     198                        $found = $q->query(
     199                                array(
     200                                        'fields'     => 'ids',
     201                                        'domain__in' => array( 'make.wordpress.org' ),
     202                                )
     203                        );
     204
     205                        $expected = array(
     206                                self::$network_ids['make.wordpress.org/'],
     207                        );
     208
     209                        $this->assertEqualSets( $expected, $found );
     210                }
     211
     212                public function test_wp_network_query_by_domain__in_with_multiple_domains() {
     213                        $q     = new WP_Network_Query();
     214                        $found = $q->query(
     215                                array(
     216                                        'fields'     => 'ids',
     217                                        'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
     218                                )
     219                        );
     220
     221                        $expected = array(
     222                                self::$network_ids['wordpress.org/'],
     223                                self::$network_ids['make.wordpress.org/'],
     224                        );
     225
     226                        $this->assertEqualSets( $expected, $found );
     227                }
     228
     229                public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number() {
     230                        $q     = new WP_Network_Query();
     231                        $found = $q->query(
     232                                array(
     233                                        'fields'     => 'ids',
     234                                        'number'     => 1,
     235                                        'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
     236                                )
     237                        );
     238
     239                        $expected = array(
     240                                self::$network_ids['wordpress.org/'],
     241                        );
     242
     243                        $this->assertEqualSets( $expected, $found );
     244                }
     245
     246                public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number_and_offset() {
     247                        $q     = new WP_Network_Query();
     248                        $found = $q->query(
     249                                array(
     250                                        'fields'     => 'ids',
     251                                        'number'     => 1,
     252                                        'offset'     => 1,
     253                                        'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
     254                                )
     255                        );
     256
     257                        $expected = array(
     258                                self::$network_ids['make.wordpress.org/'],
     259                        );
     260
     261                        $this->assertEqualSets( $expected, $found );
     262                }
     263
     264                public function test_wp_network_query_by_domain__not_in_with_single_domain() {
     265                        $q     = new WP_Network_Query();
     266                        $found = $q->query(
     267                                array(
     268                                        'fields'         => 'ids',
     269                                        'domain__not_in' => array( 'www.w.org' ),
     270                                )
     271                        );
     272
     273                        $expected = array(
     274                                get_current_site()->id, // Account for the initial network added by the test suite.
     275                                self::$network_ids['wordpress.org/'],
     276                                self::$network_ids['make.wordpress.org/'],
     277                                self::$network_ids['www.wordpress.net/'],
     278                        );
     279
     280                        $this->assertEqualSets( $expected, $found );
     281                }
     282
     283                public function test_wp_network_query_by_domain__not_in_with_multiple_domains() {
     284                        $q     = new WP_Network_Query();
     285                        $found = $q->query(
     286                                array(
     287                                        'fields'         => 'ids',
     288                                        'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
     289                                )
     290                        );
     291
     292                        $expected = array(
     293                                get_current_site()->id, // Account for the initial network added by the test suite.
     294                                self::$network_ids['make.wordpress.org/'],
     295                                self::$network_ids['www.wordpress.net/'],
     296                        );
     297
     298                        $this->assertEqualSets( $expected, $found );
     299                }
     300
     301                public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number() {
     302                        $q     = new WP_Network_Query();
     303                        $found = $q->query(
     304                                array(
     305                                        'fields'         => 'ids',
     306                                        'number'         => 2,
     307                                        'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
     308                                )
     309                        );
     310
     311                        $expected = array(
     312                                get_current_site()->id, // Account for the initial network added by the test suite.
     313                                self::$network_ids['make.wordpress.org/'],
     314                        );
     315
     316                        $this->assertEqualSets( $expected, $found );
     317                }
     318
     319                public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number_and_offset() {
     320                        $q     = new WP_Network_Query();
     321                        $found = $q->query(
     322                                array(
     323                                        'fields'         => 'ids',
     324                                        'number'         => 2,
     325                                        'offset'         => 1,
     326                                        'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
     327                                )
     328                        );
     329
     330                        $expected = array(
     331                                self::$network_ids['make.wordpress.org/'],
     332                                self::$network_ids['www.wordpress.net/'],
     333                        );
     334
     335                        $this->assertEqualSets( $expected, $found );
     336                }
     337
     338                public function test_wp_network_query_by_path_with_expected_results() {
     339                        $q     = new WP_Network_Query();
     340                        $found = $q->query(
     341                                array(
     342                                        'fields'          => 'ids',
     343                                        'path'            => '/',
     344                                        'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
     345                                )
     346                        );
     347
     348                        $expected = array(
     349                                self::$network_ids['wordpress.org/'],
     350                                self::$network_ids['make.wordpress.org/'],
     351                                self::$network_ids['www.wordpress.net/'],
     352                        );
     353
     354                        $this->assertEqualSets( $expected, $found );
     355                }
     356
     357                public function test_wp_network_query_by_path_and_number_and_offset_with_expected_results() {
     358                        $q     = new WP_Network_Query();
     359                        $found = $q->query(
     360                                array(
     361                                        'fields'          => 'ids',
     362                                        'number'          => 1,
     363                                        'offset'          => 2,
     364                                        'path'            => '/',
     365                                        'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
     366                                )
     367                        );
     368
     369                        $expected = array(
     370                                self::$network_ids['www.wordpress.net/'],
     371                        );
     372
     373                        $this->assertEqualSets( $expected, $found );
     374                }
     375
     376                public function test_wp_network_query_by_path_with_no_expected_results() {
     377                        $q     = new WP_Network_Query();
     378                        $found = $q->query(
     379                                array(
     380                                        'fields' => 'ids',
     381                                        'path'   => '/bar/',
     382                                )
     383                        );
     384
     385                        $this->assertEmpty( $found );
     386                }
     387
     388                public function test_wp_network_query_by_search_with_text_in_domain() {
     389                        $q     = new WP_Network_Query();
     390                        $found = $q->query(
     391                                array(
     392                                        'fields' => 'ids',
     393                                        'search' => 'ww.word',
     394                                )
     395                        );
     396
     397                        $expected = array(
     398                                self::$network_ids['www.wordpress.net/'],
     399                        );
     400
     401                        $this->assertEqualSets( $expected, $found );
     402                }
     403
     404                public function test_wp_network_query_by_search_with_text_in_path() {
     405                        $q     = new WP_Network_Query();
     406                        $found = $q->query(
     407                                array(
     408                                        'fields' => 'ids',
     409                                        'search' => 'foo',
     410                                )
     411                        );
     412
     413                        $expected = array(
     414                                self::$network_ids['www.w.org/foo/'],
     415                        );
     416
     417                        $this->assertEqualSets( $expected, $found );
     418                }
     419
     420                public function test_wp_network_query_by_path_order_by_domain_desc() {
     421                        $q     = new WP_Network_Query();
     422                        $found = $q->query(
     423                                array(
     424                                        'fields'          => 'ids',
     425                                        'path'            => '/',
     426                                        'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
     427                                        'order'           => 'DESC',
     428                                        'orderby'         => 'domain',
     429                                )
     430                        );
     431
     432                        $expected = array(
     433                                self::$network_ids['www.wordpress.net/'],
     434                                self::$network_ids['wordpress.org/'],
     435                                self::$network_ids['make.wordpress.org/'],
     436                        );
     437
     438                        $this->assertEquals( $expected, $found );
     439                }
     440
     441                /**
     442                 * @ticket 41347
     443                 */
     444                public function test_wp_network_query_cache_with_different_fields_no_count() {
     445                        global $wpdb;
     446
     447                        $q                 = new WP_Network_Query();
     448                        $query_1           = $q->query(
     449                                array(
     450                                        'fields' => 'all',
     451                                        'number' => 3,
     452                                        'order'  => 'ASC',
     453                                )
     454                        );
     455                        $number_of_queries = $wpdb->num_queries;
     456
     457                        $query_2 = $q->query(
     458                                array(
     459                                        'fields' => 'ids',
     460                                        'number' => 3,
     461                                        'order'  => 'ASC',
     462                                )
     463                        );
     464
     465                        $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     466                }
     467
     468                /**
     469                 * @ticket 41347
     470                 */
     471                public function test_wp_network_query_cache_with_different_fields_active_count() {
     472                        global $wpdb;
     473
     474                        $q = new WP_Network_Query();
     475
     476                        $query_1           = $q->query(
     477                                array(
     478                                        'fields' => 'all',
     479                                        'number' => 3,
     480                                        'order'  => 'ASC',
     481                                        'count'  => true,
     482                                )
     483                        );
     484                        $number_of_queries = $wpdb->num_queries;
     485
     486                        $query_2 = $q->query(
     487                                array(
     488                                        'fields' => 'ids',
     489                                        'number' => 3,
     490                                        'order'  => 'ASC',
     491                                        'count'  => true,
     492                                )
     493                        );
     494                        $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     495                }
     496
     497                /**
     498                 * @ticket 41347
     499                 */
     500                public function test_wp_network_query_cache_with_same_fields_different_count() {
     501                        global $wpdb;
     502
     503                        $q = new WP_Network_Query();
     504
     505                        $query_1 = $q->query(
     506                                array(
     507                                        'fields' => 'ids',
     508                                        'number' => 3,
     509                                        'order'  => 'ASC',
     510                                )
     511                        );
     512
     513                        $number_of_queries = $wpdb->num_queries;
     514
     515                        $query_2 = $q->query(
     516                                array(
     517                                        'fields' => 'ids',
     518                                        'number' => 3,
     519                                        'order'  => 'ASC',
     520                                        'count'  => true,
     521                                )
     522                        );
     523                        $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
     524                }
    21525        }
    22526
    23         function tearDown() {
    24                 global $wpdb;
    25                 $wpdb->suppress_errors( $this->suppress );
    26                 parent::tearDown();
    27         }
    28 
    29         public static function wpSetUpBeforeClass( $factory ) {
    30                 self::$network_ids = array(
    31                         'wordpress.org/'         => array( 'domain' => 'wordpress.org',      'path' => '/' ),
    32                         'make.wordpress.org/'    => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
    33                         'www.wordpress.net/'     => array( 'domain' => 'www.wordpress.net',  'path' => '/' ),
    34                         'www.w.org/foo/'         => array( 'domain' => 'www.w.org',          'path' => '/foo/' ),
    35                 );
    36 
    37                 foreach ( self::$network_ids as &$id ) {
    38                         $id = $factory->network->create( $id );
    39                 }
    40                 unset( $id );
    41         }
    42 
    43         public static function wpTearDownAfterClass() {
    44                 global $wpdb;
    45 
    46                 foreach( self::$network_ids as $id ) {
    47                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
    48                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
    49                 }
    50         }
    51 
    52         public function test_wp_network_query_by_number() {
    53                 $q = new WP_Network_Query();
    54                 $found = $q->query( array(
    55                         'fields'   => 'ids',
    56                         'number'   => 3,
    57                 ) );
    58 
    59                 $this->assertEquals( 3, count( $found ) );
    60         }
    61 
    62         public function test_wp_network_query_by_network__in_with_order() {
    63                 $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
    64 
    65                 $q = new WP_Network_Query();
    66                 $found = $q->query( array(
    67                         'fields'      => 'ids',
    68                         'network__in' => $expected,
    69                         'order'       => 'ASC',
    70                 ) );
    71 
    72                 $this->assertEquals( $expected, $found );
    73 
    74                 $found = $q->query( array(
    75                         'fields'      => 'ids',
    76                         'network__in' => $expected,
    77                         'order'       => 'DESC',
    78                 ) );
    79 
    80                 $this->assertEquals( array_reverse( $expected ), $found );
    81         }
    82 
    83         public function test_wp_network_query_by_network__in_with_single_id() {
    84                 $expected = array( self::$network_ids['wordpress.org/'] );
    85 
    86                 $q = new WP_Network_Query();
    87                 $found = $q->query( array(
    88                         'fields'      => 'ids',
    89                         'network__in' => $expected,
    90                 ) );
    91 
    92                 $this->assertEqualSets( $expected, $found );
    93         }
    94 
    95         public function test_wp_network_query_by_network__in_with_multiple_ids() {
    96                 $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.wordpress.net/'] );
    97 
    98                 $q = new WP_Network_Query();
    99                 $found = $q->query( array(
    100                         'fields'      => 'ids',
    101                         'network__in' => $expected,
    102                 ) );
    103 
    104                 $this->assertEqualSets( $expected, $found );
    105         }
    106 
    107         public function test_wp_network_query_by_network__in_and_count_with_multiple_ids() {
    108                 $expected = array( self::$network_ids['wordpress.org/'], self::$network_ids['make.wordpress.org/'] );
    109 
    110                 $q = new WP_Network_Query();
    111                 $found = $q->query( array(
    112                         'fields'      => 'ids',
    113                         'count'       => true,
    114                         'network__in' => $expected,
    115                 ) );
    116 
    117                 $this->assertEquals( 2, $found );
    118         }
    119 
    120         public function test_wp_network_query_by_network__not_in_with_single_id() {
    121                 $excluded = array( self::$network_ids['wordpress.org/'] );
    122                 $expected = array_diff( self::$network_ids, $excluded );
    123 
    124                 // Exclude main network since we don't have control over it here.
    125                 $excluded[] = 1;
    126 
    127                 $q = new WP_Network_Query();
    128                 $found = $q->query( array(
    129                         'fields'          => 'ids',
    130                         'network__not_in' => $excluded,
    131                 ) );
    132 
    133                 $this->assertEqualSets( $expected, $found );
    134         }
    135 
    136         public function test_wp_network_query_by_network__not_in_with_multiple_ids() {
    137                 $excluded = array( self::$network_ids['wordpress.org/'], self::$network_ids['www.w.org/foo/'] );
    138                 $expected = array_diff( self::$network_ids, $excluded );
    139 
    140                 // Exclude main network since we don't have control over it here.
    141                 $excluded[] = 1;
    142 
    143                 $q = new WP_Network_Query();
    144                 $found = $q->query( array(
    145                         'fields'          => 'ids',
    146                         'network__not_in' => $excluded,
    147                 ) );
    148 
    149                 $this->assertEqualSets( $expected, $found );
    150         }
    151 
    152         public function test_wp_network_query_by_domain() {
    153                 $q = new WP_Network_Query();
    154                 $found = $q->query( array(
    155                         'fields'       => 'ids',
    156                         'domain'       => 'www.w.org',
    157                 ) );
    158 
    159                 $expected = array(
    160                         self::$network_ids['www.w.org/foo/'],
    161                 );
    162 
    163                 $this->assertEqualSets( $expected, $found );
    164         }
    165 
    166         public function test_wp_network_query_by_domain__in_with_single_domain() {
    167                 $q = new WP_Network_Query();
    168                 $found = $q->query( array(
    169                         'fields'     => 'ids',
    170                         'domain__in' => array( 'make.wordpress.org' ),
    171                 ));
    172 
    173                 $expected = array(
    174                         self::$network_ids['make.wordpress.org/'],
    175                 );
    176 
    177                 $this->assertEqualSets( $expected, $found );
    178         }
    179 
    180         public function test_wp_network_query_by_domain__in_with_multiple_domains() {
    181                 $q = new WP_Network_Query();
    182                 $found = $q->query( array(
    183                         'fields'     => 'ids',
    184                         'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
    185                 ));
    186 
    187                 $expected = array(
    188                         self::$network_ids['wordpress.org/'],
    189                         self::$network_ids['make.wordpress.org/'],
    190                 );
    191 
    192                 $this->assertEqualSets( $expected, $found );
    193         }
    194 
    195         public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number() {
    196                 $q = new WP_Network_Query();
    197                 $found = $q->query( array(
    198                         'fields'     => 'ids',
    199                         'number'     => 1,
    200                         'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
    201                 ));
    202 
    203                 $expected = array(
    204                         self::$network_ids['wordpress.org/'],
    205                 );
    206 
    207                 $this->assertEqualSets( $expected, $found );
    208         }
    209 
    210         public function test_wp_network_query_by_domain__in_with_multiple_domains_and_number_and_offset() {
    211                 $q = new WP_Network_Query();
    212                 $found = $q->query( array(
    213                         'fields'     => 'ids',
    214                         'number'     => 1,
    215                         'offset'     => 1,
    216                         'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
    217                 ));
    218 
    219                 $expected = array(
    220                         self::$network_ids['make.wordpress.org/'],
    221                 );
    222 
    223                 $this->assertEqualSets( $expected, $found );
    224         }
    225 
    226         public function test_wp_network_query_by_domain__not_in_with_single_domain() {
    227                 $q = new WP_Network_Query();
    228                 $found = $q->query( array(
    229                         'fields'         => 'ids',
    230                         'domain__not_in' => array( 'www.w.org' ),
    231                 ));
    232 
    233                 $expected = array(
    234                         get_current_site()->id, // Account for the initial network added by the test suite.
    235                         self::$network_ids['wordpress.org/'],
    236                         self::$network_ids['make.wordpress.org/'],
    237                         self::$network_ids['www.wordpress.net/'],
    238                 );
    239 
    240                 $this->assertEqualSets( $expected, $found );
    241         }
    242 
    243         public function test_wp_network_query_by_domain__not_in_with_multiple_domains() {
    244                 $q = new WP_Network_Query();
    245                 $found = $q->query( array(
    246                         'fields'         => 'ids',
    247                         'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
    248                 ));
    249 
    250                 $expected = array(
    251                         get_current_site()->id, // Account for the initial network added by the test suite.
    252                         self::$network_ids['make.wordpress.org/'],
    253                         self::$network_ids['www.wordpress.net/'],
    254                 );
    255 
    256                 $this->assertEqualSets( $expected, $found );
    257         }
    258 
    259         public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number() {
    260                 $q = new WP_Network_Query();
    261                 $found = $q->query( array(
    262                         'fields'         => 'ids',
    263                         'number'         => 2,
    264                         'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
    265                 ));
    266 
    267                 $expected = array(
    268                         get_current_site()->id, // Account for the initial network added by the test suite.
    269                         self::$network_ids['make.wordpress.org/'],
    270                 );
    271 
    272                 $this->assertEqualSets( $expected, $found );
    273         }
    274 
    275         public function test_wp_network_query_by_domain__not_in_with_multiple_domains_and_number_and_offset() {
    276                 $q = new WP_Network_Query();
    277                 $found = $q->query( array(
    278                         'fields'         => 'ids',
    279                         'number'         => 2,
    280                         'offset'         => 1,
    281                         'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
    282                 ));
    283 
    284                 $expected = array(
    285                         self::$network_ids['make.wordpress.org/'],
    286                         self::$network_ids['www.wordpress.net/'],
    287                 );
    288 
    289                 $this->assertEqualSets( $expected, $found );
    290         }
    291 
    292         public function test_wp_network_query_by_path_with_expected_results() {
    293                 $q = new WP_Network_Query();
    294                 $found = $q->query( array(
    295                         'fields'          => 'ids',
    296                         'path'            => '/',
    297                         'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
    298                 ) );
    299 
    300                 $expected = array(
    301                         self::$network_ids['wordpress.org/'],
    302                         self::$network_ids['make.wordpress.org/'],
    303                         self::$network_ids['www.wordpress.net/'],
    304                 );
    305 
    306                 $this->assertEqualSets( $expected, $found );
    307         }
    308 
    309         public function test_wp_network_query_by_path_and_number_and_offset_with_expected_results() {
    310                 $q = new WP_Network_Query();
    311                 $found = $q->query( array(
    312                         'fields'          => 'ids',
    313                         'number'          => 1,
    314                         'offset'          => 2,
    315                         'path'            => '/',
    316                         'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
    317                 ) );
    318 
    319                 $expected = array(
    320                         self::$network_ids['www.wordpress.net/'],
    321                 );
    322 
    323                 $this->assertEqualSets( $expected, $found );
    324         }
    325 
    326         public function test_wp_network_query_by_path_with_no_expected_results() {
    327                 $q = new WP_Network_Query();
    328                 $found = $q->query( array(
    329                         'fields'       => 'ids',
    330                         'path'         => '/bar/',
    331                 ) );
    332 
    333                 $this->assertEmpty( $found );
    334         }
    335 
    336         public function test_wp_network_query_by_search_with_text_in_domain() {
    337                 $q = new WP_Network_Query();
    338                 $found = $q->query( array(
    339                         'fields'       => 'ids',
    340                         'search'       => 'ww.word',
    341                 ) );
    342 
    343                 $expected = array(
    344                         self::$network_ids['www.wordpress.net/'],
    345                 );
    346 
    347                 $this->assertEqualSets( $expected, $found );
    348         }
    349 
    350         public function test_wp_network_query_by_search_with_text_in_path() {
    351                 $q = new WP_Network_Query();
    352                 $found = $q->query( array(
    353                         'fields'       => 'ids',
    354                         'search'       => 'foo',
    355                 ) );
    356 
    357                 $expected = array(
    358                         self::$network_ids['www.w.org/foo/'],
    359                 );
    360 
    361                 $this->assertEqualSets( $expected, $found );
    362         }
    363 
    364         public function test_wp_network_query_by_path_order_by_domain_desc() {
    365                 $q = new WP_Network_Query();
    366                 $found = $q->query( array(
    367                         'fields'          => 'ids',
    368                         'path'            => '/',
    369                         'network__not_in' => get_current_site()->id, // Exclude the initial network added by the test suite.
    370                         'order'           => 'DESC',
    371                         'orderby'         => 'domain',
    372                 ) );
    373 
    374                 $expected = array(
    375                         self::$network_ids['www.wordpress.net/'],
    376                         self::$network_ids['wordpress.org/'],
    377                         self::$network_ids['make.wordpress.org/'],
    378                 );
    379 
    380                 $this->assertEquals( $expected, $found );
    381         }
    382 
    383         /**
    384          * @ticket 41347
    385          */
    386         public function test_wp_network_query_cache_with_different_fields_no_count() {
    387                 global $wpdb;
    388 
    389                 $q                 = new WP_Network_Query();
    390                 $query_1           = $q->query( array(
    391                         'fields'     => 'all',
    392                         'number'     => 3,
    393                         'order'      => 'ASC',
    394                 ) );
    395                 $number_of_queries = $wpdb->num_queries;
    396 
    397                 $query_2 = $q->query( array(
    398                         'fields'     => 'ids',
    399                         'number'     => 3,
    400                         'order'      => 'ASC',
    401                 ) );
    402 
    403                 $this->assertEquals( $number_of_queries, $wpdb->num_queries );
    404         }
    405 
    406         /**
    407          * @ticket 41347
    408          */
    409         public function test_wp_network_query_cache_with_different_fields_active_count() {
    410                 global $wpdb;
    411 
    412                 $q = new WP_Network_Query();
    413 
    414                 $query_1           = $q->query( array(
    415                         'fields'     => 'all',
    416                         'number'     => 3,
    417                         'order'      => 'ASC',
    418                         'count'      => true,
    419                 ) );
    420                 $number_of_queries = $wpdb->num_queries;
    421 
    422                 $query_2 = $q->query( array(
    423                         'fields'     => 'ids',
    424                         'number'     => 3,
    425                         'order'      => 'ASC',
    426                         'count'      => true,
    427                 ) );
    428                 $this->assertEquals( $number_of_queries, $wpdb->num_queries );
    429         }
    430 
    431         /**
    432          * @ticket 41347
    433          */
    434         public function test_wp_network_query_cache_with_same_fields_different_count() {
    435                 global $wpdb;
    436 
    437                 $q = new WP_Network_Query();
    438 
    439                 $query_1 = $q->query( array(
    440                         'fields'     => 'ids',
    441                         'number'     => 3,
    442                         'order'      => 'ASC',
    443                 ) );
    444 
    445                 $number_of_queries = $wpdb->num_queries;
    446 
    447                 $query_2 = $q->query( array(
    448                         'fields'     => 'ids',
    449                         'number'     => 3,
    450                         'order'      => 'ASC',
    451                         'count'      => true,
    452                 ) );
    453                 $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
    454         }
    455 }
    456 
    457527endif;
Note: See TracChangeset for help on using the changeset viewer.