function UserSessionTest::testHasPermission

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testHasPermission()
  2. 10 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testHasPermission()
  3. 11.x core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testHasPermission()

Tests the has permission method.

@dataProvider providerTestHasPermission

Parameters

string $permission: The permission to check.

\Drupal\Core\Session\AccountInterface[] $sessions_with_access: The users with access.

\Drupal\Core\Session\AccountInterface[] $sessions_without_access: The users without access.

See also

\Drupal\Core\Session\UserSession::hasPermission()

File

core/tests/Drupal/Tests/Core/Session/UserSessionTest.php, line 142

Class

UserSessionTest
@coversDefaultClass \Drupal\Core\Session\UserSession @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testHasPermission($permission, array $sessions_with_access, array $sessions_without_access) {
    foreach ($sessions_with_access as $name) {
        $this->assertTrue($this->users[$name]
            ->hasPermission($permission));
    }
    foreach ($sessions_without_access as $name) {
        $this->assertFalse($this->users[$name]
            ->hasPermission($permission));
    }
}

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