WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/16/2015 07:51:32 PM (6 years ago)
Author:
wonderboymusic
Message:

Unit Tests: since [32953], we can just use self::delete_user() instead of using if logic for Multisite.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/postStatus.php

    r35186 r35224  
    55 */
    66class Tests_Query_PostStatus extends WP_UnitTestCase {
    7     public static $editor_user;
    8     public static $author_user;
     7    public static $editor_user_id;
     8    public static $author_user_id;
    99    public static $editor_private_post;
    1010    public static $author_private_post;
     
    1313
    1414    public static function wpSetUpBeforeClass( $factory ) {
    15         self::$editor_user = $factory->user->create( array( 'role' => 'editor' ) );
    16         self::$author_user = $factory->user->create( array( 'role' => 'author' ) );
    17 
    18         self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'private' ) );
    19         self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'private' ) );
     15        self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) );
     16        self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) );
     17
     18        self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'private' ) );
     19        self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'private' ) );
    2020
    2121        // Custom status with private=true.
    2222        register_post_status( 'privatefoo', array( 'private' => true ) );
    23         self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user, 'post_status' => 'privatefoo' ) );
    24         self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user, 'post_status' => 'privatefoo' ) );
     23        self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'privatefoo' ) );
     24        self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'privatefoo' ) );
    2525        _unregister_post_status( 'privatefoo' );
    2626    }
    2727
    2828    public static function wpTearDownAfterClass() {
    29         if ( is_multisite() ) {
    30             wpmu_delete_user( self::$editor_user );
    31             wpmu_delete_user( self::$author_user );
    32         } else {
    33             wp_delete_user( self::$editor_user );
    34             wp_delete_user( self::$author_user );
     29        $ids = array( self::$editor_user_id, self::$author_user_id );
     30        foreach ( $ids as $id ) {
     31            self::delete_user( $id );
    3532        }
    3633
     
    8784
    8885    public function test_private_should_be_included_only_for_current_user_if_perm_is_readable_and_user_cannot_read_others_posts() {
    89         wp_set_current_user( self::$author_user );
     86        wp_set_current_user( self::$author_user_id );
    9087
    9188        $q = new WP_Query( array(
     
    10299
    103100    public function test_private_should_be_included_for_all_users_if_perm_is_readable_and_user_can_read_others_posts() {
    104         wp_set_current_user( self::$editor_user );
     101        wp_set_current_user( self::$editor_user_id );
    105102
    106103        $q = new WP_Query( array(
     
    118115
    119116    public function test_private_should_be_included_only_for_current_user_if_perm_is_editable_and_user_cannot_read_others_posts() {
    120         wp_set_current_user( self::$author_user );
     117        wp_set_current_user( self::$author_user_id );
    121118
    122119        $q = new WP_Query( array(
     
    133130
    134131    public function test_private_should_be_included_for_all_users_if_perm_is_editable_and_user_can_read_others_posts() {
    135         wp_set_current_user( self::$editor_user );
     132        wp_set_current_user( self::$editor_user_id );
    136133
    137134        $q = new WP_Query( array(
     
    183180
    184181    public function test_private_statuses_should_be_included_when_current_user_can_read_private_posts() {
    185         wp_set_current_user( self::$editor_user );
     182        wp_set_current_user( self::$editor_user_id );
    186183
    187184        register_post_status( 'privatefoo', array( 'private' => true ) );
     
    196193
    197194    public function test_private_statuses_should_not_be_included_when_current_user_cannot_read_private_posts() {
    198         wp_set_current_user( self::$author_user );
     195        wp_set_current_user( self::$author_user_id );
    199196
    200197        register_post_status( 'privatefoo', array( 'private' => true ) );
     
    227224        register_post_type( 'foo_pt' );
    228225        register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
    229         $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user ) );
    230 
    231         wp_set_current_user( self::$author_user );
     226        $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
     227
     228        wp_set_current_user( self::$author_user_id );
    232229
    233230        $q = new WP_Query( array(
     
    241238        register_post_type( 'foo_pt' );
    242239        register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) );
    243         $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
    244 
    245         wp_set_current_user( self::$editor_user );
     240        $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
     241
     242        wp_set_current_user( self::$editor_user_id );
    246243
    247244        $q = new WP_Query( array(
     
    255252        register_post_type( 'foo_pt' );
    256253        register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
    257         $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user ) );
    258 
    259         wp_set_current_user( self::$author_user );
     254        $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) );
     255
     256        wp_set_current_user( self::$author_user_id );
    260257
    261258        $q = new WP_Query( array(
     
    269266        register_post_type( 'foo_pt' );
    270267        register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) );
    271         $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
    272 
    273         wp_set_current_user( self::$editor_user );
     268        $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
     269
     270        wp_set_current_user( self::$editor_user_id );
    274271
    275272        $q = new WP_Query( array(
     
    283280        register_post_type( 'foo_pt' );
    284281        register_post_status( 'foo_ps', array( 'public' => false ) );
    285         $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user ) );
    286 
    287         wp_set_current_user( self::$editor_user );
     282        $p = $this->factory->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) );
     283
     284        wp_set_current_user( self::$editor_user_id );
    288285
    289286        $q = new WP_Query( array(
Note: See TracChangeset for help on using the changeset viewer.