withTestUser
Helper trait to pose as user when running an integration test
Tags
-
author
-
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 |
loginUser()
protected
loginUser(
$user :
UserInterface
)
: mixed
Parameters
-
$user
: UserInterface
Return values
mixed
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
= []
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
giveUserPermission()
Add the test permission to a Role, then the role to the user
protected
giveUserPermission(
$user :
UserInterface
, $permission :
Permission
)
: Role
Parameters
-
$user
: UserInterface
-
$permission
: Permission
Return values
Role
— The intermidiate role