function UserRolesAccessPolicyTest::testAlterPermissions

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

Tests the alterPermissions method.

@covers ::alterPermissions

File

core/tests/Drupal/Tests/Core/Session/UserRolesAccessPolicyTest.php, line 166

Class

UserRolesAccessPolicyTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21UserRolesAccessPolicy.php/class/UserRolesAccessPolicy/11.x" title="Grants permissions based on a user&#039;s roles." class="local">\Drupal\Core\Session\UserRolesAccessPolicy</a> @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testAlterPermissions() : void {
    $account = $this->prophesize(AccountInterface::class);
    $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.