diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index b92b0db231ecb..8b99764499dd5 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -1406,6 +1406,7 @@ public function test_create_posts_caps() { // Add 'edit_foobars' primitive cap to a user. $admin->add_cap( 'edit_foobars', true ); $admin = new WP_User( $admin->ID ); + self::$users['administrator'] = $admin; $this->assertTrue( $admin->has_cap( $cap->create_posts ) ); $this->assertFalse( $author->has_cap( $cap->create_posts ) ); $this->assertFalse( $editor->has_cap( $cap->create_posts ) ); diff --git a/tests/phpunit/tests/user/countUserPosts.php b/tests/phpunit/tests/user/countUserPosts.php index d7d4e1f9c8db6..05e3019799d3d 100644 --- a/tests/phpunit/tests/user/countUserPosts.php +++ b/tests/phpunit/tests/user/countUserPosts.php @@ -156,7 +156,12 @@ public function test_count_user_posts_for_non_existent_user() { */ public function test_count_user_posts_for_user_created_after_being_assigned_posts() { global $wpdb; - $next_user_id = (int) $wpdb->get_var( "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '$wpdb->users'" ); + $next_user_id = (int) $wpdb->get_var( + $wpdb->prepare( + 'SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s', + $wpdb->users + ) + ); // Assign post to next user. self::factory()->post->create( diff --git a/tests/phpunit/tests/user/mapMetaCap.php b/tests/phpunit/tests/user/mapMetaCap.php index b6c6b0ab8a151..9628d89d6ee3b 100644 --- a/tests/phpunit/tests/user/mapMetaCap.php +++ b/tests/phpunit/tests/user/mapMetaCap.php @@ -336,22 +336,6 @@ public function test_unfiltered_html_cap() { } } - /** - * @ticket 20488 - */ - public function test_file_edit_caps_not_reliant_on_unfiltered_html_constant() { - $this->assertFalse( defined( 'DISALLOW_FILE_MODS' ) ); - $this->assertFalse( defined( 'DISALLOW_FILE_EDIT' ) ); - - if ( ! defined( 'DISALLOW_UNFILTERED_HTML' ) ) { - define( 'DISALLOW_UNFILTERED_HTML', true ); - } - - $this->assertTrue( DISALLOW_UNFILTERED_HTML ); - $this->assertSame( array( 'update_core' ), map_meta_cap( 'update_core', self::$user_id ) ); - $this->assertSame( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', self::$user_id ) ); - } - /** * Test a post without an author. * @@ -458,3 +442,30 @@ public function data_meta_caps_throw_doing_it_wrong_without_required_argument_pr ); } } + +/** + * @group user + * @group capabilities + * @covers ::map_meta_cap + */ +class Tests_User_MapMetaCap_Constants extends WP_UnitTestCase { + + /** + * @ticket 20488 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_file_edit_caps_not_reliant_on_unfiltered_html_constant() { + $this->assertFalse( defined( 'DISALLOW_FILE_MODS' ) ); + $this->assertFalse( defined( 'DISALLOW_FILE_EDIT' ) ); + + if ( ! defined( 'DISALLOW_UNFILTERED_HTML' ) ) { + define( 'DISALLOW_UNFILTERED_HTML', true ); + } + + $this->assertTrue( DISALLOW_UNFILTERED_HTML ); + $this->assertSame( array( 'update_core' ), map_meta_cap( 'update_core', 0 ) ); + $this->assertSame( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', 0 ) ); + } +} diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 5978f4bf55e58..da855fc9e22c4 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -1656,20 +1656,20 @@ public function test_calling_prepare_query_a_second_time_should_not_add_another_ */ public function test_search_by_display_name_only() { - $new_user1 = self::factory()->user->create( + $new_user1 = self::factory()->user->create( array( 'user_login' => 'name1', 'display_name' => 'Sophia Andresen', ) ); - self::$author_ids[] = $new_user1; + $author_ids = array_merge( self::$author_ids, array( $new_user1 ) ); $q = new WP_User_Query( array( 'search' => '*Sophia*', 'fields' => '', 'search_columns' => array( 'display_name' ), - 'include' => self::$author_ids, + 'include' => $author_ids, ) ); @@ -1684,20 +1684,20 @@ public function test_search_by_display_name_only() { */ public function test_search_by_display_name_only_ignore_others() { - $new_user1 = self::factory()->user->create( + $new_user1 = self::factory()->user->create( array( 'user_login' => 'Sophia Andresen', 'display_name' => 'name1', ) ); - self::$author_ids[] = $new_user1; + $author_ids = array_merge( self::$author_ids, array( $new_user1 ) ); $q = new WP_User_Query( array( 'search' => '*Sophia*', 'fields' => '', 'search_columns' => array( 'display_name' ), - 'include' => self::$author_ids, + 'include' => $author_ids, ) );