function PermissionsHashGeneratorTest::testGenerateNoAccessPolicies

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Session/PermissionsHashGeneratorTest.php \Drupal\Tests\Core\Session\PermissionsHashGeneratorTest::testGenerateNoAccessPolicies()

Tests the generate method with no access policies.

@covers ::generate

File

core/tests/Drupal/Tests/Core/Session/PermissionsHashGeneratorTest.php, line 139

Class

PermissionsHashGeneratorTest
@coversDefaultClass \Drupal\Core\Session\PermissionsHashGenerator @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testGenerateNoAccessPolicies() : void {
    $permissions = new CalculatedPermissions(new RefinableCalculatedPermissions());
    $this->processor
        ->processAccessPolicies($this->account1)
        ->willReturn($permissions);
    $this->processor
        ->processAccessPolicies($this->account2)
        ->willReturn($permissions);
    // Check that two accounts with the same permissions generate the same hash.
    $hash_1 = $this->permissionsHash
        ->generate($this->account1);
    $hash_2 = $this->permissionsHash
        ->generate($this->account2);
    $this->assertSame($hash_1, $hash_2, 'Different accounts generate the same permissions hash when there are no policies.');
    // Check that the generated hash is simply 'no-access-policies'.
    $this->assertSame('no-access-policies', $hash_1, 'Accounts generate the string "is-admin" as their permissions hash when no policies are defined.');
}

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