Skip to content

Commit 38efccb

Browse files
committed
Tests: Preserve super admin capability fixture
1 parent 842c9ae commit 38efccb

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎tests/phpunit/tests/user/capabilities.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ public function test_create_posts_caps() {
14051405

14061406
// Add 'edit_foobars' primitive cap to a user.
14071407
$admin->add_cap( 'edit_foobars', true );
1408-
$admin = new WP_User( $admin->ID );
1408+
$admin = new WP_User( $admin->ID );
14091409
self::$users['administrator'] = $admin;
14101410
$this->assertTrue( $admin->has_cap( $cap->create_posts ) );
14111411
$this->assertFalse( $author->has_cap( $cap->create_posts ) );

‎tests/phpunit/tests/user/mapMetaCap.php‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,27 @@ class Tests_User_MapMetaCap_Constants extends WP_UnitTestCase {
457457
* @preserveGlobalState disabled
458458
*/
459459
public function test_file_edit_caps_not_reliant_on_unfiltered_html_constant() {
460-
$this->assertFalse( defined( 'DISALLOW_FILE_MODS' ) );
461-
$this->assertFalse( defined( 'DISALLOW_FILE_EDIT' ) );
460+
$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
462461

463-
if ( ! defined( 'DISALLOW_UNFILTERED_HTML' ) ) {
464-
define( 'DISALLOW_UNFILTERED_HTML', true );
462+
if ( is_multisite() ) {
463+
grant_super_admin( $user_id );
465464
}
466465

467-
$this->assertTrue( DISALLOW_UNFILTERED_HTML );
468-
$this->assertSame( array( 'update_core' ), map_meta_cap( 'update_core', 0 ) );
469-
$this->assertSame( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', 0 ) );
466+
try {
467+
$this->assertFalse( defined( 'DISALLOW_FILE_MODS' ) );
468+
$this->assertFalse( defined( 'DISALLOW_FILE_EDIT' ) );
469+
470+
if ( ! defined( 'DISALLOW_UNFILTERED_HTML' ) ) {
471+
define( 'DISALLOW_UNFILTERED_HTML', true );
472+
}
473+
474+
$this->assertTrue( DISALLOW_UNFILTERED_HTML );
475+
$this->assertSame( array( 'update_core' ), map_meta_cap( 'update_core', $user_id ) );
476+
$this->assertSame( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', $user_id ) );
477+
} finally {
478+
if ( is_multisite() ) {
479+
revoke_super_admin( $user_id );
480+
}
481+
}
470482
}
471483
}

‎tests/phpunit/tests/user/query.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ public function test_calling_prepare_query_a_second_time_should_not_add_another_
16561656
*/
16571657
public function test_search_by_display_name_only() {
16581658

1659-
$new_user1 = self::factory()->user->create(
1659+
$new_user1 = self::factory()->user->create(
16601660
array(
16611661
'user_login' => 'name1',
16621662
'display_name' => 'Sophia Andresen',
@@ -1684,7 +1684,7 @@ public function test_search_by_display_name_only() {
16841684
*/
16851685
public function test_search_by_display_name_only_ignore_others() {
16861686

1687-
$new_user1 = self::factory()->user->create(
1687+
$new_user1 = self::factory()->user->create(
16881688
array(
16891689
'user_login' => 'Sophia Andresen',
16901690
'display_name' => 'name1',

0 commit comments

Comments
 (0)