Make WordPress Core


Ignore:
Timestamp:
08/13/2017 12:56:24 AM (7 years ago)
Author:
westonruter
Message:

Customize: Prevent _delete_option_fresh_site() from hitting DB if fresh_site flag already cleared.

Amends [38991].
Props dlh, westonruter.
Fixes #41039.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r41243 r41244  
    171171        $this->assertContains( 'Invalid changeset UUID', $exception->getMessage() );
    172172
    173         update_option( 'fresh_site', 0 );
     173        update_option( 'fresh_site', '0' );
    174174        $wp_customize = new WP_Customize_Manager();
    175175        $wp_customize->setup_theme();
     
    177177
    178178        // Make sure that starter content import gets queued on a fresh site.
    179         update_option( 'fresh_site', 1 );
     179        update_option( 'fresh_site', '1' );
    180180        $wp_customize->setup_theme();
    181181        $this->assertEquals( 100, has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) );
     182    }
     183
     184    /**
     185     * Test that clearing a fresh site is a no-op if the site is already fresh.
     186     *
     187     * @see _delete_option_fresh_site()
     188     * @ticket 41039
     189     */
     190    function test_fresh_site_flag_clearing() {
     191        global $wp_customize, $wpdb;
     192
     193        // Make sure fresh site flag is cleared when publishing a changeset.
     194        update_option( 'fresh_site', '1' );
     195        do_action( 'customize_save_after', $wp_customize );
     196        $this->assertEquals( '0', get_option( 'fresh_site' ) );
     197
     198        // Simulate a new, uncached request.
     199        wp_cache_delete( 'alloptions', 'options' );
     200        wp_load_alloptions();
     201
     202        // Make sure no DB write is done when publishing and a site is already non-fresh.
     203        $query_count = $wpdb->num_queries;
     204        do_action( 'customize_save_after', $wp_customize );
     205        $this->assertSame( $query_count, $wpdb->num_queries );
    182206    }
    183207
Note: See TracChangeset for help on using the changeset viewer.