mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The introduction of a Customizer test that creates a new blog [31707] causes `WP_INSTALLING` to be set by the time the `wp_get_archives()` tests run. This, in turn, causes the query counts to vary in unpredictable ways. See #31130. git-svn-id: https://develop.svn.wordpress.org/trunk@31764 602fd350-edb4-49c9-b593-d223f7449a82
115 lines
4.6 KiB
PHP
115 lines
4.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group general
|
|
*/
|
|
class Tests_General_Archives extends WP_UnitTestCase {
|
|
function setUp() {
|
|
parent::setUp();
|
|
|
|
wp_cache_delete( 'last_changed', 'posts' );
|
|
}
|
|
|
|
/**
|
|
* @ticket 23206
|
|
*/
|
|
function test_get_archives_cache() {
|
|
global $wpdb;
|
|
|
|
if ( is_multisite() ) {
|
|
$this->markTestSkipped( 'Not testable in MS: wpmu_create_blog() defines WP_INSTALLING, which causes cache misses.' );
|
|
}
|
|
|
|
$this->factory->post->create_many( 15, array( 'post_type' => 'post' ) );
|
|
wp_cache_delete( 'last_changed', 'posts' );
|
|
$this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'monthly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertNotEmpty( $time1 = wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'monthly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
|
|
// Change args, resulting in a different query string. Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'monthly', 'echo' => false, 'order' => 'ASC' ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'monthly', 'echo' => false, 'order' => 'ASC' ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Change type. Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'yearly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'yearly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
|
|
// Change type. Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'daily', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'daily', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
|
|
// Change type. Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'weekly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'weekly', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
|
|
// Change type. Cache is not primed, expect 1 query.
|
|
$result = wp_get_archives( array( 'type' => 'postbypost', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries + 1, $wpdb->num_queries );
|
|
|
|
$num_queries = $wpdb->num_queries;
|
|
|
|
// Cache is primed, expect no queries.
|
|
$result = wp_get_archives( array( 'type' => 'postbypost', 'echo' => false ) );
|
|
$this->assertInternalType( 'string', $result );
|
|
$this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
|
$this->assertEquals( $num_queries, $wpdb->num_queries );
|
|
}
|
|
} |