Changeset 37662 for trunk/tests/phpunit/tests/multisite/wpGetSites.php
- Timestamp:
- 06/09/2016 12:27:46 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/wpGetSites.php
r37660 r37662 8 8 */ 9 9 class Tests_Multisite_WP_Get_Sites extends WP_UnitTestCase { 10 protected static $site_ids; 10 11 11 /** 12 * Test the default arguments for wp_get_sites, which should return only 13 * public sites from the current network. 14 * 15 * @ticket 14511 16 * @expectedDeprecated wp_get_sites 17 */ 18 function test_wp_get_sites_with_default_arguments() { 19 self::factory()->blog->create( array( 'site_id' => 2 ) ); 12 public static function wpSetUpBeforeClass( $factory ) { 13 self::$site_ids = array( 14 'w.org/' => array( 'domain' => 'w.org', 'path' => '/', 'site_id' => 2 ), 15 'wp.org/' => array( 'domain' => 'wp.org', 'path' => '/', 'site_id' => 2, 'meta' => array( 'public' => 0 ) ), 16 'wp.org/foo/' => array( 'domain' => 'wp.org', 'path' => '/foo/', 'site_id' => 1, 'meta' => array( 'public' => 0 ) ), 17 'wp.org/oof/' => array( 'domain' => 'wp.org', 'path' => '/oof/' ), 18 ); 20 19 21 $this->assertCount( 1, wp_get_sites() ); 20 foreach ( self::$site_ids as &$id ) { 21 $id = $factory->blog->create( $id ); 22 } 23 unset( $id ); 24 } 25 26 public static function wpTearDownAfterClass() { 27 foreach( self::$site_ids as $id ) { 28 wpmu_delete_blog( $id, true ); 29 } 30 31 wp_update_network_site_counts(); 22 32 } 23 33 24 34 /** 25 * No sites should match a query that specifies an invalid network ID. 35 * @expectedDeprecated wp_get_sites 36 * @dataProvider data_wp_get_sites 26 37 * 27 * @expectedDeprecated wp_get_sites 38 * @param $expected 39 * @param $args 40 * @param $error 28 41 */ 29 function test_wp_get_sites_with_invalid_network_id() {30 $this->assert count( 0, wp_get_sites( array( 'network_id' => 999 ) ));42 public function test_wp_get_sites( $expected, $args, $error ) { 43 $this->assertCount( $expected, wp_get_sites( $args ), $error ); 31 44 } 32 45 33 46 /** 34 * A network ID of null should query for all public sites on all networks. 35 * 36 * @expectedDeprecated wp_get_sites 47 * @return array 37 48 */ 38 function test_wp_get_sites_with_network_id_null() { 39 self::factory()->blog->create( array( 'site_id' => 2 ) ); 40 41 $this->assertCount( 2, wp_get_sites( array( 'network_id' => null ) ) ); 42 } 43 44 /** 45 * Expect only sites on the specified network ID to be returned. 46 * 47 * @expectedDeprecated wp_get_sites 48 */ 49 function test_wp_get_sites_with_specific_network_id() { 50 self::factory()->blog->create( array( 'site_id' => 2 ) ); 51 52 $this->assertCount( 1, wp_get_sites( array( 'network_id' => 2 ) ) ); 53 } 54 55 /** 56 * Expect sites from both networks if both network IDs are specified. 57 * 58 * @expectedDeprecated wp_get_sites 59 */ 60 function test_wp_get_sites_with_multiple_network_ids() { 61 self::factory()->blog->create( array( 'site_id' => 2 ) ); 62 63 $this->assertCount( 2, wp_get_sites( array( 'network_id' => array( 1, 2 ) ) ) ); 64 } 65 66 /** 67 * Queries for public or non public sites should work across all networks if network ID is null. 68 * 69 * @expectedDeprecated wp_get_sites 70 */ 71 function test_wp_get_sites_with_public_meta_on_all_networks() { 72 self::factory()->blog->create( array( 'site_id' => 2, 'meta' => array( 'public' => 0 ) ) ); 73 74 $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => null ) ) ); 75 $this->assertcount( 1, wp_get_sites( array( 'public' => 0, 'network_id' => null ) ) ); 76 } 77 78 /** 79 * If a network ID is specified, queries for public sites should be restricted to that network. 80 * 81 * @expectedDeprecated wp_get_sites 82 */ 83 function test_wp_get_sites_with_public_meta_restrict_to_one_network() { 84 self::factory()->blog->create( array( 'site_id' => 1, 'meta' => array( 'public' => 0 ) ) ); 85 86 $this->assertCount( 1, wp_get_sites( array( 'public' => 1, 'network_id' => 1 ) ) ); 87 $this->assertCount( 0, wp_get_sites( array( 'public' => 1, 'network_id' => 2 ) ) ); 88 } 89 90 /** 91 * Test the limit and offset arguments for wp_get_sites when multiple sites are available. 92 * 93 * @expectedDeprecated wp_get_sites 94 */ 95 function test_wp_get_sites_limit_offset() { 96 // Create 2 more sites (in addition to the default one) 97 self::factory()->blog->create_many( 2 ); 98 99 // Expect first 2 sites when using limit 100 $this->assertCount( 2, wp_get_sites( array( 'limit' => 2 ) ) ); 101 102 // Expect only the last 2 sites when using offset of 1 (limit will default to 100) 103 $this->assertCount( 2, wp_get_sites( array( 'offset' => 1 ) ) ); 104 105 // Expect only the last 1 site when using offset of 2 and limit of 2 106 $this->assertCount( 1, wp_get_sites( array( 'limit' => 2, 'offset' => 2 ) ) ); 107 } 108 109 /** 110 * Expect 0 sites when using an offset larger than the total number of sites. 111 * 112 * @expectedDeprecated wp_get_sites 113 */ 114 function test_wp_get_sites_offset_greater_than_available_sites() { 115 $this->assertCount( 0, wp_get_sites( array( 'offset' => 20 ) ) ); 49 public function data_wp_get_sites() { 50 return array( 51 array( 3, array(), 'Default arguments should return all sites from the current network.' ), 52 array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ), 53 array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ), 54 array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ), 55 array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ), 56 array( 3, array( 'public' => 1, 'network_id' => null ), 'Public sites on all networks.' ), 57 array( 2, array( 'public' => 0, 'network_id' => null ), 'Non public sites on all networks.' ), 58 array( 2, array( 'public' => 1, 'network_id' => 1 ), 'Public sites on a single network.' ), 59 array( 1, array( 'public' => 1, 'network_id' => 2 ), 'Public sites on a second network.' ), 60 array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ), 61 array( 1, array( 'limit' => 2, 'offset' => 2 ), 'Provide both limit and offset arguments.' ), 62 array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ), 63 array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ), 64 ); 116 65 } 117 66 }
Note: See TracChangeset
for help on using the changeset viewer.