Coding Standards: Add visibility to methods in tests/phpunit/tests/.

Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-11-04 15:22:47 +00:00
parent 80380cd374
commit 40ac5de838
327 changed files with 3656 additions and 3969 deletions
+2 -2
View File
@@ -123,7 +123,7 @@ if ( is_multisite() ) :
* @param string $path The requested path.
* @param string $message The message to pass for failed tests.
*/
function test_get_network_by_path( $expected_key, $domain, $path, $message ) {
public function test_get_network_by_path( $expected_key, $domain, $path, $message ) {
$network = get_network_by_path( $domain, $path );
$this->assertSame( self::$network_ids[ $expected_key ], $network->id, $message );
}
@@ -255,7 +255,7 @@ if ( is_multisite() ) :
* @param string $domain The requested domain.
* @param string $path The requested path.
*/
function test_multisite_bootstrap( $site_key, $network_key, $domain, $path ) {
public function test_multisite_bootstrap( $site_key, $network_key, $domain, $path ) {
global $current_blog;
$expected = array(
@@ -15,7 +15,7 @@ if ( is_multisite() ) :
*
* @ticket 19879
*/
function test_get_dirsize_cache_in_recurse_dirsize_mock() {
public function test_get_dirsize_cache_in_recurse_dirsize_mock() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -34,7 +34,7 @@ if ( is_multisite() ) :
delete_transient( 'dirsize_cache' );
// Set the dirsize cache to our mock.
set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
$upload_dir = wp_upload_dir();
@@ -64,7 +64,7 @@ if ( is_multisite() ) :
*
* @ticket 19879
*/
function test_clean_dirsize_cache_file_input_mock() {
public function test_clean_dirsize_cache_file_input_mock() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -86,7 +86,7 @@ if ( is_multisite() ) :
delete_transient( 'dirsize_cache' );
// Set the dirsize cache to our mock.
set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
$this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
$this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
@@ -112,7 +112,7 @@ if ( is_multisite() ) :
*
* @ticket 19879
*/
function test_clean_dirsize_cache_folder_input_mock() {
public function test_clean_dirsize_cache_folder_input_mock() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -134,7 +134,7 @@ if ( is_multisite() ) :
delete_transient( 'dirsize_cache' );
// Set the dirsize cache to our mock.
set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
$this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
$this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
@@ -160,7 +160,7 @@ if ( is_multisite() ) :
*
* @ticket 19879
*/
function test_get_dirsize_cache_in_recurse_dirsize_upload() {
public function test_get_dirsize_cache_in_recurse_dirsize_upload() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -206,20 +206,20 @@ if ( is_multisite() ) :
*
* @ticket 19879
*/
function test_pre_recurse_dirsize_filter() {
add_filter( 'pre_recurse_dirsize', array( $this, '_filter_pre_recurse_dirsize' ) );
public function test_pre_recurse_dirsize_filter() {
add_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
$upload_dir = wp_upload_dir();
$this->assertSame( 1042, recurse_dirsize( $upload_dir['path'] ) );
remove_filter( 'pre_recurse_dirsize', array( $this, '_filter_pre_recurse_dirsize' ) );
remove_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
}
function _filter_pre_recurse_dirsize() {
public function filter_pre_recurse_dirsize() {
return 1042;
}
function _get_mock_dirsize_cache_for_site( $site_id ) {
private function get_mock_dirsize_cache_for_site( $site_id ) {
$prefix = wp_upload_dir()['basedir'];
return array(
@@ -239,7 +239,7 @@ if ( is_multisite() ) :
*
* @ticket 51913
*/
function test_5_5_transient_structure_compat() {
public function test_5_5_transient_structure_compat() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -258,7 +258,7 @@ if ( is_multisite() ) :
delete_transient( 'dirsize_cache' );
// Set the dirsize cache to our mock.
set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) );
set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
$upload_dir = wp_upload_dir();
@@ -281,7 +281,7 @@ if ( is_multisite() ) :
delete_transient( 'dirsize_cache' );
// Set the dirsize cache to our mock.
set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) );
set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
/*
* Now that the folder exists, the old cached value should be overwritten
@@ -300,7 +300,7 @@ if ( is_multisite() ) :
restore_current_blog();
}
function _get_mock_5_5_dirsize_cache( $site_id ) {
private function get_mock_5_5_dirsize_cache( $site_id ) {
$prefix = untrailingslashit( wp_upload_dir()['basedir'] );
return array(
@@ -8,7 +8,7 @@ if ( is_multisite() ) :
*/
class Tests_Multisite_GetSpaceUsed extends WP_UnitTestCase {
function test_get_space_used_switched_site() {
public function test_get_space_used_switched_site() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -42,7 +42,7 @@ if ( is_multisite() ) :
* Directories of sub sites on a network should not count against the same spaced used total for
* the main site.
*/
function test_get_space_used_main_site() {
public function test_get_space_used_main_site() {
$space_used = get_space_used();
$blog_id = self::factory()->blog->create();
@@ -76,15 +76,15 @@ if ( is_multisite() ) :
restore_current_blog();
}
function test_get_space_used_pre_get_spaced_used_filter() {
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
public function test_get_space_used_pre_get_spaced_used_filter() {
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
$this->assertSame( 300, get_space_used() );
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used' ) );
}
function _filter_space_used() {
public function filter_space_used() {
return 300;
}
}
@@ -25,9 +25,9 @@ if ( is_multisite() ) :
delete_option( 'blog_upload_space' );
delete_site_option( 'blog_upload_space' );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$this->assertTrue( $available );
}
@@ -36,9 +36,9 @@ if ( is_multisite() ) :
update_site_option( 'blog_upload_space', 10 );
update_site_option( 'upload_space_check_disabled', true );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_large' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_large' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
$this->assertTrue( $available );
}
@@ -46,19 +46,19 @@ if ( is_multisite() ) :
public function test_is_upload_space_available_space_used_is_less_then_allowed() {
update_option( 'blog_upload_space', 350 );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$this->assertTrue( $available );
}
function test_is_upload_space_available_space_used_is_more_than_allowed() {
public function test_is_upload_space_available_space_used_is_more_than_allowed() {
update_option( 'blog_upload_space', 350 );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_large' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_large' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_large' ) );
$this->assertFalse( $available );
}
@@ -67,31 +67,31 @@ if ( is_multisite() ) :
* More comprehensive testing a 0 condition is handled in the tests
* for `get_space_allowed()`. We cover one scenario here.
*/
function test_is_upload_space_available_upload_space_0_defaults_to_100() {
public function test_is_upload_space_available_upload_space_0_defaults_to_100() {
update_option( 'blog_upload_space', 0 );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$this->assertFalse( $available );
}
function test_is_upload_space_available_upload_space_negative() {
public function test_is_upload_space_available_upload_space_negative() {
update_site_option( 'blog_upload_space', -1 );
add_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
add_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$available = is_upload_space_available();
remove_filter( 'pre_get_space_used', array( $this, '_filter_space_used_small' ) );
remove_filter( 'pre_get_space_used', array( $this, 'filter_space_used_small' ) );
$this->assertFalse( $available );
}
function _filter_space_used_large() {
public function filter_space_used_large() {
return 10000000;
}
function _filter_space_used_small() {
public function filter_space_used_small() {
return 10;
}
}
@@ -13,13 +13,13 @@ if ( is_multisite() ) :
*/
class Tests_Multisite_msFilesRewriting extends WP_UnitTestCase {
function set_up() {
public function set_up() {
parent::set_up();
update_site_option( 'ms_files_rewriting', 1 );
ms_upload_constants();
}
function test_switch_upload_dir() {
public function test_switch_upload_dir() {
$this->assertTrue( is_main_site() );
$site = get_current_site();
@@ -48,7 +48,7 @@ if ( is_multisite() ) :
* that site should be removed. When wpmu_delete_blog() is run a second time, nothing
* should change with upload directories.
*/
function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
public function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() {
$filename = __FUNCTION__ . '.jpg';
$contents = __FUNCTION__ . '_contents';
+22 -22
View File
@@ -14,7 +14,7 @@ if ( is_multisite() ) :
protected static $different_network_id;
protected static $different_site_ids = array();
function tear_down() {
public function tear_down() {
global $current_site;
$current_site->id = 1;
parent::tear_down();
@@ -67,7 +67,7 @@ if ( is_multisite() ) :
/**
* By default, only one network exists and has a network ID of 1.
*/
function test_get_main_network_id_default() {
public function test_get_main_network_id_default() {
$this->assertSame( 1, get_main_network_id() );
}
@@ -75,7 +75,7 @@ if ( is_multisite() ) :
* If a second network is created, network ID 1 should still be returned
* as the main network ID.
*/
function test_get_main_network_id_two_networks() {
public function test_get_main_network_id_two_networks() {
self::factory()->network->create();
$this->assertSame( 1, get_main_network_id() );
@@ -85,7 +85,7 @@ if ( is_multisite() ) :
* When the `$current_site` global is populated with another network, the
* main network should still return as 1.
*/
function test_get_main_network_id_after_network_switch() {
public function test_get_main_network_id_after_network_switch() {
global $current_site;
$id = self::factory()->network->create();
@@ -102,7 +102,7 @@ if ( is_multisite() ) :
* @todo In the future, we'll have a smarter way of deleting a network. For now,
* fake the process with UPDATE queries.
*/
function test_get_main_network_id_after_network_delete() {
public function test_get_main_network_id_after_network_delete() {
global $wpdb, $current_site;
$temp_id = self::$different_network_id + 1;
@@ -115,20 +115,20 @@ if ( is_multisite() ) :
$this->assertSame( self::$different_network_id, $main_network_id );
}
function test_get_main_network_id_filtered() {
add_filter( 'get_main_network_id', array( $this, '_get_main_network_id' ) );
public function test_get_main_network_id_filtered() {
add_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
$this->assertSame( 3, get_main_network_id() );
remove_filter( 'get_main_network_id', array( $this, '_get_main_network_id' ) );
remove_filter( 'get_main_network_id', array( $this, 'get_main_network_id' ) );
}
function _get_main_network_id() {
public function get_main_network_id() {
return 3;
}
/**
* @ticket 37050
*/
function test_wp_network_object_id_property_is_int() {
public function test_wp_network_object_id_property_is_int() {
$id = self::factory()->network->create();
$network = WP_Network::get_instance( $id );
@@ -225,7 +225,7 @@ if ( is_multisite() ) :
/**
* @ticket 22917
*/
function test_enable_live_network_user_counts_filter() {
public function test_enable_live_network_user_counts_filter() {
// False for large networks by default.
add_filter( 'enable_live_network_counts', '__return_false' );
@@ -254,7 +254,7 @@ if ( is_multisite() ) :
remove_filter( 'enable_live_network_counts', '__return_true' );
}
function test_active_network_plugins() {
public function test_active_network_plugins() {
$path = 'hello.php';
// Local activate, should be invisible for the network.
@@ -262,7 +262,7 @@ if ( is_multisite() ) :
$active_plugins = wp_get_active_network_plugins();
$this->assertSame( array(), $active_plugins );
add_action( 'deactivated_plugin', array( $this, '_helper_deactivate_hook' ) );
add_action( 'deactivated_plugin', array( $this, 'helper_deactivate_hook' ) );
// Activate the plugin sitewide.
activate_plugin( $path, '', true ); // Enable the plugin for all sites in the network.
@@ -285,7 +285,7 @@ if ( is_multisite() ) :
/**
* @ticket 28651
*/
function test_duplicate_network_active_plugin() {
public function test_duplicate_network_active_plugin() {
$path = 'hello.php';
$mock = new MockAction();
add_action( 'activate_' . $path, array( $mock, 'action' ) );
@@ -305,21 +305,21 @@ if ( is_multisite() ) :
remove_action( 'activate_' . $path, array( $mock, 'action' ) );
}
function test_is_plugin_active_for_network_true() {
public function test_is_plugin_active_for_network_true() {
activate_plugin( 'hello.php', '', true );
$this->assertTrue( is_plugin_active_for_network( 'hello.php' ) );
}
function test_is_plugin_active_for_network_false() {
public function test_is_plugin_active_for_network_false() {
deactivate_plugins( 'hello.php', false, true );
$this->assertFalse( is_plugin_active_for_network( 'hello.php' ) );
}
function _helper_deactivate_hook() {
public function helper_deactivate_hook() {
$this->plugin_hook_count++;
}
function test_get_user_count() {
public function test_get_user_count() {
// Refresh the cache.
wp_update_network_counts();
$start_count = get_user_count();
@@ -338,7 +338,7 @@ if ( is_multisite() ) :
remove_filter( 'enable_live_network_counts', '__return_false' );
}
function test_wp_schedule_update_network_counts() {
public function test_wp_schedule_update_network_counts() {
$this->assertFalse( wp_next_scheduled( 'update_network_counts' ) );
// We can't use wp_schedule_update_network_counts() because WP_INSTALLING is set.
@@ -350,7 +350,7 @@ if ( is_multisite() ) :
/**
* @expectedDeprecated get_dashboard_blog
*/
function test_get_dashboard_blog() {
public function test_get_dashboard_blog() {
// If there is no dashboard blog set, current blog is used.
$dashboard_blog = get_dashboard_blog();
$this->assertEquals( 1, $dashboard_blog->blog_id );
@@ -368,7 +368,7 @@ if ( is_multisite() ) :
/**
* @ticket 37528
*/
function test_wp_update_network_site_counts() {
public function test_wp_update_network_site_counts() {
update_network_option( null, 'blog_count', 40 );
$expected = get_sites(
@@ -390,7 +390,7 @@ if ( is_multisite() ) :
/**
* @ticket 37528
*/
function test_wp_update_network_site_counts_on_different_network() {
public function test_wp_update_network_site_counts_on_different_network() {
update_network_option( self::$different_network_id, 'blog_count', 40 );
wp_update_network_site_counts( self::$different_network_id );
+81 -81
View File
@@ -17,13 +17,13 @@ if ( is_multisite() ) :
protected static $site_ids;
protected static $uninitialized_site_id;
function set_up() {
public function set_up() {
global $wpdb;
parent::set_up();
$this->suppress = $wpdb->suppress_errors();
}
function tear_down() {
public function tear_down() {
global $wpdb;
$wpdb->suppress_errors( $this->suppress );
parent::tear_down();
@@ -88,7 +88,7 @@ if ( is_multisite() ) :
}
}
function test_switch_restore_blog() {
public function test_switch_restore_blog() {
global $_wp_switched_stack, $wpdb;
$this->assertSame( array(), $_wp_switched_stack );
@@ -136,7 +136,7 @@ if ( is_multisite() ) :
/**
* Test the cache keys and database tables setup through the creation of a site.
*/
function test_created_site_details() {
public function test_created_site_details() {
global $wpdb;
$blog_id = self::factory()->blog->create();
@@ -221,7 +221,7 @@ if ( is_multisite() ) :
/**
* When a site is flagged as 'deleted', its data should be cleared from cache.
*/
function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
public function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
$blog_id = self::factory()->blog->create();
$details = get_blog_details( $blog_id, false );
@@ -239,7 +239,7 @@ if ( is_multisite() ) :
/**
* When a site is flagged as 'deleted', its data should remain in the database.
*/
function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
public function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
global $wpdb;
$blog_id = self::factory()->blog->create();
@@ -262,7 +262,7 @@ if ( is_multisite() ) :
/**
* When a site is fully deleted, its data should be cleared from cache.
*/
function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
public function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
$blog_id = self::factory()->blog->create();
$details = get_blog_details( $blog_id, false );
@@ -280,7 +280,7 @@ if ( is_multisite() ) :
/**
* When a site is fully deleted, its data should be removed from the database.
*/
function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
public function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
global $wpdb;
$blog_id = self::factory()->blog->create();
@@ -303,7 +303,7 @@ if ( is_multisite() ) :
/**
* When the main site of a network is fully deleted, its data should be cleared from cache.
*/
function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
public function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
$blog_id = 1; // The main site in our test suite has an ID of 1.
$details = get_blog_details( $blog_id, false );
@@ -321,7 +321,7 @@ if ( is_multisite() ) :
/**
* When the main site of a network is fully deleted, its data should remain in the database.
*/
function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
public function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
global $wpdb;
$blog_id = 1; // The main site in our test suite has an ID of 1.
@@ -344,7 +344,7 @@ if ( is_multisite() ) :
/**
* The site count of a network should change when a site is flagged as 'deleted'.
*/
function test_network_count_after_wpmu_delete_blog_drop_false() {
public function test_network_count_after_wpmu_delete_blog_drop_false() {
$blog_id = self::factory()->blog->create();
// Delete the site without forcing a table drop.
@@ -358,7 +358,7 @@ if ( is_multisite() ) :
/**
* The site count of a network should change when a site is fully deleted.
*/
function test_blog_count_after_wpmu_delete_blog_drop_true() {
public function test_blog_count_after_wpmu_delete_blog_drop_true() {
$blog_id = self::factory()->blog->create();
// Delete the site and force a table drop.
@@ -374,7 +374,7 @@ if ( is_multisite() ) :
* that site should be removed. When wpmu_delete_blog() is run a second time, nothing
* should change with upload directories.
*/
function test_upload_directories_after_multiple_wpmu_delete_blog() {
public function test_upload_directories_after_multiple_wpmu_delete_blog() {
$filename = __FUNCTION__ . '.jpg';
$contents = __FUNCTION__ . '_contents';
@@ -400,7 +400,7 @@ if ( is_multisite() ) :
$this->assertFileDoesNotExist( $file2['file'] );
}
function test_wpmu_update_blogs_date() {
public function test_wpmu_update_blogs_date() {
global $wpdb;
wpmu_update_blogs_date();
@@ -415,7 +415,7 @@ if ( is_multisite() ) :
/**
* Provide a counter to determine that hooks are firing when intended.
*/
function _action_counter_cb() {
public function action_counter_cb() {
global $test_action_counter;
$test_action_counter++;
}
@@ -425,7 +425,7 @@ if ( is_multisite() ) :
*
* @ticket 23405
*/
function test_get_blog_details_when_site_does_not_exist() {
public function test_get_blog_details_when_site_does_not_exist() {
// Create an unused site so that we can then assume an invalid site ID.
$blog_id = self::factory()->blog->create();
$blog_id++;
@@ -451,7 +451,7 @@ if ( is_multisite() ) :
/**
* Updating a field returns the sme value that was passed.
*/
function test_update_blog_status() {
public function test_update_blog_status() {
$result = update_blog_status( 1, 'spam', 0 );
$this->assertSame( 0, $result );
}
@@ -459,19 +459,19 @@ if ( is_multisite() ) :
/**
* Updating an invalid field returns the same value that was passed.
*/
function test_update_blog_status_invalid_status() {
public function test_update_blog_status_invalid_status() {
$result = update_blog_status( 1, 'doesnotexist', 'invalid' );
$this->assertSame( 'invalid', $result );
}
function test_update_blog_status_make_ham_blog_action() {
public function test_update_blog_status_make_ham_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
update_blog_details( $blog_id, array( 'spam' => 1 ) );
add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'spam', 0 );
$blog = get_site( $blog_id );
@@ -485,10 +485,10 @@ if ( is_multisite() ) :
$this->assertSame( '0', $blog->spam );
$this->assertSame( 1, $test_action_counter );
remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_content_from_spam_blog_is_not_available() {
public function test_content_from_spam_blog_is_not_available() {
$spam_blog_id = self::factory()->blog->create();
switch_to_blog( $spam_blog_id );
$post_data = array(
@@ -518,13 +518,13 @@ if ( is_multisite() ) :
$this->assertStringNotContainsString( "src=\"{$spam_embed_url}#?", $content );
}
function test_update_blog_status_make_spam_blog_action() {
public function test_update_blog_status_make_spam_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'spam', 1 );
$blog = get_site( $blog_id );
@@ -538,16 +538,16 @@ if ( is_multisite() ) :
$this->assertSame( '1', $blog->spam );
$this->assertSame( 1, $test_action_counter );
remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_archive_blog_action() {
public function test_update_blog_status_archive_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'archived', 1 );
$blog = get_site( $blog_id );
@@ -561,17 +561,17 @@ if ( is_multisite() ) :
$this->assertSame( '1', $blog->archived );
$this->assertSame( 1, $test_action_counter );
remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_unarchive_blog_action() {
public function test_update_blog_status_unarchive_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
update_blog_details( $blog_id, array( 'archived' => 1 ) );
add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'archived', 0 );
$blog = get_site( $blog_id );
@@ -584,16 +584,16 @@ if ( is_multisite() ) :
$this->assertSame( '0', $blog->archived );
$this->assertSame( 1, $test_action_counter );
remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_make_delete_blog_action() {
public function test_update_blog_status_make_delete_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'deleted', 1 );
$blog = get_site( $blog_id );
@@ -607,17 +607,17 @@ if ( is_multisite() ) :
$this->assertSame( '1', $blog->deleted );
$this->assertSame( 1, $test_action_counter );
remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_make_undelete_blog_action() {
public function test_update_blog_status_make_undelete_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
update_blog_details( $blog_id, array( 'deleted' => 1 ) );
add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'deleted', 0 );
$blog = get_site( $blog_id );
@@ -631,16 +631,16 @@ if ( is_multisite() ) :
$this->assertSame( '0', $blog->deleted );
$this->assertSame( 1, $test_action_counter );
remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_mature_blog_action() {
public function test_update_blog_status_mature_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'mature', 1 );
$blog = get_site( $blog_id );
@@ -654,17 +654,17 @@ if ( is_multisite() ) :
$this->assertSame( '1', $blog->mature );
$this->assertSame( 1, $test_action_counter );
remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_unmature_blog_action() {
public function test_update_blog_status_unmature_blog_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
update_blog_details( $blog_id, array( 'mature' => 1 ) );
add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
add_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'mature', 0 );
$blog = get_site( $blog_id );
@@ -678,16 +678,16 @@ if ( is_multisite() ) :
$this->assertSame( '0', $blog->mature );
$this->assertSame( 1, $test_action_counter );
remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
}
function test_update_blog_status_update_blog_public_action() {
public function test_update_blog_status_update_blog_public_action() {
global $test_action_counter;
$test_action_counter = 0;
$blog_id = self::factory()->blog->create();
add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
add_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
update_blog_status( $blog_id, 'public', 0 );
$blog = get_site( $blog_id );
@@ -701,13 +701,13 @@ if ( is_multisite() ) :
$this->assertSame( '0', $blog->public );
$this->assertSame( 1, $test_action_counter );
remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
remove_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
}
/**
* @ticket 27952
*/
function test_posts_count() {
public function test_posts_count() {
self::factory()->post->create();
$post2 = self::factory()->post->create();
$this->assertSame( 2, get_site()->post_count );
@@ -719,7 +719,7 @@ if ( is_multisite() ) :
/**
* @ticket 26410
*/
function test_blog_details_cache_invalidation() {
public function test_blog_details_cache_invalidation() {
update_option( 'blogname', 'foo' );
$details = get_site( get_current_blog_id() );
$this->assertSame( 'foo', $details->blogname );
@@ -733,7 +733,7 @@ if ( is_multisite() ) :
* Test the original and cached responses for a created and then deleted site when
* the blog ID is requested through get_blog_id_from_url().
*/
function test_get_blog_id_from_url() {
public function test_get_blog_id_from_url() {
$blog_id = self::factory()->blog->create();
$details = get_site( $blog_id );
$key = md5( $details->domain . $details->path );
@@ -746,7 +746,7 @@ if ( is_multisite() ) :
/**
* Test the case insensitivity of the site lookup.
*/
function test_get_blog_id_from_url_is_case_insensitive() {
public function test_get_blog_id_from_url_is_case_insensitive() {
$blog_id = self::factory()->blog->create(
array(
'domain' => 'example.com',
@@ -761,7 +761,7 @@ if ( is_multisite() ) :
/**
* Test the first and cached responses for a site that does not exist.
*/
function test_get_blog_id_from_url_that_does_not_exist() {
public function test_get_blog_id_from_url_that_does_not_exist() {
$blog_id = self::factory()->blog->create( array( 'path' => '/xyz' ) );
$details = get_site( $blog_id );
@@ -773,7 +773,7 @@ if ( is_multisite() ) :
* A blog ID is still available if only the `deleted` flag is set for a site. The same
* behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
*/
function test_get_blog_id_from_url_with_deleted_flag() {
public function test_get_blog_id_from_url_with_deleted_flag() {
$blog_id = self::factory()->blog->create();
$details = get_site( $blog_id );
$key = md5( $details->domain . $details->path );
@@ -787,7 +787,7 @@ if ( is_multisite() ) :
* When deleted with the drop parameter as true, the cache will first be false, then set to
* -1 after an attempt at `get_blog_id_from_url()` is made.
*/
function test_get_blog_id_from_url_after_dropped() {
public function test_get_blog_id_from_url_after_dropped() {
$blog_id = self::factory()->blog->create();
$details = get_site( $blog_id );
$key = md5( $details->domain . $details->path );
@@ -801,7 +801,7 @@ if ( is_multisite() ) :
/**
* Test with default parameter of site_id as null.
*/
function test_is_main_site() {
public function test_is_main_site() {
$this->assertTrue( is_main_site() );
}
@@ -809,14 +809,14 @@ if ( is_multisite() ) :
* Test with a site id of get_current_blog_id(), which should be the same as the
* default parameter tested above.
*/
function test_current_blog_id_is_main_site() {
public function test_current_blog_id_is_main_site() {
$this->assertTrue( is_main_site( get_current_blog_id() ) );
}
/**
* Test with a site ID other than the main site to ensure a false response.
*/
function test_is_main_site_is_false_with_other_blog_id() {
public function test_is_main_site_is_false_with_other_blog_id() {
$blog_id = self::factory()->blog->create();
$this->assertFalse( is_main_site( $blog_id ) );
@@ -825,7 +825,7 @@ if ( is_multisite() ) :
/**
* Test with no passed ID after switching to another site ID.
*/
function test_is_main_site_is_false_after_switch_to_blog() {
public function test_is_main_site_is_false_after_switch_to_blog() {
$blog_id = self::factory()->blog->create();
switch_to_blog( $blog_id );
@@ -834,7 +834,7 @@ if ( is_multisite() ) :
restore_current_blog();
}
function test_switch_upload_dir() {
public function test_switch_upload_dir() {
$this->assertTrue( is_main_site() );
$site = get_current_site();
@@ -867,7 +867,7 @@ if ( is_multisite() ) :
* Test the primary purpose of get_blog_post(), to retrieve a post from
* another site on the network.
*/
function test_get_blog_post_from_another_site_on_network() {
public function test_get_blog_post_from_another_site_on_network() {
$blog_id = self::factory()->blog->create();
$post_id = self::factory()->post->create(); // Create a post on the primary site, ID 1.
$post = get_post( $post_id );
@@ -882,7 +882,7 @@ if ( is_multisite() ) :
/**
* If get_blog_post() is used on the same site, it should still work.
*/
function test_get_blog_post_from_same_site() {
public function test_get_blog_post_from_same_site() {
$post_id = self::factory()->post->create();
$this->assertEquals( get_blog_post( 1, $post_id ), get_post( $post_id ) );
@@ -891,7 +891,7 @@ if ( is_multisite() ) :
/**
* A null response should be returned if an invalid post is requested.
*/
function test_get_blog_post_invalid_returns_null() {
public function test_get_blog_post_invalid_returns_null() {
$this->assertNull( get_blog_post( 1, 999999 ) );
}
@@ -899,7 +899,7 @@ if ( is_multisite() ) :
* Added as a callback to the domain_exists filter to provide manual results for
* the testing of the filter and for a test which does not need the database.
*/
function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
public function domain_exists_cb( $exists, $domain, $path, $site_id ) {
if ( 'foo' === $domain && 'bar/' === $path ) {
return 1234;
} else {
@@ -907,13 +907,13 @@ if ( is_multisite() ) :
}
}
function test_domain_exists_with_default_site_id() {
public function test_domain_exists_with_default_site_id() {
$details = get_site( 1 );
$this->assertSame( 1, domain_exists( $details->domain, $details->path ) );
}
function test_domain_exists_with_specified_site_id() {
public function test_domain_exists_with_specified_site_id() {
$details = get_site( 1 );
$this->assertSame( 1, domain_exists( $details->domain, $details->path, $details->site_id ) );
@@ -923,20 +923,20 @@ if ( is_multisite() ) :
* When the domain is valid, but the resulting site does not belong to the specified network,
* it is marked as not existing.
*/
function test_domain_does_not_exist_with_invalid_site_id() {
public function test_domain_does_not_exist_with_invalid_site_id() {
$details = get_site( 1 );
$this->assertNull( domain_exists( $details->domain, $details->path, 999 ) );
}
function test_invalid_domain_does_not_exist_with_default_site_id() {
public function test_invalid_domain_does_not_exist_with_default_site_id() {
$this->assertNull( domain_exists( 'foo', 'bar' ) );
}
function test_domain_filtered_to_exist() {
add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
public function test_domain_filtered_to_exist() {
add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
$exists = domain_exists( 'foo', 'bar' );
remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
$this->assertSame( 1234, $exists );
}
@@ -944,11 +944,11 @@ if ( is_multisite() ) :
* When a path is passed to domain_exists, it is immediately trailing slashed. A path
* value with or without the slash should result in the same return value.
*/
function test_slashed_path_in_domain_exists() {
add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
public function test_slashed_path_in_domain_exists() {
add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
$exists1 = domain_exists( 'foo', 'bar' );
$exists2 = domain_exists( 'foo', 'bar/' );
remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
// Make sure the same result is returned with or without a trailing slash.
$this->assertSame( $exists1, $exists2 );
@@ -957,7 +957,7 @@ if ( is_multisite() ) :
/**
* Tests returning an address for a given valid ID.
*/
function test_get_blogaddress_by_id_with_valid_id() {
public function test_get_blogaddress_by_id_with_valid_id() {
$blogaddress = get_blogaddress_by_id( 1 );
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/', $blogaddress );
}
@@ -965,7 +965,7 @@ if ( is_multisite() ) :
/**
* Tests returning the appropriate response for a invalid id given.
*/
function test_get_blogaddress_by_id_with_invalid_id() {
public function test_get_blogaddress_by_id_with_invalid_id() {
$blogaddress = get_blogaddress_by_id( 42 );
$this->assertSame( '', $blogaddress );
}
@@ -973,7 +973,7 @@ if ( is_multisite() ) :
/**
* @ticket 14867
*/
function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
$blog = self::factory()->blog->create();
$this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
@@ -986,7 +986,7 @@ if ( is_multisite() ) :
/**
* @ticket 14867
*/
function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
$blog = self::factory()->blog->create();
$this->assertFalse( is_ssl() );
@@ -1005,7 +1005,7 @@ if ( is_multisite() ) :
* @ticket 33620
* @dataProvider data_new_blog_url_schemes
*/
function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
public function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
$current_site = get_current_site();
$home = get_option( 'home' );
@@ -1031,7 +1031,7 @@ if ( is_multisite() ) :
$this->assertSame( $siteurl_scheme, parse_url( get_blog_option( $new, 'siteurl' ), PHP_URL_SCHEME ) );
}
function data_new_blog_url_schemes() {
public function data_new_blog_url_schemes() {
return array(
array(
'https',
@@ -1064,7 +1064,7 @@ if ( is_multisite() ) :
/**
* @ticket 36918
*/
function test_new_blog_locale() {
public function test_new_blog_locale() {
$current_site = get_current_site();
add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
@@ -1099,7 +1099,7 @@ if ( is_multisite() ) :
/**
* @ticket 40503
*/
function test_different_network_language() {
public function test_different_network_language() {
$network = get_network( self::$network_ids['make.wordpress.org/'] );
add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
@@ -1120,7 +1120,7 @@ if ( is_multisite() ) :
* @param string $original_value The original value passed to the function.
* @return string The orginal value.
*/
function filter_allow_unavailable_languages( $value, $option, $original_value ) {
public function filter_allow_unavailable_languages( $value, $option, $original_value ) {
return $original_value;
}
@@ -11,7 +11,7 @@ if ( is_multisite() ) :
* If `update_blog_details()` is called with any kind of empty arguments, it
* should return false.
*/
function test_update_blog_details_with_empty_args() {
public function test_update_blog_details_with_empty_args() {
$result = update_blog_details( 1, array() );
$this->assertFalse( $result );
}
@@ -19,12 +19,12 @@ if ( is_multisite() ) :
/**
* If the ID passed is not that of a current site, we should expect false.
*/
function test_update_blog_details_invalid_blog_id() {
public function test_update_blog_details_invalid_blog_id() {
$result = update_blog_details( 999, array( 'domain' => 'example.com' ) );
$this->assertFalse( $result );
}
function test_update_blog_details() {
public function test_update_blog_details() {
$blog_id = self::factory()->blog->create();
$result = update_blog_details(
@@ -66,7 +66,7 @@ if ( is_multisite() ) :
update_blog_details( $blog_id, array( $flag => '1' ) );
}
add_action( $hook, array( $this, '_action_counter_cb' ), 10 );
add_action( $hook, array( $this, 'action_counter_cb' ), 10 );
update_blog_details( $blog_id, array( $flag => $flag_value ) );
$blog = get_site( $blog_id );
@@ -82,7 +82,7 @@ if ( is_multisite() ) :
// The hook attached to this flag should not have fired again.
$this->assertSame( 1, $test_action_counter );
remove_action( $hook, array( $this, '_action_counter_cb' ), 10 );
remove_action( $hook, array( $this, 'action_counter_cb' ), 10 );
}
public function data_flag_hooks() {
@@ -101,7 +101,7 @@ if ( is_multisite() ) :
/**
* Provide a counter to determine that hooks are firing when intended.
*/
function _action_counter_cb() {
public function action_counter_cb() {
global $test_action_counter;
$test_action_counter++;
}
@@ -14,7 +14,7 @@ if ( is_multisite() ) :
*/
public $table = false;
function set_up() {
public function set_up() {
parent::set_up();
$this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) );
}