function AccountProxyTest::testHasRole

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

@covers ::hasRole

File

core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php, line 59

Class

AccountProxyTest
@coversDefaultClass \Drupal\Core\Session\AccountProxy @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testHasRole() : void {
    $dispatcher = $this->prophesize(EventDispatcherInterface::class);
    $dispatcher->dispatch(Argument::any(), Argument::any())
        ->willReturn(new Event());
    $account_proxy = new AccountProxy($dispatcher->reveal());
    $this->assertTrue($account_proxy->hasRole(RoleInterface::ANONYMOUS_ID));
    $current_user = $this->prophesize(UserSession::class);
    $current_user->id()
        ->willReturn(2);
    $current_user->hasRole(RoleInterface::AUTHENTICATED_ID)
        ->willReturn(TRUE);
    $account_proxy->setAccount($current_user->reveal());
    $this->assertTrue($account_proxy->hasRole(RoleInterface::AUTHENTICATED_ID));
}

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