Skip to content

Commit c759785

Browse files
committed
Build/Test Tools: Automatically skip tests in the ms-required and ms-excluded groups.
This removes the need to manually call `$this->skipWithMultisite()` and `$this->skipWithoutMultisite()` from within the test when the test only runs without Multisite or only runs on Multisite, respectively. Props jdgrimes for the suggestion. Fixes #40531 git-svn-id: https://develop.svn.wordpress.org/trunk@40564 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f72ce6d commit c759785

20 files changed

Lines changed: 11 additions & 152 deletions

tests/phpunit/includes/testcase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,17 @@ function go_to( $url ) {
577577
protected function checkRequirements() {
578578
parent::checkRequirements();
579579

580+
$annotations = $this->getAnnotations();
581+
582+
if ( ! empty( $annotations['group'] ) ) {
583+
if ( in_array( 'ms-required', $annotations['group'], true ) ) {
584+
$this->skipWithoutMultisite();
585+
}
586+
if ( in_array( 'ms-excluded', $annotations['group'], true ) ) {
587+
$this->skipWithMultisite();
588+
}
589+
}
590+
580591
// Core tests no longer check against open Trac tickets, but others using WP_UnitTestCase may do so.
581592
if ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) {
582593
return;

tests/phpunit/tests/adminbar.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ function test_merging_existing_meta_values() {
7575
* @group ms-excluded
7676
*/
7777
public function test_admin_bar_contains_correct_links_for_users_with_no_role() {
78-
$this->skipWithMultisite();
79-
8078
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
8179

8280
wp_set_current_user( self::$no_role_id );
@@ -102,8 +100,6 @@ public function test_admin_bar_contains_correct_links_for_users_with_no_role() {
102100
* @group ms-excluded
103101
*/
104102
public function test_admin_bar_contains_correct_links_for_users_with_role() {
105-
$this->skipWithMultisite();
106-
107103
$this->assertTrue( user_can( self::$editor_id, 'read' ) );
108104

109105
wp_set_current_user( self::$editor_id );
@@ -132,8 +128,6 @@ public function test_admin_bar_contains_correct_links_for_users_with_role() {
132128
* @group ms-required
133129
*/
134130
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_blog() {
135-
$this->skipWithoutMultisite();
136-
137131
$blog_id = self::factory()->blog->create( array(
138132
'user_id' => self::$admin_id,
139133
) );
@@ -181,8 +175,6 @@ public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_
181175
* @group ms-required
182176
*/
183177
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_network() {
184-
$this->skipWithoutMultisite();
185-
186178
$this->assertTrue( user_can( self::$admin_id, 'read' ) );
187179
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
188180

@@ -424,8 +416,6 @@ public function test_admin_bar_has_no_archives_link_for_pages() {
424416
* @group ms-excluded
425417
*/
426418
public function test_admin_bar_contains_correct_about_link_for_users_with_role() {
427-
$this->skipWithMultisite();
428-
429419
wp_set_current_user( self::$editor_id );
430420

431421
$wp_admin_bar = $this->get_standard_admin_bar();
@@ -443,8 +433,6 @@ public function test_admin_bar_contains_correct_about_link_for_users_with_role()
443433
* @group ms-excluded
444434
*/
445435
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role() {
446-
$this->skipWithMultisite();
447-
448436
wp_set_current_user( self::$no_role_id );
449437

450438
$wp_admin_bar = $this->get_standard_admin_bar();
@@ -464,8 +452,6 @@ public function test_admin_bar_contains_correct_about_link_for_users_with_no_rol
464452
* @group ms-required
465453
*/
466454
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() {
467-
$this->skipWithoutMultisite();
468-
469455
// User is not a member of a site.
470456
remove_user_from_blog( self::$no_role_id, get_current_blog_id() );
471457

@@ -582,8 +568,6 @@ public function test_customize_link() {
582568
* @group ms-required
583569
*/
584570
public function test_my_sites_network_menu_for_regular_user() {
585-
$this->skipWithoutMultisite();
586-
587571
wp_set_current_user( self::$editor_id );
588572

589573
$wp_admin_bar = $this->get_standard_admin_bar();
@@ -599,8 +583,6 @@ public function test_my_sites_network_menu_for_regular_user() {
599583
* @group ms-required
600584
*/
601585
public function test_my_sites_network_menu_for_super_admin() {
602-
$this->skipWithoutMultisite();
603-
604586
wp_set_current_user( self::$editor_id );
605587

606588
grant_super_admin( self::$editor_id );
@@ -618,8 +600,6 @@ public function test_my_sites_network_menu_for_super_admin() {
618600
* @group ms-required
619601
*/
620602
public function test_my_sites_network_menu_for_regular_user_with_network_caps() {
621-
$this->skipWithoutMultisite();
622-
623603
global $current_user;
624604

625605
$network_user_caps = array( 'manage_network', 'manage_network_themes', 'manage_network_plugins' );

tests/phpunit/tests/customize/setting.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ function test_is_current_blog_previewed() {
564564
* @group ms-required
565565
*/
566566
function test_previewing_with_switch_to_blog() {
567-
$this->skipWithoutMultisite();
568-
569567
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
570568
$type = 'option';
571569
$name = 'blogdescription';

tests/phpunit/tests/functions.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,6 @@ function test_wp_check_filetype_and_ext( $file, $filename, $expected ) {
938938
* @group ms-excluded
939939
*/
940940
function test_wp_check_filetype_and_ext_with_filtered_svg() {
941-
$this->skipWithMultisite();
942-
943941
if ( ! extension_loaded( 'fileinfo' ) ) {
944942
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
945943
}
@@ -965,8 +963,6 @@ function test_wp_check_filetype_and_ext_with_filtered_svg() {
965963
* @group ms-excluded
966964
*/
967965
function test_wp_check_filetype_and_ext_with_filtered_woff() {
968-
$this->skipWithMultisite();
969-
970966
if ( ! extension_loaded( 'fileinfo' ) ) {
971967
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
972968
}

tests/phpunit/tests/general/template.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ function test_has_site_icon() {
7575
* @group ms-required
7676
*/
7777
function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
78-
$this->skipWithoutMultisite();
79-
8078
$blog_id = $this->factory->blog->create();
8179
switch_to_blog( $blog_id );
8280
$this->_set_site_icon();
@@ -91,8 +89,6 @@ function test_has_site_icon_returns_true_when_called_for_other_site_with_site_ic
9189
* @group ms-required
9290
*/
9391
function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
94-
$this->skipWithoutMultisite();
95-
9692
$blog_id = $this->factory->blog->create();
9793

9894
$this->assertFalse( has_site_icon( $blog_id ) );
@@ -265,8 +261,6 @@ function test_has_custom_logo() {
265261
* @group ms-required
266262
*/
267263
function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
268-
$this->skipWithoutMultisite();
269-
270264
$blog_id = $this->factory->blog->create();
271265
switch_to_blog( $blog_id );
272266
$this->_set_custom_logo();
@@ -281,8 +275,6 @@ function test_has_custom_logo_returns_true_when_called_for_other_site_with_custo
281275
* @group ms-required
282276
*/
283277
function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
284-
$this->skipWithoutMultisite();
285-
286278
$blog_id = $this->factory->blog->create();
287279

288280
$this->assertFalse( has_custom_logo( $blog_id ) );
@@ -311,8 +303,6 @@ function test_get_custom_logo() {
311303
* @group ms-required
312304
*/
313305
function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
314-
$this->skipWithoutMultisite();
315-
316306
$blog_id = $this->factory->blog->create();
317307
switch_to_blog( $blog_id );
318308

@@ -532,8 +522,6 @@ function test_get_the_modified_time_with_post_id() {
532522
* @group ms-required
533523
*/
534524
function test_get_site_icon_url_preserves_switched_state() {
535-
$this->skipWithoutMultisite();
536-
537525
$blog_id = $this->factory->blog->create();
538526
switch_to_blog( $blog_id );
539527

@@ -553,8 +541,6 @@ function test_get_site_icon_url_preserves_switched_state() {
553541
* @group ms-required
554542
*/
555543
function test_has_custom_logo_preserves_switched_state() {
556-
$this->skipWithoutMultisite();
557-
558544
$blog_id = $this->factory->blog->create();
559545
switch_to_blog( $blog_id );
560546

@@ -574,8 +560,6 @@ function test_has_custom_logo_preserves_switched_state() {
574560
* @group ms-required
575561
*/
576562
function test_get_custom_logo_preserves_switched_state() {
577-
$this->skipWithoutMultisite();
578-
579563
$blog_id = $this->factory->blog->create();
580564
switch_to_blog( $blog_id );
581565

tests/phpunit/tests/l10n/getLocale.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public function test_should_respect_locale_global() {
2121
* @group ms-required
2222
*/
2323
public function test_local_option_should_take_precedence_on_multisite() {
24-
$this->skipWithoutMultisite();
25-
2624
global $locale;
2725
$old_locale = $locale;
2826
$locale = null;

tests/phpunit/tests/link/getDashboardUrl.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function test_get_dashboard_url_for_user_with_no_sites() {
4141
* @group ms-required
4242
*/
4343
public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
44-
$this->skipWithoutMultisite();
45-
4644
grant_super_admin( self::$user_id );
4745

4846
add_filter( 'get_blogs_of_user', '__return_empty_array' );
@@ -60,8 +58,6 @@ public function test_get_dashboard_url_for_network_administrator_with_no_sites()
6058
* @group ms-required
6159
*/
6260
public function test_get_dashboard_url_for_administrator_of_different_site() {
63-
$this->skipWithoutMultisite();
64-
6561
$site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
6662

6763
remove_user_from_blog( self::$user_id, get_current_blog_id() );

tests/phpunit/tests/oembed/controller.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ function test_request_xml() {
256256
* @group ms-required
257257
*/
258258
function test_request_ms_child_in_root_blog() {
259-
$this->skipWithoutMultisite();
260-
261259
$child = self::factory()->blog->create();
262260
switch_to_blog( $child );
263261

tests/phpunit/tests/option/networkOption.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
1616
* @group ms-required
1717
*/
1818
function test_add_network_option_not_available_on_other_network() {
19-
$this->skipWithoutMultisite();
20-
2119
$id = self::factory()->network->create();
2220
$option = __FUNCTION__;
2321
$value = __FUNCTION__;
@@ -30,8 +28,6 @@ function test_add_network_option_not_available_on_other_network() {
3028
* @group ms-required
3129
*/
3230
function test_add_network_option_available_on_same_network() {
33-
$this->skipWithoutMultisite();
34-
3531
$id = self::factory()->network->create();
3632
$option = __FUNCTION__;
3733
$value = __FUNCTION__;
@@ -44,8 +40,6 @@ function test_add_network_option_available_on_same_network() {
4440
* @group ms-required
4541
*/
4642
function test_delete_network_option_on_only_one_network() {
47-
$this->skipWithoutMultisite();
48-
4943
$id = self::factory()->network->create();
5044
$option = __FUNCTION__;
5145
$value = __FUNCTION__;
@@ -61,8 +55,6 @@ function test_delete_network_option_on_only_one_network() {
6155
* @group ms-excluded
6256
*/
6357
public function test_add_network_option_is_not_stored_as_autoload_option() {
64-
$this->skipWithMultisite();
65-
6658
$key = __FUNCTION__;
6759

6860
add_network_option( null, $key, 'Not an autoload option' );
@@ -77,8 +69,6 @@ public function test_add_network_option_is_not_stored_as_autoload_option() {
7769
* @group ms-excluded
7870
*/
7971
public function test_update_network_option_is_not_stored_as_autoload_option() {
80-
$this->skipWithMultisite();
81-
8272
$key = __FUNCTION__;
8373

8474
update_network_option( null, $key, 'Not an autoload option' );

tests/phpunit/tests/option/siteTransient.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ function test_serialized_data() {
4747
* @group ms-excluded
4848
*/
4949
public function test_set_site_transient_is_not_stored_as_autoload_option() {
50-
$this->skipWithMultisite();
51-
5250
$key = 'not_autoloaded';
5351

5452
set_site_transient( $key, 'Not an autoload option' );

0 commit comments

Comments
 (0)