Build/Test Tools: Introduce `skipWithoutMultisite()` and `skipWithMultisite`() methods into the test suite.

This brings much needed uniformity to test skipping when a test requires Multisite or when a test should be excluded from running when Multisite is enabled.

Used in conjunction with the `@group ms-required` and `@group ms-excluded` notation, this removes a significant number of skipped tests from the default test suite run.

Fixes #40531


git-svn-id: https://develop.svn.wordpress.org/trunk@40543 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-04-23 21:57:31 +00:00
parent e3a9d87083
commit 64f8351da1
20 changed files with 106 additions and 238 deletions

View File

@ -197,6 +197,28 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
}
}
/**
* Allow tests to be skipped when Multisite is not in use.
*
* Use in conjunction with the ms-required group.
*/
public function skipWithoutMultisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs on Multisite' );
}
}
/**
* Allow tests to be skipped when Multisite is in use.
*
* Use in conjunction with the ms-excluded group.
*/
public function skipWithMultisite() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run on Multisite' );
}
}
/**
* Unregister existing post types and register defaults.
*

View File

@ -75,9 +75,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$this->skipWithMultisite();
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
@ -104,9 +102,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_links_for_users_with_role() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$this->skipWithMultisite();
$this->assertTrue( user_can( self::$editor_id, 'read' ) );
@ -136,9 +132,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$blog_id = self::factory()->blog->create( array(
'user_id' => self::$admin_id,
@ -187,9 +181,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$this->assertTrue( user_can( self::$admin_id, 'read' ) );
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
@ -432,9 +424,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_role() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$this->skipWithMultisite();
wp_set_current_user( self::$editor_id );
@ -453,9 +443,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$this->skipWithMultisite();
wp_set_current_user( self::$no_role_id );
@ -476,9 +464,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
// User is not a member of a site.
remove_user_from_blog( self::$no_role_id, get_current_blog_id() );
@ -596,9 +582,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_my_sites_network_menu_for_regular_user() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
wp_set_current_user( self::$editor_id );
@ -615,9 +599,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_my_sites_network_menu_for_super_admin() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
wp_set_current_user( self::$editor_id );
@ -636,11 +618,9 @@ class Tests_AdminBar extends WP_UnitTestCase {
* @group ms-required
*/
public function test_my_sites_network_menu_for_regular_user_with_network_caps() {
global $current_user;
$this->skipWithoutMultisite();
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
global $current_user;
$network_user_caps = array( 'manage_network', 'manage_network_themes', 'manage_network_plugins' );

View File

@ -564,9 +564,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
* @group ms-required
*/
function test_previewing_with_switch_to_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Cannot test WP_Customize_Setting::is_current_blog_previewed() with switch_to_blog() if not on multisite.' );
}
$this->skipWithoutMultisite();
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
$type = 'option';

View File

@ -938,14 +938,12 @@ class Tests_Functions extends WP_UnitTestCase {
* @group ms-excluded
*/
function test_wp_check_filetype_and_ext_with_filtered_svg() {
$this->skipWithMultisite();
if ( ! extension_loaded( 'fileinfo' ) ) {
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
}
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$file = DIR_TESTDATA . '/uploads/video-play.svg';
$filename = 'video-play.svg';
@ -964,16 +962,15 @@ class Tests_Functions extends WP_UnitTestCase {
/**
* @ticket 39550
* @group ms-excluded
*/
function test_wp_check_filetype_and_ext_with_filtered_woff() {
$this->skipWithMultisite();
if ( ! extension_loaded( 'fileinfo' ) ) {
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
}
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run in multisite' );
}
$file = DIR_TESTDATA . '/uploads/dashicons.woff';
$filename = 'dashicons.woff';

View File

@ -75,9 +75,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
@ -93,9 +91,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
@ -269,9 +265,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
@ -287,9 +281,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
@ -319,9 +311,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
@ -542,9 +532,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_get_site_icon_url_preserves_switched_state() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
@ -565,9 +553,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_has_custom_logo_preserves_switched_state() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );
@ -588,9 +574,7 @@ class Tests_General_Template extends WP_UnitTestCase {
* @group ms-required
*/
function test_get_custom_logo_preserves_switched_state() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite.' );
}
$this->skipWithoutMultisite();
$blog_id = $this->factory->blog->create();
switch_to_blog( $blog_id );

View File

@ -21,9 +21,7 @@ class Tests_L10n_GetLocale extends WP_UnitTestCase {
* @group ms-required
*/
public function test_local_option_should_take_precedence_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires Multisite' );
}
$this->skipWithoutMultisite();
global $locale;
$old_locale = $locale;

View File

@ -41,9 +41,7 @@ class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
* @group ms-required
*/
public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite.' );
}
$this->skipWithoutMultisite();
grant_super_admin( self::$user_id );
@ -62,9 +60,7 @@ class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
* @group ms-required
*/
public function test_get_dashboard_url_for_administrator_of_different_site() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite.' );
}
$this->skipWithoutMultisite();
$site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );

