You are here

public function UserSessionTest::testHasPermission in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Session/UserSessionTest.php \Drupal\Tests\Core\Session\UserSessionTest::testHasPermission()
  2. 9 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 145

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));
  }
}