wordpress-develop/tests/phpunit/tests/multisite/siteDetails.php
Jonathan Desrosiers e26394bb2d General: Remove “whitelist” and “blacklist” in favor of more clear and inclusive language.
“The WordPress open source community cares about diversity. We strive to maintain a welcoming environment where everyone can feel included.”

With this commit, all occurrences of “whitelist” and “blacklist” (with the single exception of the `$new_whitelist_options` global variable) are removed. A new ticket has been opened to explore renaming the `$new_whitelist_options` variable (#50434).

Changing to more specific names or rewording sentences containing these terms not only makes the code more inclusive, but also helps provide clarity. These terms are often ambiguous. What is being blocked or allowed is not always immediately clear. This can make it more difficult for non-native English speakers to read through the codebase.

Words matter. If one contributor feels more welcome because these terms are removed, this was worth the effort.

Props strangerstudios, jorbin, desrosj, joemcgill, timothyblynjacobs, ocean90, ayeshrajans, davidbaumwald, earnjam.
See #48900, #50434.
Fixes #50413.

git-svn-id: https://develop.svn.wordpress.org/trunk@48121 602fd350-edb4-49c9-b593-d223f7449a82
2020-06-22 17:24:34 +00:00

193 lines
5.2 KiB
PHP

<?php
if ( is_multisite() ) :
/**
* Test 'site_details' functionality.
*
* @group ms-site
* @group multisite
*/
class Tests_Multisite_Site_Details extends WP_UnitTestCase {
/**
* @dataProvider data_allowed_options
*
* @ticket 40063
*/
public function test_update_allowed_option_deletes_site_details_cache( $allowed_option, $temporary_value ) {
$site = get_site();
$original_value = $site->$allowed_option;
update_option( $allowed_option, $temporary_value );
$cached_result = wp_cache_get( $site->id, 'site-details' );
/* Reset to original value. */
update_option( $allowed_option, $original_value );
$this->assertFalse( $cached_result );
}
/**
* @dataProvider data_allowed_options
*
* @ticket 40063
*/
public function test_update_allowed_option_deletes_blog_details_cache( $allowed_option, $temporary_value ) {
$blog_details = get_blog_details();
$original_value = $blog_details->$allowed_option;
update_option( $allowed_option, $temporary_value );
$cached_result = wp_cache_get( $blog_details->id, 'blog-details' );
/* Reset to original value. */
update_option( $allowed_option, $original_value );
$this->assertFalse( $cached_result );
}
/**
* @dataProvider data_allowed_options
*
* @ticket 40063
*/
public function test_update_allowed_option_does_not_delete_site_cache( $allowed_option, $temporary_value ) {
$site = get_site();
$original_value = $site->$allowed_option;
update_option( $allowed_option, $temporary_value );
$cached_result = wp_cache_get( $site->id, 'sites' );
/* Reset to original value. */
update_option( $allowed_option, $original_value );
$this->assertNotFalse( $cached_result );
}
/**
* @dataProvider data_allowed_options
*
* @ticket 40063
*/
public function test_update_allowed_option_does_not_delete_short_blog_details_cache( $allowed_option, $temporary_value ) {
$blog_details = get_blog_details( null, false );
$original_value = get_option( $allowed_option );
update_option( $allowed_option, $temporary_value );
$cached_result = wp_cache_get( $blog_details->id . 'short', 'blog-details' );
/* Reset to original value. */
update_option( $allowed_option, $original_value );
$this->assertNotFalse( $cached_result );
}
/**
* @dataProvider data_allowed_options
*
* @ticket 40063
*/
public function test_update_allowed_option_does_not_update_sites_last_changed( $allowed_option, $temporary_value ) {
$last_changed = wp_cache_get_last_changed( 'sites' );
$original_value = get_option( $allowed_option );
update_option( $allowed_option, $temporary_value );
$new_last_changed = wp_cache_get_last_changed( 'sites' );
/* Reset to original value. */
update_option( $allowed_option, $original_value );
$this->assertSame( $new_last_changed, $last_changed );
}
public function data_allowed_options() {
return array(
array( 'blogname', 'Custom Site' ),
array( 'home', 'http://custom-site-url.org' ),
array( 'siteurl', 'http://custom-site-url.org' ),
array( 'post_count', '4' ),
);
}
/**
* @ticket 40063
*/
public function test_update_random_blog_option_does_not_delete_cache() {
$site = get_site();
update_option( 'foobar_option', 'foobar_value' );
$cached_result = wp_cache_get( $site->id, 'sites' );
delete_option( 'foobar_option' );
$this->assertNotFalse( $cached_result );
}
/**
* @ticket 40247
*/
public function test_site_details_cached_including_false_values() {
$id = self::factory()->blog->create();
$site = get_site( $id );
// Trigger retrieving site details (post_count is not set on new sites).
$post_count = $site->post_count;
$cached_details = wp_cache_get( $site->id, 'site-details' );
wp_delete_site( $id );
wp_update_network_site_counts();
$this->assertNotFalse( $cached_details );
}
public function test_site_details_filter_with_blogname() {
add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
$site = get_site();
$blogname = $site->blogname;
remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
$this->assertSame( 'Foo Bar', $blogname );
}
public function _filter_site_details_blogname( $details ) {
$details->blogname = 'Foo Bar';
return $details;
}
/**
* @ticket 40458
*/
public function test_site_details_filter_with_custom_value_isetter() {
add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
$site = get_site();
$custom_value_isset = isset( $site->custom_value );
remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
$this->assertTrue( $custom_value_isset );
}
/**
* @ticket 40458
*/
public function test_site_details_filter_with_custom_value_getter() {
add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
$site = get_site();
$custom_value = $site->custom_value;
remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
$this->assertSame( 'foo', $custom_value );
}
public function _filter_site_details_custom_value( $details ) {
$details->custom_value = 'foo';
return $details;
}
}
endif;