Unit Tests: since [32953], we can just use `self::delete_user()` instead of using `if` logic for Multisite.
See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35224 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0d4a7ee029
commit
84272ff8cd
|
@ -27,11 +27,7 @@ class Tests_Auth extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$user_id );
|
||||
} else {
|
||||
wp_delete_user( self::$user_id );
|
||||
}
|
||||
self::delete_user( self::$user_id );
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
|
|
|
@ -17,11 +17,7 @@ class Tests_Comment extends WP_UnitTestCase {
|
|||
public static function wpTearDownAfterClass() {
|
||||
wp_delete_post( self::$post_id );
|
||||
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$user_id );
|
||||
} else {
|
||||
wp_delete_user( self::$user_id );
|
||||
}
|
||||
self::delete_user( self::$user_id );
|
||||
}
|
||||
|
||||
function test_wp_update_comment() {
|
||||
|
|
|
@ -9,22 +9,18 @@
|
|||
* @group feed
|
||||
*/
|
||||
class Tests_Feed_RSS2 extends WP_UnitTestCase {
|
||||
static $user;
|
||||
static $user_id;
|
||||
static $posts;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$user = $factory->user->create();
|
||||
self::$user_id = $factory->user->create();
|
||||
self::$posts = $factory->post->create_many( 5, array(
|
||||
'post_author' => self::$user,
|
||||
'post_author' => self::$user_id,
|
||||
) );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$user );
|
||||
} else {
|
||||
wp_delete_user( self::$user );
|
||||
}
|
||||
self::delete_user( self::$user_id );
|
||||
|
||||
foreach ( self::$posts as $post ) {
|
||||
wp_delete_post( $post, true );
|
||||
|
|
|
@ -25,11 +25,7 @@ class Tests_Post extends WP_UnitTestCase {
|
|||
public static function wpTearDownAfterClass() {
|
||||
$ids = array( self::$editor_id, self::$grammarian_id );
|
||||
foreach ( $ids as $id ) {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( $id );
|
||||
} else {
|
||||
wp_delete_user( $id );
|
||||
}
|
||||
self::delete_user( $id );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
|
|||
public static function wpTearDownAfterClass() {
|
||||
$ids = array( self::$admin_user_id, self::$editor_user_id, self::$author_user_id );
|
||||
foreach ( $ids as $id ) {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( $id );
|
||||
} else {
|
||||
wp_delete_user( $id );
|
||||
}
|
||||
self::delete_user( $id );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,34 +4,31 @@
|
|||
* @group query
|
||||
*/
|
||||
class Tests_Query_PostStatus extends WP_UnitTestCase {
|
||||
public static $editor_user;
|
||||
public static $author_user;
|
||||
public static $editor_user_id;
|
||||
public static $author_user_id;
|
||||
public static $editor_private_post;
|
||||
public static $author_private_post;
|
||||
public static $editor_privatefoo_post;
|
||||
public static $author_privatefoo_post;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$editor_user = $factory->user->create( array( 'role' => 'editor' ) );
|
||||
self::$author_user = $factory->user->create( array( 'role' => 'author' ) );
|
||||
self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) );
|
||||
self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) );
|
||||
|
||||
self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'private' ) );
|
||||
self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'private' ) );
|
||||
self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'private' ) );
|
||||
self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'private' ) );
|
||||
|
||||
// Custom status with private=true.
|
||||
register_post_status( 'privatefoo', array( 'private' => true ) );
|
||||
self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'privatefoo' ) );
|
||||
self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'privatefoo' ) );
|
||||
self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'privatefoo' ) );
|
||||
self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'privatefoo' ) );
|
||||
_unregister_post_status( 'privatefoo' );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$editor_user );
|
||||
wpmu_delete_user( self::$author_user );
|
||||
} else {
|
||||
wp_delete_user( self::$editor_user );
|
||||
wp_delete_user( self::$author_user );
|
||||
$ids = array( self::$editor_user_id, self::$author_user_id );
|
||||
foreach ( $ids as $id ) {
|
||||
self::delete_user( $id );
|
||||
}
|
||||
|
||||
wp_delete_post( self::$editor_private_post, true );
|
||||
|
@ -86,7 +83,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_should_be_included_only_for_current_user_if_perm_is_readable_and_user_cannot_read_others_posts() {
|
||||
wp_set_current_user( self::$author_user );
|
||||
wp_set_current_user( self::$author_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_status' => array( 'private' ),
|
||||
|
@ -101,7 +98,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_should_be_included_for_all_users_if_perm_is_readable_and_user_can_read_others_posts() {
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_status' => array( 'private' ),
|
||||
|
@ -117,7 +114,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_should_be_included_only_for_current_user_if_perm_is_editable_and_user_cannot_read_others_posts() {
|
||||
wp_set_current_user( self::$author_user );
|
||||
wp_set_current_user( self::$author_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_status' => array( 'private' ),
|
||||
|
@ -132,7 +129,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_should_be_included_for_all_users_if_perm_is_editable_and_user_can_read_others_posts() {
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'post_status' => array( 'private' ),
|
||||
|
@ -182,7 +179,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_statuses_should_be_included_when_current_user_can_read_private_posts() {
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
register_post_status( 'privatefoo', array( 'private' => true ) );
|
||||
|
||||
|
@ -195,7 +192,7 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public function test_private_statuses_should_not_be_included_when_current_user_cannot_read_private_posts() {
|
||||
wp_set_current_user( self::$author_user );
|
||||
wp_set_current_user( self::$author_user_id );
|
||||
|
||||
register_post_status( 'privatefoo', array( 'private' => true ) );
|
||||
|
||||
|
@ -226,9 +223,9 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
public function test_single_post_with_nonpublic_and_protected_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() {
|
||||
register_post_type( 'foo_pt' );
|
||||
register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
|
||||
|
||||
wp_set_current_user( self::$author_user );
|
||||
wp_set_current_user( self::$author_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'p' => $p,
|
||||
|
@ -240,9 +237,9 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
public function test_single_post_with_nonpublic_and_protected_status_should_be_shown_for_user_who_can_edit_others_posts() {
|
||||
register_post_type( 'foo_pt' );
|
||||
register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
|
||||
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'p' => $p,
|
||||
|
@ -254,9 +251,9 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
public function test_single_post_with_nonpublic_and_private_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() {
|
||||
register_post_type( 'foo_pt' );
|
||||
register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
|
||||
|
||||
wp_set_current_user( self::$author_user );
|
||||
wp_set_current_user( self::$author_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'p' => $p,
|
||||
|
@ -268,9 +265,9 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
public function test_single_post_with_nonpublic_and_private_status_should_be_shown_for_user_who_can_edit_others_posts() {
|
||||
register_post_type( 'foo_pt' );
|
||||
register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
|
||||
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'p' => $p,
|
||||
|
@ -282,9 +279,9 @@ class Tests_Query_PostStatus extends WP_UnitTestCase {
|
|||
public function test_single_post_with_nonpublic_and_protected_status_should_not_be_shown_for_any_user() {
|
||||
register_post_type( 'foo_pt' );
|
||||
register_post_status( 'foo_ps', array( 'public' => false ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
|
||||
$p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
|
||||
|
||||
wp_set_current_user( self::$editor_user );
|
||||
wp_set_current_user( self::$editor_user_id );
|
||||
|
||||
$q = new WP_Query( array(
|
||||
'p' => $p,
|
||||
|
|
|
@ -29,11 +29,7 @@ class Tests_User extends WP_UnitTestCase {
|
|||
public static function wpTearDownAfterClass() {
|
||||
$ids = array( self::$test_id, self::$author_id );
|
||||
foreach ( $ids as $id ) {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( $id );
|
||||
} else {
|
||||
wp_delete_user( $id );
|
||||
}
|
||||
self::delete_user( $id );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -595,7 +591,7 @@ class Tests_User extends WP_UnitTestCase {
|
|||
'ID' => $id2,
|
||||
'user_email' => 'blackburn@battlefield4.com',
|
||||
) );
|
||||
|
||||
|
||||
if ( ! defined( 'WP_IMPORTING' ) ) {
|
||||
$this->assertWPError( $return );
|
||||
}
|
||||
|
@ -652,7 +648,7 @@ class Tests_User extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
function _illegal_user_logins() {
|
||||
return array( 'testuser' );
|
||||
return array( 'testuser' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,11 +34,7 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
|
|||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( self::$user_id );
|
||||
} else {
|
||||
wp_delete_user( self::$user_id );
|
||||
}
|
||||
self::delete_user( self::$user_id );
|
||||
|
||||
foreach ( self::$post_ids as $post_id ) {
|
||||
wp_delete_post( $post_id, true );
|
||||
|
|
|
@ -42,11 +42,7 @@ class Tests_User_ListAuthors extends WP_UnitTestCase {
|
|||
|
||||
public static function wpTearDownAfterClass() {
|
||||
foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( $user_id );
|
||||
} else {
|
||||
wp_delete_user( $user_id );
|
||||
}
|
||||
self::delete_user( $user_id );
|
||||
}
|
||||
|
||||
foreach ( self::$posts as $post_id ) {
|
||||
|
|
|
@ -46,11 +46,7 @@ class Tests_User_Query extends WP_UnitTestCase {
|
|||
|
||||
foreach ( $sets as $set ) {
|
||||
foreach ( $set as $id ) {
|
||||
if ( is_multisite() ) {
|
||||
wpmu_delete_user( $id );
|
||||
} else {
|
||||
wp_delete_user( $id );
|
||||
}
|
||||
self::delete_user( $id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@ class Tests_User_WpDeleteUser extends WP_UnitTestCase {
|
|||
$this->assertEquals( array( 1 ), array_keys( $blogs ) );
|
||||
|
||||
// Non-existent users don't have blogs.
|
||||
if ( is_multisite() )
|
||||
wpmu_delete_user( $user_id );
|
||||
else
|
||||
wp_delete_user( $user_id );
|
||||
self::delete_user( $user_id );
|
||||
|
||||
$user = new WP_User( $user_id );
|
||||
$this->assertFalse( $user->exists(), 'WP_User->exists' );
|
||||
|
|
Loading…
Reference in New Issue