Multisite: Add get_network_by_path() and wp_get_network() to begin cleanup of multisite load.

Tries to get network detection under control by simplifying wpmu_current_site(). It now also pops off each subdomain to find a more general match. Adds unit tests for get_network_by_path() and a new network factory for unit tests.

Much of this is likely to change in 3.9 as more of ms-load.php and ms-settings.php gets hacked to bits.

props jeremyfelt.
see #27003.


git-svn-id: https://develop.svn.wordpress.org/trunk@27178 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2014-02-13 23:06:12 +00:00
parent f6af16cd76
commit 31d3af406c
4 changed files with 206 additions and 66 deletions
+47
View File
@@ -1172,6 +1172,53 @@ class Tests_MS extends WP_UnitTestCase {
// Expect 0 sites when using an offset larger than the number of sites
$this->assertCount( 0, wp_get_sites( array( 'offset' => 20 ) ) );
}
/**
* @ticket 27003
*/
function test_get_network_by_path() {
global $wpdb;
$ids = array(
'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),
'wordpress.org/one/' => array( 'domain' => 'wordpress.org', 'path' => '/one/' ),
'wordpress.net/' => array( 'domain' => 'wordpress.net', 'path' => '/' ),
'www.wordpress.net/' => array( 'domain' => 'www.wordpress.net', 'path' => '/' ),
'www.wordpress.net/two/' => array( 'domain' => 'www.wordpress.net', 'path' => '/two/' ),
'wordpress.net/three/' => array( 'domain' => 'wordpress.net', 'path' => '/three/' ),
);
foreach ( $ids as &$id ) {
$id = $this->factory->network->create( $id );
}
unset( $id );
$this->assertEquals( $ids['www.wordpress.net/'],
get_network_by_path( 'www.wordpress.net', '/notapath/' )->id );
$this->assertEquals( $ids['www.wordpress.net/two/'],
get_network_by_path( 'www.wordpress.net', '/two/' )->id );
// This should find /one/ despite the www.
$this->assertEquals( $ids['wordpress.org/one/'],
get_network_by_path( 'www.wordpress.org', '/one/' )->id );
// This should not find /one/ because the domains don't match.
$this->assertEquals( $ids['wordpress.org/'],
get_network_by_path( 'site1.wordpress.org', '/one/' )->id );
$this->assertEquals( $ids['wordpress.net/three/'],
get_network_by_path( 'wordpress.net', '/three/' )->id );
$this->assertEquals( $ids['wordpress.net/'],
get_network_by_path( 'wordpress.net', '/notapath/' )->id );
$this->assertEquals( $ids['wordpress.net/'],
get_network_by_path( 'site1.wordpress.net', '/notapath/' )->id );
$this->assertEquals( $ids['wordpress.net/'],
get_network_by_path( 'site1.wordpress.net', '/three/' )->id );
}
}
endif;