Skip to content

Commit 64f8351

Browse files
committed
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
1 parent e3a9d87 commit 64f8351

20 files changed

Lines changed: 106 additions & 238 deletions

tests/phpunit/includes/testcase.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,28 @@ public function skipOnAutomatedBranches() {
197197
}
198198
}
199199

200+
/**
201+
* Allow tests to be skipped when Multisite is not in use.
202+
*
203+
* Use in conjunction with the ms-required group.
204+
*/
205+
public function skipWithoutMultisite() {
206+
if ( ! is_multisite() ) {
207+
$this->markTestSkipped( 'Test only runs on Multisite' );
208+
}
209+
}
210+
211+
/**
212+
* Allow tests to be skipped when Multisite is in use.
213+
*
214+
* Use in conjunction with the ms-excluded group.
215+
*/
216+
public function skipWithMultisite() {
217+
if ( is_multisite() ) {
218+
$this->markTestSkipped( 'Test does not run on Multisite' );
219+
}
220+
}
221+
200222
/**
201223
* Unregister existing post types and register defaults.
202224
*

tests/phpunit/tests/adminbar.php

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ 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-
if ( is_multisite() ) {
79-
$this->markTestSkipped( 'Test does not run in multisite' );
80-
}
78+
$this->skipWithMultisite();
8179

8280
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
8381

@@ -104,9 +102,7 @@ public function test_admin_bar_contains_correct_links_for_users_with_no_role() {
104102
* @group ms-excluded
105103
*/
106104
public function test_admin_bar_contains_correct_links_for_users_with_role() {
107-
if ( is_multisite() ) {
108-
$this->markTestSkipped( 'Test does not run in multisite' );
109-
}
105+
$this->skipWithMultisite();
110106

111107
$this->assertTrue( user_can( self::$editor_id, 'read' ) );
112108

@@ -136,9 +132,7 @@ public function test_admin_bar_contains_correct_links_for_users_with_role() {
136132
* @group ms-required
137133
*/
138134
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_blog() {
139-
if ( ! is_multisite() ) {
140-
$this->markTestSkipped( 'Test only runs in multisite' );
141-
}
135+
$this->skipWithoutMultisite();
142136

143137
$blog_id = self::factory()->blog->create( array(
144138
'user_id' => self::$admin_id,
@@ -187,9 +181,7 @@ public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_
187181
* @group ms-required
188182
*/
189183
public function test_admin_bar_contains_correct_links_for_users_with_no_role_on_network() {
190-
if ( ! is_multisite() ) {
191-
$this->markTestSkipped( 'Test only runs in multisite' );
192-
}
184+
$this->skipWithoutMultisite();
193185

194186
$this->assertTrue( user_can( self::$admin_id, 'read' ) );
195187
$this->assertFalse( user_can( self::$no_role_id, 'read' ) );
@@ -432,9 +424,7 @@ public function test_admin_bar_has_no_archives_link_for_pages() {
432424
* @group ms-excluded
433425
*/
434426
public function test_admin_bar_contains_correct_about_link_for_users_with_role() {
435-
if ( is_multisite() ) {
436-
$this->markTestSkipped( 'Test does not run in multisite' );
437-
}
427+
$this->skipWithMultisite();
438428

439429
wp_set_current_user( self::$editor_id );
440430

@@ -453,9 +443,7 @@ public function test_admin_bar_contains_correct_about_link_for_users_with_role()
453443
* @group ms-excluded
454444
*/
455445
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role() {
456-
if ( is_multisite() ) {
457-
$this->markTestSkipped( 'Test does not run in multisite' );
458-
}
446+
$this->skipWithMultisite();
459447

460448
wp_set_current_user( self::$no_role_id );
461449

@@ -476,9 +464,7 @@ public function test_admin_bar_contains_correct_about_link_for_users_with_no_rol
476464
* @group ms-required
477465
*/
478466
public function test_admin_bar_contains_correct_about_link_for_users_with_no_role_in_multisite() {
479-
if ( ! is_multisite() ) {
480-
$this->markTestSkipped( 'Test only runs in multisite' );
481-
}
467+
$this->skipWithoutMultisite();
482468

483469
// User is not a member of a site.
484470
remove_user_from_blog( self::$no_role_id, get_current_blog_id() );
@@ -596,9 +582,7 @@ public function test_customize_link() {
596582
* @group ms-required
597583
*/
598584
public function test_my_sites_network_menu_for_regular_user() {
599-
if ( ! is_multisite() ) {
600-
$this->markTestSkipped( 'Test only runs in multisite' );
601-
}
585+
$this->skipWithoutMultisite();
602586

603587
wp_set_current_user( self::$editor_id );
604588

@@ -615,9 +599,7 @@ public function test_my_sites_network_menu_for_regular_user() {
615599
* @group ms-required
616600
*/
617601
public function test_my_sites_network_menu_for_super_admin() {
618-
if ( ! is_multisite() ) {
619-
$this->markTestSkipped( 'Test only runs in multisite' );
620-
}
602+
$this->skipWithoutMultisite();
621603

622604
wp_set_current_user( self::$editor_id );
623605

@@ -636,11 +618,9 @@ public function test_my_sites_network_menu_for_super_admin() {
636618
* @group ms-required
637619
*/
638620
public function test_my_sites_network_menu_for_regular_user_with_network_caps() {
639-
global $current_user;
621+
$this->skipWithoutMultisite();
640622

641-
if ( ! is_multisite() ) {
642-
$this->markTestSkipped( 'Test only runs in multisite' );
643-
}
623+
global $current_user;
644624

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

tests/phpunit/tests/customize/setting.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,7 @@ function test_is_current_blog_previewed() {
564564
* @group ms-required
565565
*/
566566
function test_previewing_with_switch_to_blog() {
567-
if ( ! is_multisite() ) {
568-
$this->markTestSkipped( 'Cannot test WP_Customize_Setting::is_current_blog_previewed() with switch_to_blog() if not on multisite.' );
569-
}
567+
$this->skipWithoutMultisite();
570568

571569
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
572570
$type = 'option';

tests/phpunit/tests/functions.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -938,14 +938,12 @@ 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+
941943
if ( ! extension_loaded( 'fileinfo' ) ) {
942944
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
943945
}
944946

945-
if ( is_multisite() ) {
946-
$this->markTestSkipped( 'Test does not run in multisite' );
947-
}
948-
949947
$file = DIR_TESTDATA . '/uploads/video-play.svg';
950948
$filename = 'video-play.svg';
951949

@@ -964,16 +962,15 @@ function test_wp_check_filetype_and_ext_with_filtered_svg() {
964962

965963
/**
966964
* @ticket 39550
965+
* @group ms-excluded
967966
*/
968967
function test_wp_check_filetype_and_ext_with_filtered_woff() {
968+
$this->skipWithMultisite();
969+
969970
if ( ! extension_loaded( 'fileinfo' ) ) {
970971
$this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' );
971972
}
972973

973-
if ( is_multisite() ) {
974-
$this->markTestSkipped( 'Test does not run in multisite' );
975-
}
976-
977974
$file = DIR_TESTDATA . '/uploads/dashicons.woff';
978975
$filename = 'dashicons.woff';
979976

tests/phpunit/tests/general/template.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ 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-
if ( ! is_multisite() ) {
79-
$this->markTestSkipped( 'This test requires multisite.' );
80-
}
78+
$this->skipWithoutMultisite();
8179

8280
$blog_id = $this->factory->blog->create();
8381
switch_to_blog( $blog_id );
@@ -93,9 +91,7 @@ function test_has_site_icon_returns_true_when_called_for_other_site_with_site_ic
9391
* @group ms-required
9492
*/
9593
function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
96-
if ( ! is_multisite() ) {
97-
$this->markTestSkipped( 'This test requires multisite.' );
98-
}
94+
$this->skipWithoutMultisite();
9995

10096
$blog_id = $this->factory->blog->create();
10197

@@ -269,9 +265,7 @@ function test_has_custom_logo() {
269265
* @group ms-required
270266
*/
271267
function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
272-
if ( ! is_multisite() ) {
273-
$this->markTestSkipped( 'This test requires multisite.' );
274-
}
268+
$this->skipWithoutMultisite();
275269

276270
$blog_id = $this->factory->blog->create();
277271
switch_to_blog( $blog_id );
@@ -287,9 +281,7 @@ function test_has_custom_logo_returns_true_when_called_for_other_site_with_custo
287281
* @group ms-required
288282
*/
289283
function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
290-
if ( ! is_multisite() ) {
291-
$this->markTestSkipped( 'This test requires multisite.' );
292-
}
284+
$this->skipWithoutMultisite();
293285

294286
$blog_id = $this->factory->blog->create();
295287

@@ -319,9 +311,7 @@ function test_get_custom_logo() {
319311
* @group ms-required
320312
*/
321313
function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
322-
if ( ! is_multisite() ) {
323-
$this->markTestSkipped( 'This test requires multisite.' );
324-
}
314+
$this->skipWithoutMultisite();
325315

326316
$blog_id = $this->factory->blog->create();
327317
switch_to_blog( $blog_id );
@@ -542,9 +532,7 @@ function test_get_the_modified_time_with_post_id() {
542532
* @group ms-required
543533
*/
544534
function test_get_site_icon_url_preserves_switched_state() {
545-
if ( ! is_multisite() ) {
546-
$this->markTestSkipped( 'This test requires multisite.' );
547-
}
535+
$this->skipWithoutMultisite();
548536

549537
$blog_id = $this->factory->blog->create();
550538
switch_to_blog( $blog_id );
@@ -565,9 +553,7 @@ function test_get_site_icon_url_preserves_switched_state() {
565553
* @group ms-required
566554
*/
567555
function test_has_custom_logo_preserves_switched_state() {
568-
if ( ! is_multisite() ) {
569-
$this->markTestSkipped( 'This test requires multisite.' );
570-
}
556+
$this->skipWithoutMultisite();
571557

572558
$blog_id = $this->factory->blog->create();
573559
switch_to_blog( $blog_id );
@@ -588,9 +574,7 @@ function test_has_custom_logo_preserves_switched_state() {
588574
* @group ms-required
589575
*/
590576
function test_get_custom_logo_preserves_switched_state() {
591-
if ( ! is_multisite() ) {
592-
$this->markTestSkipped( 'This test requires multisite.' );
593-
}
577+
$this->skipWithoutMultisite();
594578

595579
$blog_id = $this->factory->blog->create();
596580
switch_to_blog( $blog_id );

tests/phpunit/tests/l10n/getLocale.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ public function test_should_respect_locale_global() {
2121
* @group ms-required
2222
*/
2323
public function test_local_option_should_take_precedence_on_multisite() {
24-
if ( ! is_multisite() ) {
25-
$this->markTestSkipped( __METHOD__ . ' requires Multisite' );
26-
}
24+
$this->skipWithoutMultisite();
2725

2826
global $locale;
2927
$old_locale = $locale;

tests/phpunit/tests/link/getDashboardUrl.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ 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-
if ( ! is_multisite() ) {
45-
$this->markTestSkipped( 'Test only runs in multisite.' );
46-
}
44+
$this->skipWithoutMultisite();
4745

4846
grant_super_admin( self::$user_id );
4947

@@ -62,9 +60,7 @@ public function test_get_dashboard_url_for_network_administrator_with_no_sites()
6260
* @group ms-required
6361
*/
6462
public function test_get_dashboard_url_for_administrator_of_different_site() {
65-
if ( ! is_multisite() ) {
66-
$this->markTestSkipped( 'Test only runs in multisite.' );
67-
}
63+
$this->skipWithoutMultisite();
6864

6965
$site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
7066

tests/phpunit/tests/oembed/controller.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ function test_request_xml() {
256256
* @group ms-required
257257
*/
258258
function test_request_ms_child_in_root_blog() {
259-
if ( ! is_multisite() ) {
260-
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
261-
}
259+
$this->skipWithoutMultisite();
262260

263261
$child = self::factory()->blog->create();
264262
switch_to_blog( $child );

tests/phpunit/tests/option/networkOption.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class Tests_Option_NetworkOption extends WP_UnitTestCase {
1616
* @group ms-required
1717
*/
1818
function test_add_network_option_not_available_on_other_network() {
19-
if ( ! is_multisite() ) {
20-
$this->markTestSkipped( 'Test requires multisite' );
21-
}
19+
$this->skipWithoutMultisite();
2220

2321
$id = self::factory()->network->create();
2422
$option = __FUNCTION__;
@@ -32,9 +30,7 @@ function test_add_network_option_not_available_on_other_network() {
3230
* @group ms-required
3331
*/
3432
function test_add_network_option_available_on_same_network() {
35-
if ( ! is_multisite() ) {
36-
$this->markTestSkipped( 'Test requires multisite' );
37-
}
33+
$this->skipWithoutMultisite();
3834

3935
$id = self::factory()->network->create();
4036
$option = __FUNCTION__;
@@ -48,9 +44,7 @@ function test_add_network_option_available_on_same_network() {
4844
* @group ms-required
4945
*/
5046
function test_delete_network_option_on_only_one_network() {
51-
if ( ! is_multisite() ) {
52-
$this->markTestSkipped( 'Test requires multisite' );
53-
}
47+
$this->skipWithoutMultisite();
5448

5549
$id = self::factory()->network->create();
5650
$option = __FUNCTION__;
@@ -67,11 +61,9 @@ function test_delete_network_option_on_only_one_network() {
6761
* @group ms-excluded
6862
*/
6963
public function test_add_network_option_is_not_stored_as_autoload_option() {
70-
$key = __FUNCTION__;
64+
$this->skipWithMultisite();
7165

72-
if ( is_multisite() ) {
73-
$this->markTestSkipped( 'Does not apply when used in multisite.' );
74-
}
66+
$key = __FUNCTION__;
7567

7668
add_network_option( null, $key, 'Not an autoload option' );
7769

@@ -85,11 +77,9 @@ public function test_add_network_option_is_not_stored_as_autoload_option() {
8577
* @group ms-excluded
8678
*/
8779
public function test_update_network_option_is_not_stored_as_autoload_option() {
88-
$key = __FUNCTION__;
80+
$this->skipWithMultisite();
8981

90-
if ( is_multisite() ) {
91-
$this->markTestSkipped( 'Does not apply when used in multisite.' );
92-
}
82+
$key = __FUNCTION__;
9383

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

tests/phpunit/tests/option/siteTransient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ 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+
5052
$key = 'not_autoloaded';
5153

52-
if ( is_multisite() ) {
53-
$this->markTestSkipped( 'Does not apply when used in multisite.' );
54-
}
5554
set_site_transient( $key, 'Not an autoload option' );
5655

5756
$options = wp_load_alloptions();

0 commit comments

Comments
 (0)