Improve tests for domain_exists()
* Split existing tests for `domain_exists()` into many smaller tests. * Make slightly fewer, more accurate assertions. * Remove unnecessary site creation via factory. See #30080 git-svn-id: https://develop.svn.wordpress.org/trunk@30114 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f59f32104a
commit
cdc35000f9
@ -1014,6 +1014,10 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
|||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Added as a callback to the domain_exists filter to provide manual results for
|
||||||
|
* the testing of the filter and for a test which does not need the database.
|
||||||
|
*/
|
||||||
function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
|
function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
|
||||||
if ( 'foo' == $domain && 'bar/' == $path )
|
if ( 'foo' == $domain && 'bar/' == $path )
|
||||||
return 1234;
|
return 1234;
|
||||||
@ -1021,32 +1025,51 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_domain_exists() {
|
function test_domain_exists_with_default_site_id() {
|
||||||
$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
|
$details = get_blog_details( 1, false );
|
||||||
$blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );
|
|
||||||
|
|
||||||
$details = get_blog_details( $blog_id, false );
|
$this->assertEquals( 1, domain_exists( $details->domain, $details->path ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_domain_exists_with_specified_site_id() {
|
||||||
|
$details = get_blog_details( 1, false );
|
||||||
|
|
||||||
|
$this->assertEquals( 1, domain_exists( $details->domain, $details->path, $details->site_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When the domain is valid, but the resulting site does not belong to the specified network,
|
||||||
|
* it is marked as not existing.
|
||||||
|
*/
|
||||||
|
function test_domain_does_not_exist_with_invalid_site_id() {
|
||||||
|
$details = get_blog_details( 1, false );
|
||||||
|
|
||||||
$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
|
|
||||||
$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path, $details->site_id ) );
|
|
||||||
$this->assertEquals( null, domain_exists( $details->domain, $details->path, 999 ) );
|
$this->assertEquals( null, domain_exists( $details->domain, $details->path, 999 ) );
|
||||||
$this->assertEquals( null, domain_exists( 'foo', 'bar' ) );
|
}
|
||||||
|
|
||||||
|
function test_invalid_domain_does_not_exist_with_default_site_id() {
|
||||||
|
$this->assertEquals( null, domain_exists( 'foo', 'bar' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_domain_filtered_to_exist() {
|
||||||
add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
||||||
|
|
||||||
$this->assertEquals( 1234, domain_exists( 'foo', 'bar' ) );
|
$this->assertEquals( 1234, domain_exists( 'foo', 'bar' ) );
|
||||||
$this->assertEquals( null, domain_exists( 'foo', 'baz' ) );
|
|
||||||
$this->assertEquals( null, domain_exists( 'bar', 'foo' ) );
|
remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a path is passed to domain_exists, it is immediately trailing slashed. A path
|
||||||
|
* value with or without the slash should result in the same return value.
|
||||||
|
*/
|
||||||
|
function test_slashed_path_in_domain_exists() {
|
||||||
|
add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
||||||
|
|
||||||
// Make sure the same result is returned with or without a trailing slash
|
// Make sure the same result is returned with or without a trailing slash
|
||||||
$this->assertEquals( domain_exists( 'foo', 'bar' ), domain_exists( 'foo', 'bar/' ) );
|
$this->assertEquals( domain_exists( 'foo', 'bar' ), domain_exists( 'foo', 'bar/' ) );
|
||||||
|
|
||||||
remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
|
||||||
$this->assertEquals( null, domain_exists( 'foo', 'bar' ) );
|
|
||||||
|
|
||||||
wpmu_delete_blog( $blog_id );
|
|
||||||
$this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
|
|
||||||
wpmu_delete_blog( $blog_id, true );
|
|
||||||
$this->assertEquals( null, domain_exists( $details->domain, $details->path ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user