Make WordPress Core

Changeset 30175


Ignore:
Timestamp:
11/02/2014 01:04:47 AM (10 years ago)
Author:
jeremyfelt
Message:

Improve layout of test for cached invalid, then valid site details

  • Rename method to test_get_blog_details_when_site_does_not_exist().
  • Always assume MAX(blog_id) is 1 and therefore always create a burner.
  • Remove tests specific to wpmu_delete_blog() and cache, to be handled elsewhere.
  • Remove extra asertions.

See #30080, #23405

File:
1 edited

Legend:

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

    r30174 r30175  
    445445
    446446    /**
    447      * Test fetching a blog that doesn't exist and again after it exists.
     447     * Test cached data for a site that does not exist and then again after it exists.
    448448     *
    449449     * @ticket 23405
    450450     */
    451     function test_get_blog_details_blog_does_not_exist() {
    452         global $wpdb;
    453 
    454         $blog_id = $wpdb->get_var( "SELECT MAX(blog_id) FROM $wpdb->blogs" );
    455 
    456         // An idosyncrancy of the unit tests is that the max blog_id gets reset
    457         // to 1 in between test cases but picks up where it previously left off
    458         // on the next insert. If 1 is reported, burn a blog create to get
    459         // the max counter back in sync.
    460         if ( 1 == $blog_id ) {
    461             $blog_id = $this->factory->blog->create();
    462         }
     451    function test_get_blog_details_when_site_does_not_exist() {
     452        // Create an unused site so that we can then assume an invalid site ID.
     453        $blog_id = $this->factory->blog->create();
    463454        $blog_id++;
    464455
    465         $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
    466         $this->assertFalse( get_blog_details( $blog_id ) );
     456        // Prime the cache for an invalid site.
     457        get_blog_details( $blog_id );
     458
     459        // When the cache is primed with an invalid site, the value is set to -1.
    467460        $this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
    468         $this->assertFalse( get_blog_details( $blog_id ) );
    469         $this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
    470 
    471         $this->assertEquals( $blog_id, $this->factory->blog->create() );
     461
     462        // Create a site in the invalid site's place.
     463        $this->factory->blog->create();
     464
     465        // When a new site is created, its cache is cleared through refresh_blog_details.
    472466        $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' )  );
    473467
    474468        $blog = get_blog_details( $blog_id );
    475         $this->assertEquals( $blog_id, $blog->blog_id );
     469
     470        // When the cache is refreshed, it should now equal the site data.
    476471        $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
    477 
    478         wpmu_delete_blog( $blog_id );
    479         $this->assertFalse( wp_cache_get( $blog_id, 'blog-details' ) );
    480         $blog->deleted = '1';
    481         $this->assertEQuals( $blog, get_blog_details( $blog_id ) );
    482         $this->assertEquals( $blog, wp_cache_get( $blog_id, 'blog-details' ) );
    483 
    484         wpmu_delete_blog( $blog_id, true );
    485         $this->assertFalse( get_blog_details( $blog_id ) );
    486         $this->assertEquals( -1, wp_cache_get( $blog_id, 'blog-details' ) );
    487472    }
    488473
Note: See TracChangeset for help on using the changeset viewer.