Tests: Split get_blog_details() test into individual tests

* One test per method
* Clarify existing tests.
* Add test for passing a "blog slug" string to `get_blog_details()`.
* Shared fixture of sites.
* Reduce number of sites created to only those necessary.
* Remove unnecessary networks creation.

See #36566.


git-svn-id: https://develop.svn.wordpress.org/trunk@37666 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt 2016-06-09 15:57:37 +00:00
parent ead348053b
commit 56c98dd30a

View File

@ -3,85 +3,120 @@
if ( is_multisite() ) : if ( is_multisite() ) :
/** /**
* @ticket 29845
* @group ms-site * @group ms-site
* @group multisite * @group multisite
*/ */
class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase { class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase {
/** protected static $network_ids;
* @ticket 29845 protected static $site_ids;
*/
public function test_get_blog_details() { public static function wpSetUpBeforeClass( $factory ) {
$network_ids = array( self::$site_ids = array(
WP_TESTS_DOMAIN . '/foo/' => array( 'domain' => WP_TESTS_DOMAIN, 'path' => '/foo/'),
'foo.' . WP_TESTS_DOMAIN . '/' => array( 'domain' => 'foo.' . WP_TESTS_DOMAIN, 'path' => '/' ),
'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ), 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),
'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
); );
foreach ( $network_ids as &$id ) { foreach ( self::$site_ids as &$id ) {
$id = self::factory()->network->create( $id ); $id = $factory->blog->create( $id );
} }
unset( $id ); unset( $id );
$ids = array(
'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/', 'title' => 'Test 1', 'site_id' => $network_ids['wordpress.org/'] ),
'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/', 'title' => 'Test 2', 'site_id' => $network_ids['wordpress.org/'] ),
'wordpress.org/foo/bar/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/', 'title' => 'Test 3', 'site_id' => $network_ids['wordpress.org/'] ),
'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/', 'title' => 'Test 4', 'site_id' => $network_ids['make.wordpress.org/'] ),
'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/', 'title' => 'Test 5', 'site_id' => $network_ids['make.wordpress.org/'] ),
);
foreach ( $ids as &$id ) {
$id = self::factory()->blog->create( $id );
} }
unset( $id );
// Retrieve site details by passing only a blog ID. public static function wpTearDownAfterClass() {
$site = get_blog_details( $ids['wordpress.org/'] ); foreach( self::$site_ids as $id ) {
$this->assertEquals( $ids['wordpress.org/'], $site->blog_id ); wpmu_delete_blog( $id, true );
$this->assertEquals( 'Test 1', $site->blogname ); }
$site = get_blog_details( $ids['wordpress.org/foo/'] ); wp_update_network_site_counts();
$this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id ); }
$this->assertEquals( 'Test 2', $site->blogname );
$site = get_blog_details( 999 ); public function test_get_blog_details_with_no_arguments_returns_current_site() {
$site = get_blog_details();
$this->assertEquals( get_current_blog_id(), $site->blog_id );
}
public function test_get_blog_details_with_site_name_string_subdirectory() {
if ( is_subdomain_install() ) {
$this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
}
$site = get_blog_details( 'foo' );
$this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/'], $site->blog_id );
}
public function test_get_blog_details_with_site_name_string_subdomain() {
if ( ! is_subdomain_install() ) {
$this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
}
$site = get_blog_details( 'foo' );
$this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
}
public function test_get_blog_details_with_invalid_site_name_string() {
$site = get_blog_details( 'invalid' );
$this->assertFalse( $site ); $this->assertFalse( $site );
}
// Retrieve site details by passing an array containing blog_id. public function test_get_blog_details_with_site_id_int() {
$site = get_blog_details( array( 'blog_id' => $ids['wordpress.org/foo/bar/'] ) ); $site = get_blog_details( self::$site_ids['wordpress.org/'] );
$this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id ); $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
$this->assertEquals( 'Test 3', $site->blogname ); }
$site = get_blog_details( array( 'blog_id' => $ids['make.wordpress.org/'] ) ); public function test_get_blog_details_with_invalid_site_id_int() {
$this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id ); $site = get_blog_details( 99999 );
$this->assertEquals( 'Test 4', $site->blogname );
$site = get_blog_details( array( 'blog_id' => 999 ) );
$this->assertFalse( $site ); $this->assertFalse( $site );
}
// Retrieve site details by passing an array containing domain and path. public function test_get_blog_details_with_blog_id_in_fields() {
$site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
$this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
}
public function test_get_blog_details_with_invalid_blog_id_in_fields() {
$site = get_blog_details( array( 'blog_id' => 88888 ) );
$this->assertFalse( $site );
}
public function test_get_blog_details_with_domain_and_path_in_fields() {
$site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ) ); $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
$this->assertEquals( $ids['wordpress.org/'], $site->blog_id ); $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
$this->assertEquals( 'Test 1', $site->blogname ); }
$site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
$this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id );
$this->assertEquals( 'Test 2', $site->blogname );
$site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/' ) );
$this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id );
$this->assertEquals( 'Test 3', $site->blogname );
$site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/' ) );
$this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id );
$this->assertEquals( 'Test 4', $site->blogname );
$site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ) );
$this->assertEquals( $ids['make.wordpress.org/foo/'], $site->blog_id );
$this->assertEquals( 'Test 5', $site->blogname );
public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
$site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) ); $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) );
$this->assertFalse( $site ); $this->assertFalse( $site );
} }
public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
$site = get_blog_details( array( 'domain' => 'invalid.org', 'path' => '/foo/' ) );
$this->assertFalse( $site );
}
public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
if ( ! is_subdomain_install() ) {
$this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
}
$site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
$this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
}
public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
if ( is_subdomain_install() ) {
$this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
}
$site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
$this->assertFalse( $site );
}
public function test_get_blog_details_with_only_path_in_fields() {
$site = get_blog_details( array( 'path' => '/foo/' ) );
$this->assertFalse( $site );
}
} }
endif; endif;