function 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[[api-linebreak]] @group DefaultContent
Namespace
Drupal\KernelTests\Core\DefaultContentCode
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.
