| 82 | | // $get_all = false |
| 83 | | $details = get_blog_details( $blog_id, false ); |
| 84 | | $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); |
| 85 | | |
| 86 | | // get_id_from_blogname(), see #20950 |
| 87 | | $this->assertEquals( $blog_id, get_id_from_blogname( $details->path ) ); |
| 88 | | $this->assertEquals( $blog_id, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| | 82 | $this->assertInternalType( 'int', $blog_id ); |
| | 83 | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
| 90 | | // get_blog_id_from_url() |
| 91 | | $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); |
| 92 | | $key = md5( $details->domain . $details->path ); |
| 93 | | $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) ); |
| | 85 | // $get_all = false, only retrieve details from the blogs table |
| | 86 | $details = get_blog_details( $blog_id, false ); |
| 105 | | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| 106 | | $suppress = $wpdb->suppress_errors(); |
| 107 | | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| 108 | | $wpdb->suppress_errors( $suppress ); |
| 109 | | $this->assertNotEmpty( $table_fields ); |
| 110 | | $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" ); |
| 111 | | if ( 'commentmeta' == $table || 'links' == $table ) |
| 112 | | $this->assertEmpty( $result ); |
| 113 | | else |
| 114 | | $this->assertNotEmpty( $result ); |
| | 93 | // get_id_from_blogname(), see #20950 |
| | 94 | $this->assertEquals( $blog_id, get_id_from_blogname( $details->path ) ); |
| | 95 | $this->assertEquals( $blog_id, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| | 96 | |
| | 97 | // get_blogaddress_by_name() |
| | 98 | $this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) ); |
| | 99 | |
| | 100 | // These are empty until get_blog_details() is called with $get_all = true |
| | 101 | $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); |
| | 102 | $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); |
| | 103 | |
| | 104 | // $get_all = true, populate the full blog-details cache and the blog slug lookup cache |
| | 105 | $details = get_blog_details( $blog_id, true ); |
| | 106 | $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) ); |
| | 107 | $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) ); |
| | 108 | |
| | 109 | // Check existence of each database table for the created site. |
| | 110 | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| | 111 | $suppress = $wpdb->suppress_errors(); |
| | 112 | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| | 113 | $wpdb->suppress_errors( $suppress ); |
| | 114 | |
| | 115 | // The table should exist. |
| | 116 | $this->assertNotEmpty( $table_fields ); |
| | 117 | |
| | 118 | // And the table should not be empty, unless commentmeta or links. |
| | 119 | $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" ); |
| | 120 | if ( 'commentmeta' == $table || 'links' == $table ) { |
| | 121 | $this->assertEmpty( $result ); |
| | 122 | } else { |
| | 123 | $this->assertNotEmpty( $result ); |
| 167 | | function test_getters(){ |
| 168 | | global $current_site; |
| 169 | | |
| 170 | | $blog_id = get_current_blog_id(); |
| 171 | | $blog = get_blog_details( $blog_id ); |
| 172 | | $this->assertEquals( $blog_id, $blog->blog_id ); |
| 173 | | $this->assertEquals( $current_site->domain, $blog->domain ); |
| 174 | | $this->assertEquals( '/', $blog->path ); |
| 175 | | |
| 176 | | // Test defaulting to current blog |
| 177 | | $this->assertEquals( $blog, get_blog_details() ); |
| 178 | | |
| 179 | | $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); |
| 180 | | $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogname', 'title' => 'Test Title' ) ); |
| 181 | | $this->assertInternalType( 'int', $blog_id ); |
| 182 | | |
| 183 | | $this->assertEquals( 'http://' . $current_site->domain . $current_site->path . 'test_blogname/', get_blogaddress_by_name('test_blogname') ); |
| 184 | | |
| 185 | | $this->assertEquals( $blog_id, get_id_from_blogname('test_blogname') ); |
| 186 | | } |
| 187 | | |