function SuperUserAccessPolicyTest::testAlterPermissions

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Session/SuperUserAccessPolicyTest.php \Drupal\Tests\Core\Session\SuperUserAccessPolicyTest::testAlterPermissions()

Tests the alterPermissions method.

@covers ::alterPermissions @dataProvider alterPermissionsProvider

Parameters

int $uid: The UID for the account the policy checks.

File

core/tests/Drupal/Tests/Core/Session/SuperUserAccessPolicyTest.php, line 104

Class

SuperUserAccessPolicyTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21SuperUserAccessPolicy.php/class/SuperUserAccessPolicy/10" title="Grants user 1 an all access pass." class="local">\Drupal\Core\Session\SuperUserAccessPolicy</a> @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testAlterPermissions(int $uid) : void {
    $account = $this->prophesize(AccountInterface::class);
    $account->id()
        ->willReturn($uid);
    $calculated_permissions = new RefinableCalculatedPermissions();
    $calculated_permissions->addItem(new CalculatedPermissionsItem([
        'foo',
    ]));
    $calculated_permissions->addCacheTags([
        'bar',
    ]);
    $calculated_permissions->addCacheContexts([
        'baz',
    ]);
    $this->accessPolicy
        ->alterPermissions($account->reveal(), AccessPolicyInterface::SCOPE_DRUPAL, $calculated_permissions);
    $this->assertSame([
        'foo',
    ], $calculated_permissions->getItem()
        ->getPermissions());
    $this->assertSame([
        'bar',
    ], $calculated_permissions->getCacheTags());
    $this->assertSame([
        'baz',
    ], $calculated_permissions->getCacheContexts());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.