Make WordPress Core


Ignore:
Timestamp:
09/14/2013 09:12:26 PM (12 years ago)
Author:
nacin
Message:

Introduce wp_get_sites(), a long-awaited replacement for get_blog_list().

props jeremyfelt.
see #14511.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ms.php

    r25409 r25445  
    10301030    }
    10311031
     1032    /**
     1033     * @ticket 14511
     1034     */
     1035    function test_wp_get_sites() {
     1036        global $wpdb;
     1037        $this->factory->blog->create_many( 2, array( 'site_id' => 2, 'meta' => array( 'public' => 1 ) ) );
     1038        $this->factory->blog->create_many( 3, array( 'site_id' => 3, 'meta' => array( 'public' => 0 ) ) );
     1039
     1040        // Expect no sites when passed an invalid network_id
     1041        $this->assertCount( 0, wp_get_sites( array( 'network_id' => 0 ) ) );
     1042        $this->assertCount( 0, wp_get_sites( array( 'network_id' => 4 ) ) );
     1043
     1044        // Expect 1 site when no network_id is specified - defaults to current network.
     1045        $this->assertCount( 1, wp_get_sites() );
     1046        // Expect 6 sites when network_id = null.
     1047        $this->assertCount( 6, wp_get_sites( array( 'network_id' => null ) ) );
     1048
     1049        // Expect 1 site with a network_id of 1, 2 for network_id 2, 3 for 3
     1050        $this->assertCount( 1, wp_get_sites( array( 'network_id' => 1 ) ) );
     1051        $this->assertCount( 2, wp_get_sites( array( 'network_id' => 2 ) ) );
     1052        $this->assertCount( 3, wp_get_sites( array( 'network_id' => 3 ) ) );
     1053
     1054        // Expect 6 sites when public is null (across all networks)
     1055        $this->assertCount( 6, wp_get_sites( array( 'public' => null, 'network_id' => null ) ) );
     1056
     1057        // Expect 3 sites when public is 1
     1058        $this->assertCount( 3, wp_get_sites( array( 'public' => 1, 'network_id' => null ) ) );
     1059
     1060        // Expect 2 sites when public is 1 and network_id is 2
     1061        $this->assertCount( 2, wp_get_sites( array( 'network_id' => 2, 'public' => 1 ) ) );
     1062
     1063        // Expect no sites when public is set to 0 and network_id is not 3
     1064        $this->assertCount( 0, wp_get_sites( array( 'network_id' => 1, 'public' => 0 ) ) );
     1065
     1066        // Test public + network_id = 3
     1067        $this->assertCount( 0, wp_get_sites( array( 'network_id' => 3, 'public' => 1 ) ) );
     1068        $this->assertCount( 3, wp_get_sites( array( 'network_id' => 3, 'public' => 0 ) ) );
     1069    }
     1070
    10321071}
    10331072
Note: See TracChangeset for help on using the changeset viewer.