mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-10 21:40:08 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user