Skip to content

Commit

Permalink
Merge pull request Sylius#33 from Zales0123/describe-customized-behav…
Browse files Browse the repository at this point in the history
…iour-in-behat-features

Describe customized behavior
  • Loading branch information
lchrusciel committed Mar 23, 2018
2 parents f3c35ba + 235392f commit 9459c57
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 0 deletions.
2 changes: 2 additions & 0 deletions behat.yml.dist
@@ -1,11 +1,13 @@
imports:
- vendor/sylius/sylius/behat.yml.dist
- tests/Behat/Resources/config/suites.yml

default:
extensions:
FriendsOfBehat\ContextServiceExtension:
imports:
- "vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml"
- "tests/Behat/Resources/config/services.xml"

FriendsOfBehat\SuiteSettingsExtension:
paths:
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Expand Up @@ -77,6 +77,11 @@
},
"classmap": ["app/AppKernel.php", "app/AppCache.php"]
},
"autoload-dev": {
"psr-4": {
"Tests\\Behat\\": "tests/Behat/"
}
},
"config": {
"bin-dir": "bin"
},
Expand Down
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

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
13 changes: 13 additions & 0 deletions features/preventing_channel_addition.feature
@@ -0,0 +1,13 @@
@managing_channels
Feature: Preventing a new channel addition
In order to prevent breaking Sylius Demo application
As an Administrator
I want to not be able to add a new channel

Background:
Given I am logged in as an administrator

@ui
Scenario: Being prevented from adding a new channel
When I try to create a new channel
Then I should be notified that I cannot create a new channel on Sylius Demo
17 changes: 17 additions & 0 deletions features/preventing_default_administrator_deletion.feature
@@ -0,0 +1,17 @@
@managing_administrators
Feature: Preventing default administrator deletion
In order to prevent breaking Sylius Demo application
As an Administrator
I want to be prevented from deleting administrator with email "sylius@example.com"

Background:
Given there is an administrator "sylius@example.com"
And there is also an administrator "admin@example.com"
And I am logged in as "admin@example.com" administrator

@ui
Scenario: Being prevented from deleting default administrator
When I browse administrators
And I delete administrator with email "sylius@example.com"
Then I should be notified that I cannot delete Administrator of Sylius Demo
And I should see the administrator "sylius@example.com" in the list
19 changes: 19 additions & 0 deletions features/preventing_default_administrator_edition.feature
@@ -0,0 +1,19 @@
@managing_administrators
Feature: Preventing default administrator edition
In order to prevent breaking Sylius Demo application
As an Administrator
I want to be prevented from editing administrator with email "sylius@example.com"

Background:
Given there is also an administrator "admin@example.com"
And there is an administrator "sylius@example.com"
And I am logged in as "admin@example.com" administrator

@ui
Scenario: Being prevented from edition default administrator
When I want to edit administrator "sylius@example.com"
And I change its name to "Jon Snow"
And I change its email to "jon@example.com"
And I save my changes
Then I should be notified that I cannot edit Administrator of Sylius Demo
And I should see the administrator "sylius@example.com" in the list
70 changes: 70 additions & 0 deletions tests/Behat/Context/Ui/Admin/ManagingAdministratorsContext.php
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Tests\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Administrator\UpdatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Component\Core\Model\AdminUser;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;

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

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

/** @var UpdatePageInterface */
private $adminUserUpdatePage;

public function __construct(
NotificationCheckerInterface $notificationChecker,
RepositoryInterface $adminUserRepository,
UpdatePageInterface $adminUserUpdatePage
) {
$this->notificationChecker = $notificationChecker;
$this->adminUserRepository = $adminUserRepository;
$this->adminUserUpdatePage = $adminUserUpdatePage;
}

/**
* @When I want to edit administrator :email
*/
public function iWantToEditAdministrator(string $email): void
{
/** @var AdminUser $admin */
$admin = $this->adminUserRepository->findOneBy(['email' => $email]);

Assert::notNull($admin);

$this->adminUserUpdatePage->open(['id' => $admin->getId()]);
}

/**
* @Then I should be notified that I cannot delete Administrator of Sylius Demo
*/
public function iShouldBeNotifierThatICannotDeleteAdministratorOfSyliusDemo(): void
{
$this->notificationChecker->checkNotification(
'You cannot delete administrator of Sylius Demo!',
NotificationType::failure()
);
}

/**
* @Then I should be notified that I cannot edit Administrator of Sylius Demo
*/
public function iShouldBeNotifierThatICannotEditAdministratorOfSyliusDemo(): void
{
$this->notificationChecker->checkNotification(
'You cannot edit administrator of Sylius Demo!',
NotificationType::failure()
);
}
}
44 changes: 44 additions & 0 deletions tests/Behat/Context/Ui/Admin/ManagingChannelsContext.php
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Tests\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;

final class ManagingChannelsContext implements Context
{
/** @var CreatePageInterface */
private $channelCreatePage;

/** @var NotificationCheckerInterface */
private $notificationChecker;

public function __construct(CreatePageInterface $channelCreatePage, NotificationCheckerInterface $notificationChecker)
{
$this->channelCreatePage = $channelCreatePage;
$this->notificationChecker = $notificationChecker;
}

/**
* @When I try to create a new channel
*/
public function iTryToCreateANewChannel(): void
{
$this->channelCreatePage->tryToOpen();
}

/**
* @Then I should be notified that I cannot create a new channel on Sylius Demo
*/
public function shouldBeNotifiedThatICannotCreateANewChannelOnSyliusDemo(): void
{
$this->notificationChecker->checkNotification(
'You cannot create channel on Sylius Demo!',
NotificationType::failure()
);
}
}
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()
);
}
}
31 changes: 31 additions & 0 deletions tests/Behat/Resources/config/services.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service
id="sylius_demo.behat.context.ui.admin.managing_administrators_context"
class="Tests\Behat\Context\Ui\Admin\ManagingAdministratorsContext">
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="__symfony__.sylius.repository.admin_user" />
<argument type="service" id="sylius.behat.page.admin.administrator.update" />
<tag name="fob.context_service" />
</service>

<service
id="sylius_demo.behat.context.ui.admin.managing_channels_context"
class="Tests\Behat\Context\Ui\Admin\ManagingChannelsContext">
<argument type="service" id="sylius.behat.page.admin.channel.create" />
<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>
67 changes: 67 additions & 0 deletions tests/Behat/Resources/config/suites.yml
@@ -0,0 +1,67 @@
default:
suites:
ui_managing_channels:
contexts_services:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.channel
- sylius.behat.context.transform.currency
- sylius.behat.context.transform.locale
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.zone

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.currency
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.payment
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.shipping
- sylius.behat.context.setup.zone

- sylius.behat.context.ui.admin.managing_channels
- sylius.behat.context.ui.admin.notification

- sylius_demo.behat.context.ui.admin.managing_channels_context
filters:
tags: "@managing_channels && @ui"
ui_managing_administrators:
contexts_services:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.locale

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.locale
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.admin_user

- sylius.behat.context.ui.admin.dashboard
- sylius.behat.context.ui.admin.managing_administrators
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.admin.login

- 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 9459c57

Please sign in to comment.