mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Behat] Extracted email related steps to EmailContext
This commit is contained in:
parent
23c1cd4797
commit
e343a5fc03
7 changed files with 104 additions and 88 deletions
94
src/Sylius/Behat/Context/Ui/EmailContext.php
Normal file
94
src/Sylius/Behat/Context/Ui/EmailContext.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Behat\Context\Ui;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Component\Core\Test\Services\EmailCheckerInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @author Jan Góralski <jan.goralski@lakion.com>
|
||||
*/
|
||||
final class EmailContext implements Context
|
||||
{
|
||||
/**
|
||||
* @var EmailCheckerInterface
|
||||
*/
|
||||
private $emailChecker;
|
||||
|
||||
/**
|
||||
* @param EmailCheckerInterface $emailChecker
|
||||
*/
|
||||
public function __construct(EmailCheckerInterface $emailChecker)
|
||||
{
|
||||
$this->emailChecker = $emailChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then it should be sent to :recipient
|
||||
* @Then the email with reset token should be sent to :recipient
|
||||
*/
|
||||
public function anEmailShouldBeSentTo($recipient)
|
||||
{
|
||||
$this->assertEmailHasRecipient($recipient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :count email(s) should be sent to :recipient
|
||||
*/
|
||||
public function numberOfEmailsShouldBeSentTo($count, $recipient)
|
||||
{
|
||||
$this->assertEmailHasRecipient($recipient);
|
||||
|
||||
Assert::eq(
|
||||
$this->emailChecker->getMessagesCount(),
|
||||
$count,
|
||||
sprintf(
|
||||
'%d messages were sent, while there should be %d.',
|
||||
$this->emailChecker->getMessagesCount(),
|
||||
$count
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,11 +46,6 @@ final class LoginContext implements Context
|
|||
*/
|
||||
private $currentPageResolver;
|
||||
|
||||
/**
|
||||
* @var EmailCheckerInterface
|
||||
*/
|
||||
private $emailChecker;
|
||||
|
||||
/**
|
||||
* @var NotificationCheckerInterface
|
||||
*/
|
||||
|
|
@ -61,7 +56,6 @@ final class LoginContext implements Context
|
|||
* @param LoginPageInterface $loginPage
|
||||
* @param ResetPasswordPageInterface $resetPasswordPage
|
||||
* @param CurrentPageResolverInterface $currentPageResolver
|
||||
* @param EmailCheckerInterface $emailChecker
|
||||
* @param NotificationCheckerInterface $notificationChecker
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -69,14 +63,12 @@ final class LoginContext implements Context
|
|||
LoginPageInterface $loginPage,
|
||||
ResetPasswordPageInterface $resetPasswordPage,
|
||||
CurrentPageResolverInterface $currentPageResolver,
|
||||
EmailCheckerInterface $emailChecker,
|
||||
NotificationCheckerInterface $notificationChecker
|
||||
) {
|
||||
$this->homePage = $homePage;
|
||||
$this->loginPage = $loginPage;
|
||||
$this->resetPasswordPage = $resetPasswordPage;
|
||||
$this->currentPageResolver = $currentPageResolver;
|
||||
$this->emailChecker = $emailChecker;
|
||||
$this->notificationChecker = $notificationChecker;
|
||||
}
|
||||
|
||||
|
|
@ -190,17 +182,6 @@ final class LoginContext implements Context
|
|||
$this->notificationChecker->checkNotification('If the email you have specified exists in our system, we have sent there an instruction on how to reset your password.', NotificationType::success());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then the email with reset token should be sent to :email
|
||||
*/
|
||||
public function theEmailWithResetTokenShouldBeSentTo($email)
|
||||
{
|
||||
Assert::true(
|
||||
$this->emailChecker->hasRecipient($email),
|
||||
sprintf('Email should have been sent to %s.', $email)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the :elementName is required
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
|
|||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Behat\Service\SecurityServiceInterface;
|
||||
use Sylius\Component\Core\Model\ShopUserInterface;
|
||||
use Sylius\Component\Core\Test\Services\EmailCheckerInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -66,11 +65,6 @@ class RegistrationContext implements Context
|
|||
*/
|
||||
private $securityService;
|
||||
|
||||
/**
|
||||
* @var EmailCheckerInterface
|
||||
*/
|
||||
private $emailChecker;
|
||||
|
||||
/**
|
||||
* @var CurrentPageResolverInterface
|
||||
*/
|
||||
|
|
@ -89,7 +83,6 @@ class RegistrationContext implements Context
|
|||
* @param VerificationPageInterface $verificationPage
|
||||
* @param ProfileUpdatePageInterface $profileUpdatePage
|
||||
* @param SecurityServiceInterface $securityService
|
||||
* @param EmailCheckerInterface $emailChecker
|
||||
* @param CurrentPageResolverInterface $currentPageResolver
|
||||
* @param NotificationCheckerInterface $notificationChecker
|
||||
*/
|
||||
|
|
@ -101,7 +94,6 @@ class RegistrationContext implements Context
|
|||
VerificationPageInterface $verificationPage,
|
||||
ProfileUpdatePageInterface $profileUpdatePage,
|
||||
SecurityServiceInterface $securityService,
|
||||
EmailCheckerInterface $emailChecker,
|
||||
CurrentPageResolverInterface $currentPageResolver,
|
||||
NotificationCheckerInterface $notificationChecker
|
||||
) {
|
||||
|
|
@ -112,7 +104,6 @@ class RegistrationContext implements Context
|
|||
$this->verificationPage = $verificationPage;
|
||||
$this->profileUpdatePage = $profileUpdatePage;
|
||||
$this->securityService = $securityService;
|
||||
$this->emailChecker = $emailChecker;
|
||||
$this->currentPageResolver = $currentPageResolver;
|
||||
$this->notificationChecker = $notificationChecker;
|
||||
}
|
||||
|
|
@ -382,64 +373,6 @@ class RegistrationContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then it should be sent to :recipient
|
||||
*/
|
||||
public function anEmailShouldBeSentTo($recipient)
|
||||
{
|
||||
$this->assertEmailHasRecipient($recipient);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :count email(s) should be sent to :recipient
|
||||
*/
|
||||
public function numberOfEmailsShouldBeSentTo($count, $recipient)
|
||||
{
|
||||
$this->assertEmailHasRecipient($recipient);
|
||||
|
||||
Assert::eq(
|
||||
$this->emailChecker->getMessagesCount(),
|
||||
$count,
|
||||
sprintf(
|
||||
'%d messages were sent, while there should be %d.',
|
||||
$this->emailChecker->getMessagesCount(),
|
||||
$count
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I subscribe to the newsletter
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -310,7 +310,6 @@
|
|||
<argument type="service" id="sylius.behat.page.shop.account.login" />
|
||||
<argument type="service" id="sylius.behat.page.shop.account.reset_password" />
|
||||
<argument type="service" id="sylius.behat.current_page_resolver" />
|
||||
<argument type="service" id="sylius.behat.email_checker" container="symfony"/>
|
||||
<argument type="service" id="sylius.behat.notification_checker" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
|
@ -329,7 +328,6 @@
|
|||
<argument type="service" id="sylius.behat.page.shop.account.verify" />
|
||||
<argument type="service" id="sylius.behat.page.shop.account.profile_update" />
|
||||
<argument type="service" id="sylius.behat.shop_security" />
|
||||
<argument type="service" id="sylius.behat.email_checker" container="symfony" />
|
||||
<argument type="service" id="sylius.behat.current_page_resolver" />
|
||||
<argument type="service" id="sylius.behat.notification_checker" />
|
||||
<tag name="sylius.behat.context" />
|
||||
|
|
@ -339,5 +337,10 @@
|
|||
<argument type="service" id="sylius.behat.page.shop.static_content.show" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.ui.email" class="Sylius\Behat\Context\Ui\EmailContext" scope="scenario">
|
||||
<argument type="service" id="sylius.behat.email_checker" container="symfony" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ default:
|
|||
ui_customer_login:
|
||||
contexts_as_services:
|
||||
- sylius.behat.context.hook.doctrine_orm
|
||||
- sylius.behat.context.hook.email_spool
|
||||
|
||||
- sylius.behat.context.transform.user
|
||||
|
||||
- sylius.behat.context.setup.channel
|
||||
- sylius.behat.context.setup.user
|
||||
|
||||
- sylius.behat.context.ui.email
|
||||
- sylius.behat.context.ui.shop.login
|
||||
filters:
|
||||
tags: "@customer_login && @ui"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ default:
|
|||
ui_customer_registration:
|
||||
contexts_as_services:
|
||||
- sylius.behat.context.hook.doctrine_orm
|
||||
- sylius.behat.context.hook.email_spool
|
||||
|
||||
- sylius.behat.context.transform.shared_storage
|
||||
- sylius.behat.context.transform.customer
|
||||
|
|
@ -16,6 +17,7 @@ default:
|
|||
- sylius.behat.context.setup.shop_security
|
||||
- sylius.behat.context.setup.user
|
||||
|
||||
- sylius.behat.context.ui.email
|
||||
- sylius.behat.context.ui.shop.registration
|
||||
filters:
|
||||
tags: "@customer_registration && @ui"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ default:
|
|||
- sylius.behat.context.setup.shop_security
|
||||
- sylius.behat.context.setup.user
|
||||
|
||||
- sylius.behat.context.ui.email
|
||||
- sylius.behat.context.ui.shop.registration
|
||||
filters:
|
||||
tags: "@email_verification && @ui"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue