WordPress.org

Make WordPress Core

Changeset 35224


Ignore:
Timestamp:
10/16/2015 07:51:32 PM (5 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.

Location:
trunk/tests/phpunit/tests
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/auth.php

    r35186 r35224  
    2828
    2929    public static function wpTearDownAfterClass() {
    30         if ( is_multisite() ) {
    31             wpmu_delete_user( self::$user_id );
    32         } else {
    33             wp_delete_user( self::$user_id );
    34         }
     30        self::delete_user( self::$user_id );
    3531    }
    3632
  • trunk/tests/phpunit/tests/comment.php

    r35186 r35224  
    1818        wp_delete_post( self::$post_id );
    1919
    20         if ( is_multisite() ) {
    21             wpmu_delete_user( self::$user_id );
    22         } else {
    23             wp_delete_user( self::$user_id );
    24         }
     20        self::delete_user( self::$user_id );
    2521    }
    2622
  • trunk/tests/phpunit/tests/feed/rss2.php

    r35186 r35224  
    1010 */
    1111class Tests_Feed_RSS2 extends WP_UnitTestCase {
    12     static $user;
     12    static $user_id;
    1313    static $posts;
    1414
    1515    public static function wpSetUpBeforeClass( $factory ) {
    16         self::$user = $factory->user->create();
     16        self::$user_id = $factory->user->create();
    1717        self::$posts = $factory->post->create_many( 5, array(
    18             'post_author' => self::$user,
     18            'post_author' => self::$user_id,
    1919        ) );
    2020    }
    2121
    2222    public static function wpTearDownAfterClass() {
    23         if ( is_multisite() ) {
    24             wpmu_delete_user( self::$user );
    25         } else {
    26             wp_delete_user( self::$user );
    27         }
     23        self::delete_user( self::$user_id );
    2824
    2925        foreach ( self::$posts as $post ) {
  • trunk/tests/phpunit/tests/post.php

    r35186 r35224  
    2626        $ids = array( self::$editor_id, self::$grammarian_id );
    2727        foreach ( $ids as $id ) {
    28             if ( is_multisite() ) {
    29                 wpmu_delete_user( $id );
    30             } else {
    31                 wp_delete_user( $id );
    32             }
     28            self::delete_user( $id );
    3329        }
    3430    }
  • trunk/tests/phpunit/tests/post/revisions.php

    r35193 r35224  
    1919        $ids = array( self::$admin_user_id, self::$editor_user_id, self::$author_user_id );
    2020        foreach ( $ids as $id ) {
    21             if ( is_multisite() ) {
    22                 wpmu_delete_user( $id );
    23             } else {
    24                 wp_delete_user( $id );
    25             }
     21            self::delete_user( $id );
    2622        }
    2723    }
  • 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(
  • trunk/tests/phpunit/tests/user.php

    r35189 r35224  
    3030        $ids = array( self::$test_id, self::$author_id );
    3131        foreach ( $ids as $id ) {
    32             if ( is_multisite() ) {
    33                 wpmu_delete_user( $id );
    34             } else {
    35                 wp_delete_user( $id );
    36             }
     32            self::delete_user( $id );
    3733        }
    3834    }
     
    596592                'user_email' => 'blackburn@battlefield4.com',
    597593            ) );
    598            
     594
    599595            if ( ! defined( 'WP_IMPORTING' ) ) {
    600596                $this->assertWPError( $return );
     
    653649
    654650    function _illegal_user_logins() {
    655         return array( 'testuser' ); 
     651        return array( 'testuser' );
    656652    }
    657653
  • trunk/tests/phpunit/tests/user/countUserPosts.php

    r35186 r35224  
    3535
    3636    public static function wpTearDownAfterClass() {
    37         if ( is_multisite() ) {
    38             wpmu_delete_user( self::$user_id );
    39         } else {
    40             wp_delete_user( self::$user_id );
    41         }
     37        self::delete_user( self::$user_id );
    4238
    4339        foreach ( self::$post_ids as $post_id ) {
  • trunk/tests/phpunit/tests/user/listAuthors.php

    r35186 r35224  
    4343    public static function wpTearDownAfterClass() {
    4444        foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) {
    45             if ( is_multisite() ) {
    46                 wpmu_delete_user( $user_id );
    47             } else {
    48                 wp_delete_user( $user_id );
    49             }
     45            self::delete_user( $user_id );
    5046        }
    5147
  • trunk/tests/phpunit/tests/user/query.php

    r35206 r35224  
    4747        foreach ( $sets as $set ) {
    4848            foreach ( $set as $id ) {
    49                 if ( is_multisite() ) {
    50                     wpmu_delete_user( $id );
    51                 } else {
    52                     wp_delete_user( $id );
    53                 }
     49                self::delete_user( $id );
    5450            }
    5551        }
  • trunk/tests/phpunit/tests/user/wpDeleteUser.php

    r34034 r35224  
    2020
    2121        // Non-existent users don't have blogs.
    22         if ( is_multisite() )
    23             wpmu_delete_user( $user_id );
    24         else
    25             wp_delete_user( $user_id );
     22        self::delete_user( $user_id );
    2623
    2724        $user = new WP_User( $user_id );
Note: See TracChangeset for help on using the changeset viewer.