Skip to content

Commit

Permalink
Describe displaying verification link in after-registration flash
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Mar 23, 2018
1 parent 5bc8255 commit 9b17f1f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
20 changes: 20 additions & 0 deletions features/displaying_verification_link_after_registration.feature
@@ -0,0 +1,20 @@
@customer_registration
Feature: Displaying verification link after registration
In order to be able to use registered account
As a Visitor
I want to have account verification link displayed rather than sent by email

Background:
Given the store operates on a single channel in "United States"

@ui
Scenario: Seeing account verification link in flash message after registration
When I want to register a new account
And I specify the first name as "Gandalf"
And I specify the last name as "The White"
And I specify the email as "gandalf@middle-earth.com"
And I specify the password as "go!go!gondor!"
And I confirm this password
And I register this account
Then I should have account verification link for "gandalf@middle-earth.com" displayed in flash message
But I should not be logged in
55 changes: 55 additions & 0 deletions tests/Behat/Context/Ui/Shop/RegistrationContext.php
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Tests\Behat\Context\Ui\Shop;

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;

final class RegistrationContext implements Context
{
/** @var NotificationCheckerInterface */
private $notificationChecker;

/** @var UrlGeneratorInterface */
private $urlGenerator;

/** @var RepositoryInterface */
private $shopUserRepository;

public function __construct(
NotificationCheckerInterface $notificationChecker,
UrlGeneratorInterface $urlGenerator,
RepositoryInterface $shopUserRepository
) {
$this->notificationChecker = $notificationChecker;
$this->urlGenerator = $urlGenerator;
$this->shopUserRepository = $shopUserRepository;
}

/**
* @Then I should have account verification link for :email displayed in flash message
*/
public function iShouldHaveAccountVerificationLinkDisplayedInFlashMessage(string $email): void
{
/** @var ShopUserInterface $shopUser */
$shopUser = $this->shopUserRepository->findOneBy(['username' => $email]);
Assert::notNull($shopUser);

$verificationLink = $this->urlGenerator->generate(
'sylius_shop_user_verification',
['_locale' => 'en_US', 'token' => $shopUser->getEmailVerificationToken()]
);

$this->notificationChecker->checkNotification(
sprintf('For demo purposes you can visit http://localhost:8080%s to verify the account.', $verificationLink),
NotificationType::success()
);
}
}
9 changes: 9 additions & 0 deletions tests/Behat/Resources/config/services.xml
Expand Up @@ -18,5 +18,14 @@
<argument type="service" id="sylius.behat.notification_checker" />
<tag name="fob.context_service" />
</service>

<service
id="sylius_demo.behat.context.ui.shop.registration_context"
class="Tests\Behat\Context\Ui\Shop\RegistrationContext">
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="__symfony__.router" />
<argument type="service" id="__symfony__.sylius.repository.shop_user" />
<tag name="fob.context_service" />
</service>
</services>
</container>
20 changes: 20 additions & 0 deletions tests/Behat/Resources/config/suites.yml
Expand Up @@ -45,3 +45,23 @@ default:
- sylius_demo.behat.context.ui.admin.managing_administrators_context
filters:
tags: "@managing_administrators && @ui"
ui_customer_registration:
contexts_services:
- sylius.behat.context.hook.doctrine_orm
- sylius.behat.context.hook.email_spool

- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.customer

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.customer
- sylius.behat.context.setup.order
- sylius.behat.context.setup.shop_security
- sylius.behat.context.setup.user

- sylius.behat.context.ui.email
- sylius.behat.context.ui.shop.registration

- sylius_demo.behat.context.ui.shop.registration_context
filters:
tags: "@customer_registration && @ui"

0 comments on commit 9b17f1f

Please sign in to comment.