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/includes/factory.php

    r26252 r27178  
    4242     */
    4343    public $blog;
     44
     45    /**
     46     * @var WP_UnitTest_Factory_For_Network
     47     */
     48    public $network;
    4449
    4550    function __construct() {
     
    5156        $this->category = new WP_UnitTest_Factory_For_Term( $this, 'category' );
    5257        $this->tag = new WP_UnitTest_Factory_For_Term( $this, 'post_tag' );
    53         if ( is_multisite() )
     58        if ( is_multisite() ) {
    5459            $this->blog = new WP_UnitTest_Factory_For_Blog( $this );
     60            $this->network = new WP_UnitTest_Factory_For_Network( $this );
     61        }
    5562    }
    5663}
     
    177184}
    178185
     186
     187class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing {
     188
     189    function __construct( $factory = null ) {
     190        parent::__construct( $factory );
     191        $this->default_generation_definitions = array(
     192            'domain' => WP_TESTS_DOMAIN,
     193            'title' => new WP_UnitTest_Generator_Sequence( 'Network %s' ),
     194            'path' => new WP_UnitTest_Generator_Sequence( '/testpath%s/' ),
     195            'network_id' => new WP_UnitTest_Generator_Sequence( '%s', 2 ),
     196            'subdomain_install' => false,
     197        );
     198    }
     199
     200    function create_object( $args ) {
     201        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     202
     203        if ( ! isset( $args['user'] ) ) {
     204            $email = WP_TESTS_EMAIL;
     205        } else {
     206            $email = get_userdata( $args['user'] )->user_email;
     207        }
     208
     209        populate_network( $args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install'] );
     210        return $args['network_id'];
     211    }
     212
     213    function update_object( $network_id, $fields ) {}
     214
     215    function get_object_by_id( $network_id ) {
     216        return wp_get_network( $network_id );
     217    }
     218}
    179219
    180220class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing {
Note: See TracChangeset for help on using the changeset viewer.