Make WordPress Core


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

    r41059 r42343  
    33if ( is_multisite() ) :
    44
    5 /**
    6  * Test site query functionality in multisite.
    7  *
    8  * @group ms-site
    9  * @group multisite
    10  */
    11 class Tests_Multisite_Site_Query extends WP_UnitTestCase {
    12     protected static $network_ids;
    13     protected static $site_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 site query functionality in multisite.
     7     *
     8     * @group ms-site
     9     * @group multisite
     10     */
     11    class Tests_Multisite_Site_Query extends WP_UnitTestCase {
     12        protected static $network_ids;
     13        protected static $site_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            );
     44
     45            foreach ( self::$network_ids as &$id ) {
     46                $id = $factory->network->create( $id );
     47            }
     48            unset( $id );
     49
     50            self::$site_ids = array(
     51                'wordpress.org/'          => array(
     52                    'domain'  => 'wordpress.org',
     53                    'path'    => '/',
     54                    'site_id' => self::$network_ids['wordpress.org/'],
     55                ),
     56                'wordpress.org/foo/'      => array(
     57                    'domain'  => 'wordpress.org',
     58                    'path'    => '/foo/',
     59                    'site_id' => self::$network_ids['wordpress.org/'],
     60                ),
     61                'wordpress.org/foo/bar/'  => array(
     62                    'domain'  => 'wordpress.org',
     63                    'path'    => '/foo/bar/',
     64                    'site_id' => self::$network_ids['wordpress.org/'],
     65                ),
     66                'make.wordpress.org/'     => array(
     67                    'domain'  => 'make.wordpress.org',
     68                    'path'    => '/',
     69                    'site_id' => self::$network_ids['make.wordpress.org/'],
     70                ),
     71                'make.wordpress.org/foo/' => array(
     72                    'domain'  => 'make.wordpress.org',
     73                    'path'    => '/foo/',
     74                    'site_id' => self::$network_ids['make.wordpress.org/'],
     75                ),
     76                'www.w.org/'              => array(
     77                    'domain' => 'www.w.org',
     78                    'path'   => '/',
     79                ),
     80                'www.w.org/foo/'          => array(
     81                    'domain' => 'www.w.org',
     82                    'path'   => '/foo/',
     83                ),
     84                'www.w.org/foo/bar/'      => array(
     85                    'domain' => 'www.w.org',
     86                    'path'   => '/foo/bar/',
     87                ),
     88                'www.w.org/make/'         => array(
     89                    'domain' => 'www.w.org',
     90                    'path'   => '/make/',
     91                    'meta'   => array(
     92                        'public'  => 1,
     93                        'lang_id' => 1,
     94                    ),
     95                ),
     96            );
     97
     98            foreach ( self::$site_ids as &$id ) {
     99                $id = $factory->blog->create( $id );
     100            }
     101            unset( $id );
     102        }
     103
     104        public static function wpTearDownAfterClass() {
     105            global $wpdb;
     106
     107            foreach ( self::$site_ids as $id ) {
     108                wpmu_delete_blog( $id, true );
     109            }
     110
     111            foreach ( self::$network_ids as $id ) {
     112                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
     113                $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
     114            }
     115
     116            wp_update_network_site_counts();
     117        }
     118
     119        public function test_wp_site_query_by_ID() {
     120            $q     = new WP_Site_Query();
     121            $found = $q->query(
     122                array(
     123                    'fields' => 'ids',
     124                    'ID'     => self::$site_ids['www.w.org/'],
     125                )
     126            );
     127
     128            $this->assertEqualSets( array( self::$site_ids['www.w.org/'] ), $found );
     129        }
     130
     131        public function test_wp_site_query_by_number() {
     132            $q     = new WP_Site_Query();
     133            $found = $q->query(
     134                array(
     135                    'fields' => 'ids',
     136                    'number' => 3,
     137                )
     138            );
     139
     140            $this->assertEquals( 3, count( $found ) );
     141        }
     142
     143        public function test_wp_site_query_by_site__in_with_single_id() {
     144            $expected = array( self::$site_ids['wordpress.org/foo/'] );
     145
     146            $q     = new WP_Site_Query();
     147            $found = $q->query(
     148                array(
     149                    'fields'   => 'ids',
     150                    'site__in' => $expected,
     151                )
     152            );
     153
     154            $this->assertEqualSets( $expected, $found );
     155        }
     156
     157        public function test_wp_site_query_by_site__in_with_multiple_ids() {
     158            $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
     159
     160            $q     = new WP_Site_Query();
     161            $found = $q->query(
     162                array(
     163                    'fields'   => 'ids',
     164                    'site__in' => $expected,
     165                )
     166            );
     167
     168            $this->assertEqualSets( $expected, $found );
     169        }
     170
     171        /**
     172         * Test the `count` query var
     173         */
     174        public function test_wp_site_query_by_site__in_and_count_with_multiple_ids() {
     175            $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
     176
     177            $q     = new WP_Site_Query();
     178            $found = $q->query(
     179                array(
     180                    'fields'   => 'ids',
     181                    'count'    => true,
     182                    'site__in' => $expected,
     183                )
     184            );
     185
     186            $this->assertEquals( 2, $found );
     187        }
     188
     189        public function test_wp_site_query_by_site__not_in_with_single_id() {
     190            $excluded = array( self::$site_ids['wordpress.org/foo/'] );
     191            $expected = array_diff( self::$site_ids, $excluded );
     192
     193            // Exclude main site since we don't have control over it here.
     194            $excluded[] = 1;
     195
     196            $q     = new WP_Site_Query();
     197            $found = $q->query(
     198                array(
     199                    'fields'       => 'ids',
     200                    'site__not_in' => $excluded,
     201                )
     202            );
     203
     204            $this->assertEqualSets( $expected, $found );
     205        }
     206
     207        public function test_wp_site_query_by_site__not_in_with_multiple_ids() {
     208            $excluded = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
     209            $expected = array_diff( self::$site_ids, $excluded );
     210
     211            // Exclude main site since we don't have control over it here.
     212            $excluded[] = 1;
     213
     214            $q     = new WP_Site_Query();
     215            $found = $q->query(
     216                array(
     217                    'fields'       => 'ids',
     218                    'site__not_in' => $excluded,
     219                )
     220            );
     221
     222            $this->assertEqualSets( $expected, $found );
     223        }
     224
     225        public function test_wp_site_query_by_network_id_with_order() {
     226            $q     = new WP_Site_Query();
     227            $found = $q->query(
     228                array(
     229                    'fields'     => 'ids',
     230                    'network_id' => self::$network_ids['wordpress.org/'],
     231                    'number'     => 3,
     232                    'order'      => 'ASC',
     233                )
     234            );
     235
     236            $expected = array(
     237                self::$site_ids['wordpress.org/'],
     238                self::$site_ids['wordpress.org/foo/'],
     239                self::$site_ids['wordpress.org/foo/bar/'],
     240            );
     241
     242            $this->assertEquals( $expected, $found );
     243
     244            $found = $q->query(
     245                array(
     246                    'fields'     => 'ids',
     247                    'network_id' => self::$network_ids['wordpress.org/'],
     248                    'number'     => 3,
     249                    'order'      => 'DESC',
     250                )
     251            );
     252
     253            $this->assertEquals( array_reverse( $expected ), $found );
     254        }
     255
     256        public function test_wp_site_query_by_network_id_with_existing_sites() {
     257            $q     = new WP_Site_Query();
     258            $found = $q->query(
     259                array(
     260                    'fields'     => 'ids',
     261                    'network_id' => self::$network_ids['make.wordpress.org/'],
     262                )
     263            );
     264
     265            $expected = array(
     266                self::$site_ids['make.wordpress.org/'],
     267                self::$site_ids['make.wordpress.org/foo/'],
     268            );
     269
     270            $this->assertEqualSets( $expected, $found );
     271        }
     272
     273        public function test_wp_site_query_by_network_id_with_no_existing_sites() {
     274            $q     = new WP_Site_Query();
     275            $found = $q->query(
     276                array(
     277                    'fields'     => 'ids',
     278                    'network_id' => self::$network_ids['www.wordpress.net/'],
     279                )
     280            );
     281
     282            $this->assertEmpty( $found );
     283        }
     284
     285        public function test_wp_site_query_by_domain() {
     286            $q     = new WP_Site_Query();
     287            $found = $q->query(
     288                array(
     289                    'fields' => 'ids',
     290                    'domain' => 'www.w.org',
     291                )
     292            );
     293
     294            $expected = array(
     295                self::$site_ids['www.w.org/'],
     296                self::$site_ids['www.w.org/foo/'],
     297                self::$site_ids['www.w.org/foo/bar/'],
     298                self::$site_ids['www.w.org/make/'],
     299            );
     300
     301            $this->assertEqualSets( $expected, $found );
     302        }
     303
     304        public function test_wp_site_query_by_domain_and_offset() {
     305            $q     = new WP_Site_Query();
     306            $found = $q->query(
     307                array(
     308                    'fields' => 'ids',
     309                    'domain' => 'www.w.org',
     310                    'offset' => 1,
     311                )
     312            );
     313
     314            $expected = array(
     315                self::$site_ids['www.w.org/foo/'],
     316                self::$site_ids['www.w.org/foo/bar/'],
     317                self::$site_ids['www.w.org/make/'],
     318            );
     319
     320            $this->assertEqualSets( $expected, $found );
     321        }
     322
     323        public function test_wp_site_query_by_domain_and_number_and_offset() {
     324            $q     = new WP_Site_Query();
     325            $found = $q->query(
     326                array(
     327                    'fields' => 'ids',
     328                    'domain' => 'www.w.org',
     329                    'number' => 2,
     330                    'offset' => 1,
     331                )
     332            );
     333
     334            $expected = array(
     335                self::$site_ids['www.w.org/foo/'],
     336                self::$site_ids['www.w.org/foo/bar/'],
     337            );
     338
     339            $this->assertEqualSets( $expected, $found );
     340        }
     341
     342        public function test_wp_site_query_by_domain__in_with_single_domain() {
     343            $q     = new WP_Site_Query();
     344            $found = $q->query(
     345                array(
     346                    'fields'     => 'ids',
     347                    'domain__in' => array( 'make.wordpress.org' ),
     348                )
     349            );
     350
     351            $expected = array(
     352                self::$site_ids['make.wordpress.org/'],
     353                self::$site_ids['make.wordpress.org/foo/'],
     354            );
     355
     356            $this->assertEqualSets( $expected, $found );
     357        }
     358
     359        public function test_wp_site_query_by_domain__in_with_multiple_domains() {
     360            $q     = new WP_Site_Query();
     361            $found = $q->query(
     362                array(
     363                    'fields'     => 'ids',
     364                    'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
     365                )
     366            );
     367
     368            $expected = array(
     369                self::$site_ids['wordpress.org/'],
     370                self::$site_ids['wordpress.org/foo/'],
     371                self::$site_ids['wordpress.org/foo/bar/'],
     372                self::$site_ids['make.wordpress.org/'],
     373                self::$site_ids['make.wordpress.org/foo/'],
     374            );
     375
     376            $this->assertEqualSets( $expected, $found );
     377        }
     378
     379        public function test_wp_site_query_by_domain__not_in_with_single_domain() {
     380            $q     = new WP_Site_Query();
     381            $found = $q->query(
     382                array(
     383                    'fields'         => 'ids',
     384                    'domain__not_in' => array( 'www.w.org' ),
     385                )
     386            );
     387
     388            $expected = array(
     389                get_current_blog_id(), // Account for the initial site added by the test suite.
     390                self::$site_ids['wordpress.org/'],
     391                self::$site_ids['wordpress.org/foo/'],
     392                self::$site_ids['wordpress.org/foo/bar/'],
     393                self::$site_ids['make.wordpress.org/'],
     394                self::$site_ids['make.wordpress.org/foo/'],
     395            );
     396
     397            $this->assertEqualSets( $expected, $found );
     398        }
     399
     400        public function test_wp_site_query_by_domain__not_in_with_multiple_domains() {
     401            $q     = new WP_Site_Query();
     402            $found = $q->query(
     403                array(
     404                    'fields'         => 'ids',
     405                    'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
     406                )
     407            );
     408
     409            $expected = array(
     410                get_current_blog_id(), // Account for the initial site added by the test suite.
     411                self::$site_ids['make.wordpress.org/'],
     412                self::$site_ids['make.wordpress.org/foo/'],
     413            );
     414
     415            $this->assertEqualSets( $expected, $found );
     416        }
     417
     418        public function test_wp_site_query_by_path_with_expected_results() {
     419            $q     = new WP_Site_Query();
     420            $found = $q->query(
     421                array(
     422                    'fields' => 'ids',
     423                    'path'   => '/foo/bar/',
     424                )
     425            );
     426
     427            $expected = array(
     428                self::$site_ids['wordpress.org/foo/bar/'],
     429                self::$site_ids['www.w.org/foo/bar/'],
     430            );
     431
     432            $this->assertEqualSets( $expected, $found );
     433        }
     434
     435        public function test_wp_site_query_by_path_with_no_expected_results() {
     436            $q     = new WP_Site_Query();
     437            $found = $q->query(
     438                array(
     439                    'fields' => 'ids',
     440                    'path'   => '/foo/bar/foo/',
     441                )
     442            );
     443
     444            $this->assertEmpty( $found );
     445        }
     446
     447        // archived, mature, spam, deleted, public
     448
     449        public function test_wp_site_query_by_archived() {
     450            $q     = new WP_Site_Query();
     451            $found = $q->query(
     452                array(
     453                    'fields'       => 'ids',
     454                    // Exclude main site since we don't have control over it here.
     455                    'site__not_in' => array( 1 ),
     456                    'archived'     => '0',
     457                )
     458            );
     459
     460            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     461        }
     462
     463        public function test_wp_site_query_by_mature() {
     464            $q     = new WP_Site_Query();
     465            $found = $q->query(
     466                array(
     467                    'fields'       => 'ids',
     468                    // Exclude main site since we don't have control over it here.
     469                    'site__not_in' => array( 1 ),
     470                    'mature'       => '0',
     471                )
     472            );
     473
     474            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     475        }
     476
     477        public function test_wp_site_query_by_spam() {
     478            $q     = new WP_Site_Query();
     479            $found = $q->query(
     480                array(
     481                    'fields'       => 'ids',
     482                    // Exclude main site since we don't have control over it here.
     483                    'site__not_in' => array( 1 ),
     484                    'spam'         => '0',
     485                )
     486            );
     487
     488            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     489        }
     490
     491        public function test_wp_site_query_by_deleted() {
     492            $q     = new WP_Site_Query();
     493            $found = $q->query(
     494                array(
     495                    'fields'       => 'ids',
     496                    // Exclude main site since we don't have control over it here.
     497                    'site__not_in' => array( 1 ),
     498                    'deleted'      => '0',
     499                )
     500            );
     501
     502            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     503        }
     504
     505        public function test_wp_site_query_by_deleted_with_no_results() {
     506            $q     = new WP_Site_Query();
     507            $found = $q->query(
     508                array(
     509                    'fields'  => 'ids',
     510                    'deleted' => '1',
     511                )
     512            );
     513
     514            $this->assertEmpty( $found );
     515        }
     516
     517        public function test_wp_site_query_by_public() {
     518            $q     = new WP_Site_Query();
     519            $found = $q->query(
     520                array(
     521                    'fields'       => 'ids',
     522                    // Exclude main site since we don't have control over it here.
     523                    'site__not_in' => array( 1 ),
     524                    'public'       => '1',
     525                )
     526            );
     527
     528            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     529        }
     530
     531        public function test_wp_site_query_by_lang_id_with_zero() {
     532            $q     = new WP_Site_Query();
     533            $found = $q->query(
     534                array(
     535                    'fields'       => 'ids',
     536                    // Exclude main site since we don't have control over it here.
     537                    'site__not_in' => array( 1 ),
     538                    'lang_id'      => 0,
     539                )
     540            );
     541
     542            $this->assertEqualSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
     543        }
     544
     545        public function test_wp_site_query_by_lang_id() {
     546            $q     = new WP_Site_Query();
     547            $found = $q->query(
     548                array(
     549                    'fields'  => 'ids',
     550                    'lang_id' => 1,
     551                )
     552            );
     553
     554            $expected = array(
     555                self::$site_ids['www.w.org/make/'],
     556            );
     557
     558            $this->assertEqualSets( $expected, $found );
     559        }
     560
     561        public function test_wp_site_query_by_lang_id_with_no_results() {
     562            $q     = new WP_Site_Query();
     563            $found = $q->query(
     564                array(
     565                    'fields'  => 'ids',
     566                    'lang_id' => 2,
     567                )
     568            );
     569
     570            $this->assertEmpty( $found );
     571        }
     572
     573        public function test_wp_site_query_by_lang__in() {
     574            $q     = new WP_Site_Query();
     575            $found = $q->query(
     576                array(
     577                    'fields'   => 'ids',
     578                    'lang__in' => array( 1 ),
     579                )
     580            );
     581
     582            $expected = array(
     583                self::$site_ids['www.w.org/make/'],
     584            );
     585
     586            $this->assertEqualSets( $expected, $found );
     587        }
     588
     589        public function test_wp_site_query_by_lang__in_with_multiple_ids() {
     590            $q     = new WP_Site_Query();
     591            $found = $q->query(
     592                array(
     593                    'fields'       => 'ids',
     594                    // Exclude main site since we don't have control over it here.
     595                    'site__not_in' => array( 1 ),
     596                    'lang__in'     => array( 0, 1 ),
     597                )
     598            );
     599
     600            $this->assertEqualSets( array_values( self::$site_ids ), $found );
     601        }
     602
     603        public function test_wp_site_query_by_lang__not_in() {
     604            $q     = new WP_Site_Query();
     605            $found = $q->query(
     606                array(
     607                    'fields'       => 'ids',
     608                    'lang__not_in' => array( 0 ),
     609                )
     610            );
     611
     612            $expected = array(
     613                self::$site_ids['www.w.org/make/'],
     614            );
     615
     616            $this->assertEqualSets( $expected, $found );
     617        }
     618
     619        public function test_wp_site_query_by_lang__not_in_with_multiple_ids() {
     620            $q     = new WP_Site_Query();
     621            $found = $q->query(
     622                array(
     623                    'fields'       => 'ids',
     624                    'lang__not_in' => array( 0, 1 ),
     625                )
     626            );
     627
     628            $this->assertEmpty( $found );
     629        }
     630
     631        public function test_wp_site_query_by_search_with_text_in_domain() {
     632            $q     = new WP_Site_Query();
     633            $found = $q->query(
     634                array(
     635                    'fields' => 'ids',
     636                    'search' => 'ke.wordp',
     637                )
     638            );
     639
     640            $expected = array(
     641                self::$site_ids['make.wordpress.org/'],
     642                self::$site_ids['make.wordpress.org/foo/'],
     643            );
     644
     645            $this->assertEqualSets( $expected, $found );
     646        }
     647
     648        public function test_wp_site_query_by_search_with_text_in_path() {
     649            $q     = new WP_Site_Query();
     650            $found = $q->query(
     651                array(
     652                    'fields' => 'ids',
     653                    'search' => 'foo',
     654                )
     655            );
     656
     657            $expected = array(
     658                self::$site_ids['wordpress.org/foo/'],
     659                self::$site_ids['wordpress.org/foo/bar/'],
     660                self::$site_ids['make.wordpress.org/foo/'],
     661                self::$site_ids['www.w.org/foo/'],
     662                self::$site_ids['www.w.org/foo/bar/'],
     663            );
     664
     665            $this->assertEqualSets( $expected, $found );
     666        }
     667
     668        public function test_wp_site_query_by_search_with_text_in_path_and_domain() {
     669            $q     = new WP_Site_Query();
     670            $found = $q->query(
     671                array(
     672                    'fields' => 'ids',
     673                    'search' => 'make',
     674                )
     675            );
     676
     677            $expected = array(
     678                self::$site_ids['make.wordpress.org/'],
     679                self::$site_ids['make.wordpress.org/foo/'],
     680                self::$site_ids['www.w.org/make/'],
     681            );
     682
     683            $this->assertEqualSets( $expected, $found );
     684        }
     685
     686        public function test_wp_site_query_by_search_with_text_in_path_and_domain_order_by_domain_desc() {
     687            $q     = new WP_Site_Query();
     688            $found = $q->query(
     689                array(
     690                    'fields'  => 'ids',
     691                    'search'  => 'make',
     692                    'order'   => 'DESC',
     693                    'orderby' => 'domain',
     694                )
     695            );
     696
     697            $expected = array(
     698                self::$site_ids['www.w.org/make/'],
     699                self::$site_ids['make.wordpress.org/'],
     700                self::$site_ids['make.wordpress.org/foo/'],
     701            );
     702
     703            $this->assertEquals( $expected, $found );
     704        }
     705
     706        public function test_wp_site_query_by_search_with_text_in_path_exclude_domain_from_search() {
     707            $q     = new WP_Site_Query();
     708            $found = $q->query(
     709                array(
     710                    'fields'         => 'ids',
     711                    'search'         => 'make',
     712                    'search_columns' => array( 'path' ),
     713                )
     714            );
     715
     716            $expected = array(
     717                self::$site_ids['www.w.org/make/'],
     718            );
     719
     720            $this->assertEquals( $expected, $found );
     721        }
     722
     723        public function test_wp_site_query_by_search_with_text_in_domain_exclude_path_from_search() {
     724            $q     = new WP_Site_Query();
     725            $found = $q->query(
     726                array(
     727                    'fields'         => 'ids',
     728                    'search'         => 'make',
     729                    'search_columns' => array( 'domain' ),
     730                )
     731            );
     732
     733            $expected = array(
     734                self::$site_ids['make.wordpress.org/'],
     735                self::$site_ids['make.wordpress.org/foo/'],
     736            );
     737
     738            $this->assertEquals( $expected, $found );
     739        }
     740
     741        public function test_wp_site_query_by_search_with_wildcard_in_text() {
     742            $q     = new WP_Site_Query();
     743            $found = $q->query(
     744                array(
     745                    'fields' => 'ids',
     746                    'search' => 'm*ke',
     747                )
     748            );
     749
     750            $expected = array(
     751                self::$site_ids['www.w.org/make/'],
     752                self::$site_ids['make.wordpress.org/'],
     753                self::$site_ids['make.wordpress.org/foo/'],
     754            );
     755
     756            $this->assertEqualSets( $expected, $found );
     757        }
     758
     759        public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
     760            $q     = new WP_Site_Query();
     761            $found = $q->query(
     762                array(
     763                    'fields'         => 'ids',
     764                    'search'         => 'm*ke',
     765                    'search_columns' => array( 'domain' ),
     766                )
     767            );
     768
     769            $expected = array(
     770                self::$site_ids['make.wordpress.org/'],
     771                self::$site_ids['make.wordpress.org/foo/'],
     772            );
     773
     774            $this->assertEqualSets( $expected, $found );
     775        }
     776
     777        public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
     778            $q     = new WP_Site_Query();
     779            $found = $q->query(
     780                array(
     781                    'fields'         => 'ids',
     782                    'search'         => 'm*ke',
     783                    'search_columns' => array( 'path' ),
     784                )
     785            );
     786
     787            $expected = array(
     788                self::$site_ids['www.w.org/make/'],
     789            );
     790
     791            $this->assertEqualSets( $expected, $found );
     792        }
     793
     794        /**
     795         * @ticket 41197
     796         */
     797        public function test_wp_site_query_cache_with_different_fields_no_count() {
     798            global $wpdb;
     799            $q                 = new WP_Site_Query();
     800            $query_1           = $q->query(
     801                array(
     802                    'fields'     => 'all',
     803                    'network_id' => self::$network_ids['wordpress.org/'],
     804                    'number'     => 3,
     805                    'order'      => 'ASC',
     806                )
     807            );
     808            $number_of_queries = $wpdb->num_queries;
     809
     810            $query_2 = $q->query(
     811                array(
     812                    'fields'     => 'ids',
     813                    'network_id' => self::$network_ids['wordpress.org/'],
     814                    'number'     => 3,
     815                    'order'      => 'ASC',
     816                )
     817            );
     818
     819            $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     820        }
     821
     822        /**
     823         * @ticket 41197
     824         */
     825        public function test_wp_site_query_cache_with_different_fields_active_count() {
     826            global $wpdb;
     827            $q = new WP_Site_Query();
     828
     829            $query_1           = $q->query(
     830                array(
     831                    'fields'     => 'all',
     832                    'network_id' => self::$network_ids['wordpress.org/'],
     833                    'number'     => 3,
     834                    'order'      => 'ASC',
     835                    'count'      => true,
     836                )
     837            );
     838            $number_of_queries = $wpdb->num_queries;
     839
     840            $query_2 = $q->query(
     841                array(
     842                    'fields'     => 'ids',
     843                    'network_id' => self::$network_ids['wordpress.org/'],
     844                    'number'     => 3,
     845                    'order'      => 'ASC',
     846                    'count'      => true,
     847                )
     848            );
     849            $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     850        }
     851
     852        /**
     853         * @ticket 41197
     854         */
     855        public function test_wp_site_query_cache_with_same_fields_different_count() {
     856            global $wpdb;
     857            $q = new WP_Site_Query();
     858
     859            $query_1 = $q->query(
     860                array(
     861                    'fields'     => 'ids',
     862                    'network_id' => self::$network_ids['wordpress.org/'],
     863                    'number'     => 3,
     864                    'order'      => 'ASC',
     865                )
     866            );
     867
     868            $number_of_queries = $wpdb->num_queries;
     869
     870            $query_2 = $q->query(
     871                array(
     872                    'fields'     => 'ids',
     873                    'network_id' => self::$network_ids['wordpress.org/'],
     874                    'number'     => 3,
     875                    'order'      => 'ASC',
     876                    'count'      => true,
     877                )
     878            );
     879            $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
     880        }
    21881    }
    22882
    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         );
    35 
    36         foreach ( self::$network_ids as &$id ) {
    37             $id = $factory->network->create( $id );
    38         }
    39         unset( $id );
    40 
    41         self::$site_ids = array(
    42             'wordpress.org/'              => array( 'domain' => 'wordpress.org',      'path' => '/',         'site_id' => self::$network_ids['wordpress.org/'] ),
    43             'wordpress.org/foo/'          => array( 'domain' => 'wordpress.org',      'path' => '/foo/',     'site_id' => self::$network_ids['wordpress.org/'] ),
    44             'wordpress.org/foo/bar/'      => array( 'domain' => 'wordpress.org',      'path' => '/foo/bar/', 'site_id' => self::$network_ids['wordpress.org/'] ),
    45             'make.wordpress.org/'         => array( 'domain' => 'make.wordpress.org', 'path' => '/',         'site_id' => self::$network_ids['make.wordpress.org/'] ),
    46             'make.wordpress.org/foo/'     => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/',     'site_id' => self::$network_ids['make.wordpress.org/'] ),
    47             'www.w.org/'                  => array( 'domain' => 'www.w.org',          'path' => '/' ),
    48             'www.w.org/foo/'              => array( 'domain' => 'www.w.org',          'path' => '/foo/' ),
    49             'www.w.org/foo/bar/'          => array( 'domain' => 'www.w.org',          'path' => '/foo/bar/' ),
    50             'www.w.org/make/'             => array( 'domain' => 'www.w.org',          'path' => '/make/', 'meta' => array( 'public' => 1, 'lang_id' => 1 ) ),
    51         );
    52 
    53         foreach ( self::$site_ids as &$id ) {
    54             $id = $factory->blog->create( $id );
    55         }
    56         unset( $id );
    57     }
    58 
    59     public static function wpTearDownAfterClass() {
    60         global $wpdb;
    61 
    62         foreach( self::$site_ids as $id ) {
    63             wpmu_delete_blog( $id, true );
    64         }
    65 
    66         foreach( self::$network_ids as $id ) {
    67             $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
    68             $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
    69         }
    70 
    71         wp_update_network_site_counts();
    72     }
    73 
    74     public function test_wp_site_query_by_ID() {
    75         $q = new WP_Site_Query();
    76         $found = $q->query( array(
    77             'fields' => 'ids',
    78             'ID'     => self::$site_ids['www.w.org/'],
    79         ) );
    80 
    81         $this->assertEqualSets( array( self::$site_ids['www.w.org/'] ), $found );
    82     }
    83 
    84     public function test_wp_site_query_by_number() {
    85         $q = new WP_Site_Query();
    86         $found = $q->query( array(
    87             'fields'   => 'ids',
    88             'number' => 3,
    89         ) );
    90 
    91         $this->assertEquals( 3, count( $found ) );
    92     }
    93 
    94     public function test_wp_site_query_by_site__in_with_single_id() {
    95         $expected = array( self::$site_ids['wordpress.org/foo/'] );
    96 
    97         $q = new WP_Site_Query();
    98         $found = $q->query( array(
    99             'fields'   => 'ids',
    100             'site__in' => $expected,
    101         ) );
    102 
    103         $this->assertEqualSets( $expected, $found );
    104     }
    105 
    106     public function test_wp_site_query_by_site__in_with_multiple_ids() {
    107         $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
    108 
    109         $q = new WP_Site_Query();
    110         $found = $q->query( array(
    111             'fields'   => 'ids',
    112             'site__in' => $expected,
    113         ) );
    114 
    115         $this->assertEqualSets( $expected, $found );
    116     }
    117 
    118     /**
    119      * Test the `count` query var
    120      */
    121     public function test_wp_site_query_by_site__in_and_count_with_multiple_ids() {
    122         $expected = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
    123 
    124         $q = new WP_Site_Query();
    125         $found = $q->query( array(
    126             'fields'   => 'ids',
    127             'count' => true,
    128             'site__in' => $expected,
    129         ) );
    130 
    131         $this->assertEquals( 2, $found );
    132     }
    133 
    134     public function test_wp_site_query_by_site__not_in_with_single_id() {
    135         $excluded = array( self::$site_ids['wordpress.org/foo/'] );
    136         $expected = array_diff( self::$site_ids, $excluded );
    137 
    138         // Exclude main site since we don't have control over it here.
    139         $excluded[] = 1;
    140 
    141         $q = new WP_Site_Query();
    142         $found = $q->query( array(
    143             'fields'       => 'ids',
    144             'site__not_in' => $excluded,
    145         ) );
    146 
    147         $this->assertEqualSets( $expected, $found );
    148     }
    149 
    150     public function test_wp_site_query_by_site__not_in_with_multiple_ids() {
    151         $excluded = array( self::$site_ids['wordpress.org/'], self::$site_ids['wordpress.org/foo/'] );
    152         $expected = array_diff( self::$site_ids, $excluded );
    153 
    154         // Exclude main site since we don't have control over it here.
    155         $excluded[] = 1;
    156 
    157         $q = new WP_Site_Query();
    158         $found = $q->query( array(
    159             'fields'       => 'ids',
    160             'site__not_in' => $excluded,
    161         ) );
    162 
    163         $this->assertEqualSets( $expected, $found );
    164     }
    165 
    166     public function test_wp_site_query_by_network_id_with_order() {
    167         $q = new WP_Site_Query();
    168         $found = $q->query( array(
    169             'fields'     => 'ids',
    170             'network_id' => self::$network_ids['wordpress.org/'],
    171             'number'     => 3,
    172             'order'      => 'ASC',
    173         ) );
    174 
    175         $expected = array(
    176             self::$site_ids['wordpress.org/'],
    177             self::$site_ids['wordpress.org/foo/'],
    178             self::$site_ids['wordpress.org/foo/bar/'],
    179         );
    180 
    181         $this->assertEquals( $expected, $found );
    182 
    183         $found = $q->query( array(
    184             'fields'     => 'ids',
    185             'network_id' => self::$network_ids['wordpress.org/'],
    186             'number'     => 3,
    187             'order'      => 'DESC',
    188         ) );
    189 
    190         $this->assertEquals( array_reverse( $expected ), $found );
    191     }
    192 
    193     public function test_wp_site_query_by_network_id_with_existing_sites() {
    194         $q = new WP_Site_Query();
    195         $found = $q->query( array(
    196             'fields'       => 'ids',
    197             'network_id'   => self::$network_ids['make.wordpress.org/'],
    198         ) );
    199 
    200         $expected = array(
    201             self::$site_ids['make.wordpress.org/'],
    202             self::$site_ids['make.wordpress.org/foo/'],
    203         );
    204 
    205         $this->assertEqualSets( $expected, $found );
    206     }
    207 
    208     public function test_wp_site_query_by_network_id_with_no_existing_sites() {
    209         $q = new WP_Site_Query();
    210         $found = $q->query( array(
    211             'fields'       => 'ids',
    212             'network_id'   => self::$network_ids['www.wordpress.net/'],
    213         ) );
    214 
    215         $this->assertEmpty( $found );
    216     }
    217 
    218     public function test_wp_site_query_by_domain() {
    219         $q = new WP_Site_Query();
    220         $found = $q->query( array(
    221             'fields'       => 'ids',
    222             'domain'       => 'www.w.org',
    223         ) );
    224 
    225         $expected = array(
    226             self::$site_ids['www.w.org/'],
    227             self::$site_ids['www.w.org/foo/'],
    228             self::$site_ids['www.w.org/foo/bar/'],
    229             self::$site_ids['www.w.org/make/'],
    230         );
    231 
    232         $this->assertEqualSets( $expected, $found );
    233     }
    234 
    235     public function test_wp_site_query_by_domain_and_offset() {
    236         $q = new WP_Site_Query();
    237         $found = $q->query( array(
    238             'fields'       => 'ids',
    239             'domain'       => 'www.w.org',
    240             'offset'       => 1,
    241         ) );
    242 
    243         $expected = array(
    244             self::$site_ids['www.w.org/foo/'],
    245             self::$site_ids['www.w.org/foo/bar/'],
    246             self::$site_ids['www.w.org/make/'],
    247         );
    248 
    249         $this->assertEqualSets( $expected, $found );
    250     }
    251 
    252     public function test_wp_site_query_by_domain_and_number_and_offset() {
    253         $q = new WP_Site_Query();
    254         $found = $q->query( array(
    255             'fields'       => 'ids',
    256             'domain'       => 'www.w.org',
    257             'number'       => 2,
    258             'offset'       => 1,
    259         ) );
    260 
    261         $expected = array(
    262             self::$site_ids['www.w.org/foo/'],
    263             self::$site_ids['www.w.org/foo/bar/'],
    264         );
    265 
    266         $this->assertEqualSets( $expected, $found );
    267     }
    268 
    269     public function test_wp_site_query_by_domain__in_with_single_domain() {
    270         $q = new WP_Site_Query();
    271         $found = $q->query( array(
    272             'fields' => 'ids',
    273             'domain__in' => array( 'make.wordpress.org' ),
    274         ));
    275 
    276         $expected = array(
    277             self::$site_ids['make.wordpress.org/'],
    278             self::$site_ids['make.wordpress.org/foo/'],
    279         );
    280 
    281         $this->assertEqualSets( $expected, $found );
    282     }
    283 
    284     public function test_wp_site_query_by_domain__in_with_multiple_domains() {
    285         $q = new WP_Site_Query();
    286         $found = $q->query( array(
    287             'fields' => 'ids',
    288             'domain__in' => array( 'wordpress.org', 'make.wordpress.org' ),
    289         ));
    290 
    291         $expected = array(
    292             self::$site_ids['wordpress.org/'],
    293             self::$site_ids['wordpress.org/foo/'],
    294             self::$site_ids['wordpress.org/foo/bar/'],
    295             self::$site_ids['make.wordpress.org/'],
    296             self::$site_ids['make.wordpress.org/foo/'],
    297         );
    298 
    299         $this->assertEqualSets( $expected, $found );
    300     }
    301 
    302     public function test_wp_site_query_by_domain__not_in_with_single_domain() {
    303         $q = new WP_Site_Query();
    304         $found = $q->query( array(
    305             'fields' => 'ids',
    306             'domain__not_in' => array( 'www.w.org' ),
    307         ));
    308 
    309         $expected = array(
    310             get_current_blog_id(), // Account for the initial site added by the test suite.
    311             self::$site_ids['wordpress.org/'],
    312             self::$site_ids['wordpress.org/foo/'],
    313             self::$site_ids['wordpress.org/foo/bar/'],
    314             self::$site_ids['make.wordpress.org/'],
    315             self::$site_ids['make.wordpress.org/foo/'],
    316         );
    317 
    318         $this->assertEqualSets( $expected, $found );
    319     }
    320 
    321     public function test_wp_site_query_by_domain__not_in_with_multiple_domains() {
    322         $q = new WP_Site_Query();
    323         $found = $q->query( array(
    324             'fields' => 'ids',
    325             'domain__not_in' => array( 'wordpress.org', 'www.w.org' ),
    326         ));
    327 
    328         $expected = array(
    329             get_current_blog_id(), // Account for the initial site added by the test suite.
    330             self::$site_ids['make.wordpress.org/'],
    331             self::$site_ids['make.wordpress.org/foo/'],
    332         );
    333 
    334         $this->assertEqualSets( $expected, $found );
    335     }
    336 
    337     public function test_wp_site_query_by_path_with_expected_results() {
    338         $q = new WP_Site_Query();
    339         $found = $q->query( array(
    340             'fields'       => 'ids',
    341             'path'         => '/foo/bar/',
    342         ) );
    343 
    344         $expected = array(
    345             self::$site_ids['wordpress.org/foo/bar/'],
    346             self::$site_ids['www.w.org/foo/bar/'],
    347         );
    348 
    349         $this->assertEqualSets( $expected, $found );
    350     }
    351 
    352     public function test_wp_site_query_by_path_with_no_expected_results() {
    353         $q = new WP_Site_Query();
    354         $found = $q->query( array(
    355             'fields'       => 'ids',
    356             'path'         => '/foo/bar/foo/',
    357         ) );
    358 
    359         $this->assertEmpty( $found );
    360     }
    361 
    362     // archived, mature, spam, deleted, public
    363 
    364     public function test_wp_site_query_by_archived() {
    365         $q = new WP_Site_Query();
    366         $found = $q->query( array(
    367             'fields'       => 'ids',
    368             // Exclude main site since we don't have control over it here.
    369             'site__not_in' => array( 1 ),
    370             'archived'     => '0',
    371         ) );
    372 
    373         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    374     }
    375 
    376     public function test_wp_site_query_by_mature() {
    377         $q = new WP_Site_Query();
    378         $found = $q->query( array(
    379             'fields'       => 'ids',
    380             // Exclude main site since we don't have control over it here.
    381             'site__not_in' => array( 1 ),
    382             'mature'     => '0',
    383         ) );
    384 
    385         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    386     }
    387 
    388     public function test_wp_site_query_by_spam() {
    389         $q = new WP_Site_Query();
    390         $found = $q->query( array(
    391             'fields'       => 'ids',
    392             // Exclude main site since we don't have control over it here.
    393             'site__not_in' => array( 1 ),
    394             'spam'     => '0',
    395         ) );
    396 
    397         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    398     }
    399 
    400     public function test_wp_site_query_by_deleted() {
    401         $q = new WP_Site_Query();
    402         $found = $q->query( array(
    403             'fields'       => 'ids',
    404             // Exclude main site since we don't have control over it here.
    405             'site__not_in' => array( 1 ),
    406             'deleted'     => '0',
    407         ) );
    408 
    409         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    410     }
    411 
    412     public function test_wp_site_query_by_deleted_with_no_results() {
    413         $q = new WP_Site_Query();
    414         $found = $q->query( array(
    415             'fields'       => 'ids',
    416             'deleted'      => '1',
    417         ) );
    418 
    419         $this->assertEmpty( $found );
    420     }
    421 
    422     public function test_wp_site_query_by_public() {
    423         $q = new WP_Site_Query();
    424         $found = $q->query( array(
    425             'fields'       => 'ids',
    426             // Exclude main site since we don't have control over it here.
    427             'site__not_in' => array( 1 ),
    428             'public'     => '1',
    429         ) );
    430 
    431         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    432     }
    433 
    434     public function test_wp_site_query_by_lang_id_with_zero() {
    435         $q = new WP_Site_Query();
    436         $found = $q->query( array(
    437             'fields'       => 'ids',
    438             // Exclude main site since we don't have control over it here.
    439             'site__not_in' => array( 1 ),
    440             'lang_id'      => 0,
    441         ) );
    442 
    443         $this->assertEqualSets( array_diff( array_values( self::$site_ids ), array( self::$site_ids['www.w.org/make/'] ) ), $found );
    444     }
    445 
    446     public function test_wp_site_query_by_lang_id() {
    447         $q = new WP_Site_Query();
    448         $found = $q->query( array(
    449             'fields'       => 'ids',
    450             'lang_id'      => 1,
    451         ) );
    452 
    453         $expected = array(
    454             self::$site_ids['www.w.org/make/'],
    455         );
    456 
    457         $this->assertEqualSets( $expected, $found );
    458     }
    459 
    460     public function test_wp_site_query_by_lang_id_with_no_results() {
    461         $q = new WP_Site_Query();
    462         $found = $q->query( array(
    463             'fields'       => 'ids',
    464             'lang_id'      => 2,
    465         ) );
    466 
    467         $this->assertEmpty( $found );
    468     }
    469 
    470     public function test_wp_site_query_by_lang__in() {
    471         $q = new WP_Site_Query();
    472         $found = $q->query( array(
    473             'fields' => 'ids',
    474             'lang__in' => array( 1 ),
    475         ) );
    476 
    477         $expected = array(
    478             self::$site_ids['www.w.org/make/'],
    479         );
    480 
    481         $this->assertEqualSets( $expected, $found );
    482     }
    483 
    484     public function test_wp_site_query_by_lang__in_with_multiple_ids() {
    485         $q = new WP_Site_Query();
    486         $found = $q->query( array(
    487             'fields' => 'ids',
    488             // Exclude main site since we don't have control over it here.
    489             'site__not_in' => array( 1 ),
    490             'lang__in' => array( 0, 1 ),
    491         ) );
    492 
    493         $this->assertEqualSets( array_values( self::$site_ids ), $found );
    494     }
    495 
    496     public function test_wp_site_query_by_lang__not_in() {
    497         $q = new WP_Site_Query();
    498         $found = $q->query( array(
    499             'fields' => 'ids',
    500             'lang__not_in' => array( 0 ),
    501         ) );
    502 
    503         $expected = array(
    504             self::$site_ids['www.w.org/make/'],
    505         );
    506 
    507         $this->assertEqualSets( $expected, $found );
    508     }
    509 
    510     public function test_wp_site_query_by_lang__not_in_with_multiple_ids() {
    511         $q = new WP_Site_Query();
    512         $found = $q->query( array(
    513             'fields' => 'ids',
    514             'lang__not_in' => array( 0, 1 ),
    515         ) );
    516 
    517         $this->assertEmpty( $found );
    518     }
    519 
    520     public function test_wp_site_query_by_search_with_text_in_domain() {
    521         $q = new WP_Site_Query();
    522         $found = $q->query( array(
    523             'fields'       => 'ids',
    524             'search'       => 'ke.wordp',
    525         ) );
    526 
    527         $expected = array(
    528             self::$site_ids['make.wordpress.org/'],
    529             self::$site_ids['make.wordpress.org/foo/'],
    530         );
    531 
    532         $this->assertEqualSets( $expected, $found );
    533     }
    534 
    535     public function test_wp_site_query_by_search_with_text_in_path() {
    536         $q = new WP_Site_Query();
    537         $found = $q->query( array(
    538             'fields'       => 'ids',
    539             'search'       => 'foo',
    540         ) );
    541 
    542         $expected = array(
    543             self::$site_ids['wordpress.org/foo/'],
    544             self::$site_ids['wordpress.org/foo/bar/'],
    545             self::$site_ids['make.wordpress.org/foo/'],
    546             self::$site_ids['www.w.org/foo/'],
    547             self::$site_ids['www.w.org/foo/bar/'],
    548         );
    549 
    550         $this->assertEqualSets( $expected, $found );
    551     }
    552 
    553     public function test_wp_site_query_by_search_with_text_in_path_and_domain() {
    554         $q = new WP_Site_Query();
    555         $found = $q->query( array(
    556             'fields'       => 'ids',
    557             'search'       => 'make',
    558         ) );
    559 
    560         $expected = array(
    561             self::$site_ids['make.wordpress.org/'],
    562             self::$site_ids['make.wordpress.org/foo/'],
    563             self::$site_ids['www.w.org/make/'],
    564         );
    565 
    566         $this->assertEqualSets( $expected, $found );
    567     }
    568 
    569     public function test_wp_site_query_by_search_with_text_in_path_and_domain_order_by_domain_desc() {
    570         $q = new WP_Site_Query();
    571         $found = $q->query( array(
    572             'fields'       => 'ids',
    573             'search'       => 'make',
    574             'order'        => 'DESC',
    575             'orderby'      => 'domain',
    576         ) );
    577 
    578         $expected = array(
    579             self::$site_ids['www.w.org/make/'],
    580             self::$site_ids['make.wordpress.org/'],
    581             self::$site_ids['make.wordpress.org/foo/'],
    582         );
    583 
    584         $this->assertEquals( $expected, $found );
    585     }
    586 
    587     public function test_wp_site_query_by_search_with_text_in_path_exclude_domain_from_search() {
    588         $q = new WP_Site_Query();
    589         $found = $q->query( array(
    590             'fields' => 'ids',
    591             'search' => 'make',
    592             'search_columns' => array( 'path' ),
    593         ) );
    594 
    595         $expected = array(
    596             self::$site_ids['www.w.org/make/'],
    597         );
    598 
    599         $this->assertEquals( $expected, $found );
    600     }
    601 
    602     public function test_wp_site_query_by_search_with_text_in_domain_exclude_path_from_search() {
    603         $q = new WP_Site_Query();
    604         $found = $q->query( array(
    605             'fields' => 'ids',
    606             'search' => 'make',
    607             'search_columns' => array( 'domain' ),
    608         ) );
    609 
    610         $expected = array(
    611             self::$site_ids['make.wordpress.org/'],
    612             self::$site_ids['make.wordpress.org/foo/'],
    613         );
    614 
    615         $this->assertEquals( $expected, $found );
    616     }
    617 
    618     public function test_wp_site_query_by_search_with_wildcard_in_text() {
    619         $q = new WP_Site_Query();
    620         $found = $q->query( array(
    621             'fields'       => 'ids',
    622             'search'       => 'm*ke',
    623         ) );
    624 
    625         $expected = array(
    626             self::$site_ids['www.w.org/make/'],
    627             self::$site_ids['make.wordpress.org/'],
    628             self::$site_ids['make.wordpress.org/foo/'],
    629         );
    630 
    631         $this->assertEqualSets( $expected, $found );
    632     }
    633 
    634     public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
    635         $q = new WP_Site_Query();
    636         $found = $q->query( array(
    637             'fields' => 'ids',
    638             'search' => 'm*ke',
    639             'search_columns' => array( 'domain' ),
    640         ) );
    641 
    642         $expected = array(
    643             self::$site_ids['make.wordpress.org/'],
    644             self::$site_ids['make.wordpress.org/foo/'],
    645         );
    646 
    647         $this->assertEqualSets( $expected, $found );
    648     }
    649 
    650     public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
    651         $q = new WP_Site_Query();
    652         $found = $q->query( array(
    653             'fields' => 'ids',
    654             'search' => 'm*ke',
    655             'search_columns' => array( 'path' ),
    656         ) );
    657 
    658         $expected = array(
    659             self::$site_ids['www.w.org/make/'],
    660         );
    661 
    662         $this->assertEqualSets( $expected, $found );
    663     }
    664 
    665     /**
    666      * @ticket 41197
    667      */
    668     public function test_wp_site_query_cache_with_different_fields_no_count() {
    669         global $wpdb;
    670         $q                 = new WP_Site_Query();
    671         $query_1           = $q->query( array(
    672             'fields'     => 'all',
    673             'network_id' => self::$network_ids['wordpress.org/'],
    674             'number'     => 3,
    675             'order'      => 'ASC',
    676         ) );
    677         $number_of_queries = $wpdb->num_queries;
    678 
    679         $query_2 = $q->query( array(
    680             'fields'     => 'ids',
    681             'network_id' => self::$network_ids['wordpress.org/'],
    682             'number'     => 3,
    683             'order'      => 'ASC',
    684         ) );
    685 
    686         $this->assertEquals( $number_of_queries, $wpdb->num_queries );
    687     }
    688 
    689     /**
    690      * @ticket 41197
    691      */
    692     public function test_wp_site_query_cache_with_different_fields_active_count() {
    693         global $wpdb;
    694         $q                 = new WP_Site_Query();
    695 
    696         $query_1 = $q->query( array(
    697             'fields'     => 'all',
    698             'network_id' => self::$network_ids['wordpress.org/'],
    699             'number'     => 3,
    700             'order'      => 'ASC',
    701             'count'      => true,
    702         ) );
    703         $number_of_queries = $wpdb->num_queries;
    704 
    705         $query_2 = $q->query( array(
    706             'fields'     => 'ids',
    707             'network_id' => self::$network_ids['wordpress.org/'],
    708             'number'     => 3,
    709             'order'      => 'ASC',
    710             'count'      => true,
    711         ) );
    712         $this->assertEquals( $number_of_queries, $wpdb->num_queries );
    713     }
    714 
    715     /**
    716      * @ticket 41197
    717      */
    718     public function test_wp_site_query_cache_with_same_fields_different_count() {
    719         global $wpdb;
    720         $q = new WP_Site_Query();
    721 
    722         $query_1 = $q->query( array(
    723             'fields'     => 'ids',
    724             'network_id' => self::$network_ids['wordpress.org/'],
    725             'number'     => 3,
    726             'order'      => 'ASC',
    727         ) );
    728 
    729         $number_of_queries = $wpdb->num_queries;
    730 
    731         $query_2 = $q->query( array(
    732             'fields'     => 'ids',
    733             'network_id' => self::$network_ids['wordpress.org/'],
    734             'number'     => 3,
    735             'order'      => 'ASC',
    736             'count'      => true,
    737         ) );
    738         $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
    739     }
    740 }
    741 
    742883endif;
Note: See TracChangeset for help on using the changeset viewer.