Ticket #34941: 34941.diff
File 34941.diff, 28.2 KB (added by , 9 years ago) |
---|
-
src/wp-includes/ms-load.php
261 261 } 262 262 263 263 /** 264 * Given a requested domain and path, try to identify the network and site of a 265 * requested domain and path as part of the multisite bootstrap process. 266 * 267 * Usually, it's easier to query the site first, which then declares its network. 268 * In limited situations, we either can or must find the network first. 269 * 270 * If a network and site are found, a `true` response will be returned so that the 271 * request can be continued. 272 * 273 * If either a network or site is not found, either `false` or a URL string will be 274 * returned so that either a redirect can be occur or an error shown. 275 * 276 * Prior to 4.5.0, this was a procedural block in `ms-settings.php`. It should not be 277 * used outside of the multisite bootstrap. 278 * 279 * @since 4.5.0 280 * 281 * @global wpdb $wpdb 282 * @global WP_Network $current_site The current network. 283 * @global object $current_blog The current site. 284 * 285 * @param string $domain 286 * @param string $path 287 * 288 * @return bool|string True if bootstrap successfully populated `$current_blog` and `$current_site`. 289 * False if bootstrap could not be properly completed. 290 * Redirect URL if parts exist, but the request as a whole can not be fulfilled. 291 */ 292 function ms_bootstrap( $domain, $path ) { 293 global $wpdb, $current_site, $current_blog; 294 295 // If the network is defined in wp-config.php, we can simply use that. 296 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 297 $current_site = new stdClass; 298 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; 299 $current_site->domain = DOMAIN_CURRENT_SITE; 300 $current_site->path = PATH_CURRENT_SITE; 301 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 302 $current_site->blog_id = BLOG_ID_CURRENT_SITE; 303 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. 304 $current_site->blog_id = BLOGID_CURRENT_SITE; 305 } 306 307 if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) { 308 $current_blog = get_site_by_path( $domain, $path ); 309 } elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) { 310 // If the current network has a path and also matches the domain and path of the request, 311 // we need to look for a site using the first path segment following the network's path. 312 $current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) ); 313 } else { 314 // Otherwise, use the first path segment (as usual). 315 $current_blog = get_site_by_path( $domain, $path, 1 ); 316 } 317 318 } elseif ( ! is_subdomain_install() ) { 319 /* 320 * A "subdomain" install can be re-interpreted to mean "can support any domain". 321 * If we're not dealing with one of these installs, then the important part is determining 322 * the network first, because we need the network's path to identify any sites. 323 */ 324 if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) { 325 // Are there even two networks installed? 326 $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic] 327 if ( 1 === $wpdb->num_rows ) { 328 $current_site = new WP_Network( $one_network ); 329 wp_cache_add( 'current_network', $current_site, 'site-options' ); 330 } elseif ( 0 === $wpdb->num_rows ) { 331 // A network not found hook should fire here. 332 return false; 333 } 334 } 335 if ( empty( $current_site ) ) { 336 $current_site = WP_Network::get_by_path( $domain, $path, 1 ); 337 } 338 339 if ( empty( $current_site ) ) { 340 /** 341 * Fires when a network cannot be found based on the requested domain and path. 342 * 343 * At the time of this action, the only recourse is to redirect somewhere 344 * and exit. If you want to declare a particular network, do so earlier. 345 * 346 * @since 4.4.0 347 * 348 * @param string $domain The domain used to search for a network. 349 * @param string $path The path used to search for a path. 350 */ 351 do_action( 'ms_network_not_found', $domain, $path ); 352 353 return false; 354 } elseif ( $path === $current_site->path ) { 355 $current_blog = get_site_by_path( $domain, $path ); 356 } else { 357 // Search the network path + one more path segment (on top of the network path). 358 $current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) ); 359 } 360 } else { 361 // Find the site by the domain and at most the first path segment. 362 $current_blog = get_site_by_path( $domain, $path, 1 ); 363 if ( $current_blog ) { 364 $current_site = WP_Network::get_instance( $current_blog->site_id ? $current_blog->site_id : 1 ); 365 } else { 366 // If you don't have a site with the same domain/path as a network, you're pretty screwed, but: 367 $current_site = WP_Network::get_by_path( $domain, $path, 1 ); 368 } 369 } 370 371 // The network declared by the site trumps any constants. 372 if ( $current_blog && $current_blog->site_id != $current_site->id ) { 373 $current_site = WP_Network::get_instance( $current_blog->site_id ); 374 } 375 376 // No network has been found, bail. 377 if ( empty( $current_site ) ) { 378 /** This action is documented in wp-includes/ms-settings.php */ 379 do_action( 'ms_network_not_found', $domain, $path ); 380 381 return false; 382 } 383 384 // During activation of a new subdomain, the requested site does not yet exist. 385 if ( empty( $current_blog ) && wp_installing() ) { 386 $current_blog = new stdClass; 387 $current_blog->blog_id = $blog_id = 1; 388 $current_blog->public = 1; 389 } 390 391 // No site has been found, bail. 392 if ( empty( $current_blog ) ) { 393 // We're going to redirect to the network URL, with some possible modifications. 394 $scheme = is_ssl() ? 'https' : 'http'; 395 $destination = "$scheme://{$current_site->domain}{$current_site->path}"; 396 397 /** 398 * Fires when a network can be determined but a site cannot. 399 * 400 * At the time of this action, the only recourse is to redirect somewhere 401 * and exit. If you want to declare a particular site, do so earlier. 402 * 403 * @since 3.9.0 404 * 405 * @param object $current_site The network that had been determined. 406 * @param string $domain The domain used to search for a site. 407 * @param string $path The path used to search for a site. 408 */ 409 do_action( 'ms_site_not_found', $current_site, $domain, $path ); 410 411 if ( is_subdomain_install() && ! defined( 'NOBLOGREDIRECT' ) ) { 412 // For a "subdomain" install, redirect to the signup form specifically. 413 $destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain ); 414 } elseif ( is_subdomain_install() ) { 415 // For a "subdomain" install, the NOBLOGREDIRECT constant 416 // can be used to avoid a redirect to the signup form. 417 // Using the ms_site_not_found action is preferred to the constant. 418 if ( '%siteurl%' !== NOBLOGREDIRECT ) { 419 $destination = NOBLOGREDIRECT; 420 } 421 } elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) { 422 /* 423 * If the domain we were searching for matches the network's domain, 424 * it's no use redirecting back to ourselves -- it'll cause a loop. 425 * As we couldn't find a site, we're simply not installed. 426 */ 427 return false; 428 } 429 430 return $destination; 431 } 432 433 // Figure out the current network's main site. 434 if ( empty( $current_site->blog_id ) ) { 435 if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) { 436 $current_site->blog_id = $current_blog->blog_id; 437 } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) { 438 $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", 439 $current_site->domain, $current_site->path ) ); 440 wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' ); 441 } 442 } 443 444 return true; 445 } 446 447 /** 264 448 * Displays a failure message. 265 449 * 266 450 * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well. -
src/wp-includes/ms-settings.php
10 10 * @since 3.0.0 11 11 */ 12 12 13 /** 14 * Will hold objects representing the current network and current site. 15 * 16 * These may be populated through a custom `sunrise.php`. If not, then this 17 * file will attempt to populate them based on the current request. 18 * 19 * @global WP_Network $current_site The current network. 20 * @global object $current_blog The current site. 21 * @since 3.0.0 22 */ 23 global $current_site, $current_blog; 24 13 25 /** WP_Network class */ 14 26 require_once( ABSPATH . WPINC . '/class-wp-network.php' ); 15 27 … … 26 38 /** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */ 27 39 ms_subdomain_constants(); 28 40 41 /** 42 * This block will process a request when either the current network or current site 43 * object is not yet populated in the global scope through something like `sunrise.php`. 44 * 45 * Possible outcomes: 46 * 47 * - `$current_site` and `$current_blog` are populated fully. 48 * - In a subdirectory configuration, if 0 networks exist, show an error. 49 * - In a subdirectory configuration, if no matching networks (domain/path) are found, show an error. 50 * - In either configuration, if no matching network is found, show an error. 51 * - In a subdomain configuration, if a network is found and a site is not found, redirect to signup. 52 * - In a subdirectory configuration, if a network is found and a site is not found, redirect to main site. 53 * - In a subdirectory configuration, if a network is found, a site is not found, and a redirect would 54 * cause a loop, show an error. 55 */ 29 56 if ( !isset( $current_site ) || !isset( $current_blog ) ) { 30 57 31 // Given the domain and path, let's try to identify the network and site.32 // Usually, it's easier to query the site first, which declares its network.33 // In limited situations, though, we either can or must find the network first.34 35 58 $domain = strtolower( stripslashes( $_SERVER['HTTP_HOST'] ) ); 36 59 if ( substr( $domain, -3 ) == ':80' ) { 37 60 $domain = substr( $domain, 0, -3 ); … … 47 70 } 48 71 list( $path ) = explode( '?', $path ); 49 72 50 // If the network is defined in wp-config.php, we can simply use that. 51 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 52 $current_site = new stdClass; 53 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; 54 $current_site->domain = DOMAIN_CURRENT_SITE; 55 $current_site->path = PATH_CURRENT_SITE; 56 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { 57 $current_site->blog_id = BLOG_ID_CURRENT_SITE; 58 } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. 59 $current_site->blog_id = BLOGID_CURRENT_SITE; 60 } 61 62 if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) { 63 $current_blog = get_site_by_path( $domain, $path ); 64 } elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) { 65 // If the current network has a path and also matches the domain and path of the request, 66 // we need to look for a site using the first path segment following the network's path. 67 $current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) ); 68 } else { 69 // Otherwise, use the first path segment (as usual). 70 $current_blog = get_site_by_path( $domain, $path, 1 ); 71 } 72 73 } elseif ( ! is_subdomain_install() ) { 74 /* 75 * A "subdomain" install can be re-interpreted to mean "can support any domain". 76 * If we're not dealing with one of these installs, then the important part is determining 77 * the network first, because we need the network's path to identify any sites. 78 */ 79 if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) { 80 // Are there even two networks installed? 81 $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic] 82 if ( 1 === $wpdb->num_rows ) { 83 $current_site = new WP_Network( $one_network ); 84 wp_cache_add( 'current_network', $current_site, 'site-options' ); 85 } elseif ( 0 === $wpdb->num_rows ) { 86 ms_not_installed( $domain, $path ); 87 } 88 } 89 if ( empty( $current_site ) ) { 90 $current_site = WP_Network::get_by_path( $domain, $path, 1 ); 91 } 92 93 if ( empty( $current_site ) ) { 94 /** 95 * Fires when a network cannot be found based on the requested domain and path. 96 * 97 * At the time of this action, the only recourse is to redirect somewhere 98 * and exit. If you want to declare a particular network, do so earlier. 99 * 100 * @since 4.4.0 101 * 102 * @param string $domain The domain used to search for a network. 103 * @param string $path The path used to search for a path. 104 */ 105 do_action( 'ms_network_not_found', $domain, $path ); 106 107 ms_not_installed( $domain, $path ); 108 } elseif ( $path === $current_site->path ) { 109 $current_blog = get_site_by_path( $domain, $path ); 110 } else { 111 // Search the network path + one more path segment (on top of the network path). 112 $current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) ); 113 } 114 } else { 115 // Find the site by the domain and at most the first path segment. 116 $current_blog = get_site_by_path( $domain, $path, 1 ); 117 if ( $current_blog ) { 118 $current_site = WP_Network::get_instance( $current_blog->site_id ? $current_blog->site_id : 1 ); 119 } else { 120 // If you don't have a site with the same domain/path as a network, you're pretty screwed, but: 121 $current_site = WP_Network::get_by_path( $domain, $path, 1 ); 122 } 123 } 124 125 // The network declared by the site trumps any constants. 126 if ( $current_blog && $current_blog->site_id != $current_site->id ) { 127 $current_site = WP_Network::get_instance( $current_blog->site_id ); 128 } 129 130 // No network has been found, bail. 131 if ( empty( $current_site ) ) { 132 /** This action is documented in wp-includes/ms-settings.php */ 133 do_action( 'ms_network_not_found', $domain, $path ); 73 $bootstrap_result = ms_bootstrap( $domain, $path ); 134 74 75 if ( true === $bootstrap_result ) { 76 // `$current_blog` and `$current_site are now populated. 77 } elseif ( false === $bootstrap_result ) { 135 78 ms_not_installed( $domain, $path ); 136 } 137 138 // During activation of a new subdomain, the requested site does not yet exist. 139 if ( empty( $current_blog ) && wp_installing() ) { 140 $current_blog = new stdClass; 141 $current_blog->blog_id = $blog_id = 1; 142 $current_blog->public = 1; 143 } 144 145 // No site has been found, bail. 146 if ( empty( $current_blog ) ) { 147 // We're going to redirect to the network URL, with some possible modifications. 148 $scheme = is_ssl() ? 'https' : 'http'; 149 $destination = "$scheme://{$current_site->domain}{$current_site->path}"; 150 151 /** 152 * Fires when a network can be determined but a site cannot. 153 * 154 * At the time of this action, the only recourse is to redirect somewhere 155 * and exit. If you want to declare a particular site, do so earlier. 156 * 157 * @since 3.9.0 158 * 159 * @param object $current_site The network that had been determined. 160 * @param string $domain The domain used to search for a site. 161 * @param string $path The path used to search for a site. 162 */ 163 do_action( 'ms_site_not_found', $current_site, $domain, $path ); 164 165 if ( is_subdomain_install() && ! defined( 'NOBLOGREDIRECT' ) ) { 166 // For a "subdomain" install, redirect to the signup form specifically. 167 $destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain ); 168 } elseif ( is_subdomain_install() ) { 169 // For a "subdomain" install, the NOBLOGREDIRECT constant 170 // can be used to avoid a redirect to the signup form. 171 // Using the ms_site_not_found action is preferred to the constant. 172 if ( '%siteurl%' !== NOBLOGREDIRECT ) { 173 $destination = NOBLOGREDIRECT; 174 } 175 } elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) { 176 /* 177 * If the domain we were searching for matches the network's domain, 178 * it's no use redirecting back to ourselves -- it'll cause a loop. 179 * As we couldn't find a site, we're simply not installed. 180 */ 181 ms_not_installed( $domain, $path ); 182 } 183 184 header( 'Location: ' . $destination ); 79 } else { 80 header( 'Location: ' . $bootstrap_result ); 185 81 exit; 186 82 } 187 188 // Figure out the current network's main site. 189 if ( empty( $current_site->blog_id ) ) { 190 if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) { 191 $current_site->blog_id = $current_blog->blog_id; 192 } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) { 193 $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", 194 $current_site->domain, $current_site->path ) ); 195 wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' ); 196 } 197 } 83 unset( $bootstrap_result ); 198 84 199 85 $blog_id = $current_blog->blog_id; 200 86 $public = $current_blog->public; -
tests/phpunit/tests/multisite/bootstrap.php
23 23 parent::tearDown(); 24 24 } 25 25 26 27 26 /** 28 27 * @ticket 27003 29 28 */ … … 186 185 } 187 186 unset( $id ); 188 187 189 $this->_setup_host_request( 'wordpress.org', '/' ); 190 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id ); 191 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 192 193 $this->_setup_host_request( 'wordpress.org', '/2014/04/23/hello-world/' ); 194 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id ); 195 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 196 197 $this->_setup_host_request( 'wordpress.org', '/sample-page/' ); 198 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id ); 199 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 200 201 $this->_setup_host_request( 'wordpress.org', '/?p=1' ); 202 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id ); 203 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 204 205 $this->_setup_host_request( 'wordpress.org', '/wp-admin/' ); 206 $this->assertEquals( $ids['wordpress.org/'], $current_blog->blog_id ); 207 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 208 209 $this->_setup_host_request( 'wordpress.org', '/foo/' ); 210 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 211 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 212 213 $this->_setup_host_request( 'wordpress.org', '/FOO/' ); 214 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 215 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 216 217 $this->_setup_host_request( 'wordpress.org', '/foo/2014/04/23/hello-world/' ); 218 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 219 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 220 221 $this->_setup_host_request( 'wordpress.org', '/foo/sample-page/' ); 222 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 223 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 224 225 $this->_setup_host_request( 'wordpress.org', '/foo/?p=1' ); 226 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 227 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 228 229 $this->_setup_host_request( 'wordpress.org', '/foo/wp-admin/' ); 230 $this->assertEquals( $ids['wordpress.org/foo/'], $current_blog->blog_id ); 231 $this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 188 $requests = array( 189 'wordpress.org/' => array( 190 'network_id' => $network_ids['wordpress.org/'], 191 'site_id' => $ids['wordpress.org/'], 192 'domain' => 'wordpress.org', 193 'path' => '/', 194 'response' => true, 195 'message' => false, 196 ), 197 'wordpress.org/2014/04/23/hello-world/' => array( 198 'network_id' => $network_ids['wordpress.org/'], 199 'site_id' => $ids['wordpress.org/'], 200 'domain' => 'wordpress.org', 201 'path' => '/2014/04/23/hello-world/', 202 'response' => true, 203 'message' => 'A post or 404 on a site should result in the correct site and network.', 204 ), 205 'wordpress.org/sample-page/' => array( 206 'network_id' => $network_ids['wordpress.org/'], 207 'site_id' => $ids['wordpress.org/'], 208 'domain' => 'wordpress.org', 209 'path' => '/sample-page/', 210 'response' => true, 211 'message' => 'A page or 404 on a site should result in the correct site and network.', 212 ), 213 'wordpress.org/?p=1' => array( 214 'network_id' => $network_ids['wordpress.org/'], 215 'site_id' => $ids['wordpress.org/'], 216 'domain' => 'wordpress.org', 217 'path' => '/?p=1', 218 'response' => true, 219 'message' => 'A non pretty-permalink URL should result in the correct site and network.', 220 ), 221 'wordpress.org/wp-admin/' => array( 222 'network_id' => $network_ids['wordpress.org/'], 223 'site_id' => $ids['wordpress.org/'], 224 'domain' => 'wordpress.org', 225 'path' => '/wp-admin/', 226 'response' => true, 227 'message' => 'The standard admin area of the main site should load the correct site and network.', 228 ), 229 'wordpress.org/wp-admin/network/' => array( 230 'network_id' => $network_ids['wordpress.org/'], 231 'site_id' => $ids['wordpress.org/'], 232 'domain' => 'wordpress.org', 233 'path' => '/', 234 'response' => true, 235 'message' => 'The network admin area of the main site should load the correct site and network.', 236 ), 237 // See #17376, this is not correct behavior. 238 'wordpress.org/invalid/wp-admin/users.php' => array( 239 'network_id' => $network_ids['wordpress.org/'], 240 'site_id' => $ids['wordpress.org/'], 241 'domain' => 'wordpress.org', 242 'path' => '/', 243 'response' => true, 244 'message' => 'If wp-admin is requested after an invalid path, the parent site and network should still load.', 245 ), 246 // See #17376, this is not correct behavior. 247 'wordpress.org/invalid/wp-admin/network/users.php' => array( 248 'network_id' => $network_ids['wordpress.org/'], 249 'site_id' => $ids['wordpress.org/'], 250 'domain' => 'wordpress.org', 251 'path' => '/', 252 'response' => true, 253 'message' => 'Valid', 254 ), 255 'wordpress.org/foo/' => array( 256 'network_id' => $network_ids['wordpress.org/'], 257 'site_id' => $ids['wordpress.org/foo/'], 258 'domain' => 'wordpress.org', 259 'path' => '/foo/', 260 'response' => true, 261 'message' => 'A valid sub-site should load the correct site and network.', 262 ), 263 'wordpress.org/FOO/' => array( 264 'network_id' => $network_ids['wordpress.org/'], 265 'site_id' => $ids['wordpress.org/foo/'], 266 'domain' => 'wordpress.org', 267 'path' => '/FOO/', 268 'response' => true, 269 'message' => 'A valid sub-site should not be case sensitive.', 270 ), 271 'wordpress.org/foo/2014/04/23/hello-world/' => array( 272 'network_id' => $network_ids['wordpress.org/'], 273 'site_id' => $ids['wordpress.org/foo/'], 274 'domain' => 'wordpress.org', 275 'path' => '/foo/2014/04/23/hello-world/', 276 'response' => true, 277 'message' => 'A post or 404 on a valid sub site should load the correct site and network.', 278 ), 279 'wordpress.org/foo/sample-page/' => array( 280 'network_id' => $network_ids['wordpress.org/'], 281 'site_id' => $ids['wordpress.org/foo/'], 282 'domain' => 'wordpress.org', 283 'path' => '/foo/sample-page/', 284 'response' => true, 285 'message' => 'A page or 404 on a valid sub site should load the correct site and network.', 286 ), 287 'wordpress.org/foo/?p=1' => array( 288 'network_id' => $network_ids['wordpress.org/'], 289 'site_id' => $ids['wordpress.org/foo/'], 290 'domain' => 'wordpress.org', 291 'path' => '/foo/?p=1', 292 'response' => true, 293 'message' => 'A non pretty-permalink URL on a valid sub site should load the correct site and network.', 294 ), 295 'wordpress.org/foo/wp-admin/' => array( 296 'network_id' => $network_ids['wordpress.org/'], 297 'site_id' => $ids['wordpress.org/foo/'], 298 'domain' => 'wordpress.org', 299 'path' => '/foo/wp-admin/', 300 'response' => true, 301 'message' => 'If wp-admin is requested on a valid sub-site, the correct network and site should load.', 302 ), 303 // This will eventually redirect to the main site, but not during bootstrap. 304 'wordpress.org/foo/wp-admin/network/' => array( 305 'network_id' => $network_ids['wordpress.org/'], 306 'site_id' => $ids['wordpress.org/foo/'], 307 'domain' => 'wordpress.org', 308 'path' => '/foo/wp-admin/network/', 309 'response' => true, 310 'message' => 'If the network admin is requested on a valid sub-site, the correct network and site should still populate.', 311 ), 312 'make.wordpress.org/' => array( 313 'network_id' => $network_ids['make.wordpress.org/'], 314 'site_id' => $ids['make.wordpress.org/'], 315 'domain' => 'make.wordpress.org', 316 'path' => '/', 317 'response' => true, 318 'message' => false, 319 ), 320 'make.wordpress.org/foo/' => array( 321 'network_id' => $network_ids['make.wordpress.org/'], 322 'site_id' => $ids['make.wordpress.org/foo/'], 323 'domain' => 'make.wordpress.org', 324 'path' => '/foo/', 325 'response' => true, 326 'message' => false, 327 ), 328 'core.wordpress.org/' => array( 329 'domain' => 'core.wordpress.org', 330 'path' => '/', 331 'response' => 'http://wordpress.org/', 332 'message' => 'An invalid subdomain should redirect to the top level network address.', 333 ), 334 'invalidsite.org/' => array( 335 'domain' => 'invalidsite.org', 336 'path' => '/', 337 'response' => false, 338 'message' => 'An invalid site/network should result in false.', 339 ) 340 ); 341 342 /** 343 * Loop through the possible requests and assert that the proper string/true/false response is received 344 * from `ms_bootstrap`. 345 * 346 * In cases where a response is successful, the blog_id and site_id properties of `$current_blog` 347 * should also be checked to match expectations. 348 */ 349 foreach( $requests as $request_url => $request_data ) { 350 $message = $request_data['domain'] . $request_data['path'] . ' ' . $request_data['message']; 351 $this->assertEquals( $request_data['response'], ms_bootstrap( $request_data['domain'], $request_data['path'] ), $message ); 352 353 // For successful responses, also test the resulting site and network information. 354 if ( true === $request_data['response'] ) { 355 $this->assertEquals( $request_data['site_id'], $current_blog->blog_id ); 356 $this->assertEquals( $request_data['network_id'], $current_blog->site_id ); 357 } 358 } 232 359 233 360 // @todo not currently passing. 234 // $this->_setup_host_request( 'wordpress.org', '/foo/bar/' );361 //ms_bootstrap( 'wordpress.org', '/foo/bar/' ); 235 362 //$this->assertEquals( $ids['wordpress.org/foo/bar/'], $current_blog->blog_id ); 236 363 //$this->assertEquals( $network_ids['wordpress.org/'], $current_blog->site_id ); 237 364 238 $this->_setup_host_request( 'make.wordpress.org', '/' );239 $this->assertEquals( $ids['make.wordpress.org/'], $current_blog->blog_id );240 $this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );241 242 $this->_setup_host_request( 'make.wordpress.org', '/foo/' );243 $this->assertEquals( $ids['make.wordpress.org/foo/'], $current_blog->blog_id );244 $this->assertEquals( $network_ids['make.wordpress.org/'], $current_blog->site_id );245 246 365 // Request the original tests domain and path to unpollute the stack. 247 $this->_setup_host_request( WP_TESTS_DOMAIN, '/' );366 ms_bootstrap( WP_TESTS_DOMAIN, '/' ); 248 367 } 249 368 250 369 /**