public function ChainGroupPermissionCalculatorTest::testCalculateOutsiderPermissions in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/ChainGroupPermissionCalculatorTest.php \Drupal\Tests\group\Kernel\ChainGroupPermissionCalculatorTest::testCalculateOutsiderPermissions()
Tests the calculation of the outsider permissions.
@covers ::calculateOutsiderPermissions
File
- tests/
src/ Kernel/ ChainGroupPermissionCalculatorTest.php, line 103
Class
- ChainGroupPermissionCalculatorTest
- Tests the calculation of group permissions.
Namespace
Drupal\Tests\group\KernelCode
public function testCalculateOutsiderPermissions() {
// @todo Use a proper set-up instead of the one from GroupKernelTestBase?
$account = $this
->createUser([
'roles' => [
'test',
],
]);
$group_role_id = $this->roleSynchronizer
->getGroupRoleId('default', 'test');
$permissions = [
'default' => [
'join group',
'view group',
],
'other' => [],
];
$cache_tags = [
'config:group.role.default-outsider',
'config:group.role.other-outsider',
'config:group.role.' . $group_role_id,
'config:group.role.' . $this->roleSynchronizer
->getGroupRoleId('other', 'test'),
'config:group_type_list',
'group_permissions',
];
sort($cache_tags);
$calculated_permissions = $this->permissionCalculator
->calculateOutsiderPermissions($account);
$converted = $this
->convertCalculatedPermissionsToArray($calculated_permissions);
$this
->assertEqualsCanonicalizing($permissions, $converted, 'Outsider permissions are returned per group type.');
$this
->assertSame(-1, $calculated_permissions
->getCacheMaxAge(), 'Outsider permissions have the right max cache age.');
$this
->assertSame($cache_tags, $calculated_permissions
->getCacheTags(), 'Outsider permissions have the right cache tags.');
$group_role = $this->entityTypeManager
->getStorage('group_role')
->load('other-outsider');
$group_role
->grantPermission('view group')
->save();
$permissions['other'][] = 'view group';
$calculated_permissions = $this->permissionCalculator
->calculateOutsiderPermissions($account);
$converted = $this
->convertCalculatedPermissionsToArray($calculated_permissions);
$this
->assertEqualsCanonicalizing($permissions, $converted, 'Updated outsider permissions are returned per group type.');
$this
->assertSame(-1, $calculated_permissions
->getCacheMaxAge(), 'Updated outsider permissions have the right max cache age.');
$this
->assertSame($cache_tags, $calculated_permissions
->getCacheTags(), 'Updated outsider permissions have the right cache tags.');
$group_role = $this->entityTypeManager
->getStorage('group_role')
->load($group_role_id);
$group_role
->grantPermission('edit group')
->save();
$permissions['default'][] = 'edit group';
$calculated_permissions = $this->permissionCalculator
->calculateOutsiderPermissions($account);
$converted = $this
->convertCalculatedPermissionsToArray($calculated_permissions);
$this
->assertEqualsCanonicalizing($permissions, $converted, 'Updated synchronized outsider permissions are returned per group type.');
$this
->assertSame(-1, $calculated_permissions
->getCacheMaxAge(), 'Updated synchronized outsider permissions have the right max cache age.');
$this
->assertSame($cache_tags, $calculated_permissions
->getCacheTags(), 'Updated synchronized outsider permissions have the right cache tags.');
$this
->createGroupType([
'id' => 'test',
]);
$permissions['test'] = [];
$cache_tags[] = 'config:group.role.test-outsider';
$cache_tags[] = 'config:group.role.' . $this->roleSynchronizer
->getGroupRoleId('test', 'test');
sort($cache_tags);
$calculated_permissions = $this->permissionCalculator
->calculateOutsiderPermissions($account);
$converted = $this
->convertCalculatedPermissionsToArray($calculated_permissions);
$this
->assertEqualsCanonicalizing($permissions, $converted, 'Outsider permissions are updated after introducing a new group type.');
$this
->assertSame(-1, $calculated_permissions
->getCacheMaxAge(), 'Outsider permissions have the right max cache age after introducing a new group type.');
$this
->assertSame($cache_tags, $calculated_permissions
->getCacheTags(), 'Outsider permissions have the right cache tags after introducing a new group type.');
}