Make WordPress Core


Ignore:
Timestamp:
02/13/2014 11:06:12 PM (10 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ms.php

    r27087 r27178  
    11731173        $this->assertCount( 0, wp_get_sites( array( 'offset' => 20 ) ) );
    11741174    }
     1175
     1176    /**
     1177     * @ticket 27003
     1178     */
     1179    function test_get_network_by_path() {
     1180        global $wpdb;
     1181
     1182        $ids = array(
     1183            'wordpress.org/'         => array( 'domain' => 'wordpress.org', 'path' => '/' ),
     1184            'wordpress.org/one/'     => array( 'domain' => 'wordpress.org', 'path' => '/one/' ),
     1185            'wordpress.net/'         => array( 'domain' => 'wordpress.net', 'path' => '/' ),
     1186            'www.wordpress.net/'     => array( 'domain' => 'www.wordpress.net', 'path' => '/' ),
     1187            'www.wordpress.net/two/' => array( 'domain' => 'www.wordpress.net', 'path' => '/two/' ),
     1188            'wordpress.net/three/'   => array( 'domain' => 'wordpress.net', 'path' => '/three/' ),
     1189        );
     1190
     1191        foreach ( $ids as &$id ) {
     1192            $id = $this->factory->network->create( $id );
     1193        }
     1194        unset( $id );
     1195
     1196        $this->assertEquals( $ids['www.wordpress.net/'],
     1197            get_network_by_path( 'www.wordpress.net', '/notapath/' )->id );
     1198
     1199        $this->assertEquals( $ids['www.wordpress.net/two/'],
     1200            get_network_by_path( 'www.wordpress.net', '/two/' )->id );
     1201
     1202        // This should find /one/ despite the www.
     1203        $this->assertEquals( $ids['wordpress.org/one/'],
     1204            get_network_by_path( 'www.wordpress.org', '/one/' )->id );
     1205
     1206        // This should not find /one/ because the domains don't match.
     1207        $this->assertEquals( $ids['wordpress.org/'],
     1208            get_network_by_path( 'site1.wordpress.org', '/one/' )->id );
     1209
     1210        $this->assertEquals( $ids['wordpress.net/three/'],
     1211            get_network_by_path( 'wordpress.net', '/three/' )->id );
     1212
     1213        $this->assertEquals( $ids['wordpress.net/'],
     1214            get_network_by_path( 'wordpress.net', '/notapath/' )->id );
     1215
     1216        $this->assertEquals( $ids['wordpress.net/'],
     1217            get_network_by_path( 'site1.wordpress.net', '/notapath/' )->id );
     1218
     1219        $this->assertEquals( $ids['wordpress.net/'],
     1220            get_network_by_path( 'site1.wordpress.net', '/three/' )->id );
     1221    }
    11751222}
    11761223
Note: See TracChangeset for help on using the changeset viewer.