public function ChainGroupPermissionCalculatorTest::testAnonymousAuthenticatedSameResult in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/ChainGroupPermissionCalculatorTest.php \Drupal\Tests\group\Kernel\ChainGroupPermissionCalculatorTest::testAnonymousAuthenticatedSameResult()
Tests whether anonymous users and 'pure' outsiders can get the same result.
This is important for hash generation based on the calculated permissions. If both audiences can get a similar result, it means they can share a hash and therefore cache objects.
@depends testCalculateAnonymousPermissions @depends testCalculateAuthenticatedPermissions
File
- tests/
src/ Kernel/ ChainGroupPermissionCalculatorTest.php, line 265
Class
- ChainGroupPermissionCalculatorTest
- Tests the calculation of group permissions.
Namespace
Drupal\Tests\group\KernelCode
public function testAnonymousAuthenticatedSameResult() {
// @todo Use a proper set-up instead of the one from GroupKernelTestBase?
$account = $this
->createUser();
$this
->assertNotEqualsCanonicalizing($this
->convertCalculatedPermissionsToArray($this->permissionCalculator
->calculateAnonymousPermissions()), $this
->convertCalculatedPermissionsToArray($this->permissionCalculator
->calculateAuthenticatedPermissions($account)), 'Calculated permissions for an anonymous and outsider user with different group permissions differ.');
// Update 'default' anonymous role to have same permissions as the
// 'default' outsider role.
$group_role = $this->entityTypeManager
->getStorage('group_role')
->load('default-anonymous');
$group_role
->grantPermissions([
'join group',
'view group',
])
->save();
$this
->assertEqualsCanonicalizing($this
->convertCalculatedPermissionsToArray($this->permissionCalculator
->calculateAnonymousPermissions()), $this
->convertCalculatedPermissionsToArray($this->permissionCalculator
->calculateAuthenticatedPermissions($account)), 'Calculated permissions for an anonymous and outsider user with the same group permissions are the same.');
}