Skip to content

Commit

Permalink
fix: correction de URL dans le email de réinitialisation de mot de pa…
Browse files Browse the repository at this point in the history
…sse (#1599)

Co-authored-by: upskaling <[email protected]>
  • Loading branch information
upskaling and upskaling authored Jan 25, 2025
1 parent a534693 commit 764cb73
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function resetPassword(User $user)
$this->userRepository->save($user);

$login = $user->getUsername();
$url = $this->urlGenerator->generate('admin_login');
$url = $this->urlGenerator->generate('admin_login', [], UrlGeneratorInterface::ABSOLUTE_URL);
$message = new Message(
'AFUP : Mot de passe perdu ?',
new MailUser($this->sender),
Expand Down
80 changes: 80 additions & 0 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,84 @@ public function printLastResponseHeaders(): void

echo implode("\n", $headers);
}

/**
* @When I request a password reset for :arg1
*/
public function iRequestAPasswordReset(string $arg1): void
{
$this->minkContext->iAmOnHomepage();
$this->minkContext->assertPageContainsText("Tous les trois mois, des nouvelles de L'AFUP");
$this->minkContext->clickLink("Se connecter");
$this->minkContext->assertPageContainsText("Email ou nom d'utilisateur");
$this->minkContext->clickLink("Mot de passe perdu");
$this->minkContext->assertPageContainsText("Mot de passe perdu");
$this->minkContext->fillField("form_email", $arg1);
$this->minkContext->pressButton("Demander un nouveau mot de passe");
$this->minkContext->assertPageContainsText("Votre demande a été prise en compte. Si un compte correspond à cet email vous recevez un nouveau mot de passe rapidement.");
}

/**
* @Then I should receive an email
*/
public function iShouldReceiveAnEmail(): void
{
$content = file_get_contents(self::MAILCATCHER_URL.'/messages');
$decodedContent = json_decode($content, true);

$foundEmails = [];
foreach ($decodedContent as $mail) {
$foundEmails[] = [
'to' => $mail['to'],
'subject' => $mail['subject'],
];
}

if (count($foundEmails) !== 1) {
throw new ExpectationException(
sprintf(
'The email has not been received "%s" (expected "%s")',
var_export($foundEmails, true),
)
);
}
}

/**
* @Then the email should contain a full URL starting with :arg1
*/
public function theEmailShouldContainAFullUrlStartingWith(string $arg1): void
{
$content = file_get_contents(self::MAILCATCHER_URL.'/messages');
$decodedContent = json_decode($content, true);

$foundEmails = [];
foreach ($decodedContent as $mail) {
$foundEmails[] = [
'id' => $mail['id'],
'to' => $mail['to'],
'subject' => $mail['subject'],
];
}

if (count($foundEmails) !== 1) {
throw new ExpectationException(
sprintf(
'The email has not been received "%s" (expected "%s")',
var_export($foundEmails, true),
)
);
}

$content = file_get_contents(self::MAILCATCHER_URL.'/messages/'.$foundEmails[0]['id'].'.plain');
if (false === strpos($content, $arg1)) {
throw new ExpectationException(
sprintf(
'The email content does not contain the expected URL "%s" (expected "%s")',
$content,
$arg1
)
);
}
}
}
8 changes: 8 additions & 0 deletions tests/behat/features/Admin/PasswordReset.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Password Reset

@reloadDbWithTestData
@clearEmails
Scenario: L'utilisateur reçoit une URL de connexion complète dans l'e-mail de réinitialisation du mot de passe.
When I request a password reset for "[email protected]"
Then I should receive an email
And the email should contain a full URL starting with "https://apachephptest:80/admin/login"

0 comments on commit 764cb73

Please sign in to comment.