[Registration] Implement subscribing to the newsletter during registration

This commit is contained in:
Grzegorz Sadowski 2016-08-30 13:32:15 +02:00
parent a994867d52
commit 6016720e54
8 changed files with 66 additions and 23 deletions

View file

@ -7,7 +7,7 @@ Feature: Subscribing to the newsletter during registration
Background:
Given the store operates on a single channel in "United States"
@todo
@ui
Scenario: Subscribing to the newsletter during registration
Given I want to register a new account
When I specify the first name as "Saul"
@ -18,5 +18,4 @@ Feature: Subscribing to the newsletter during registration
And I subscribe to the newsletter
And I register this account
Then I should be notified that new account has been successfully created
And I should be logged in
And subscription to the newsletter should be enabled

View file

@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Ui\Shop;
use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface;
use Sylius\Behat\Page\Shop\Account\VerificationPageInterface;
use Sylius\Behat\Page\Shop\Account\RegisterPageInterface;
use Sylius\Behat\Page\Shop\HomePageInterface;
@ -31,9 +32,9 @@ use Webmozart\Assert\Assert;
class RegistrationContext implements Context
{
/**
* @var CurrentPageResolverInterface
* @var SharedStorageInterface
*/
private $currentPageResolver;
private $sharedStorage;
/**
* @var DashboardPageInterface
@ -45,11 +46,6 @@ class RegistrationContext implements Context
*/
private $homePage;
/**
* @var NotificationCheckerInterface
*/
private $notificationChecker;
/**
* @var RegisterPageInterface
*/
@ -60,6 +56,11 @@ class RegistrationContext implements Context
*/
private $verificationPage;
/**
* @var ProfileUpdatePageInterface
*/
private $profileUpdatePage;
/**
* @var SecurityServiceInterface
*/
@ -71,41 +72,49 @@ class RegistrationContext implements Context
private $emailChecker;
/**
* @var SharedStorageInterface
* @var CurrentPageResolverInterface
*/
private $sharedStorage;
private $currentPageResolver;
/**
* @param CurrentPageResolverInterface $currentPageResolver
* @var NotificationCheckerInterface
*/
private $notificationChecker;
/**
* @param SharedStorageInterface $sharedStorage
* @param DashboardPageInterface $dashboardPage
* @param HomePageInterface $homePage
* @param NotificationCheckerInterface $notificationChecker
* @param RegisterPageInterface $registerPage
* @param VerificationPageInterface $verificationPage
* @param ProfileUpdatePageInterface $profileUpdatePage
* @param SecurityServiceInterface $securityService
* @param EmailCheckerInterface $emailChecker
* @param SharedStorageInterface $sharedStorage
* @param CurrentPageResolverInterface $currentPageResolver
* @param NotificationCheckerInterface $notificationChecker
*/
public function __construct(
CurrentPageResolverInterface $currentPageResolver,
SharedStorageInterface $sharedStorage,
DashboardPageInterface $dashboardPage,
HomePageInterface $homePage,
NotificationCheckerInterface $notificationChecker,
RegisterPageInterface $registerPage,
VerificationPageInterface $verificationPage,
ProfileUpdatePageInterface $profileUpdatePage,
SecurityServiceInterface $securityService,
EmailCheckerInterface $emailChecker,
SharedStorageInterface $sharedStorage
CurrentPageResolverInterface $currentPageResolver,
NotificationCheckerInterface $notificationChecker
) {
$this->currentPageResolver = $currentPageResolver;
$this->sharedStorage = $sharedStorage;
$this->dashboardPage = $dashboardPage;
$this->homePage = $homePage;
$this->notificationChecker = $notificationChecker;
$this->registerPage = $registerPage;
$this->verificationPage = $verificationPage;
$this->profileUpdatePage = $profileUpdatePage;
$this->securityService = $securityService;
$this->emailChecker = $emailChecker;
$this->sharedStorage = $sharedStorage;
$this->currentPageResolver = $currentPageResolver;
$this->notificationChecker = $notificationChecker;
}
/**
@ -431,6 +440,27 @@ class RegistrationContext implements Context
);
}
/**
* @When I subscribe to the newsletter
*/
public function iSubscribeToTheNewsletter()
{
$this->registerPage->subscribeToTheNewsletter();
}
/**
* @Then subscription to the newsletter should be enabled
*/
public function subscriptionToTheNewsletterShouldBeEnabled()
{
$this->profileUpdatePage->open();
Assert::true(
$this->profileUpdatePage->isSubscribedToTheNewsletter(),
'Subscription to the newsletter should be enabled'
);
}
/**
* @param string $element
* @param string $expectedMessage

View file

@ -96,6 +96,11 @@ class RegisterPage extends SymfonyPage implements RegisterPageInterface
$this->getDocument()->fillField('Verification', $password);
}
public function subscribeToTheNewsletter()
{
$this->getDocument()->checkField('Subscribe to the newsletter');
}
/**
* {@inheritdoc}
*/

View file

@ -57,4 +57,6 @@ interface RegisterPageInterface extends SymfonyPageInterface
* @param string $password
*/
public function verifyPassword($password);
public function subscribeToTheNewsletter();
}

View file

@ -322,15 +322,16 @@
</service>
<service id="sylius.behat.context.ui.shop.registration" class="Sylius\Behat\Context\Ui\Shop\RegistrationContext" scope="scenario">
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="sylius.behat.page.shop.account.dashboard" />
<argument type="service" id="sylius.behat.page.shop.home" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="sylius.behat.page.shop.account.register" />
<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.shared_storage" />
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="sylius.behat.context" />
</service>

View file

@ -36,6 +36,10 @@ class CustomerRegistrationType extends CustomerSimpleRegistrationType
'required' => false,
'label' => 'sylius.form.customer.phone_number',
])
->add('subscribedToNewsletter', 'checkbox', [
'required' => false,
'label' => 'sylius.form.customer.subscribed_to_newsletter',
])
;
}

View file

@ -44,6 +44,7 @@ class CustomerRegistrationTypeSpec extends ObjectBehavior
$builder->add('email', 'email', Argument::type('array'))->shouldbeCalled()->willReturn($builder);
$builder->add('user', 'sylius_shop_user_registration', Argument::type('array'))->shouldbeCalled()->willReturn($builder);
$builder->add('phoneNumber', 'text', Argument::type('array'))->shouldbeCalled()->willReturn($builder);
$builder->add('subscribedToNewsletter', 'checkbox', Argument::type('array'))->shouldbeCalled()->willReturn($builder);
$builder->addEventSubscriber(
Argument::type(CustomerRegistrationFormSubscriber::class)
)->shouldbeCalled()->willReturn($builder);

View file

@ -5,6 +5,7 @@
</div>
{{ form_row(form.email) }}
{{ form_row(form.phoneNumber) }}
{{ form_row(form.subscribedToNewsletter) }}
<h4 class="ui dividing header">{{ 'sylius.ui.account_credentials'|trans }}</h4>
{{ form_row(form.user.plainPassword.first) }}
{{ form_row(form.user.plainPassword.second) }}