WordPress.org

Make WordPress Core

Changeset 30114


Ignore:
Timestamp:
10/30/2014 05:43:31 AM (6 years ago)
Author:
jeremyfelt
Message:

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

File:
1 edited

Legend:

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

    r30106 r30114  
    10151015    }
    10161016
     1017    /**
     1018     * Added as a callback to the domain_exists filter to provide manual results for
     1019     * the testing of the filter and for a test which does not need the database.
     1020     */
    10171021    function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
    10181022        if ( 'foo' == $domain && 'bar/' == $path )
     
    10221026    }
    10231027
    1024     function test_domain_exists() {
    1025         $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    1026         $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );
    1027 
    1028         $details = get_blog_details( $blog_id, false );
    1029 
    1030         $this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
    1031         $this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path, $details->site_id ) );
     1028    function test_domain_exists_with_default_site_id() {
     1029        $details = get_blog_details( 1, false );
     1030
     1031        $this->assertEquals( 1, domain_exists( $details->domain, $details->path ) );
     1032    }
     1033
     1034    function test_domain_exists_with_specified_site_id() {
     1035        $details = get_blog_details( 1, false );
     1036
     1037        $this->assertEquals( 1, domain_exists( $details->domain, $details->path, $details->site_id ) );
     1038    }
     1039
     1040    /**
     1041     * When the domain is valid, but the resulting site does not belong to the specified network,
     1042     * it is marked as not existing.
     1043     */
     1044    function test_domain_does_not_exist_with_invalid_site_id() {
     1045        $details = get_blog_details( 1, false );
     1046
    10321047        $this->assertEquals( null, domain_exists( $details->domain, $details->path, 999 ) );
     1048    }
     1049
     1050    function test_invalid_domain_does_not_exist_with_default_site_id() {
    10331051        $this->assertEquals( null, domain_exists( 'foo', 'bar' ) );
    1034 
     1052    }
     1053
     1054    function test_domain_filtered_to_exist() {
    10351055        add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     1056
    10361057        $this->assertEquals( 1234, domain_exists( 'foo', 'bar' ) );
    1037         $this->assertEquals( null, domain_exists( 'foo', 'baz' ) );
    1038         $this->assertEquals( null, domain_exists( 'bar', 'foo' ) );
     1058
     1059        remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     1060    }
     1061
     1062    /**
     1063     * When a path is passed to domain_exists, it is immediately trailing slashed. A path
     1064     * value with or without the slash should result in the same return value.
     1065     */
     1066    function test_slashed_path_in_domain_exists() {
     1067        add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
    10391068
    10401069        // Make sure the same result is returned with or without a trailing slash
     
    10421071
    10431072        remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
    1044         $this->assertEquals( null, domain_exists( 'foo', 'bar' ) );
    1045 
    1046         wpmu_delete_blog( $blog_id );
    1047         $this->assertEquals( $blog_id, domain_exists( $details->domain, $details->path ) );
    1048         wpmu_delete_blog( $blog_id, true );
    1049         $this->assertEquals( null, domain_exists( $details->domain, $details->path ) );
    10501073    }
    10511074}
Note: See TracChangeset for help on using the changeset viewer.