You are here

public function ChainGroupPermissionCalculatorTest::testCalculatePermissions in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/ChainGroupPermissionCalculatorTest.php \Drupal\Tests\group\Kernel\ChainGroupPermissionCalculatorTest::testCalculatePermissions()

Tests the calculation of an account's permissions.

@covers ::calculatePermissions @depends testCalculateAnonymousPermissions @depends testCalculateAuthenticatedPermissions

File

tests/src/Kernel/ChainGroupPermissionCalculatorTest.php, line 238

Class

ChainGroupPermissionCalculatorTest
Tests the calculation of group permissions.

Namespace

Drupal\Tests\group\Kernel

Code

public function testCalculatePermissions() {
  $account = new AnonymousUserSession();
  $calculated_permissions = $this->permissionCalculator
    ->calculateAnonymousPermissions();
  $this
    ->assertEquals($calculated_permissions, $this->permissionCalculator
    ->calculatePermissions($account), 'The calculated anonymous permissions are returned for an anonymous user.');
  $account = $this
    ->createUser();
  $group = $this
    ->createGroup([
    'type' => 'default',
  ]);
  $group
    ->addMember($account);
  $calculated_permissions = new RefinableCalculatedGroupPermissions();
  $calculated_permissions
    ->merge($this->permissionCalculator
    ->calculateOutsiderPermissions($account))
    ->merge($this->permissionCalculator
    ->calculateMemberPermissions($account));
  $calculated_permissions = new CalculatedGroupPermissions($calculated_permissions);
  $this
    ->assertEquals($calculated_permissions, $this->permissionCalculator
    ->calculatePermissions($account), 'Calculated permissions for a member are returned as a merge of outsider and member permissions.');
}