Tests: Increase use of shared fixtures in capability checks.

See #51802.


git-svn-id: https://develop.svn.wordpress.org/trunk@49932 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson 2021-01-04 23:32:49 +00:00
parent abe9dd3c03
commit 429c7b8ddc
2 changed files with 20 additions and 29 deletions

View File

@ -15,9 +15,10 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$author_id = $factory->user->create(
array(
'role' => 'author',
'user_login' => 'test_author',
'description' => 'test_author',
'role' => 'author',
'user_login' => 'test_author',
'display_name' => 'Test Author',
'description' => 'test_author',
)
);
@ -48,13 +49,13 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
$user = new WP_User( self::$author_id );
$this->assertSame( $user->display_name, $author_name );
$this->assertSame( 'test_author', $author_name );
$this->assertSame( 'Test Author', $author_name );
}
function test_get_the_author_meta() {
$this->assertSame( 'test_author', get_the_author_meta( 'login' ) );
$this->assertSame( 'test_author', get_the_author_meta( 'user_login' ) );
$this->assertSame( 'test_author', get_the_author_meta( 'display_name' ) );
$this->assertSame( 'Test Author', get_the_author_meta( 'display_name' ) );
$this->assertSame( 'test_author', trim( get_the_author_meta( 'description' ) ) );
$this->assertSame( 'test_author', get_the_author_meta( 'user_description' ) );
@ -110,12 +111,7 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
* @ticket 30355
*/
public function test_get_the_author_posts_link_no_permalinks() {
$author = self::factory()->user->create_and_get(
array(
'display_name' => 'Foo',
'user_nicename' => 'bar',
)
);
$author = get_userdata( self::$author_id );
$GLOBALS['authordata'] = $author->data;
@ -124,8 +120,8 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
$url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID );
$this->assertContains( $url, $link );
$this->assertContains( 'Posts by Foo', $link );
$this->assertContains( '>Foo</a>', $link );
$this->assertContains( 'Posts by Test Author', $link );
$this->assertContains( '>Test Author</a>', $link );
unset( $GLOBALS['authordata'] );
}
@ -136,12 +132,7 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
public function test_get_the_author_posts_link_with_permalinks() {
$this->set_permalink_structure( '/%postname%/' );
$author = self::factory()->user->create_and_get(
array(
'display_name' => 'Foo',
'user_nicename' => 'bar',
)
);
$author = get_userdata( self::$author_id );
$GLOBALS['authordata'] = $author;
@ -152,8 +143,8 @@ class Tests_User_Author_Template extends WP_UnitTestCase {
$this->set_permalink_structure( '' );
$this->assertContains( $url, $link );
$this->assertContains( 'Posts by Foo', $link );
$this->assertContains( '>Foo</a>', $link );
$this->assertContains( 'Posts by Test Author', $link );
$this->assertContains( '>Test Author</a>', $link );
unset( $GLOBALS['authordata'] );
}

View File

@ -1004,7 +1004,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
*/
function test_user_add_cap() {
// There are two contributors.
$id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) );
$id_1 = self::$users['contributor']->ID;
$id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) );
// User 1 has an extra capability.
@ -1043,7 +1043,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
*/
function test_user_remove_cap() {
// There are two contributors.
$id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) );
$id_1 = self::$users['contributor']->ID;
$id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) );
// User 1 has an extra capability.
@ -1075,7 +1075,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
*/
function test_user_level_update() {
// User starts as an author.
$id = self::factory()->user->create( array( 'role' => 'author' ) );
$id = self::$users['author']->ID;
$user = new WP_User( $id );
$this->assertTrue( $user->exists(), "Problem getting user $id" );
@ -1098,7 +1098,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
function test_user_remove_all_caps() {
// User starts as an author.
$id = self::factory()->user->create( array( 'role' => 'author' ) );
$id = self::$users['author']->ID;
$user = new WP_User( $id );
$this->assertTrue( $user->exists(), "Problem getting user $id" );
@ -1153,10 +1153,10 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertTrue( $author->exists(), "Problem getting user $author->ID" );
// Add some other users.
$admin = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
$admin = self::$users['administrator'];
$author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
$editor = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) );
$contributor = new WP_User( self::factory()->user->create( array( 'role' => 'contributor' ) ) );
$editor = self::$users['editor'];
$contributor = self::$users['contributor'];
// Administrators, editors and the post owner can edit it.
$this->assertTrue( $admin->has_cap( 'edit_post', $post ) );
@ -1900,7 +1900,7 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
* @ticket 35488
*/
function test_wp_logout_should_clear_current_user() {
$user_id = self::factory()->user->create();
$user_id = self::$users['author']->ID;
wp_set_current_user( $user_id );
wp_logout();