Skip to:
Content

BuddyPress.org

Changeset 7362


Ignore:
Timestamp:
09/02/2013 02:52:10 AM (11 years ago)
Author:
boonebgorges
Message:

Introduces grant_bp_moderate() to testcase

In some cases, we have to test on the fly whether a given user has the
bp_moderate cap. This utility method makes it easy to do so in the unit
tests. Note that this implementation depends on using bp_current_user_can(),
rather than the WP equivalent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.8/tests/includes/testcase.php

    r7237 r7362  
    1010
    1111class BP_UnitTestCase extends WP_UnitTestCase {
     12
     13    protected $temp_has_bp_moderate = array();
    1214
    1315    public function setUp() {
     
    264266    }
    265267
     268    public function grant_bp_moderate( $user_id ) {
     269        if ( ! isset( $this->temp_has_bp_moderate[ $user_id ] ) ) {
     270            $this->temp_has_bp_moderate[ $user_id ] = 1;
     271        }
     272        add_filter( 'bp_current_user_can', array( $this, 'grant_bp_moderate_cb' ), 10, 2 );
     273    }
     274
     275    public function revoke_bp_moderate( $user_id ) {
     276        if ( isset( $this->temp_has_bp_moderate[ $user_id ] ) ) {
     277            unset( $this->temp_has_bp_moderate[ $user_id ] );
     278        }
     279        remove_filter( 'bp_current_user_can', array( $this, 'grant_bp_moderate_cb' ), 10, 2 );
     280    }
     281
     282    public function grant_bp_moderate_cb( $retval, $capability ) {
     283        $current_user = bp_loggedin_user_id();
     284        if ( ! isset( $this->temp_has_bp_moderate[ $current_user ] ) ) {
     285            return $retval;
     286        }
     287
     288        if ( 'bp_moderate' == $capability ) {
     289            $retval = true;
     290        }
     291
     292        return $retval;
     293    }
     294
    266295    /**
    267296     * Go to the root blog. This helps reset globals after moving between
Note: See TracChangeset for help on using the changeset viewer.