function AdminAccountSwitcherTest::testSwitchToAdministrator

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/DefaultContent/AdminAccountSwitcherTest.php \Drupal\KernelTests\Core\DefaultContent\AdminAccountSwitcherTest::testSwitchToAdministrator()

Tests switching to a user with an administrative role.

File

core/tests/Drupal/KernelTests/Core/DefaultContent/AdminAccountSwitcherTest.php, line 47

Class

AdminAccountSwitcherTest
@covers \Drupal\Core\DefaultContent\AdminAccountSwitcher @group DefaultContent

Namespace

Drupal\KernelTests\Core\DefaultContent

Code

public function testSwitchToAdministrator() : void {
    
    /** @var \Drupal\Core\Session\AccountInterface $account */
    $account = $this->createUser(admin: TRUE);
    $this->assertSame($account->id(), $this->container
        ->get(AdminAccountSwitcher::class)
        ->switchToAdministrator()
        ->id());
    $this->assertSame($account->id(), $this->container
        ->get('current_user')
        ->id());
}

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