WordPress.org

Make WordPress Core

Ticket #18387: 18387-ut.diff

File 18387-ut.diff, 3.0 KB (added by ryan, 6 years ago)

Unit tests

  • tests/cache.php

     
    2020
    2121        function &init_cache() {
    2222                $cache = new WP_Object_Cache();
    23                 $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
     23                $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
    2424                return $cache;
    2525        }
    2626
  • tests/ms.php

     
    2727                        $this->assertEquals( $blog_id, get_id_from_blogname( $details->path ) );
    2828                        $this->assertEquals( $blog_id, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );
    2929
     30                        // get_blog_id_from_url()
     31                        $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
     32                        $key = md5( $details->domain . $details->path );
     33                        $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
     34
    3035                        // These are empty until get_blog_details() is called with $get_all = true
    3136                        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
    3237                        $key = md5( $details->domain . $details->path );
     
    6873                        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
    6974                        $key = md5( $details->domain . $details->path );
    7075                        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
     76                        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
    7177
    7278                        $prefix = $wpdb->get_blog_prefix( $blog_id );
    7379                        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
     
    530536                wpmu_delete_blog( $blog_id, true );
    531537                $this->assertEquals( null, domain_exists( $details->domain, $details->path ) );
    532538        }
     539
     540        function test_get_blog_id_from_url() {
     541                $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     542                $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) );
     543       
     544                $details = get_blog_details( $blog_id, false );
     545
     546                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
     547                $key = md5( $details->domain . $details->path );
     548                $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );
     549
     550                $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) );
     551
     552                wpmu_delete_blog( $blog_id );
     553                $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) );
     554                wpmu_delete_blog( $blog_id, true );
     555
     556                $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
     557                $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );
     558        }
    533559}
    534560
    535561endif;