Make WordPress Core

Changeset 30719


Ignore:
Timestamp:
12/03/2014 05:51:33 AM (10 years ago)
Author:
jeremyfelt
Message:

Split tests for get_blog_id_from_url()

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

See #30080

File:
1 edited

Legend:

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

    r30715 r30719  
    883883     */
    884884    function test_get_blog_id_from_url() {
    885         $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    886         $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );
    887 
     885        $blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
    888886        $details = get_blog_details( $blog_id, false );
    889887        $key = md5( $details->domain . $details->path );
     
    892890        $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    893891        $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    894 
    895         // Test the case insensitivity of the site lookup.
    896         $this->assertEquals( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ) , strtoupper( $details->path ) ) );
    897 
    898         // Test the first and cached responses for a non existent site.
     892    }
     893
     894    /**
     895     * Test the case insensitivity of the site lookup.
     896     */
     897    function test_get_blog_id_from_url_is_case_insensitive() {
     898        $blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
     899        $details = get_blog_details( $blog_id, false );
     900
     901        $this->assertEquals( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ), strtoupper( $details->path ) ) );
     902    }
     903
     904    /**
     905     * Test the first and cached responses for a site that does not exist.
     906     */
     907    function test_get_blog_id_from_url_that_does_not_exist() {
     908        $blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
     909        $details = get_blog_details( $blog_id, false );
     910
    899911        $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
    900912        $this->assertEquals( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
    901 
    902         // A blog ID is still available if only the 'deleted' flag is set for a site.
     913    }
     914
     915    /**
     916     * A blog ID is still available if only the `deleted` flag is set for a site. The same
     917     * behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
     918     */
     919    function test_get_blog_id_from_url_with_deleted_flag() {
     920        $blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
     921        $details = get_blog_details( $blog_id, false );
     922        $key = md5( $details->domain . $details->path );
    903923        wpmu_delete_blog( $blog_id );
     924
    904925        $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    905926        $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    906 
    907         // Explicitly pass $drop = false (default), a blog ID will still be available.
    908         wpmu_delete_blog( $blog_id, false );
    909         $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    910         $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    911 
    912         // When deleted with the drop parameter at true, the cache will first be false, and then
    913         // set to -1 after an attempt at get_blog_id_from_url() is made.
     927    }
     928
     929    /**
     930     * When deleted with the drop parameter as true, the cache will first be false, then set to
     931     * -1 after an attempt at `get_blog_id_from_url()` is made.
     932     */
     933    function test_get_blog_id_from_url_after_dropped() {
     934        $blog_id = $this->factory->blog->create( array( 'path' => '/xyz', 'title' => 'Test Title' ) );
     935        $details = get_blog_details( $blog_id, false );
     936        $key = md5( $details->domain . $details->path );
    914937        wpmu_delete_blog( $blog_id, true );
     938
    915939        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    916940        $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );
Note: See TracChangeset for help on using the changeset viewer.