trait ProphesizePermissionsTrait in GraphQL 8.3
Trait to simulate user permissions.
Hierarchy
- trait \Drupal\Tests\graphql\Traits\ProphesizePermissionsTrait
1 file declares its use of ProphesizePermissionsTrait
- GraphQLTestBase.php in tests/
src/ Kernel/ GraphQLTestBase.php
File
- tests/
src/ Traits/ ProphesizePermissionsTrait.php, line 11
Namespace
Drupal\Tests\graphql\TraitsView source
trait ProphesizePermissionsTrait {
protected $accountProphecy;
/**
* Set the prophesized permissions.
*
* @return string[]
* The permissions to set on the prophesized user.
*/
protected function userPermissions() {
return [
'execute graphql requests',
'bypass graphql field security',
];
}
/**
* Set the prophesized roles.
*
* @return string[]
*/
protected function userRoles() {
return [
'anonymous',
];
}
/**
* Bypass user access.
*/
protected function injectAccount() {
// Replace the current user with a prophecy that has the defined
// permissions.
$user = $this
->prophesize(AccountProxyInterface::class);
$permissions = $this
->userPermissions();
$user
->hasPermission(Argument::type('string'), Argument::cetera())
->will(function ($args) use ($permissions) {
return in_array($args[0], $permissions);
});
$user
->getRoles(Argument::any())
->willReturn($this
->userRoles());
$user
->id()
->willReturn(0);
$user
->isAnonymous()
->willReturn(TRUE);
$user
->isAuthenticated()
->willReturn(FALSE);
$this->accountProphecy = $user;
$this->container
->set('current_user', $user
->reveal());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProphesizePermissionsTrait:: |
protected | property | ||
ProphesizePermissionsTrait:: |
protected | function | Bypass user access. | |
ProphesizePermissionsTrait:: |
protected | function | Set the prophesized permissions. | 3 |
ProphesizePermissionsTrait:: |
protected | function | Set the prophesized roles. |