public function testRoleAccess($path,
$grant_accounts,
$deny_accounts) { $cache_contexts_manager =
$this->
prophesize(CacheContextsManager::
class);
$cache_contexts_manager->
assertValidTokens()->
willReturn(TRUE
);
$cache_contexts_manager->
reveal();
$container =
new Container();
$container->
set('cache_contexts_manager',
$cache_contexts_manager);
\Drupal::
setContainer($container);
$role_access_check =
new RoleAccessCheck();
$collection =
$this->
getTestRouteCollection();
foreach ($grant_accounts as $account) { $message =
sprintf('Access granted for user with the roles %s on path: %s',
implode(', ',
$account->
getRoles()),
$path);
$this->
assertEquals(AccessResult::
allowed()->
addCacheContexts(['user.roles'
]),
$role_access_check->
access($collection->
get($path),
$account),
$message);
} // Check all users which don't have access.
foreach ($deny_accounts as $account) { $message =
sprintf('Access denied for user %s with the roles %s on path: %s',
$account->
id(),
implode(', ',
$account->
getRoles()),
$path);
$has_access =
$role_access_check->
access($collection->
get($path),
$account);