UserFrosting API

withTestUser

Helper trait to pose as user when running an integration test

Tags
author

Louis Charette

Table of Contents

loginUser() mixed
logoutCurrentUser() Logout mixed
createTestUser() Create a test user with no settings/permissions for a controller test trait:short
getRandomUserId() Returns a random user id, exclusing th master id int
giveUserTestPermission() Gives a user a new test permission trait:short
giveUserPermission() Add the test permission to a Role, then the role to the user trait:short

Methods

logoutCurrentUser()

Logout

protected logoutCurrentUser( ) : mixed
Return values
mixed

createTestUser()

Create a test user with no settings/permissions for a controller test

protected createTestUser( [ $isMaster : bool = false ] [, $login : bool = false ] [, $params : array = [] ] ) : User
Parameters
$isMaster : bool = false

Does this user have root access? Will bypass all permissions

$login : bool = false

Login this user, setting him as the currentUser

$params : array = []

User account params

Return values
User

getRandomUserId()

Returns a random user id, exclusing th master id

protected getRandomUserId( $masterId : int ) : int
Parameters
$masterId : int
Return values
int

giveUserTestPermission()

Gives a user a new test permission

protected giveUserTestPermission( $user : UserInterface , $slug : string [, $conditions : string = 'always()' ] ) : Permission
Parameters
$user : UserInterface
$slug : string
$conditions : string = 'always()'
Return values
Permission

Search results