function UserRolesCacheContextTest::testCalculatedRole
Same name in other branches
- 11.x core/tests/Drupal/Tests/Core/Cache/Context/UserRolesCacheContextTest.php \Drupal\Tests\Core\Cache\Context\UserRolesCacheContextTest::testCalculatedRole()
@covers ::getContext
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ Context/ UserRolesCacheContextTest.php, line 20
Class
- UserRolesCacheContextTest
- @coversDefaultClass \Drupal\Core\Cache\Context\UserRolesCacheContext @group Cache
Namespace
Drupal\Tests\Core\Cache\ContextCode
public function testCalculatedRole() : void {
$current_user = $this->prophesize(AccountInterface::class);
// Ensure the ID is not 1. This cache context gives user 1 a special superuser value.
$current_user->id()
->willReturn(2);
$current_user->getRoles()
->willReturn([
'role1',
'role2',
]);
$cache_context = new UserRolesCacheContext($current_user->reveal());
$this->assertSame('true', $cache_context->getContext('role1'));
$this->assertSame('false', $cache_context->getContext('role-not-held'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.