From 64f8351da1e10a41560c07e650bc0fc9a4228229 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 23 Apr 2017 21:57:31 +0000 Subject: [PATCH] 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 --- tests/phpunit/includes/testcase.php | 22 ++++++++++ tests/phpunit/tests/adminbar.php | 42 +++++------------- tests/phpunit/tests/customize/setting.php | 4 +- tests/phpunit/tests/functions.php | 13 +++--- tests/phpunit/tests/general/template.php | 32 ++++---------- tests/phpunit/tests/l10n/getLocale.php | 4 +- tests/phpunit/tests/link/getDashboardUrl.php | 8 +--- tests/phpunit/tests/oembed/controller.php | 4 +- tests/phpunit/tests/option/networkOption.php | 24 +++------- tests/phpunit/tests/option/siteTransient.php | 5 +-- .../tests/rest-api/rest-users-controller.php | 44 +++++-------------- tests/phpunit/tests/rewrite.php | 9 +--- tests/phpunit/tests/theme/WPTheme.php | 16 ++----- tests/phpunit/tests/user.php | 4 +- tests/phpunit/tests/user/capabilities.php | 33 ++++---------- tests/phpunit/tests/user/countUsers.php | 10 +---- tests/phpunit/tests/user/query.php | 40 +++++------------ .../tests/user/wpAuthenticateSpamCheck.php | 12 ++--- tests/phpunit/tests/user/wpDeleteUser.php | 8 +--- .../tests/user/wpGetUsersWithNoRole.php | 10 +---- 20 files changed, 106 insertions(+), 238 deletions(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 0f2bf7423f..95feba846c 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -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. * diff --git a/tests/phpunit/tests/adminbar.php b/tests/phpunit/tests/adminbar.php index 3c98a50aa3..a7cdbaf398 100644 --- a/tests/phpunit/tests/adminbar.php +++ b/tests/phpunit/tests/adminbar.php @@ -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' ); diff --git a/tests/phpunit/tests/customize/setting.php b/tests/phpunit/tests/customize/setting.php index a857b3d629..cb0cdf8296 100644 --- a/tests/phpunit/tests/customize/setting.php +++ b/tests/phpunit/tests/customize/setting.php @@ -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'; diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 9b6cf41526..8400720026 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -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'; diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index d6108d6dc6..3001c04eef 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -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 ); diff --git a/tests/phpunit/tests/l10n/getLocale.php b/tests/phpunit/tests/l10n/getLocale.php index f6032b3aaf..513bc92aac 100644 --- a/tests/phpunit/tests/l10n/getLocale.php +++ b/tests/phpunit/tests/l10n/getLocale.php @@ -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; diff --git a/tests/phpunit/tests/link/getDashboardUrl.php b/tests/phpunit/tests/link/getDashboardUrl.php index 0d1b1bd82c..07c2711ca3 100644 --- a/tests/phpunit/tests/link/getDashboardUrl.php +++ b/tests/phpunit/tests/link/getDashboardUrl.php @@ -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 ) ); diff --git a/tests/phpunit/tests/oembed/controller.php b/tests/phpunit/tests/oembed/controller.php index 25d613cad1..aa9b3418d7 100644 --- a/tests/phpunit/tests/oembed/controller.php +++ b/tests/phpunit/tests/oembed/controller.php @@ -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 ); diff --git a/tests/phpunit/tests/option/networkOption.php b/tests/phpunit/tests/option/networkOption.php index 496bb4733c..8aec0d7408 100644 --- a/tests/phpunit/tests/option/networkOption.php +++ b/tests/phpunit/tests/option/networkOption.php @@ -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' ); diff --git a/tests/phpunit/tests/option/siteTransient.php b/tests/phpunit/tests/option/siteTransient.php index 708712d838..d7da947285 100644 --- a/tests/phpunit/tests/option/siteTransient.php +++ b/tests/phpunit/tests/option/siteTransient.php @@ -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(); diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 9f26371547..062a90e770 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -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( diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index b0b1d551a5..e740f21b0a 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -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 ); diff --git a/tests/phpunit/tests/theme/WPTheme.php b/tests/phpunit/tests/theme/WPTheme.php index fc660f6201..b379d3b044 100644 --- a/tests/phpunit/tests/theme/WPTheme.php +++ b/tests/phpunit/tests/theme/WPTheme.php @@ -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' ); diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index 917cbc65d3..c36002c68f 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -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', diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 81ba7cd0ff..26051b5ff3 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -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 ) ); diff --git a/tests/phpunit/tests/user/countUsers.php b/tests/phpunit/tests/user/countUsers.php index 337ce1c707..9d5f63d050 100644 --- a/tests/phpunit/tests/user/countUsers.php +++ b/tests/phpunit/tests/user/countUsers.php @@ -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( diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index b9559686f3..5ac9a0b352 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -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' ); diff --git a/tests/phpunit/tests/user/wpAuthenticateSpamCheck.php b/tests/phpunit/tests/user/wpAuthenticateSpamCheck.php index 799e219856..7e3cd13c51 100644 --- a/tests/phpunit/tests/user/wpAuthenticateSpamCheck.php +++ b/tests/phpunit/tests/user/wpAuthenticateSpamCheck.php @@ -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 ); diff --git a/tests/phpunit/tests/user/wpDeleteUser.php b/tests/phpunit/tests/user/wpDeleteUser.php index b733f92bb0..ddcec2cd18 100644 --- a/tests/phpunit/tests/user/wpDeleteUser.php +++ b/tests/phpunit/tests/user/wpDeleteUser.php @@ -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 ) ); diff --git a/tests/phpunit/tests/user/wpGetUsersWithNoRole.php b/tests/phpunit/tests/user/wpGetUsersWithNoRole.php index 1a7535f623..3346f1869a 100644 --- a/tests/phpunit/tests/user/wpGetUsersWithNoRole.php +++ b/tests/phpunit/tests/user/wpGetUsersWithNoRole.php @@ -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(