[Behat] Checked whether a customer receives the welcoming email

This commit is contained in:
Jan Goralski 2016-08-30 20:02:18 +02:00
parent a91d26e964
commit 9a9e3b4b28
No known key found for this signature in database
GPG key ID: 48749B194497003F
2 changed files with 44 additions and 12 deletions

View file

@ -47,3 +47,9 @@ Feature: Account registration
Then I should be notified that new account has been successfully created
And I should be logged in
And my email should be "goodman@gmail.com"
@ui @email
Scenario: Receiving a welcoming email after registration
When I register with email "ghastly@bespoke.com" and password "suitsarelife"
Then I should be notified that new account has been successfully created
And a welcoming email should have been sent to "ghastly@bespoke.com"

View file

@ -374,25 +374,19 @@ class RegistrationContext implements Context
}
/**
* @Then it should be sent to :email
* @Then it should be sent to :recipient
*/
public function verificationEmailShouldBeSentTo($email)
public function anEmailShouldBeSentTo($recipient)
{
Assert::true(
$this->emailChecker->hasRecipient($email),
'The verification email should have been sent.'
);
$this->assertEmailHasRecipient($recipient);
}
/**
* @Then :count email(s) should be sent to :email
* @Then :count email(s) should be sent to :recipient
*/
public function numberOfEmailsShouldBeSentTo($count, $email)
public function numberOfEmailsShouldBeSentTo($count, $recipient)
{
Assert::true(
$this->emailChecker->hasRecipient($email),
sprintf('At least 1 email should have been sent to %s.', $email)
);
$this->assertEmailHasRecipient($recipient);
Assert::eq(
$this->emailChecker->getMessagesCount(),
@ -405,6 +399,38 @@ class RegistrationContext implements Context
);
}
/**
* @Then a welcoming email should have been sent to :recipient
*/
public function aWelcomingEmailShouldHaveBeenSentTo($recipient)
{
$this->assertEmailHasRecipient($recipient);
$this->assertEmailContainsMessage('Welcome to our store');
}
/**
* @param string $recipient
*/
private function assertEmailHasRecipient($recipient)
{
Assert::true(
$this->emailChecker->hasRecipient($recipient),
'An email should have been sent to %s.'
);
}
/**
* @param string $message
*/
private function assertEmailContainsMessage($message)
{
Assert::true(
$this->emailChecker->hasMessage($message),
sprintf('Message "%s" was not found in any email.', $message)
);
}
/**
* @param string $element
* @param string $expectedMessage