Skip to content

Commit

Permalink
Utilize the fast logout method for step definitions
Browse files Browse the repository at this point in the history
- Also utilizes fast logout during user cleanup.
- Addresses #62
  • Loading branch information
jhedstrom committed Dec 1, 2017
1 parent b8c8a4d commit 4003825
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/Drupal/DrupalExtension/Context/DrupalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public static function getTranslationResources() {
*/
public function assertAnonymousUser() {
// Verify the user is logged out.
if ($this->loggedIn()) {
$this->logout();
}
$this->logout(TRUE);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/Drupal/DrupalExtension/Context/RawDrupalContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Drupal\DrupalExtension\Hook\Scope\BeforeNodeCreateScope;
use Drupal\DrupalExtension\Hook\Scope\BeforeUserCreateScope;
use Drupal\DrupalExtension\Hook\Scope\BeforeTermCreateScope;
use Drupal\DrupalExtension\Manager\FastLogoutInterface;


/**
Expand Down Expand Up @@ -251,9 +252,7 @@ public function cleanUsers() {
}
$this->getDriver()->processBatch();
$this->userManager->clearUsers();
if ($this->loggedIn()) {
$this->logout();
}
$this->logout(TRUE);
}
}

Expand Down Expand Up @@ -511,9 +510,17 @@ public function login(\stdClass $user) {

/**
* Logs the current user out.
*
* @param bool $fast
* Utilize direct logout by session if available.
*/
public function logout() {
$this->getAuthenticationManager()->logOut();
public function logout($fast = FALSE) {
if ($fast && $this->getAuthenticationManager() instanceof FastLogoutInterface) {
$this->getAuthenticationManager()->fastLogout();
}
else {
$this->getAuthenticationManager()->logOut();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Default implementation of the Drupal authentication manager service.
*/
class DrupalAuthenticationManager implements DrupalAuthenticationManagerInterface
class DrupalAuthenticationManager implements DrupalAuthenticationManagerInterface, FastLogoutInterface
{

use DrupalParametersTrait;
Expand Down Expand Up @@ -124,12 +124,9 @@ public function loggedIn() {
}

/**
* Logs out by directly resetting the session.
*
* A fast logout method that resets the session and doesn't need to
* bootstrap Drupal. This should not be used if logout hooks need to fire.
* {@inheritdoc}
*/
protected function fastLogout()
public function fastLogout()
{
$this->getSession()->reset();
$this->userManager->setCurrentUser(FALSE);
Expand Down
17 changes: 17 additions & 0 deletions src/Drupal/DrupalExtension/Manager/FastLogoutInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Drupal\DrupalExtension\Manager;

/**
* Interface for authentication managers that support fast logout.
*/
interface FastLogoutInterface
{
/**
* Logs out by directly resetting the session.
*
* A fast logout method that resets the session and doesn't need to
* bootstrap Drupal. This should not be used if logout hooks need to fire.
*/
public function fastLogout();
}

0 comments on commit 4003825

Please sign in to comment.