Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 04:30:23 PM (6 months ago)
Author:
espellcaste
Message:

Unit Tests: Conducted a thorough review of existing unit tests files and improved them to ensure robustness.

Props imath.

Closes https://github.com/buddypress/buddypress/pull/295
Fixes #9081

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/caps.php

    r13314 r13980  
    2020
    2121    public function tear_down() {
     22        self::set_current_user( $this->reset_user_id );
    2223        parent::tear_down();
    23 
    24         $this->set_current_user( $this->reset_user_id );
    2524    }
    2625
     
    3332        $u = self::factory()->user->create();
    3433
    35         $this->set_current_user( $u );
     34        self::set_current_user( $u );
    3635
    3736        add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     
    5554        $u = self::factory()->user->create();
    5655
    57         $this->set_current_user( $u );
     56        self::set_current_user( $u );
    5857
    5958        add_filter( 'user_has_cap', array( $this, 'grant_cap_foo' ), 10, 2 );
     
    8988        );
    9089
    91         $this->set_current_user( $u );
     90        self::set_current_user( $u );
    9291
    9392        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Administrator can `bp_moderate` on default WordPress config' );
     
    109108        );
    110109
    111         $this->set_current_user( $u );
     110        self::set_current_user( $u );
    112111
    113112        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Users having a `manage_options` cap into their role can `bp_moderate`' );
     
    131130        );
    132131
    133         $this->set_current_user( $u1 );
     132        self::set_current_user( $u1 );
    134133
    135134        $email = self::factory()->post->create(
     
    141140        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails they created' );
    142141
    143         $this->set_current_user( $u2 );
     142        self::set_current_user( $u2 );
    144143
    145144        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Administrator should be able to edit emails others created when BuddyPress is not network activated' );
     
    172171        switch_to_blog( $this->blog_id );
    173172
    174         $this->set_current_user( $u1 );
     173        self::set_current_user( $u1 );
    175174        $this->assertTrue( bp_current_user_can( 'bp_moderate' ), 'Only Super Admins can `bp_moderate` when BuddyPress is network activated' );
    176175
    177         $this->set_current_user( $u2 );
     176        self::set_current_user( $u2 );
    178177
    179178        $this->assertFalse( bp_current_user_can( 'bp_moderate' ), 'Regular Admins cannot `bp_moderate` when BuddyPress is network activated' );
     
    220219        restore_current_blog();
    221220
    222         $this->set_current_user( $u1 );
     221        self::set_current_user( $u1 );
    223222        $this->assertTrue( current_user_can( 'edit_post', $email ), 'Super Admins should be able to edit emails they created' );
    224223
    225         $this->set_current_user( $u2 );
     224        self::set_current_user( $u2 );
    226225        $this->assertFalse( current_user_can( 'edit_post', $email ), 'Administrator should not be able to edit emails others created when BuddyPress is network activated' );
    227226
Note: See TracChangeset for help on using the changeset viewer.