function SuperUserAccessPolicyTest::testCalculatePermissions
Tests the calculatePermissions method.
@covers ::calculatePermissions
      
    
@dataProvider calculatePermissionsProvider
Parameters
int $uid: The UID for the account the policy checks.
bool $expect_admin_rights: Whether to expect admin rights to be granted.
File
- 
              core/
tests/ Drupal/ Tests/ Core/ Session/ SuperUserAccessPolicyTest.php, line 66  
Class
- SuperUserAccessPolicyTest
 - @coversDefaultClass \Drupal\Core\Session\SuperUserAccessPolicy[[api-linebreak]] @group Session
 
Namespace
Drupal\Tests\Core\SessionCode
public function testCalculatePermissions(int $uid, bool $expect_admin_rights) : void {
  $account = $this->prophesize(AccountInterface::class);
  $account->id()
    ->willReturn($uid);
  $calculated_permissions = $this->accessPolicy
    ->calculatePermissions($account->reveal(), AccessPolicyInterface::SCOPE_DRUPAL);
  if ($expect_admin_rights) {
    $this->assertCount(1, $calculated_permissions->getItems(), 'Only one calculated permissions item was added.');
    $item = $calculated_permissions->getItem();
    $this->assertSame([], $item->getPermissions());
    $this->assertTrue($item->isAdmin());
  }
  $this->assertSame([], $calculated_permissions->getCacheTags());
  $this->assertSame([
    'user.is_super_user',
  ], $calculated_permissions->getCacheContexts());
  $this->assertSame(Cache::PERMANENT, $calculated_permissions->getCacheMaxAge());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.