Split tests for `get_blog_id_from_url()`

Breaks the many assertions for `get_blog_id_from_url()` into individual tests.

See #30080


git-svn-id: https://develop.svn.wordpress.org/trunk@30719 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt 2014-12-03 05:51:33 +00:00
parent 9adaec183e
commit 6213bb9689
1 changed files with 38 additions and 14 deletions

View File

@ -882,36 +882,60 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
* the blog ID is requested through get_blog_id_from_url().
*/
function test_get_blog_id_from_url() {
$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );
$blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
$details = get_blog_details( $blog_id, false );
$key = md5( $details->domain . $details->path );
// Test the original response and cached response for the newly created site.
$this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
$this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
}
// Test the case insensitivity of the site lookup.
$this->assertEquals( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ) , strtoupper( $details->path ) ) );
/**
* Test the case insensitivity of the site lookup.
*/
function test_get_blog_id_from_url_is_case_insensitive() {
$blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
$details = get_blog_details( $blog_id, false );
$this->assertEquals( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ), strtoupper( $details->path ) ) );
}
/**
* Test the first and cached responses for a site that does not exist.
*/
function test_get_blog_id_from_url_that_does_not_exist() {
$blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
$details = get_blog_details( $blog_id, false );
// Test the first and cached responses for a non existent site.
$this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
$this->assertEquals( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
}
// A blog ID is still available if only the 'deleted' flag is set for a site.
/**
* A blog ID is still available if only the `deleted` flag is set for a site. The same
* behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
*/
function test_get_blog_id_from_url_with_deleted_flag() {
$blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
$details = get_blog_details( $blog_id, false );
$key = md5( $details->domain . $details->path );
wpmu_delete_blog( $blog_id );
$this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
$this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
}
// Explicitly pass $drop = false (default), a blog ID will still be available.
wpmu_delete_blog( $blog_id, false );
$this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
$this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
// When deleted with the drop parameter at true, the cache will first be false, and then
// set to -1 after an attempt at get_blog_id_from_url() is made.
/**
* When deleted with the drop parameter as true, the cache will first be false, then set to
* -1 after an attempt at `get_blog_id_from_url()` is made.
*/
function test_get_blog_id_from_url_after_dropped() {
$blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
$details = get_blog_details( $blog_id, false );
$key = md5( $details->domain . $details->path );
wpmu_delete_blog( $blog_id, true );
$this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
$this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );
$this->assertEquals( -1, wp_cache_get( $key, 'blog-id-cache' ) );