| 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() { |
| | 132 | function test_data_in_cache_after_wpmu_delete_blog_drop_false() { |
| | 133 | $blog_id = $this->factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo', 'title' => 'Site To Delete', 'site_id' => 1 ) ); |
| | 134 | |
| | 135 | $details = get_blog_details( $blog_id, false ); |
| | 136 | $key = md5( $details->domain . $details->path ); |
| | 137 | |
| | 138 | // Delete the site without forcing a table drop. |
| | 139 | wpmu_delete_blog( $blog_id, false ); |
| | 140 | |
| | 141 | $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| | 142 | $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); |
| | 143 | $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); |
| | 144 | $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); |
| | 145 | $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); |
| | 146 | } |
| | 147 | |
| | 148 | function test_data_in_tables_after_wpmu_delete_blog_drop_false() { |
| | 149 | global $wpdb; |
| | 150 | |
| | 151 | $blog_id = $this->factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo', 'title' => 'Site To Delete', 'site_id' => 1 ) ); |
| | 152 | |
| | 153 | // Delete the site without forcing a table drop. |
| | 154 | wpmu_delete_blog( $blog_id, false ); |
| | 155 | |
| | 156 | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
| | 157 | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| | 158 | $suppress = $wpdb->suppress_errors(); |
| | 159 | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| | 160 | $wpdb->suppress_errors( $suppress ); |
| | 161 | $this->assertNotEmpty( $table_fields, $prefix . $table ); |
| | 162 | } |
| | 163 | } |
| | 164 | |
| | 165 | function test_data_in_cache_after_wpmu_delete_blog_drop_true() { |
| | 166 | $blog_id = $this->factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo', 'title' => 'Site to Delete', 'site_id' => 1 ) ); |
| | 167 | |
| | 168 | $details = get_blog_details( $blog_id, false ); |
| | 169 | $key = md5( $details->domain . $details->path ); |
| | 170 | |
| | 171 | // Delete the site and force a table drop. |
| | 172 | wpmu_delete_blog( $blog_id, true ); |
| | 173 | |
| | 174 | $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| | 175 | $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); |
| | 176 | $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); |
| | 177 | $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); |
| | 178 | $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); |
| | 179 | } |
| | 180 | |
| | 181 | function test_data_in_tables_after_wpmu_delete_blog_drop_true() { |
| | 182 | global $wpdb; |
| | 183 | |
| | 184 | $blog_id = $this->factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo', 'title' => 'Site to Delete', 'site_id' => 1 ) ); |
| | 185 | |
| | 186 | // Delete the site and force a table drop. |
| | 187 | wpmu_delete_blog( $blog_id, true ); |
| | 188 | |
| | 189 | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
| | 190 | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| | 191 | $suppress = $wpdb->suppress_errors(); |
| | 192 | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| | 193 | $wpdb->suppress_errors( $suppress ); |
| | 194 | $this->assertEmpty( $table_fields ); |
| | 195 | } |
| | 196 | } |
| | 197 | |
| | 198 | function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() { |
| | 199 | $blog_id = 1; // The main site in our testing is ID 1. |
| | 200 | $this->factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo', 'title' => 'Site to Delete', 'site_id' => 1 ) ); |
| | 201 | |
| | 202 | $details = get_blog_details( $blog_id, false ); |
| | 203 | $key = md5( $details->domain . $details->path ); |
| | 204 | |
| | 205 | // Delete the site and force a table drop. |
| | 206 | wpmu_delete_blog( $blog_id, true ); |
| | 207 | |
| | 208 | $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| | 209 | $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); |
| | 210 | $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); |
| | 211 | $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); |
| | 212 | $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); |
| | 213 | } |
| | 214 | |
| | 215 | function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() { |
| 143 | | // Delete both sites, but keep the database tables for one. |
| 144 | | foreach ( $blog_ids as $blog_id ) { |
| 145 | | // drop tables for every second blog |
| 146 | | $drop_tables = ! $drop_tables; |
| 147 | | |
| 148 | | $details = get_blog_details( $blog_id, false ); |
| 149 | | |
| 150 | | wpmu_delete_blog( $blog_id, $drop_tables ); |
| 151 | | |
| 152 | | $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) ); |
| 153 | | $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); |
| 154 | | $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); |
| 155 | | $key = md5( $details->domain . $details->path ); |
| 156 | | $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); |
| 157 | | $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); |
| 158 | | |
| 159 | | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
| 160 | | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| 161 | | $suppress = $wpdb->suppress_errors(); |
| 162 | | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| 163 | | $wpdb->suppress_errors( $suppress ); |
| 164 | | if ( $drop_tables ) { |
| 165 | | $this->assertEmpty( $table_fields ); |
| 166 | | } else { |
| 167 | | $this->assertNotEmpty( $table_fields, $prefix . $table ); |
| 168 | | } |
| 169 | | } |
| | 224 | $prefix = $wpdb->get_blog_prefix( $blog_id ); |
| | 225 | foreach ( $wpdb->tables( 'blog', false ) as $table ) { |
| | 226 | $suppress = $wpdb->suppress_errors(); |
| | 227 | $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" ); |
| | 228 | $wpdb->suppress_errors( $suppress ); |
| | 229 | $this->assertNotEmpty( $table_fields, $prefix . $table ); |