Changeset 30006
- Timestamp:
- 10/24/2014 04:50:57 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r29916 r30006 72 72 } 73 73 74 function test_create_and_delete_blog() { 74 /** 75 * Test the cache keys and database tables setup through the creation of a site. 76 */ 77 function test_created_site_details() { 75 78 global $wpdb; 76 79 77 $blog_ids = $this->factory->blog->create_many( 4 ); 78 foreach ( $blog_ids as $blog_id ) { 79 $this->assertInternalType( 'int', $blog_id ); 80 $prefix = $wpdb->get_blog_prefix( $blog_id ); 81 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' ) ); 89 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' ) ); 94 95 // These are empty until get_blog_details() is called with $get_all = true 96 $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); 97 $key = md5( $details->domain . $details->path ); 98 $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); 99 100 // $get_all = true should propulate the full blog-details cache and the blog slug lookup cache 101 $details = get_blog_details( $blog_id, true ); 102 $this->assertEquals( $details, wp_cache_get( $blog_id, 'blog-details' ) ); 103 $this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) ); 104 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 ); 80 $blog_id = $this->factory->blog->create(); 81 82 $this->assertInternalType( 'int', $blog_id ); 83 $prefix = $wpdb->get_blog_prefix( $blog_id ); 84 85 // $get_all = false, only retrieve details from the blogs table 86 $details = get_blog_details( $blog_id, false ); 87 88 // Combine domain and path for a site specific cache key. 89 $key = md5( $details->domain . $details->path ); 90 91 $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); 92 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 ); 115 124 } 116 125 } … … 118 127 // update the blog count cache to use get_blog_count() 119 128 wp_update_network_counts(); 120 $this->assertEquals( 4 + 1, (int) get_blog_count() ); 129 $this->assertEquals( 2, (int) get_blog_count() ); 130 } 131 132 /** 133 * Test the deletion of a site, including a case where database tables are 134 * intentionally not deleted. 135 */ 136 function test_wpmu_delete_blog() { 137 global $wpdb; 138 139 $blog_ids = $this->factory->blog->create_many( 2 ); 121 140 122 141 $drop_tables = false; 123 // delete all blogs 142 143 // Delete both sites, but keep the database tables for one. 124 144 foreach ( $blog_ids as $blog_id ) { 125 145 // drop tables for every second blog 126 146 $drop_tables = ! $drop_tables; 147 127 148 $details = get_blog_details( $blog_id, false ); 128 149 … … 141 162 $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); 142 163 $wpdb->suppress_errors( $suppress ); 143 if ( $drop_tables ) 164 if ( $drop_tables ) { 144 165 $this->assertEmpty( $table_fields ); 145 else166 } else { 146 167 $this->assertNotEmpty( $table_fields, $prefix . $table ); 168 } 147 169 } 148 170 } … … 163 185 $time_difference = $current_time - strtotime( $blog->last_updated ); 164 186 $this->assertLessThan( 2, $time_difference ); 165 }166 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 blog177 $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 } 187 188
Note: See TracChangeset
for help on using the changeset viewer.