diff --git a/tests/features/bootstrap/VarbaseContext.php b/tests/features/bootstrap/VarbaseContext.php index 7f7ad387f333f5d18f1413facd801c2a3fbd2ea2..7d05ddb38a5edc57f1e517e542330c6054cea60c 100644 --- a/tests/features/bootstrap/VarbaseContext.php +++ b/tests/features/bootstrap/VarbaseContext.php @@ -72,21 +72,28 @@ class VarbaseContext extends RawDrupalContext implements SnippetAcceptingContext */ public function iAmloggedInUserWithTheUser($username) { - try { - $password = $this->users[$username]; - } - catch (Exception $e) { - throw new \Exception("Password not found for '$username'."); + if (isset($this->users[$username])) { + try { + $password = $this->users[$username]; + } + catch (Exception $e) { + throw new \Exception("Password not found for '$username'."); + } + + if ($this->loggedIn()) { + $this->logout(); + } + + $element = $this->getSession()->getPage(); + $this->getSession()->visit($this->locatePath('/user')); + $element->fillField('edit-name', $username); + $element->fillField('edit-pass', $password); + $submit = $element->findButton('op'); + $submit->click(); } - if ($this->loggedIn()) { - $this->logout(); + else { + throw new \Exception("The '$username' user name is wrong or it was not listed in the list of default testing users."); } - $element = $this->getSession()->getPage(); - $this->getSession()->visit($this->locatePath('/user')); - $element->fillField('edit-name', $username); - $element->fillField('edit-pass', $password); - $submit = $element->findButton('op'); - $submit->click(); } /**