Make WordPress Core

Changeset 37666


Ignore:
Timestamp:
06/09/2016 03:57:37 PM (9 years ago)
Author:
jeremyfelt
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/getBlogDetails.php

    r37665 r37666  
    44
    55/**
     6 * @ticket 29845
    67 * @group ms-site
    78 * @group multisite
    89 */
    910class Tests_Multisite_Get_Blog_Details extends WP_UnitTestCase {
    10     /**
    11      * @ticket 29845
    12      */
    13     public function test_get_blog_details() {
    14         $network_ids = array(
    15             'wordpress.org/'         => array( 'domain' => 'wordpress.org', 'path' => '/' ),
    16             'make.wordpress.org/'    => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
     11    protected static $network_ids;
     12    protected static $site_ids;
     13
     14    public static function wpSetUpBeforeClass( $factory ) {
     15        self::$site_ids = array(
     16            WP_TESTS_DOMAIN . '/foo/'      => array( 'domain' => WP_TESTS_DOMAIN,          'path' => '/foo/'),
     17            'foo.' . WP_TESTS_DOMAIN . '/' => array( 'domain' => 'foo.' . WP_TESTS_DOMAIN, 'path' => '/' ),
     18            'wordpress.org/'               => array( 'domain' => 'wordpress.org',          'path' => '/' ),
    1719        );
    1820
    19         foreach ( $network_ids as &$id ) {
    20             $id = self::factory()->network->create( $id );
     21        foreach ( self::$site_ids as &$id ) {
     22            $id = $factory->blog->create( $id );
    2123        }
    2224        unset( $id );
     25    }
    2326
    24         $ids = array(
    25             'wordpress.org/'              => array( 'domain' => 'wordpress.org',      'path' => '/',         'title' => 'Test 1', 'site_id' => $network_ids['wordpress.org/'] ),
    26             'wordpress.org/foo/'          => array( 'domain' => 'wordpress.org',      'path' => '/foo/',     'title' => 'Test 2', 'site_id' => $network_ids['wordpress.org/'] ),
    27             'wordpress.org/foo/bar/'      => array( 'domain' => 'wordpress.org',      'path' => '/foo/bar/', 'title' => 'Test 3', 'site_id' => $network_ids['wordpress.org/'] ),
    28             'make.wordpress.org/'         => array( 'domain' => 'make.wordpress.org', 'path' => '/',         'title' => 'Test 4', 'site_id' => $network_ids['make.wordpress.org/'] ),
    29             'make.wordpress.org/foo/'     => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/',     'title' => 'Test 5', 'site_id' => $network_ids['make.wordpress.org/'] ),
    30         );
     27    public static function wpTearDownAfterClass() {
     28        foreach( self::$site_ids as $id ) {
     29            wpmu_delete_blog( $id, true );
     30        }
    3131
    32         foreach ( $ids as &$id ) {
    33             $id = self::factory()->blog->create( $id );
     32        wp_update_network_site_counts();
     33    }
     34
     35    public function test_get_blog_details_with_no_arguments_returns_current_site() {
     36        $site = get_blog_details();
     37        $this->assertEquals( get_current_blog_id(), $site->blog_id );
     38    }
     39
     40    public function test_get_blog_details_with_site_name_string_subdirectory() {
     41        if ( is_subdomain_install() ) {
     42            $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
    3443        }
    35         unset( $id );
    3644
    37         // Retrieve site details by passing only a blog ID.
    38         $site = get_blog_details( $ids['wordpress.org/'] );
    39         $this->assertEquals( $ids['wordpress.org/'], $site->blog_id );
    40         $this->assertEquals( 'Test 1', $site->blogname );
     45        $site = get_blog_details( 'foo' );
     46        $this->assertEquals( self::$site_ids[ WP_TESTS_DOMAIN . '/foo/'], $site->blog_id );
     47    }
    4148
    42         $site = get_blog_details( $ids['wordpress.org/foo/'] );
    43         $this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id );
    44         $this->assertEquals( 'Test 2', $site->blogname );
     49    public function test_get_blog_details_with_site_name_string_subdomain() {
     50        if ( ! is_subdomain_install() ) {
     51            $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
     52        }
    4553
    46         $site = get_blog_details( 999 );
     54        $site = get_blog_details( 'foo' );
     55        $this->assertEquals( self::$site_ids[ 'foo.' . WP_TESTS_DOMAIN . '/' ], $site->blog_id );
     56    }
     57
     58    public function test_get_blog_details_with_invalid_site_name_string() {
     59        $site = get_blog_details( 'invalid' );
    4760        $this->assertFalse( $site );
     61    }
    4862
    49         // Retrieve site details by passing an array containing blog_id.
    50         $site = get_blog_details( array( 'blog_id' => $ids['wordpress.org/foo/bar/'] ) );
    51         $this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id );
    52         $this->assertEquals( 'Test 3', $site->blogname );
     63    public function test_get_blog_details_with_site_id_int() {
     64        $site = get_blog_details( self::$site_ids['wordpress.org/'] );
     65        $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     66    }
    5367
    54         $site = get_blog_details( array( 'blog_id' => $ids['make.wordpress.org/'] ) );
    55         $this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id );
    56         $this->assertEquals( 'Test 4', $site->blogname );
     68    public function test_get_blog_details_with_invalid_site_id_int() {
     69        $site = get_blog_details( 99999 );
     70        $this->assertFalse( $site );
     71    }
    5772
    58         $site = get_blog_details( array( 'blog_id' => 999 ) );
     73    public function test_get_blog_details_with_blog_id_in_fields() {
     74        $site = get_blog_details( array( 'blog_id' => self::$site_ids['wordpress.org/'] ) );
     75        $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     76    }
     77
     78    public function test_get_blog_details_with_invalid_blog_id_in_fields() {
     79        $site = get_blog_details( array( 'blog_id' => 88888 ) );
    5980        $this->assertFalse( $site );
     81    }
    6082
    61         // Retrieve site details by passing an array containing domain and path.
     83    public function test_get_blog_details_with_domain_and_path_in_fields() {
    6284        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
    63         $this->assertEquals( $ids['wordpress.org/'], $site->blog_id );
    64         $this->assertEquals( 'Test 1', $site->blogname );
     85        $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     86    }
    6587
    66         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
    67         $this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id );
    68         $this->assertEquals( 'Test 2', $site->blogname );
     88    public function test_get_blog_details_with_domain_and_invalid_path_in_fields() {
     89        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) );
     90        $this->assertFalse( $site );
     91    }
    6992
    70         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/' ) );
    71         $this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id );
    72         $this->assertEquals( 'Test 3', $site->blogname );
     93    public function test_get_blog_details_with_path_and_invalid_domain_in_fields() {
     94        $site = get_blog_details( array( 'domain' => 'invalid.org', 'path' => '/foo/' ) );
     95        $this->assertFalse( $site );
     96    }
    7397
    74         $site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/' ) );
    75         $this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id );
    76         $this->assertEquals( 'Test 4', $site->blogname );
     98    public function test_get_blog_details_with_only_domain_in_fields_subdomain() {
     99        if ( ! is_subdomain_install() ) {
     100            $this->markTestSkipped( 'This test is only valid in a subdomain configuration.' );
     101        }
    77102
    78         $site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ) );
    79         $this->assertEquals( $ids['make.wordpress.org/foo/'], $site->blog_id );
    80         $this->assertEquals( 'Test 5', $site->blogname );
     103        $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
     104        $this->assertEquals( self::$site_ids['wordpress.org/'], $site->blog_id );
     105    }
    81106
    82         $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) );
     107    public function test_get_blog_details_with_only_domain_in_fields_subdirectory() {
     108        if ( is_subdomain_install() ) {
     109            $this->markTestSkipped( 'This test is only valid in a subdirectory configuration.' );
     110        }
     111
     112        $site = get_blog_details( array( 'domain' => 'wordpress.org' ) );
     113        $this->assertFalse( $site );
     114    }
     115
     116    public function test_get_blog_details_with_only_path_in_fields() {
     117        $site = get_blog_details( array( 'path' => '/foo/' ) );
    83118        $this->assertFalse( $site );
    84119    }
Note: See TracChangeset for help on using the changeset viewer.