From 9d781dc7f580e0390ccc183ace148d3be4783a07 Mon Sep 17 00:00:00 2001 From: "Eirik S. Morland" Date: Tue, 22 Nov 2022 13:46:37 +0100 Subject: [PATCH] Add a helper for the getting of the login submit element --- .../Manager/DrupalAuthenticationManager.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Drupal/DrupalExtension/Manager/DrupalAuthenticationManager.php b/src/Drupal/DrupalExtension/Manager/DrupalAuthenticationManager.php index abe85676..2b5ee3f3 100644 --- a/src/Drupal/DrupalExtension/Manager/DrupalAuthenticationManager.php +++ b/src/Drupal/DrupalExtension/Manager/DrupalAuthenticationManager.php @@ -2,6 +2,7 @@ namespace Drupal\DrupalExtension\Manager; +use Behat\Mink\Element\DocumentElement; use Behat\Mink\Exception\DriverException; use Behat\Mink\Mink; use Drupal\Driver\AuthenticationDriverInterface; @@ -52,6 +53,14 @@ public function __construct(Mink $mink, DrupalUserManagerInterface $drupalUserMa $this->setDrupalParameters($drupalParameters); } + /** + * Helper to get the element we want to use for submitting the login form. + */ + protected function getLoginSubmitElement(DocumentElement $element) + { + return $element->findButton($this->getDrupalText('log_in')); + } + /** * {@inheritdoc} */ @@ -64,7 +73,7 @@ public function logIn(\stdClass $user) $element = $this->getSession()->getPage(); $element->fillField($this->getDrupalText('username_field'), $user->name); $element->fillField($this->getDrupalText('password_field'), $user->pass); - $submit = $element->findButton($this->getDrupalText('log_in')); + $submit = $this->getLoginSubmitElement($element); if (empty($submit)) { throw new \Exception(sprintf("No submit button at %s", $this->getSession()->getCurrentUrl())); }