Make WordPress Core

Changeset 37233


Ignore:
Timestamp:
04/18/2016 01:28:56 AM (9 years ago)
Author:
jeremyfelt
Message:

Tests: Improve get_blog_count() tests

  • Use wp_update_network_counts() to update the database with the most current data before testing.
  • Use wp_update_network_counts() to update the database with the most current data after deleting the sites created during the test.
  • Create only 1 extra site in each test rather than 4. This shaves several seconds off the test time.
  • Stop testing for an extra count now that we update the network counts properly. Previously we looked at $site_count_start + 9 rather than 8. Now this is + 1, which aligns with the actual number of sites created.
  • Test 3 explicit conditions - default, filter applied as true, and filter applied as false.
  • Reset data before testing assertion to avoid a suspended state.

See #36566.

File:
1 edited

Legend:

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

    r35242 r37233  
    8787     * @ticket 22917
    8888     */
    89     function test_enable_live_network_site_counts_filter() {
     89    public function test_get_blog_count_no_filter_applied() {
     90        wp_update_network_counts();
    9091        $site_count_start = get_blog_count();
    91         // false for large networks by default
    92         add_filter( 'enable_live_network_counts', '__return_false' );
    93         self::factory()->blog->create_many( 4 );
    94 
    95         // count only updated when cron runs, so unchanged
    96         $this->assertEquals( $site_count_start, (int) get_blog_count() );
    97 
    98         add_filter( 'enable_live_network_counts', '__return_true' );
    99         $site_ids = self::factory()->blog->create_many( 4 );
    100 
    101         $this->assertEquals( $site_count_start + 9, (int) get_blog_count() );
    102 
    103         //clean up
    104         remove_filter( 'enable_live_network_counts', '__return_false' );
    105         remove_filter( 'enable_live_network_counts', '__return_true' );
     92
     93        $site_ids = self::factory()->blog->create_many( 1 );
     94        $actual = (int) get_blog_count(); // count only updated when cron runs, so unchanged
     95
    10696        foreach ( $site_ids as $site_id ) {
    10797            wpmu_delete_blog( $site_id, true );
    10898        }
    109     }
     99        wp_update_network_counts();
     100
     101        $this->assertEquals( $site_count_start + 1, $actual );
     102    }
     103
     104    /**
     105     * @ticket 22917
     106     */
     107    public function test_get_blog_count_enable_live_network_counts_false() {
     108        wp_update_network_counts();
     109        $site_count_start = get_blog_count();
     110
     111        add_filter( 'enable_live_network_counts', '__return_false' );
     112        $site_ids = self::factory()->blog->create_many( 1 );
     113        $actual = (int) get_blog_count(); // count only updated when cron runs, so unchanged
     114        remove_filter( 'enable_live_network_counts', '__return_false' );
     115
     116        foreach ( $site_ids as $site_id ) {
     117            wpmu_delete_blog( $site_id, true );
     118        }
     119        wp_update_network_counts();
     120
     121        $this->assertEquals( $site_count_start, $actual );
     122    }
     123
     124    /**
     125     * @ticket 22917
     126     */
     127    public function test_get_blog_count_enabled_live_network_counts_true() {
     128        wp_update_network_counts();
     129        $site_count_start = get_blog_count();
     130
     131        add_filter( 'enable_live_network_counts', '__return_true' );
     132        $site_ids = self::factory()->blog->create_many( 1 );
     133        $actual = get_blog_count();
     134        remove_filter( 'enable_live_network_counts', '__return_true' );
     135
     136        foreach ( $site_ids as $site_id ) {
     137            wpmu_delete_blog( $site_id, true );
     138        }
     139        wp_update_network_counts();
     140
     141        $this->assertEquals( $site_count_start + 1, $actual );
     142    }
     143
    110144    /**
    111145     * @ticket 22917
Note: See TracChangeset for help on using the changeset viewer.