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.

40 calls to UiHelperTrait::drupalLogout()
BlockTest::testBlockCacheTags in core/modules/block/tests/src/Functional/BlockTest.php
Tests that cache tags are properly set and bubbled up to the page cache.
BlockTest::testBlockVisibility in core/modules/block/tests/src/Functional/BlockTest.php
Tests block visibility.
BlockTest::testBlockVisibilityListedEmpty in core/modules/block/tests/src/Functional/BlockTest.php
Tests block visibility when leaving "pages" textarea empty.
ConfigTranslationCacheTest::testFieldConfigTranslation in core/modules/config_translation/tests/src/Functional/ConfigTranslationCacheTest.php
Tests the translation of field and field storage configuration.
ConfigTranslationUiTest::testContactConfigEntityTranslation in core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
Tests the contact form translation.

... See full list

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.