Build/Test Tools: Introduce `ms-required` and `ms-excluded` groups for tests.

Tests in the `ms-excluded` group are now excluded when running tests with multisite enabled, and tests in the `ms-required` group are excluded when running tests without multisite enabled. The end result is a significantly reduced number of skipped tests polluting PHPUnit's output, which means verbose mode can be used to more easily see which tests are skipped or incomplete, and why.

See #40531


git-svn-id: https://develop.svn.wordpress.org/trunk@40520 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-04-22 18:58:46 +00:00
parent c717bfbba9
commit 4f8057f7d5
20 changed files with 131 additions and 8 deletions

View File

@ -23,6 +23,7 @@
<exclude>
<group>ajax</group>
<group>ms-files</group>
<group>ms-required</group>
<group>external-http</group>
</exclude>
</groups>

View File

@ -24,6 +24,7 @@
<exclude>
<group>ajax</group>
<group>ms-files</group>
<group>ms-excluded</group>
<group>external-http</group>
<group>oembed-headers</group>
</exclude>

View File

@ -72,6 +72,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 25162
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role() {
if ( is_multisite() ) {
@ -100,6 +101,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 25162
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_links_for_users_with_role() {
if ( is_multisite() ) {
@ -131,6 +133,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 25162
* @group multisite
* @group ms-required
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_blog() {
if ( ! is_multisite() ) {
@ -181,6 +184,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 25162
* @group multisite
* @group ms-required
*/
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_network() {
if ( ! is_multisite() ) {
@ -425,6 +429,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 37949
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_role() {
if ( is_multisite() ) {
@ -445,6 +450,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 37949
* @group ms-excluded
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role() {
if ( is_multisite() ) {
@ -467,6 +473,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 37949
* @group multisite
* @group ms-required
*/
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() {
if ( ! is_multisite() ) {
@ -586,6 +593,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 39082
* @group ms-required
*/
public function test_my_sites_network_menu_for_regular_user() {
if ( ! is_multisite() ) {
@ -604,6 +612,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 39082
* @group ms-required
*/
public function test_my_sites_network_menu_for_super_admin() {
if ( ! is_multisite() ) {
@ -624,6 +633,7 @@ class Tests_AdminBar extends WP_UnitTestCase {
/**
* @ticket 39082
* @group ms-required
*/
public function test_my_sites_network_menu_for_regular_user_with_network_caps() {
global $current_user;

View File

@ -561,6 +561,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
*
* @ticket 31428
* @group multisite
* @group ms-required
*/
function test_previewing_with_switch_to_blog() {
if ( ! is_multisite() ) {

View File

@ -72,6 +72,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @group site_icon
* @group multisite
* @group ms-required
*/
function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
if ( ! is_multisite() ) {
@ -89,6 +90,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @group site_icon
* @group multisite
* @group ms-required
*/
function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
if ( ! is_multisite() ) {
@ -264,6 +266,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @group custom_logo
* @group multisite
* @group ms-required
*/
function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
if ( ! is_multisite() ) {
@ -281,6 +284,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @group custom_logo
* @group multisite
* @group ms-required
*/
function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
if ( ! is_multisite() ) {
@ -312,6 +316,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @group custom_logo
* @group multisite
* @group ms-required
*/
function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
if ( ! is_multisite() ) {
@ -534,6 +539,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @ticket 38253
* @group ms-required
*/
function test_get_site_icon_url_preserves_switched_state() {
if ( ! is_multisite() ) {
@ -556,6 +562,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @ticket 38253
* @group ms-required
*/
function test_has_custom_logo_preserves_switched_state() {
if ( ! is_multisite() ) {
@ -578,6 +585,7 @@ class Tests_General_Template extends WP_UnitTestCase {
/**
* @ticket 38253
* @group ms-required
*/
function test_get_custom_logo_preserves_switched_state() {
if ( ! is_multisite() ) {

View File

@ -17,6 +17,9 @@ class Tests_L10n_GetLocale extends WP_UnitTestCase {
$this->assertSame( 'foo', $found );
}
/**
* @group ms-required
*/
public function test_local_option_should_take_precedence_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires Multisite' );
@ -35,6 +38,9 @@ class Tests_L10n_GetLocale extends WP_UnitTestCase {
$this->assertSame( 'en_GB', $found );
}
/**
* @group ms-required
*/
public function test_network_option_should_be_fallback_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires Multisite' );
@ -52,6 +58,9 @@ class Tests_L10n_GetLocale extends WP_UnitTestCase {
$this->assertSame( 'es_ES', $found );
}
/**
* @group ms-excluded
*/
public function test_option_should_be_respected_on_nonmultisite() {
if ( is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' does not apply to Multisite' );

View File

@ -66,6 +66,9 @@ class Tests_Get_User_Locale extends WP_UnitTestCase {
$this->assertSame( 'en_US', get_locale() );
}
/**
* @group ms-required
*/
public function test_user_locale_is_same_across_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( __METHOD__ . ' requires multisite' );

View File

@ -38,6 +38,7 @@ class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
/**
* @ticket 39065
* @group ms-required
*/
public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
if ( ! is_multisite() ) {
@ -58,6 +59,7 @@ class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
/**
* @ticket 39065
* @group ms-required
*/
public function test_get_dashboard_url_for_administrator_of_different_site() {
if ( ! is_multisite() ) {

View File

@ -253,6 +253,7 @@ class Test_oEmbed_Controller extends WP_UnitTestCase {
/**
* @group multisite
* @group ms-required
*/
function test_request_ms_child_in_root_blog() {
if ( ! is_multisite() ) {

View File

@ -11,6 +11,10 @@
* @group multisite
*/
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' );
@ -24,6 +28,9 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
$this->assertFalse( get_network_option( $id, $option, false ) );
}
/**
* @group ms-required
*/
function test_add_network_option_available_on_same_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
@ -37,6 +44,9 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
$this->assertEquals( $value, get_network_option( $id, $option, false ) );
}
/**
* @group ms-required
*/
function test_delete_network_option_on_only_one_network() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite' );
@ -54,6 +64,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
/**
* @ticket 22846
* @group ms-excluded
*/
public function test_add_network_option_is_not_stored_as_autoload_option() {
$key = __FUNCTION__;
@ -71,6 +82,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
/**
* @ticket 22846
* @group ms-excluded
*/
public function test_update_network_option_is_not_stored_as_autoload_option() {
$key = __FUNCTION__;

View File

@ -44,6 +44,7 @@ class Tests_Option_SiteTransient extends WP_UnitTestCase {
/**
* @ticket 22846
* @group ms-excluded
*/
public function test_set_site_transient_is_not_stored_as_autoload_option() {
$key = 'not_autoloaded';

View File

@ -992,6 +992,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertEquals( 'Sorry, that username is not allowed.', $errors['username'] );
}
/**
* @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.' );
@ -1021,6 +1024,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertFalse( $user_is_member );
}
/**
* @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.' );
@ -1054,6 +1060,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertTrue( $user_is_member );
}
/**
* @group ms-required
*/
public function test_create_existing_network_user_on_sub_site_has_error() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test requires multisite.' );
@ -1441,6 +1450,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertArrayNotHasKey( 'administrator', $user->caps );
}
/**
* @group ms-excluded
*/
public function test_update_user_role_invalid_privilege_deescalation() {
if ( is_multisite() ) {
return $this->markTestSkipped( 'Test only intended for single site.' );
@ -1471,6 +1483,9 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
$this->assertArrayNotHasKey( 'editor', $user->caps );
}
/**
* @group ms-required
*/
public function test_update_user_role_privilege_deescalation_multisite() {
if ( ! is_multisite() ) {
return $this->markTestSkipped( 'Test only intended for multisite.' );
@ -2220,6 +2235,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_get_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
@ -2241,6 +2257,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_get_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {
@ -2262,6 +2279,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_update_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
@ -2285,6 +2303,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_update_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {
@ -2308,6 +2327,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_delete_item_from_different_site_as_site_administrator() {
if ( ! is_multisite() ) {
@ -2331,6 +2351,7 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
/**
* @ticket 39701
* @group ms-required
*/
public function test_delete_item_from_different_site_as_network_administrator() {
if ( ! is_multisite() ) {

View File

@ -119,6 +119,7 @@ class Tests_Rewrite extends WP_UnitTestCase {
/**
* @ticket 35531
* @group multisite
* @group ms-required
*/
function test_url_to_postid_of_http_site_when_current_site_uses_https() {
if ( ! is_multisite() ) {
@ -315,14 +316,12 @@ class Tests_Rewrite extends WP_UnitTestCase {
/**
* Reveals bug introduced in WP 3.0
*
* Run tests using multisite `phpunit -c multisite`
* @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' );
return false;
}
$blog_id = self::factory()->blog->create( array( 'path' => '/example' ) );

View File

@ -145,6 +145,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* Enable a single theme on a network.
*
* @ticket 30594
* @group ms-required
*/
function test_wp_theme_network_enable_single_theme() {
if ( ! is_multisite() ) {
@ -165,6 +166,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* Enable multiple themes on a network.
*
* @ticket 30594
* @group ms-required
*/
function test_wp_theme_network_enable_multiple_themes() {
if ( ! is_multisite() ) {
@ -185,6 +187,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* Disable a single theme on a network.
*
* @ticket 30594
* @group ms-required
*/
function test_network_disable_single_theme() {
if ( ! is_multisite() ) {
@ -209,6 +212,7 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase {
* Disable multiple themes on a network.
*
* @ticket 30594
* @group ms-required
*/
function test_network_disable_multiple_themes() {
if ( ! is_multisite() ) {

View File

@ -649,6 +649,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 27317
* @group ms-required
*/
function test_illegal_user_logins_multisite() {
if ( ! is_multisite() ) {

View File

@ -611,10 +611,12 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
return $data;
}
/**
* @group ms-required
*/
function test_super_admin_caps() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
return;
}
$caps = $this->getAllCapsAndRoles();
$user = self::$super_admin;
@ -1355,10 +1357,12 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
wp_set_current_user( $old_uid );
}
/**
* @group ms-required
*/
function test_borked_current_user_can_for_blog() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
return;
}
$orig_blog_id = get_current_blog_id();
@ -1416,10 +1420,12 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertFalse( current_user_can( 'edit_post', $post + 1 ) );
}
/**
* @group ms-required
*/
function test_multisite_administrator_can_not_edit_users() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs in multisite' );
return;
}
$user = self::$users['administrator'];
@ -1450,6 +1456,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertFalse( user_can( self::$users['subscriber']->ID, 'remove_user', self::$users['subscriber']->ID ) );
}
/**
* @group ms-required
*/
public function test_only_super_admins_can_delete_users_on_multisite() {
if ( ! is_multisite() ) {
$this->markTestSkipped( 'Test only runs on multisite' );
@ -1464,6 +1473,9 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertFalse( user_can( self::$users['subscriber']->ID, 'delete_user', self::$users['subscriber']->ID ) );
}
/**
* @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' );
@ -1522,10 +1534,12 @@ 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' );
return;
}
$user = self::$users['administrator'];
@ -1541,10 +1555,12 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertTrue( $can_edit_user );
}
/**
* @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' );
return;
}
$user = self::$users['administrator'];
@ -1764,6 +1780,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
/**
* @ticket 39063
* @group ms-required
*/
public function test_only_super_admins_can_remove_themselves_on_multisite() {
if ( ! is_multisite() ) {

View File

@ -9,6 +9,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
* @ticket 22993
*
* @dataProvider data_count_users_strategies
* @group ms-excluded
*/
public function test_count_users_is_accurate( $strategy ) {
@ -57,6 +58,7 @@ class Tests_User_CountUsers extends WP_UnitTestCase {
/**
* @ticket 22993
* @group multisite
* @group ms-required
*
* @dataProvider data_count_users_strategies
*/

View File

@ -551,6 +551,9 @@ class Tests_User_Query extends WP_UnitTestCase {
$this->assertSame( array( 'author' => true ), $user->caps );
}
/**
* @group ms-required
*/
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.' );
@ -569,6 +572,9 @@ class Tests_User_Query extends WP_UnitTestCase {
$this->assertSame( array( 'author' => true ), $user->caps );
}
/**
* @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.' );
@ -587,6 +593,9 @@ class Tests_User_Query extends WP_UnitTestCase {
$this->assertSame( array( 'author' => true ), $user->caps );
}
/**
* @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.' );
@ -612,6 +621,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 31878
* @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() ) {
@ -637,6 +647,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 32019
* @group ms-required
*/
public function test_who_authors() {
if ( ! is_multisite() ) {
@ -663,6 +674,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 32019
* @group ms-required
*/
public function test_who_authors_should_work_alongside_meta_query() {
if ( ! is_multisite() ) {
@ -698,6 +710,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 36724
* @group ms-required
*/
public function test_who_authors_should_work_alongside_meta_params() {
if ( ! is_multisite() ) {
@ -791,6 +804,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 32250
* @group ms-required
*/
public function test_has_published_posts_should_respect_blog_id() {
if ( ! is_multisite() ) {
@ -1358,6 +1372,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 22212
* @group ms-required
*/
public function test_blog_id_should_restrict_by_blog_without_requiring_a_named_role() {
if ( ! is_multisite() ) {
@ -1380,6 +1395,7 @@ class Tests_User_Query extends WP_UnitTestCase {
/**
* @ticket 22212
* @ticket 21119
* @group ms-required
*/
public function test_calling_prepare_query_a_second_time_should_not_add_another_cap_query_on_multisite() {
if ( ! is_multisite() ) {

View File

@ -4,6 +4,10 @@
* @group user
*/
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.' );
@ -17,6 +21,9 @@ class Tests_User_WpAuthenticateSpamCheck extends WP_UnitTestCase {
$this->assertEquals( $user->user_login, $actual_user->user_login );
}
/**
* @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.' );
@ -30,6 +37,9 @@ class Tests_User_WpAuthenticateSpamCheck extends WP_UnitTestCase {
$this->assertEquals( $user->user_login, $actual_user->user_login );
}
/**
* @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.' );

View File

@ -123,6 +123,9 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
$this->assertEquals( $reassign, $post->post_author );
}
/**
* @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.' );
@ -144,6 +147,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
/**
* @ticket 33800
* @group ms-excluded
*/
public function test_should_return_false_for_object_user_id() {
if ( is_multisite() ) {