function UserSessionTest::testHasPermission

Same name and namespace in other branches
  1. 8.9.x 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 145

Class

UserSessionTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Session%21UserSession.php/class/UserSession/9" title="An implementation of the user account interface for the global user." class="local">\Drupal\Core\Session\UserSession</a> @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.