Skip to content

Commit

Permalink
Fix for issue #680: Refactor DrupalAuthenticationManager::logout to fix
Browse files Browse the repository at this point in the history
Add new Drupal Text name and url for the logout confirmation page.

Refactor DrupalAuthenticationManager::logout to check if a logout
confirmation page is present and if it is click submit.
  • Loading branch information
tame4tex committed Oct 18, 2024
1 parent 099cc02 commit 9deecf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ protected function getLoginSubmitElement(DocumentElement $element)
return $element->findButton($this->getDrupalText('log_in'));
}

/**
* Helper to get the submit element for the logout confirmation form.
*/
protected function getLogoutConfirmSubmitElement(DocumentElement $element)
{
return $element->findButton($this->getDrupalText('log_out'));
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -102,7 +110,13 @@ public function logIn(\stdClass $user)
*/
public function logout()
{
$this->getSession()->visit($this->locatePath($this->getDrupalText('logout_url')));
$session = $this->getSession();
$session->visit($this->locatePath($this->getDrupalText('logout_url')));
// Check to see if the user is on the logout confirm page (10.3+).
if ($session->getCurrentUrl() === $this->locatePath($this->getDrupalText('logout_confirm_url'))) {
$submit = $this->getLogoutConfirmSubmitElement($session->getPage());
$submit->click();
}
$this->userManager->setCurrentUser(false);

// Log the user out on the backend if possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function configure(ArrayNodeDefinition $builder)
'Text strings, such as Log out or the Username field can be altered via behat.yml if they vary from the default values.' . PHP_EOL
. ' login_url: "/user"' . PHP_EOL
. ' logout_url: "/user/logout"' . PHP_EOL
. ' logout_confirm_url: "/user/logout/confirm"' . PHP_EOL
. ' log_out: "Sign out"' . PHP_EOL
. ' log_in: "Sign in"' . PHP_EOL
. ' password_field: "Enter your password"' . PHP_EOL
Expand All @@ -144,6 +145,9 @@ public function configure(ArrayNodeDefinition $builder)
scalarNode('logout_url')->
defaultValue('/user/logout')->
end()->
scalarNode('logout_confirm_url')->
defaultValue('/user/logout/confirm')->
end()->
scalarNode('log_in')->
defaultValue('Log in')->
end()->
Expand Down

0 comments on commit 9deecf3

Please sign in to comment.