mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
See #47632. git-svn-id: https://develop.svn.wordpress.org/trunk@45588 602fd350-edb4-49c9-b593-d223f7449a82
175 lines
4.7 KiB
PHP
175 lines
4.7 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;
|
|
|
|
self::factory()->post->create_many( 3, 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 );
|
|
$time1 = wp_cache_get( 'last_changed', 'posts' );
|
|
$this->assertNotEmpty( $time1 );
|
|
$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 );
|
|
}
|
|
}
|