mirror of
git://develop.git.wordpress.org/
synced 2025-01-29 10:38:22 +01:00
Multisite: Add specific tests for clean_blog_cache()
and refresh_blog_details()
.
See #40201. git-svn-id: https://develop.svn.wordpress.org/trunk@41715 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
260b9917d7
commit
2e051261f3
@ -1057,6 +1057,133 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
|
||||
public function test_is_main_site_different_network_random_site() {
|
||||
$this->assertFalse( is_main_site( self::$site_ids['make.wordpress.org/foo/'], self::$network_ids['make.wordpress.org/'] ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
* @dataProvider data_get_site_caches
|
||||
*/
|
||||
public function test_clean_blog_cache( $key, $group ) {
|
||||
$site = get_site( self::$site_ids['make.wordpress.org/'] );
|
||||
|
||||
$replacements = array(
|
||||
'%blog_id%' => $site->blog_id,
|
||||
'%domain%' => $site->domain,
|
||||
'%path%' => $site->path,
|
||||
'%domain_path_key%' => md5( $site->domain . $site->path ),
|
||||
);
|
||||
|
||||
$key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
|
||||
|
||||
if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
|
||||
wp_cache_set( $key, (object) $site->to_array(), $group );
|
||||
} else {
|
||||
wp_cache_set( $key, 'something', $group );
|
||||
}
|
||||
|
||||
clean_blog_cache( $site );
|
||||
$this->assertFalse( wp_cache_get( $key, $group ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
*/
|
||||
public function test_clean_blog_cache_resets_last_changed() {
|
||||
$site = get_site( self::$site_ids['make.wordpress.org/'] );
|
||||
|
||||
wp_cache_delete( 'last_changed', 'sites' );
|
||||
|
||||
clean_blog_cache( $site );
|
||||
$this->assertNotFalse( wp_cache_get( 'last_changed', 'sites' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
*/
|
||||
public function test_clean_blog_cache_fires_action() {
|
||||
$site = get_site( self::$site_ids['make.wordpress.org/'] );
|
||||
|
||||
$old_count = did_action( 'clean_site_cache' );
|
||||
|
||||
clean_blog_cache( $site );
|
||||
$this->assertEquals( $old_count + 1, did_action( 'clean_site_cache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
*/
|
||||
public function test_clean_blog_cache_bails_on_suspend_cache_invalidation() {
|
||||
$site = get_site( self::$site_ids['make.wordpress.org/'] );
|
||||
|
||||
$old_count = did_action( 'clean_site_cache' );
|
||||
|
||||
$suspend = wp_suspend_cache_invalidation();
|
||||
clean_blog_cache( $site );
|
||||
wp_suspend_cache_invalidation( $suspend );
|
||||
$this->assertEquals( $old_count, did_action( 'clean_site_cache' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
* @dataProvider data_get_site_caches
|
||||
*/
|
||||
public function test_refresh_blog_details( $key, $group ) {
|
||||
$site = get_site( self::$site_ids['make.wordpress.org/'] );
|
||||
|
||||
$replacements = array(
|
||||
'%blog_id%' => $site->blog_id,
|
||||
'%domain%' => $site->domain,
|
||||
'%path%' => $site->path,
|
||||
'%domain_path_key%' => md5( $site->domain . $site->path ),
|
||||
);
|
||||
|
||||
$key = str_replace( array_keys( $replacements ), array_values( $replacements ), $key );
|
||||
|
||||
if ( 'sites' === $group ) { // This needs to be actual data for get_site() lookups.
|
||||
wp_cache_set( $key, (object) $site->to_array(), $group );
|
||||
} else {
|
||||
wp_cache_set( $key, 'something', $group );
|
||||
}
|
||||
|
||||
refresh_blog_details( $site->blog_id );
|
||||
$this->assertFalse( wp_cache_get( $key, $group ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
*/
|
||||
public function test_refresh_blog_details_works_with_deleted_site() {
|
||||
$site_id = 12345;
|
||||
|
||||
wp_cache_set( $site_id, 'something', 'site-details' );
|
||||
|
||||
refresh_blog_details( $site_id );
|
||||
$this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40201
|
||||
*/
|
||||
public function test_refresh_blog_details_uses_current_site_as_default() {
|
||||
$site_id = get_current_blog_id();
|
||||
|
||||
wp_cache_set( $site_id, 'something', 'site-details' );
|
||||
|
||||
refresh_blog_details();
|
||||
$this->assertFalse( wp_cache_get( $site_id, 'site-details' ) );
|
||||
}
|
||||
|
||||
public function data_get_site_caches() {
|
||||
return array(
|
||||
array( '%blog_id%', 'sites' ),
|
||||
array( '%blog_id%', 'site-details' ),
|
||||
array( '%blog_id%', 'blog-details' ),
|
||||
array( '%blog_id%' . 'short' , 'blog-details' ),
|
||||
array( '%domain_path_key%', 'blog-lookup' ),
|
||||
array( '%domain_path_key%', 'blog-id-cache' ),
|
||||
array( 'current_blog_%domain%', 'site-options' ),
|
||||
array( 'current_blog_%domain%%path%', 'site-options' ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
Loading…
x
Reference in New Issue
Block a user