mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Previously, if a network's domain started with `www.` in a subdomain configuration, a slug lookup with `get_id_from_blogname()` would not match an existing site. A similar lookup in a subdirectory configuration would work fine. This strips `www.` from the network's domain in a subdomain configuration during the lookup and returns the site as expected. Adds tests which would previously fail in a subdomain configuration, but now pass in both configurations. Props igmoweb, flixos90. Fixes #34450. git-svn-id: https://develop.svn.wordpress.org/trunk@38658 602fd350-edb4-49c9-b593-d223f7449a82
113 lines
3.4 KiB
PHP
113 lines
3.4 KiB
PHP
<?php
|
|
|
|
if ( is_multisite() ) :
|
|
/**
|
|
* Test get_id_from_blogname() in multisite.
|
|
*
|
|
* @group blogname
|
|
* @group ms-site
|
|
* @group multisite
|
|
*/
|
|
class Tests_Multisite_Get_Id_From_Blogname extends WP_UnitTestCase {
|
|
protected static $network_ids;
|
|
protected static $site_ids;
|
|
|
|
public static function wpSetUpBeforeClass( $factory ) {
|
|
self::$network_ids = array(
|
|
'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),
|
|
'www.wordpress.net/' => array( 'domain' => 'www.wordpress.net', 'path' => '/' ),
|
|
);
|
|
|
|
foreach ( self::$network_ids as &$id ) {
|
|
$id = $factory->network->create( $id );
|
|
}
|
|
unset( $id );
|
|
|
|
self::$site_ids = array(
|
|
'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/', 'site_id' => self::$network_ids['wordpress.org/'] ),
|
|
'foo.wordpress.org/' => array( 'domain' => 'foo.wordpress.org', 'path' => '/', 'site_id' => self::$network_ids['wordpress.org/'] ),
|
|
'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/', 'site_id' => self::$network_ids['wordpress.org/'] ),
|
|
'www.wordpress.net/' => array( 'domain' => 'www.wordpress.net', 'path' => '/', 'site_id' => self::$network_ids['www.wordpress.net/'] ),
|
|
'foo.wordpress.net/' => array( 'domain' => 'foo.wordpress.net', 'path' => '/', 'site_id' => self::$network_ids['www.wordpress.net/'] ),
|
|
'www.wordpress.net/foo/' => array( 'domain' => 'www.wordpress.net', 'path' => '/foo/', 'site_id' => self::$network_ids['www.wordpress.net/'] ),
|
|
);
|
|
|
|
foreach ( self::$site_ids as &$id ) {
|
|
$id = $factory->blog->create( $id );
|
|
}
|
|
unset( $id );
|
|
}
|
|
|
|
public static function wpTearDownAfterClass() {
|
|
global $wpdb;
|
|
|
|
foreach( self::$site_ids as $id ) {
|
|
wpmu_delete_blog( $id, true );
|
|
}
|
|
|
|
foreach( self::$network_ids as $id ) {
|
|
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
|
|
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
|
|
}
|
|
|
|
wp_update_network_site_counts();
|
|
}
|
|
|
|
/**
|
|
* @ticket 34450
|
|
*/
|
|
public function test_get_id_from_blogname_no_www() {
|
|
global $current_site;
|
|
|
|
$original_network = $current_site;
|
|
$current_site = get_network( self::$network_ids['wordpress.org/'] );
|
|
|
|
if ( is_subdomain_install() ) {
|
|
$expected = self::$site_ids['foo.wordpress.org/'];
|
|
} else {
|
|
$expected = self::$site_ids['wordpress.org/foo/'];
|
|
}
|
|
|
|
$result = get_id_from_blogname( 'foo' );
|
|
$current_site = $original_network;
|
|
|
|
$this->assertEquals( $expected, $result );
|
|
}
|
|
|
|
/**
|
|
* @ticket 34450
|
|
*/
|
|
public function test_get_id_from_blogname_www() {
|
|
global $current_site;
|
|
|
|
$original_network = $current_site;
|
|
$current_site = get_network( self::$network_ids['www.wordpress.net/'] );
|
|
|
|
if ( is_subdomain_install() ) {
|
|
$expected = self::$site_ids['foo.wordpress.net/'];
|
|
} else {
|
|
$expected = self::$site_ids['www.wordpress.net/foo/'];
|
|
}
|
|
|
|
$result = get_id_from_blogname( 'foo' );
|
|
$current_site = $original_network;
|
|
|
|
$this->assertEquals( $expected, $result );
|
|
}
|
|
|
|
public function test_get_id_from_blogname_invalid_slug() {
|
|
global $current_site;
|
|
|
|
$original_network = $current_site;
|
|
$current_site = get_network( self::$network_ids['wordpress.org/'] );
|
|
|
|
$result = get_id_from_blogname( 'bar' );
|
|
$current_site = $original_network;
|
|
|
|
$this->assertEquals( null, $result );
|
|
}
|
|
|
|
}
|
|
|
|
endif;
|