Changeset 60148 for trunk/tests/phpunit/tests/multisite/getBlogDetails.php
- Timestamp:
- 04/09/2025 01:29:39 PM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/getBlogDetails.php
r51860 r60148 1 1 <?php 2 2 3 if ( is_multisite() ) : 3 /** 4 * @ticket 29845 5 * @group ms-required 6 * @group ms-site 7 * @group multisite 8 */ 9 class Tests_Multisite_GetBlogDetails extends WP_UnitTestCase { 10 11 protected static $network_ids; 12 protected static $site_ids; 13 14 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 15 self::$site_ids = array( 16 WP_TESTS_DOMAIN . '/foo/' => array( 17 'domain' => WP_TESTS_DOMAIN, 18 'path' => '/foo/', 19 ), 20 'foo.' . WP_TESTS_DOMAIN . '/' => array( 21 'domain' => 'foo.' . WP_TESTS_DOMAIN, 22 'path' => '/', 23 ), 24 'wordpress.org/' => array( 25 'domain' => 'wordpress.org', 26 'path' => '/', 27 ), 28 ); 29 30 foreach ( self::$site_ids as &$id ) { 31 $id = $factory->blog->create( $id ); 32 } 33 unset( $id ); 34 } 35 36 public static function wpTearDownAfterClass() { 37 foreach ( self::$site_ids as $id ) { 38 wp_delete_site( $id ); 39 } 40 41 wp_update_network_site_counts(); 42 } 43 44 public function test_get_blog_details_with_no_arguments_returns_current_site() { 45 $site = get_blog_details(); 46 $this->assertEquals( get_current_blog_id(), $site->blog_id ); 47 } 48 49 public function test_get_blog_details_with_site_name_string_subdirectory() { 50 if ( is_subdomain_install() ) { 51 $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' ); 52 } 53 54 $site = get_blog_details( 'foo' ); 55 $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/' ], $site->blog_id ); 56 } 57 58 public function test_get_blog_details_with_site_name_string_subdomain() { 59 if ( ! is_subdomain_install() ) { 60 $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' ); 61 } 62 63 $site = get_blog_details( 'foo' ); 64 $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id ); 65 } 66 67 public function test_get_blog_details_with_invalid_site_name_string() { 68 $site = get_blog_details( 'invalid' ); 69 $this->assertFalse( $site ); 70 } 71 72 public function test_get_blog_details_with_site_id_int() { 73 $site = get_blog_details( self::$site_ids['wordpress.org/'] ); 74 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 75 } 76 77 public function test_get_blog_details_with_invalid_site_id_int() { 78 $site = get_blog_details( 99999 ); 79 $this->assertFalse( $site ); 80 } 81 82 public function test_get_blog_details_with_blog_id_in_fields() { 83 $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) ); 84 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 85 } 86 87 public function test_get_blog_details_with_invalid_blog_id_in_fields() { 88 $site = get_blog_details( array( 'blog_id' => 88888 ) ); 89 $this->assertFalse( $site ); 90 } 91 92 public function test_get_blog_details_with_domain_and_path_in_fields() { 93 $site = get_blog_details( 94 array( 95 'domain' => 'wordpress.org', 96 'path' => '/', 97 ) 98 ); 99 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 100 } 101 102 public function test_get_blog_details_with_domain_and_invalid_path_in_fields() { 103 $site = get_blog_details( 104 array( 105 'domain' => 'wordpress.org', 106 'path' => '/zxy/', 107 ) 108 ); 109 $this->assertFalse( $site ); 110 } 111 112 public function test_get_blog_details_with_path_and_invalid_domain_in_fields() { 113 $site = get_blog_details( 114 array( 115 'domain' => 'invalid.org', 116 'path' => '/foo/', 117 ) 118 ); 119 $this->assertFalse( $site ); 120 } 121 122 public function test_get_blog_details_with_only_domain_in_fields_subdomain() { 123 if ( ! is_subdomain_install() ) { 124 $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' ); 125 } 126 127 $site = get_blog_details( array( 'domain' => 'wordpress.org' ) ); 128 $this->assertSame( self::$site_ids['wordpress.org/'], $site->blog_id ); 129 } 130 131 public function test_get_blog_details_with_only_domain_in_fields_subdirectory() { 132 if ( is_subdomain_install() ) { 133 $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' ); 134 } 135 136 $site = get_blog_details( array( 'domain' => 'wordpress.org' ) ); 137 $this->assertFalse( $site ); 138 } 139 140 public function test_get_blog_details_with_only_path_in_fields() { 141 $site = get_blog_details( array( 'path' => '/foo/' ) ); 142 $this->assertFalse( $site ); 143 } 4 144 5 145 /** 6 * @ticket 29845 7 * @group ms-site 8 * @group multisite 146 * @ticket 50391 9 147 */ 10 class Tests_Multisite_GetBlogDetails extends WP_UnitTestCase { 11 protected static $network_ids; 12 protected static $site_ids; 13 14 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 15 self::$site_ids = array( 16 WP_TESTS_DOMAIN . '/foo/' => array( 17 'domain' => WP_TESTS_DOMAIN, 18 'path' => '/foo/', 19 ), 20 'foo.' . WP_TESTS_DOMAIN . '/' => array( 21 'domain' => 'foo.' . WP_TESTS_DOMAIN, 22 'path' => '/', 23 ), 24 'wordpress.org/' => array( 25 'domain' => 'wordpress.org', 26 'path' => '/', 27 ), 28 ); 29 30 foreach ( self::$site_ids as &$id ) { 31 $id = $factory->blog->create( $id ); 32 } 33 unset( $id ); 34 } 35 36 public static function wpTearDownAfterClass() { 37 foreach ( self::$site_ids as $id ) { 38 wp_delete_site( $id ); 39 } 40 41 wp_update_network_site_counts(); 42 } 43 44 public function test_get_blog_details_with_no_arguments_returns_current_site() { 45 $site = get_blog_details(); 46 $this->assertEquals( get_current_blog_id(), $site->blog_id ); 47 } 48 49 public function test_get_blog_details_with_site_name_string_subdirectory() { 50 if ( is_subdomain_install() ) { 51 $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' ); 52 } 53 54 $site = get_blog_details( 'foo' ); 55 $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/' ], $site->blog_id ); 56 } 57 58 public function test_get_blog_details_with_site_name_string_subdomain() { 59 if ( ! is_subdomain_install() ) { 60 $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' ); 61 } 62 63 $site = get_blog_details( 'foo' ); 64 $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id ); 65 } 66 67 public function test_get_blog_details_with_invalid_site_name_string() { 68 $site = get_blog_details( 'invalid' ); 69 $this->assertFalse( $site ); 70 } 71 72 public function test_get_blog_details_with_site_id_int() { 73 $site = get_blog_details( self::$site_ids['wordpress.org/'] ); 74 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 75 } 76 77 public function test_get_blog_details_with_invalid_site_id_int() { 78 $site = get_blog_details( 99999 ); 79 $this->assertFalse( $site ); 80 } 81 82 public function test_get_blog_details_with_blog_id_in_fields() { 83 $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) ); 84 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 85 } 86 87 public function test_get_blog_details_with_invalid_blog_id_in_fields() { 88 $site = get_blog_details( array( 'blog_id' => 88888 ) ); 89 $this->assertFalse( $site ); 90 } 91 92 public function test_get_blog_details_with_domain_and_path_in_fields() { 93 $site = get_blog_details( 148 public function test_get_blog_details_does_not_switch_to_current_blog() { 149 $count = did_action( 'switch_blog' ); 150 151 get_blog_details(); 152 $this->assertSame( $count, did_action( 'switch_blog' ) ); 153 } 154 155 /** 156 * @dataProvider data_get_all 157 * 158 * @ticket 40228 159 */ 160 public function test_get_blog_details_get_object_vars( $get_all ) { 161 $site = get_blog_details( 162 array( 163 'domain' => 'wordpress.org', 164 'path' => '/', 165 ), 166 $get_all 167 ); 168 169 $result = array_keys( get_object_vars( $site ) ); 170 171 $this->assertSameSets( $this->get_fields( $get_all ), $result ); 172 } 173 174 /** 175 * @dataProvider data_get_all 176 * 177 * @ticket 40228 178 */ 179 public function test_get_blog_details_iterate_over_result( $get_all ) { 180 $site = get_blog_details( 181 array( 182 'domain' => 'wordpress.org', 183 'path' => '/', 184 ), 185 $get_all 186 ); 187 188 $result = array(); 189 foreach ( $site as $key => $value ) { 190 $result[] = $key; 191 } 192 193 $this->assertSameSets( $this->get_fields( $get_all ), $result ); 194 } 195 196 public function data_get_all() { 197 return array( 198 array( false ), 199 array( true ), 200 ); 201 } 202 203 protected function get_fields( $all = false ) { 204 $fields = array( 205 'blog_id', 206 'domain', 207 'path', 208 'site_id', 209 'registered', 210 'last_updated', 211 'public', 212 'archived', 213 'mature', 214 'spam', 215 'deleted', 216 'lang_id', 217 ); 218 219 if ( $all ) { 220 $fields = array_merge( 221 $fields, 94 222 array( 95 'domain' => 'wordpress.org', 96 'path' => '/', 223 'blogname', 224 'siteurl', 225 'post_count', 226 'home', 97 227 ) 98 228 ); 99 $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id ); 100 } 101 102 public function test_get_blog_details_with_domain_and_invalid_path_in_fields() { 103 $site = get_blog_details( 104 array( 105 'domain' => 'wordpress.org', 106 'path' => '/zxy/', 107 ) 108 ); 109 $this->assertFalse( $site ); 110 } 111 112 public function test_get_blog_details_with_path_and_invalid_domain_in_fields() { 113 $site = get_blog_details( 114 array( 115 'domain' => 'invalid.org', 116 'path' => '/foo/', 117 ) 118 ); 119 $this->assertFalse( $site ); 120 } 121 122 public function test_get_blog_details_with_only_domain_in_fields_subdomain() { 123 if ( ! is_subdomain_install() ) { 124 $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' ); 125 } 126 127 $site = get_blog_details( array( 'domain' => 'wordpress.org' ) ); 128 $this->assertSame( self::$site_ids['wordpress.org/'], $site->blog_id ); 129 } 130 131 public function test_get_blog_details_with_only_domain_in_fields_subdirectory() { 132 if ( is_subdomain_install() ) { 133 $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' ); 134 } 135 136 $site = get_blog_details( array( 'domain' => 'wordpress.org' ) ); 137 $this->assertFalse( $site ); 138 } 139 140 public function test_get_blog_details_with_only_path_in_fields() { 141 $site = get_blog_details( array( 'path' => '/foo/' ) ); 142 $this->assertFalse( $site ); 143 } 144 145 /** 146 * @ticket 50391 147 */ 148 public function test_get_blog_details_does_not_switch_to_current_blog() { 149 $count = did_action( 'switch_blog' ); 150 151 get_blog_details(); 152 $this->assertSame( $count, did_action( 'switch_blog' ) ); 153 } 154 155 /** 156 * @dataProvider data_get_all 157 * 158 * @ticket 40228 159 */ 160 public function test_get_blog_details_get_object_vars( $get_all ) { 161 $site = get_blog_details( 162 array( 163 'domain' => 'wordpress.org', 164 'path' => '/', 165 ), 166 $get_all 167 ); 168 169 $result = array_keys( get_object_vars( $site ) ); 170 171 $this->assertSameSets( $this->get_fields( $get_all ), $result ); 172 } 173 174 /** 175 * @dataProvider data_get_all 176 * 177 * @ticket 40228 178 */ 179 public function test_get_blog_details_iterate_over_result( $get_all ) { 180 $site = get_blog_details( 181 array( 182 'domain' => 'wordpress.org', 183 'path' => '/', 184 ), 185 $get_all 186 ); 187 188 $result = array(); 189 foreach ( $site as $key => $value ) { 190 $result[] = $key; 191 } 192 193 $this->assertSameSets( $this->get_fields( $get_all ), $result ); 194 } 195 196 public function data_get_all() { 197 return array( 198 array( false ), 199 array( true ), 200 ); 201 } 202 203 protected function get_fields( $all = false ) { 204 $fields = array( 205 'blog_id', 206 'domain', 207 'path', 208 'site_id', 209 'registered', 210 'last_updated', 211 'public', 212 'archived', 213 'mature', 214 'spam', 215 'deleted', 216 'lang_id', 217 ); 218 219 if ( $all ) { 220 $fields = array_merge( 221 $fields, 222 array( 223 'blogname', 224 'siteurl', 225 'post_count', 226 'home', 227 ) 228 ); 229 } 230 231 return $fields; 232 } 233 } 234 235 endif; 229 } 230 231 return $fields; 232 } 233 }
Note: See TracChangeset
for help on using the changeset viewer.