public function GroupContentAccessControlHandlerTest::entityAccessProvider in Group 8
Data provider for testEntityAccess().
Return value
array A list of testEntityAccess method arguments.
File
- tests/
src/ Unit/ GroupContentAccessControlHandlerTest.php, line 430
Class
- GroupContentAccessControlHandlerTest
- Tests the default GroupContentEnabler access handler.
Namespace
Drupal\Tests\group\UnitCode
public function entityAccessProvider() {
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_grouped) {
foreach ([
TRUE,
FALSE,
] as $is_ownable) {
foreach ([
TRUE,
FALSE,
] as $is_owner) {
foreach ([
TRUE,
FALSE,
] as $is_publishable) {
foreach ([
TRUE,
FALSE,
] as $is_published) {
foreach ([
'view',
$this
->randomMachineName(),
] as $operation) {
$case = $scenario;
$check_published = $operation === 'view' && $is_publishable;
// Default varies on whether the entity is grouped.
$case['expected'] = function () use ($is_grouped, $own_permission, $check_published) {
$result = AccessResult::forbiddenIf($is_grouped);
if ($is_grouped) {
$result
->addCacheContexts([
'user.group_permissions',
]);
if ($own_permission) {
$result
->addCacheContexts([
'user',
]);
}
if ($own_permission || $check_published) {
$result
->addCacheTags([
'some_entity:foo',
]);
$result
->mergeCacheMaxAge(9999);
}
}
return $result;
};
$admin_permission = $case['definition']['admin_permission'];
if ($is_grouped && ($admin_permission || $any_permission || $own_permission)) {
$admin_access = $admin_permission && $case['has_admin_permission'];
if (!$check_published || $is_published) {
$any_access = $any_permission && $case['has_permission'];
$own_access = $is_ownable && $is_owner && $own_permission && $has_own_permission;
}
elseif ($check_published && !$is_published) {
$any_access = $any_permission && $case['has_permission'];
$own_access = $is_ownable && $is_owner && $own_permission && $has_own_permission;
}
else {
$any_access = FALSE;
$own_access = FALSE;
}
$case['expected'] = function () use ($admin_access, $any_access, $own_access, $own_permission, $check_published) {
$result = AccessResult::allowedIf($admin_access || $any_access || $own_access);
if (!$result
->isAllowed()) {
$result = AccessResult::forbidden();
}
if ($own_permission) {
$result
->addCacheContexts([
'user',
]);
}
if ($own_permission || $check_published) {
$result
->addCacheTags([
'some_entity:foo',
]);
$result
->mergeCacheMaxAge(9999);
}
return $result
->addCacheContexts([
'user.group_permissions',
]);
};
}
$case['has_own_permission'] = $has_own_permission;
$case['any_permission'] = $any_permission;
$case['own_permission'] = $own_permission;
$case['is_grouped'] = $is_grouped;
$case['is_ownable'] = $is_ownable;
$case['is_owner'] = $is_owner;
$case['is_publishable'] = $is_publishable;
$case['is_published'] = $is_published;
$case['operation'] = $operation;
(yield $case);
}
}
}
}
}
}
}
}
}
}
}