function UiHelperTrait::drupalLogout

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::drupalLogout()
  2. 10 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::drupalLogout()
  3. 8.9.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::drupalLogout()

Logs a user out of the Mink controlled browser and confirms.

Confirms logout by checking the login page.

3 calls to UiHelperTrait::drupalLogout()
MenuActiveTrail403Test::testMenuActiveTrail403Cache in core/tests/Drupal/FunctionalTests/Menu/MenuActiveTrail403Test.php
Tests that visiting 403 page does not override original active trail.
UiHelperTrait::drupalLogin in core/tests/Drupal/Tests/UiHelperTrait.php
Logs in a user using the Mink controlled browser.
UserLanguageCreationTest::testLocalUserCreation in core/modules/user/tests/src/Functional/UserLanguageCreationTest.php
Functional test for language handling during user creation.

File

core/tests/Drupal/Tests/UiHelperTrait.php, line 272

Class

UiHelperTrait
Provides UI helper methods.

Namespace

Drupal\Tests

Code

protected function drupalLogout() {
  // Make a request to the logout page, and redirect to the user page, the
  // idea being if you were properly logged out you should be seeing a login
  // screen.
  $assert_session = $this->assertSession();
  $destination = Url::fromRoute('user.page')->toString();
  $this->drupalGet(Url::fromRoute('user.logout', [], [
    'query' => [
      'destination' => $destination,
    ],
  ]));
  $assert_session->fieldExists('name');
  $assert_session->fieldExists('pass');
  // @see BrowserTestBase::drupalUserIsLoggedIn()
  unset($this->loggedInUser->sessionId);
  $this->loggedInUser = FALSE;
  \Drupal::currentUser()->setAccount(new AnonymousUserSession());
}

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