Changeset 60148 for trunk/tests/phpunit/tests/multisite/wpGetSites.php
- Timestamp:
- 04/09/2025 01:29:39 PM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/wpGetSites.php
r51860 r60148 1 1 <?php 2 2 3 if ( is_multisite() ) : 3 /** 4 * @group ms-required 5 * @group ms-site 6 * @group multisite 7 */ 8 class Tests_Multisite_wpGetSites extends WP_UnitTestCase { 9 protected static $site_ids; 10 11 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 12 self::$site_ids = array( 13 'w.org/' => array( 14 'domain' => 'w.org', 15 'path' => '/', 16 'network_id' => 2, 17 ), 18 'wp.org/' => array( 19 'domain' => 'wp.org', 20 'path' => '/', 21 'network_id' => 2, 22 'public' => 0, 23 ), 24 'wp.org/foo/' => array( 25 'domain' => 'wp.org', 26 'path' => '/foo/', 27 'network_id' => 1, 28 'public' => 0, 29 ), 30 'wp.org/oof/' => array( 31 'domain' => 'wp.org', 32 'path' => '/oof/', 33 ), 34 ); 35 36 foreach ( self::$site_ids as &$id ) { 37 $id = $factory->blog->create( $id ); 38 } 39 unset( $id ); 40 } 41 42 public static function wpTearDownAfterClass() { 43 foreach ( self::$site_ids as $id ) { 44 wp_delete_site( $id ); 45 } 46 47 wp_update_network_site_counts(); 48 } 4 49 5 50 /** 6 * @group wp-get-site 7 * @group ms-site 8 * @group multisite 51 * @expectedDeprecated wp_get_sites 9 52 */ 10 class Tests_Multisite_wpGetSites extends WP_UnitTestCase { 11 protected static $site_ids; 53 public function test_wp_get_sites_site_is_expected_array() { 12 54 13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 14 self::$site_ids = array( 15 'w.org/' => array( 16 'domain' => 'w.org', 17 'path' => '/', 55 $keys = array( 56 'blog_id', 57 'site_id', 58 'domain', 59 'path', 60 'registered', 61 'last_updated', 62 'public', 63 'archived', 64 'mature', 65 'spam', 66 'deleted', 67 'lang_id', 68 ); 69 $sites = wp_get_sites(); 70 71 $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] ); 72 73 $this->assertSame( array(), $missing_keys, 'Keys are missing from site arrays.' ); 74 } 75 76 /** 77 * @expectedDeprecated wp_get_sites 78 * @dataProvider data_wp_get_sites 79 * 80 * @param $expected 81 * @param $args 82 * @param $error 83 */ 84 public function test_wp_get_sites( $expected, $args, $error ) { 85 $this->assertCount( $expected, wp_get_sites( $args ), $error ); 86 } 87 88 /** 89 * @return array 90 */ 91 public function data_wp_get_sites() { 92 return array( 93 array( 3, array(), 'Default arguments should return all sites from the current network.' ), 94 array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ), 95 array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ), 96 array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ), 97 array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ), 98 array( 99 3, 100 array( 101 'public' => 1, 102 'network_id' => null, 103 ), 104 'Public sites on all networks.', 105 ), 106 array( 107 2, 108 array( 109 'public' => 0, 110 'network_id' => null, 111 ), 112 'Non public sites on all networks.', 113 ), 114 array( 115 2, 116 array( 117 'public' => 1, 118 'network_id' => 1, 119 ), 120 'Public sites on a single network.', 121 ), 122 array( 123 1, 124 array( 125 'public' => 1, 18 126 'network_id' => 2, 19 127 ), 20 'wp.org/' => array( 21 'domain' => 'wp.org', 22 'path' => '/', 23 'network_id' => 2, 24 'public' => 0, 128 'Public sites on a second network.', 129 ), 130 array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ), 131 array( 132 1, 133 array( 134 'limit' => 2, 135 'offset' => 2, 25 136 ), 26 'wp.org/foo/' => array( 27 'domain' => 'wp.org', 28 'path' => '/foo/', 29 'network_id' => 1, 30 'public' => 0, 31 ), 32 'wp.org/oof/' => array( 33 'domain' => 'wp.org', 34 'path' => '/oof/', 35 ), 36 ); 37 38 foreach ( self::$site_ids as &$id ) { 39 $id = $factory->blog->create( $id ); 40 } 41 unset( $id ); 42 } 43 44 public static function wpTearDownAfterClass() { 45 foreach ( self::$site_ids as $id ) { 46 wp_delete_site( $id ); 47 } 48 49 wp_update_network_site_counts(); 50 } 51 52 /** 53 * @expectedDeprecated wp_get_sites 54 */ 55 public function test_wp_get_sites_site_is_expected_array() { 56 57 $keys = array( 58 'blog_id', 59 'site_id', 60 'domain', 61 'path', 62 'registered', 63 'last_updated', 64 'public', 65 'archived', 66 'mature', 67 'spam', 68 'deleted', 69 'lang_id', 70 ); 71 $sites = wp_get_sites(); 72 73 $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] ); 74 75 $this->assertSame( array(), $missing_keys, 'Keys are missing from site arrays.' ); 76 } 77 78 /** 79 * @expectedDeprecated wp_get_sites 80 * @dataProvider data_wp_get_sites 81 * 82 * @param $expected 83 * @param $args 84 * @param $error 85 */ 86 public function test_wp_get_sites( $expected, $args, $error ) { 87 $this->assertCount( $expected, wp_get_sites( $args ), $error ); 88 } 89 90 /** 91 * @return array 92 */ 93 public function data_wp_get_sites() { 94 return array( 95 array( 3, array(), 'Default arguments should return all sites from the current network.' ), 96 array( 0, array( 'network_id' => 999 ), 'No sites should match a query with an invalid network ID.' ), 97 array( 5, array( 'network_id' => null ), 'A network ID of null should return all sites on all networks.' ), 98 array( 2, array( 'network_id' => 2 ), 'Only sites on a specified network ID should be returned.' ), 99 array( 5, array( 'network_id' => array( 1, 2 ) ), 'If multiple network IDs are specified, sites from both should be returned.' ), 100 array( 101 3, 102 array( 103 'public' => 1, 104 'network_id' => null, 105 ), 106 'Public sites on all networks.', 107 ), 108 array( 109 2, 110 array( 111 'public' => 0, 112 'network_id' => null, 113 ), 114 'Non public sites on all networks.', 115 ), 116 array( 117 2, 118 array( 119 'public' => 1, 120 'network_id' => 1, 121 ), 122 'Public sites on a single network.', 123 ), 124 array( 125 1, 126 array( 127 'public' => 1, 128 'network_id' => 2, 129 ), 130 'Public sites on a second network.', 131 ), 132 array( 2, array( 'limit' => 2 ), 'Provide only a limit argument.' ), 133 array( 134 1, 135 array( 136 'limit' => 2, 137 'offset' => 2, 138 ), 139 'Provide both limit and offset arguments.', 140 ), 141 array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ), 142 array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ), 143 ); 144 } 137 'Provide both limit and offset arguments.', 138 ), 139 array( 2, array( 'offset' => 1 ), 'Provide only an offset argument.' ), 140 array( 0, array( 'offset' => 20 ), 'Expect 0 sites when using an offset larger than the total number of sites.' ), 141 ); 145 142 } 146 147 endif; 143 }
Note: See TracChangeset
for help on using the changeset viewer.