Make WordPress Core

Changeset 30007


Ignore:
Timestamp:
10/24/2014 05:30:14 AM (12 years ago)
Author:
jeremyfelt
Message:

Improve tests for get_blog_id_from_url()

Expand tests to cover additional cache and lookup scenarios. Explicitly test the reaction of get_blog_id_from_url() when $drop = false is passed to wpmu_delete_blog(). See #30080

Fixes #30088

File:
1 edited

Legend:

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

    r30006 r30007  
    734734        }
    735735
     736        /**
     737         * Test the original and cached responses for a created and then deleted site when
     738         * the blog ID is requested through get_blog_id_from_url().
     739         */
    736740        function test_get_blog_id_from_url() {
    737741                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
    … …  
    739743
    740744                $details = get_blog_details( $blog_id, false );
    741 
     745                $key = md5( $details->domain . $details->path );
     746
     747                // Test the original response and cached response for the newly created site.
    742748                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
    743                 $key = md5( $details->domain . $details->path );
    744749                $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
    745750
     751                // Test the case insensitivity of the site lookup.
     752                $this->assertEquals( $blog_id, get_blog_id_from_url( strtoupper( $details->domain ) , strtoupper( $details->path ) ) );
     753
     754                // Test the first and cached responses for a non existent site.
    746755                $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
    747 
     756                $this->assertEquals( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );
     757
     758                // A blog ID is still available if only the 'deleted' flag is set for a site.
    748759                wpmu_delete_blog( $blog_id );
    749760                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
     761                $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
     762
     763                // Explicitly pass $drop = false (default), a blog ID will still be available.
     764                wpmu_delete_blog( $blog_id, false );
     765                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
     766                $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
     767
     768                // When deleted with the drop parameter at true, the cache will first be false, and then
     769                // set to -1 after an attempt at get_blog_id_from_url() is made.
    750770                wpmu_delete_blog( $blog_id, true );
    751 
    752771                $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    753772                $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );
     773                $this->assertEquals( -1, wp_cache_get( $key, 'blog-id-cache' ) );
    754774        }
    755775
Note: See TracChangeset for help on using the changeset viewer.