View File

@ -256,9 +256,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
* @group ms-required
*/
function test_request_ms_child_in_root_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
}
$this->skipWithoutMultisite();
$child = self::factory()->blog->create();
switch_to_blog( $child );

View File

@ -16,9 +16,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
* @group ms-required
*/
function test_add_network_option_not_available_on_other_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
}
$this->skipWithoutMultisite();
$id = self::factory()->network->create();
$option = __FUNCTION__;
@ -32,9 +30,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
* @group ms-required
*/
function test_add_network_option_available_on_same_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
}
$this->skipWithoutMultisite();
$id = self::factory()->network->create();
$option = __FUNCTION__;
@ -48,9 +44,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
* @group ms-required
*/
function test_delete_network_option_on_only_one_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
}
$this->skipWithoutMultisite();
$id = self::factory()->network->create();
$option = __FUNCTION__;
@ -67,11 +61,9 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_add_network_option_is_not_stored_as_autoload_option() {
$key = __FUNCTION__;
$this->skipWithMultisite();
if ( is_multisite() ) {
$this->markTestSkipped( 'Does not apply when used in multisite.' );
}
$key = __FUNCTION__;
add_network_option( null, $key, 'Not an autoload option' );
@ -85,11 +77,9 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_update_network_option_is_not_stored_as_autoload_option() {
$key = __FUNCTION__;
$this->skipWithMultisite();
if ( is_multisite() ) {
$this->markTestSkipped( 'Does not apply when used in multisite.' );
}
$key = __FUNCTION__;
update_network_option( null, $key, 'Not an autoload option' );

View File

@ -47,11 +47,10 @@ class Tests_Option_SiteTransient extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_set_site_transient_is_not_stored_as_autoload_option() {
$this->skipWithMultisite();
$key = 'not_autoloaded';
if ( is_multisite() ) {
$this->markTestSkipped( 'Does not apply when used in multisite.' );
}
set_site_transient( $key, 'Not an autoload option' );
$options = wp_load_alloptions();

View File

@ -996,9 +996,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_create_new_network_user_on_site_does_not_add_user_to_sub_site() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite.' );
}
$this->skipWithoutMultisite();
$this->allow_user_to_manage_multisite();
@ -1028,9 +1026,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_create_new_network_user_on_sub_site_adds_user_to_site() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite.' );
}
$this->skipWithoutMultisite();
$this->allow_user_to_manage_multisite();
@ -1064,9 +1060,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_create_existing_network_user_on_sub_site_has_error() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite.' );
}
$this->skipWithoutMultisite();
$this->allow_user_to_manage_multisite();
@ -1454,9 +1448,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-excluded
*/
public function test_update_user_role_invalid_privilege_deescalation() {
if ( is_multisite() ) {
return $this->markTestSkipped( 'Test only intended for single site.' );
}
$this->skipWithMultisite();
$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
@ -1487,9 +1479,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_update_user_role_privilege_deescalation_multisite() {
if ( ! is_multisite() ) {
return $this->markTestSkipped( 'Test only intended for multisite.' );
}
$this->skipWithoutMultisite();
$user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
@ -2238,9 +2228,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_get_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(
@ -2260,9 +2248,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_get_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(
@ -2282,9 +2268,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_update_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(
@ -2306,9 +2290,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_update_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(
@ -2330,9 +2312,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_delete_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(
@ -2354,9 +2334,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
* @group ms-required
*/
public function test_delete_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
switch_to_blog( self::$site );
$user_id = $this->factory->user->create( array(

View File

@ -122,9 +122,7 @@ class Tests_Rewrite extends WP_UnitTestCase {
* @group ms-required
*/
function test_url_to_postid_of_http_site_when_current_site_uses_https() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite' );
}
$this->skipWithoutMultisite();
$_SERVER['HTTPS'] = 'on';
@ -319,10 +317,7 @@ class Tests_Rewrite extends WP_UnitTestCase {
* @group ms-required
*/
function test_url_to_postid_ms_home_url_collision() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'test_url_to_postid_ms_home_url_collision requires multisite' );
}
$this->skipWithoutMultisite();
$blog_id = self::factory()->blog->create( array( 'path' => '/example' ) );
switch_to_blog( $blog_id );

View File

@ -148,9 +148,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* @group ms-required
*/
function test_wp_theme_network_enable_single_theme() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite' );
}
$this->skipWithoutMultisite();
$theme = 'testtheme-1';
$current_allowed_themes = get_site_option( 'allowedthemes' );
@ -169,9 +167,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* @group ms-required
*/
function test_wp_theme_network_enable_multiple_themes() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite' );
}
$this->skipWithoutMultisite();
$themes = array( 'testtheme-2', 'testtheme-3' );
$current_allowed_themes = get_site_option( 'allowedthemes' );
@ -190,9 +186,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* @group ms-required
*/
function test_network_disable_single_theme() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite' );
}
$this->skipWithoutMultisite();
$current_allowed_themes = get_site_option( 'allowedthemes' );
@ -215,9 +209,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* @group ms-required
*/
function test_network_disable_multiple_themes() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test requires multisite' );
}
$this->skipWithoutMultisite();
$current_allowed_themes = get_site_option( 'allowedthemes' );

View File

@ -652,9 +652,7 @@ class Tests_User extends WP_UnitTestCase {
* @group ms-required
*/
function test_illegal_user_logins_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$user_data = array(
'user_login' => 'testuser',

View File

@ -615,9 +615,8 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
function test_super_admin_caps() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$caps = $this->getAllCapsAndRoles();
$user = self::$super_admin;
@ -1361,9 +1360,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
function test_borked_current_user_can_for_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$orig_blog_id = get_current_blog_id();
$blog_id = self::factory()->blog->create();
@ -1424,9 +1421,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
function test_multisite_administrator_can_not_edit_users() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$user = self::$users['administrator'];
$other_user = self::$users['subscriber'];
@ -1460,9 +1455,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
public function test_only_super_admins_can_delete_users_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs on multisite' );
}
$this->skipWithoutMultisite();
$this->assertTrue( user_can( self::$super_admin->ID, 'delete_user', self::$users['subscriber']->ID ) );
@ -1477,9 +1470,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_only_admins_can_delete_users_on_single_site() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run on multisite' );
}
$this->skipWithMultisite();
$this->assertTrue( user_can( self::$users['administrator']->ID, 'delete_user', self::$users['subscriber']->ID ) );
@ -1538,9 +1529,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
function test_multisite_administrator_with_manage_network_users_can_edit_users() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$user = self::$users['administrator'];
$user->add_cap( 'manage_network_users' );
@ -1559,9 +1548,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
function test_multisite_administrator_with_manage_network_users_can_not_edit_super_admin() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
}
$this->skipWithoutMultisite();
$user = self::$users['administrator'];
$user->add_cap( 'manage_network_users' );
@ -1783,9 +1770,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @group ms-required
*/
public function test_only_super_admins_can_remove_themselves_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite.' );
}
$this->skipWithoutMultisite();
$this->assertTrue( user_can( self::$super_admin->ID, 'remove_user', self::$super_admin->ID ) );

View File

@ -12,10 +12,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_count_users_is_accurate( $strategy ) {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run on multisite' );
}
$this->skipWithMultisite();
// Setup users
$admin = self::factory()->user->create( array(
@ -63,10 +60,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
* @dataProvider data_count_users_strategies
*/
public function test_count_users_multisite_is_accurate( $strategy ) {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
}
$this->skipWithoutMultisite();
// Setup users
$admin = self::factory()->user->create( array(

View File

@ -555,9 +555,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_blog_id_on_nonms() {
if ( is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' is a non-multisite-only test.' );
}
$this->skipWithMultisite();
$query = new WP_User_Query( array(
'include' => self::$author_ids[0],
@ -576,9 +574,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_current_blog_id_on_ms() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
}
$this->skipWithoutMultisite();
$query = new WP_User_Query( array(
'include' => self::$author_ids[0],
@ -597,9 +593,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all_with_meta() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
}
$this->skipWithoutMultisite();
$b = self::factory()->blog->create();
@ -624,9 +618,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
}
$this->skipWithoutMultisite();
$b = self::factory()->blog->create();
add_user_to_blog( $b, self::$author_ids[0], 'author' );
@ -650,9 +642,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_who_authors() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$b = self::factory()->blog->create();
@ -677,9 +667,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_who_authors_should_work_alongside_meta_query() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$b = self::factory()->blog->create();
@ -713,9 +701,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_who_authors_should_work_alongside_meta_params() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$b = self::factory()->blog->create();
@ -807,9 +793,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_has_published_posts_should_respect_blog_id() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$blogs = self::factory()->blog->create_many( 2 );
@ -1375,9 +1359,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_blog_id_should_restrict_by_blog_without_requiring_a_named_role() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite.' );
}
$this->skipWithoutMultisite();
$sites = self::factory()->blog->create_many( 2 );
@ -1398,9 +1380,7 @@ class Tests_User_Query extends WP_UnitTestCase {
* @group ms-required
*/
public function test_calling_prepare_query_a_second_time_should_not_add_another_cap_query_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires Multisite.' );
}
$this->skipWithoutMultisite();
$site_id = get_current_blog_id();
add_user_to_blog( $site_id, self::$author_ids[0], 'author' );

View File

@ -9,9 +9,7 @@ class Tests_User_WpAuthenticateSpamCheck extends WP_UnitTestCase {
* @group ms-excluded
*/
function test_wp_authenticate_spam_check_returns_user_when_single_site() {
if ( is_multisite() ) {
$this->markTestSkipped( 'This test applies to single site only.' );
}
$this->skipWithMultisite();
$user_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
$user = new WP_User( $user_id );
@ -25,9 +23,7 @@ class Tests_User_WpAuthenticateSpamCheck extends WP_UnitTestCase {
* @group ms-required
*/
function test_wp_authenticate_spam_check_returns_user_when_not_flagged() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test applies to multisite only.' );
}
$this->skipWithoutMultisite();
$user_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
$user = new WP_User( $user_id );
@ -41,9 +37,7 @@ class Tests_User_WpAuthenticateSpamCheck extends WP_UnitTestCase {
* @group ms-required
*/
function test_wp_authenticate_spam_check_returns_wp_error_when_flagged() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'This test applies to multisite only.' );
}
$this->skipWithoutMultisite();
$user_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
update_user_status( $user_id, 'spam', 1 );

View File

@ -127,9 +127,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_numeric_string_user_id() {
if ( is_multisite() ) {
$this->markTestSkipped( 'wp_delete_user() does not delete user records in Multisite.' );
}
$this->skipWithMultisite();
$u = self::factory()->user->create();
@ -150,9 +148,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_should_return_false_for_object_user_id() {
if ( is_multisite() ) {
$this->markTestSkipped( 'wp_delete_user() does not delete user records in Multisite.' );
}
$this->skipWithMultisite();
$u_obj = self::factory()->user->create_and_get();
$this->assertFalse( wp_delete_user( $u_obj ) );

View File

@ -10,10 +10,7 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase {
* @group ms-excluded
*/
public function test_get_users_with_no_role_is_accurate() {
if ( is_multisite() ) {
$this->markTestSkipped( 'Test does not run on multisite' );
}
$this->skipWithMultisite();
// Setup users
$admin = self::factory()->user->create( array(
@ -45,10 +42,7 @@ class Tests_User_GetUsersWithNoRole extends WP_UnitTestCase {
* @group ms-required
*/
public function test_get_users_with_no_role_multisite_is_accurate() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
}
$this->skipWithoutMultisite();
// Setup users
$admin = self::factory()->user->create( array(