function AdminAccountSwitcherTest::testNoAdministratorsExist

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

Tests that there is an error if there are no administrative users.

File

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

Class

AdminAccountSwitcherTest
@covers \Drupal\Core\DefaultContent\AdminAccountSwitcher[[api-linebreak]] @group DefaultContent

Namespace

Drupal\KernelTests\Core\DefaultContent

Code

public function testNoAdministratorsExist() : void {
  /** @var \Drupal\Core\Session\AccountInterface $account */
  $account = $this->createUser();
  $this->assertSame(1, (int) $account->id());
  $this->expectException(AccessException::class);
  $this->expectExceptionMessage("There are no user accounts with administrative roles.");
  $this->container
    ->get(AdminAccountSwitcher::class)
    ->switchToAdministrator();
}

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