Users

The Mantle Test Framework provides a method, acting_as( $user ) to execute a test as a given user or a user in the given role. This is best explained through code, so here are some examples of using this method:

$this->acting_as( 'administrator' );
$this->assertTrue( current_user_can( 'manage_options' ) );
$this->acting_as( 'contributor' );
$this->get( '/some-admin-only-page/' )
     ->assertForbidden();
$user = $this->acting_as( 'editor' );
$this->acting_as( $some_user_created_elsewhere );