public function GroupContentAccessControlHandlerTest::relationAccessProvider in Group 8
Data provider for testRelationAccess().
Return value
array A list of testRelationAccess method arguments.
File
- tests/
src/ Unit/ GroupContentAccessControlHandlerTest.php, line 151
Class
- GroupContentAccessControlHandlerTest
- Tests the default GroupContentEnabler access handler.
Namespace
Drupal\Tests\group\UnitCode
public function relationAccessProvider() {
$cases = [];
foreach ($this
->getAccessControlHandlerScenarios() as $scenario) {
foreach ([
'any some permission name',
FALSE,
] as $any_permission) {
foreach ([
'own some permission name',
FALSE,
] as $own_permission) {
foreach ([
TRUE,
FALSE,
] as $has_own_permission) {
foreach ([
TRUE,
FALSE,
] as $is_owner) {
$case = $scenario;
// Default is neutral result if no permissions are defined.
$case['expected'] = function () {
return AccessResult::neutral();
};
$admin_permission = $case['definition']['admin_permission'];
if ($admin_permission || $any_permission || $own_permission) {
$has_admin = $admin_permission && $case['has_admin_permission'];
$has_any = $any_permission && $case['has_permission'];
$has_own = $is_owner && $own_permission && $has_own_permission;
$permissions_were_checked = $admin_permission || $any_permission || $is_owner && $own_permission;
$case['expected'] = function () use ($has_admin, $has_any, $has_own, $permissions_were_checked, $own_permission) {
$result = AccessResult::allowedIf($has_admin || $has_any || $has_own);
// Only add the permissions context if they were checked.
if ($permissions_were_checked) {
$result
->addCacheContexts([
'user.group_permissions',
]);
}
// Add the user context and the relation's cache metadata if
// we're dealing with an owner permission.
if ($own_permission) {
$result
->addCacheContexts([
'user',
]);
// Tags and max-age as defined in ::testRelationAccess().
$result
->addCacheTags([
'group_content:foo',
]);
$result
->mergeCacheMaxAge(9999);
}
return $result;
};
}
$case['has_own_permission'] = $has_own_permission;
$case['any_permission'] = $any_permission;
$case['own_permission'] = $own_permission;
$case['is_owner'] = $is_owner;
$cases[] = $case;
}
}
}
}
}
return $cases;
}