Make WordPress Core

Changeset 30106


Ignore:
Timestamp:
10/30/2014 01:59:02 AM (10 years ago)
Author:
jeremyfelt
Message:

Expand tests around wpmu_delete_blog()

  • Test cache after a site is deleted or flagged as deleted.
  • Test tables after a site is deleted or flagged as deleted.
  • Test tables and cache after the main site is deleted.
  • Test site count after a site is deleted or flagged as deleted.

See #30080

File:
1 edited

Legend:

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

    r30007 r30106  
    131131
    132132    /**
    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() {
     133     * When a site is flagged as 'deleted', its data should be cleared from cache.
     134     */
     135    function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
     136        $blog_id = $this->factory->blog->create();
     137
     138        $details = get_blog_details( $blog_id, false );
     139        $key = md5( $details->domain . $details->path );
     140
     141        // Delete the site without forcing a table drop.
     142        wpmu_delete_blog( $blog_id, false );
     143
     144        $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );
     145        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     146        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     147        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
     148        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
     149    }
     150
     151    /**
     152     * When a site is flagged as 'deleted', its data should remain in the database.
     153     */
     154    function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
    137155        global $wpdb;
    138156
    139         $blog_ids = $this->factory->blog->create_many( 2 );
    140 
    141         $drop_tables = false;
    142 
    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             }
     157        $blog_id = $this->factory->blog->create();
     158
     159        // Delete the site without forcing a table drop.
     160        wpmu_delete_blog( $blog_id, false );
     161
     162        $prefix = $wpdb->get_blog_prefix( $blog_id );
     163        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
     164            $suppress = $wpdb->suppress_errors();
     165            $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
     166            $wpdb->suppress_errors( $suppress );
     167            $this->assertNotEmpty( $table_fields, $prefix . $table );
    170168        }
     169    }
     170
     171    /**
     172     * When a site is fully deleted, its data should be cleared from cache.
     173     */
     174    function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
     175        $blog_id = $this->factory->blog->create();
     176
     177        $details = get_blog_details( $blog_id, false );
     178        $key = md5( $details->domain . $details->path );
     179
     180        // Delete the site and force a table drop.
     181        wpmu_delete_blog( $blog_id, true );
     182
     183        $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );
     184        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     185        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     186        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
     187        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
     188    }
     189
     190    /**
     191     * When a site is fully deleted, its data should be removed from the database.
     192     */
     193    function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
     194        global $wpdb;
     195
     196        $blog_id = $this->factory->blog->create();
     197
     198        // Delete the site and force a table drop.
     199        wpmu_delete_blog( $blog_id, true );
     200
     201        $prefix = $wpdb->get_blog_prefix( $blog_id );
     202        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
     203            $suppress = $wpdb->suppress_errors();
     204            $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
     205            $wpdb->suppress_errors( $suppress );
     206            $this->assertEmpty( $table_fields );
     207        }
     208    }
     209
     210    /**
     211     * When the main site of a network is fully deleted, its data should be cleared from cache.
     212     */
     213    function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
     214        $blog_id = 1; // The main site in our test suite has an ID of 1.
     215
     216        $details = get_blog_details( $blog_id, false );
     217        $key = md5( $details->domain . $details->path );
     218
     219        // Delete the site and force a table drop.
     220        wpmu_delete_blog( $blog_id, true );
     221
     222        $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );
     223        $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) );
     224        $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
     225        $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );
     226        $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );
     227    }
     228
     229    /**
     230     * When the main site of a network is fully deleted, its data should remain in the database.
     231     */
     232    function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
     233        global $wpdb;
     234
     235        $blog_id = 1; // The main site in our test suite has an ID of 1.
     236
     237        // Delete the site and force a table drop.
     238        wpmu_delete_blog( $blog_id, true );
     239
     240        $prefix = $wpdb->get_blog_prefix( $blog_id );
     241        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
     242            $suppress = $wpdb->suppress_errors();
     243            $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
     244            $wpdb->suppress_errors( $suppress );
     245            $this->assertNotEmpty( $table_fields, $prefix . $table );
     246        }
     247    }
     248
     249    /**
     250     * The site count of a network should change when a site is flagged as 'deleted'.
     251     */
     252    function test_network_count_after_wpmu_delete_blog_drop_false() {
     253        $blog_id = $this->factory->blog->create();
     254
     255        // Delete the site without forcing a table drop.
     256        wpmu_delete_blog( $blog_id, false );
     257
     258        // update the blog count cache to use get_blog_count()
     259        wp_update_network_counts();
     260        $this->assertEquals( 1, get_blog_count() );
     261    }
     262
     263    /**
     264     * The site count of a network should change when a site is fully deleted.
     265     */
     266    function test_blog_count_after_wpmu_delete_blog_drop_true() {
     267        $blog_id = $this->factory->blog->create();
     268
     269        // Delete the site and force a table drop.
     270        wpmu_delete_blog( $blog_id, true );
    171271
    172272        // update the blog count cache to use get_blog_count()
Note: See TracChangeset for help on using the changeset viewer.