Make WordPress Core


Ignore:
Timestamp:
03/27/2017 07:47:53 PM (10 years ago)
Author:
jeremyfelt
Message:

Multisite: Add lang_id support to WP_Site_Query.

Sites can now be queried by lang_id, lang__in, and lang__not_in.

Props ocean90.
Fixes #40196.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/siteQuery.php

    r38085 r40340  
    4848                        'www.w.org/foo/'              => array( 'domain' => 'www.w.org',          'path' => '/foo/' ),
    4949                        '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/' ),
     50                        'www.w.org/make/'             => array( 'domain' => 'www.w.org',          'path' => '/make/', 'meta' => array( 'public' => 1, 'lang_id' => 1 ) ),
    5151                );
    5252
    … …  
    432432        }
    433433
     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
    434520        public function test_wp_site_query_by_search_with_text_in_domain() {
    435521                $q = new WP_Site_Query();
Note: See TracChangeset for help on using the changeset viewer.