function AdminAccountSwitcherTest::testSwitchToAndSwitchBack

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/DefaultContent/AdminAccountSwitcherTest.php \Drupal\KernelTests\Core\DefaultContent\AdminAccountSwitcherTest::testSwitchToAndSwitchBack()
  2. 10 core/tests/Drupal/KernelTests/Core/DefaultContent/AdminAccountSwitcherTest.php \Drupal\KernelTests\Core\DefaultContent\AdminAccountSwitcherTest::testSwitchToAndSwitchBack()

Tests switching and switching back.

File

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

Class

AdminAccountSwitcherTest
Tests Admin Account Switcher.

Namespace

Drupal\KernelTests\Core\DefaultContent

Code

public function testSwitchToAndSwitchBack() : void {
  $this->assertTrue($this->container
    ->get('current_user')
    ->isAnonymous());
  /** @var \Drupal\Core\Session\AccountInterface $account */
  $account = $this->createUser();
  $switcher = $this->container
    ->get(AdminAccountSwitcher::class);
  $this->assertSame($switcher, $switcher->switchTo($account));
  $this->assertSame($account->id(), $this->container
    ->get('current_user')
    ->id());
  $this->assertSame($switcher, $switcher->switchBack());
  $this->assertTrue($this->container
    ->get('current_user')
    ->isAnonymous());
}

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