protected function ProphesizePermissionsTrait::injectAccount in GraphQL 8.3
Bypass user access.
1 call to ProphesizePermissionsTrait::injectAccount()
- GraphQLTestBase::setUp in tests/
src/ Kernel/ GraphQLTestBase.php
File
- tests/
src/ Traits/ ProphesizePermissionsTrait.php, line 40
Class
- ProphesizePermissionsTrait
- Trait to simulate user permissions.
Namespace
Drupal\Tests\graphql\TraitsCode
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());
}