mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Behat] Add validation feature
This commit is contained in:
parent
121e69a0a2
commit
e4e6b93148
12 changed files with 197 additions and 82 deletions
|
|
@ -133,6 +133,7 @@
|
|||
<service id="sylius.behat.context.ui.admin.managing_taxons" class="%sylius.behat.context.ui.admin.managing_taxons.class%" scope="scenario">
|
||||
<argument type="service" id="sylius.behat.page.admin.taxon.create" />
|
||||
<argument type="service" id="sylius.behat.page.admin.taxon.update" />
|
||||
<argument type="service" id="sylius.behat.current_page_resolver" />
|
||||
<argument type="service" id="sylius.behat.notification_checker" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ Feature: Adding a new taxon
|
|||
And I describe it as "Main taxonomy for products." in "English (United States)"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the "Category" taxon with "category" permalink and "Main taxonomy for products." description should appear in the registry
|
||||
And the "Category" taxon should appear in the registry
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new taxon with parent taxon
|
||||
|
|
@ -37,4 +37,4 @@ Feature: Adding a new taxon
|
|||
And I choose "Category" as a parent taxon
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the "Stickers" taxon with "Category" parent taxon should appear in the registry
|
||||
And the "Stickers" taxon should appear in the registry
|
||||
|
|
|
|||
|
|
@ -1,53 +1,53 @@
|
|||
@managing_taxons
|
||||
Feature: Editing a taxon
|
||||
In order to change categorization of my merchandise
|
||||
As an Administrator
|
||||
I want to be able to edit a taxon
|
||||
In order to change categorization of my merchandise
|
||||
As an Administrator
|
||||
I want to be able to edit a taxon
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And the store classifies its products as "T-Shirts" and "Accessories"
|
||||
And I am logged in as an administrator
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And the store classifies its products as "T-Shirts" and "Accessories"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Renaming a taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon name should be "Stickers"
|
||||
@ui
|
||||
Scenario: Renaming a taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon name should be "Stickers"
|
||||
|
||||
@ui
|
||||
Scenario: Changing description
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon description should be "Main taxonomy for stickers"
|
||||
@ui
|
||||
Scenario: Changing description
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon description should be "Main taxonomy for stickers"
|
||||
|
||||
@ui
|
||||
Scenario: Changing permalink
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I change its permalink to "stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon permalink should be "stickers"
|
||||
@ui
|
||||
Scenario: Changing permalink
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I change its permalink to "stickers" in "English (United States)"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon permalink should be "stickers"
|
||||
|
||||
@ui
|
||||
Scenario: Changing parent taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I change its permalink to "stickers" in "English (United States)"
|
||||
And I change its parent taxon to "Accessories"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon should belongs to "Accessories"
|
||||
@ui
|
||||
Scenario: Changing parent taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
When I rename it to "Stickers" in "English (United States)"
|
||||
And I change its description to "Main taxonomy for stickers" in "English (United States)"
|
||||
And I change its permalink to "stickers" in "English (United States)"
|
||||
And I change its parent taxon to "Accessories"
|
||||
And I save my changes
|
||||
Then I should be notified that it has been successfully edited
|
||||
And this taxon should belongs to "Accessories"
|
||||
|
||||
@ui
|
||||
Scenario: Seeing a disabled code field when editing a taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
Then the code field should be disabled
|
||||
@ui
|
||||
Scenario: Seeing a disabled code field when editing a taxon
|
||||
Given I want to modify the "T-Shirts" taxon
|
||||
Then the code field should be disabled
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
@managing_taxons
|
||||
Feature: Taxon unique code validation
|
||||
In order to uniquely identify taxons
|
||||
As an Administrator
|
||||
I want to be prevented from adding two taxons with same code
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And the store classifies its products as "T-Shirts"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Trying to add taxon with taken code
|
||||
Given I want to create a new taxon
|
||||
When I specify its code as "t_shirts"
|
||||
And I name it "T-Shirts" in "English (United States)"
|
||||
And I try to add it
|
||||
Then I should be notified that taxon with this code already exists
|
||||
And there should still be only one taxon with code "t_shirts"
|
||||
25
features/taxonomy/managing_taxons/taxon_validation.feature
Normal file
25
features/taxonomy/managing_taxons/taxon_validation.feature
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
@managing_taxons
|
||||
Feature: Taxon validation
|
||||
In order to avoid making mistakes when managing a taxons
|
||||
As an Administrator
|
||||
I want to be prevented from adding it without specifying required fields
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@ui
|
||||
Scenario: Trying to add a taxon without specifying its code
|
||||
Given I want to create a new taxon
|
||||
When I do not specify its code
|
||||
And I name it "T-Shirts" in "English (United States)"
|
||||
And I try to add it
|
||||
Then I should be notified that code is required
|
||||
|
||||
@ui
|
||||
Scenario: Trying to add a taxon without specifying its name
|
||||
Given I want to create a new taxon
|
||||
When I specify its code as "t-shirts"
|
||||
And I do not specify its name
|
||||
And I try to add it
|
||||
Then I should be notified that name is required
|
||||
|
|
@ -13,6 +13,7 @@ namespace Sylius\Behat\Context\Transform;
|
|||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
|
|
@ -39,15 +40,19 @@ final class TaxonContext implements Context
|
|||
* @Transform /^"([^"]+)" as a parent taxon$/
|
||||
* @Transform /^"([^"]+)" parent taxon$/
|
||||
* @Transform /^parent taxon to "([^"]+)"$/
|
||||
* @Transform /^taxon with "([^"]+)" name/
|
||||
*/
|
||||
public function getTaxonByName($taxonName)
|
||||
{
|
||||
$taxon = $this->taxonRepository->findOneByName($taxonName);
|
||||
if (null === $taxon) {
|
||||
throw new \InvalidArgumentException(sprintf('Taxon with name "%s" does not exist.', $taxonName));
|
||||
}
|
||||
return $this->getTaxonBy(['name' => $taxonName]);
|
||||
}
|
||||
|
||||
return $taxon;
|
||||
/**
|
||||
* @Transform /^taxon with "([^"]+)" code$/
|
||||
*/
|
||||
public function getTaxonByCode($code)
|
||||
{
|
||||
return $this->getTaxonBy(['code' => $code]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,4 +65,17 @@ final class TaxonContext implements Context
|
|||
$this->getTaxonByName($secondTaxon)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
private function getTaxonBy(array $parameters)
|
||||
{
|
||||
$taxon = $this->taxonRepository->findOneBy($parameters);
|
||||
Assert::notNull($taxon, 'Taxon does not exist.');
|
||||
|
||||
return $taxon;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Ui\Admin;
|
|||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Behat\Page\Admin\Taxon\CreatePageInterface;
|
||||
use Sylius\Behat\Page\Admin\Taxon\UpdatePageInterface;
|
||||
use Sylius\Behat\Service\CurrentPageResolverInterface;
|
||||
use Sylius\Behat\Service\NotificationCheckerInterface;
|
||||
use Sylius\Component\Core\Model\TaxonInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
|
@ -35,6 +36,11 @@ final class ManagingTaxonsContext implements Context
|
|||
*/
|
||||
private $updatePage;
|
||||
|
||||
/**
|
||||
* @var CurrentPageResolverInterface
|
||||
*/
|
||||
private $currentPageResolver;
|
||||
|
||||
/**
|
||||
* @var NotificationCheckerInterface
|
||||
*/
|
||||
|
|
@ -43,15 +49,18 @@ final class ManagingTaxonsContext implements Context
|
|||
/**
|
||||
* @param CreatePageInterface $createPage
|
||||
* @param UpdatePageInterface $updatePage
|
||||
* @param CurrentPageResolverInterface $currentPageResolver
|
||||
* @param NotificationCheckerInterface $notificationChecker
|
||||
*/
|
||||
public function __construct(
|
||||
CreatePageInterface $createPage,
|
||||
UpdatePageInterface $updatePage,
|
||||
CurrentPageResolverInterface $currentPageResolver,
|
||||
NotificationCheckerInterface $notificationChecker
|
||||
) {
|
||||
$this->createPage = $createPage;
|
||||
$this->updatePage = $updatePage;
|
||||
$this->currentPageResolver = $currentPageResolver;
|
||||
$this->notificationChecker = $notificationChecker;
|
||||
}
|
||||
|
||||
|
|
@ -143,6 +152,22 @@ final class ManagingTaxonsContext implements Context
|
|||
$this->updatePage->chooseParent($taxon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I do not specify its code
|
||||
*/
|
||||
public function iDoNotSpecifyItsCode()
|
||||
{
|
||||
// Intentionally left blank to fulfill context expectation
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I do not specify its name
|
||||
*/
|
||||
public function iDoNotSpecifyItsName()
|
||||
{
|
||||
// Intentionally left blank to fulfill context expectation
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I add it
|
||||
* @When I try to add it
|
||||
|
|
@ -189,30 +214,6 @@ final class ManagingTaxonsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the ("[^"]+" taxon) with "([^"]*)" permalink and "([^"]*)" description should appear in the registry$/
|
||||
*/
|
||||
public function theTaxonWithPermalinkAndDescriptionShouldAppearInTheRegistry(TaxonInterface $taxon, $permalink, $description)
|
||||
{
|
||||
$this->updatePage->open(['id' => $taxon->getId()]);
|
||||
Assert::true(
|
||||
$this->updatePage->hasResourceValues(['code' => $taxon->getCode(), 'permalink' => $permalink, 'description' => $description]),
|
||||
sprintf('Taxon %s should have %s permalink and %s description.', $taxon->getName(), $permalink, $description)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the ("[^"]+" taxon) with ("[^"]+" parent taxon) should appear in the registry$/
|
||||
*/
|
||||
public function theTaxonWithParentTaxonShouldAppearInTheRegistry(TaxonInterface $taxon, TaxonInterface $parentTaxon)
|
||||
{
|
||||
$this->updatePage->open(['id' => $taxon->getId()]);
|
||||
Assert::true(
|
||||
$this->updatePage->hasResourceValues(['parent' => $parentTaxon->getId()]),
|
||||
sprintf('Taxon %s should have %s parent taxon', $taxon->getName(), $parentTaxon->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then this taxon :element should be :value
|
||||
*/
|
||||
|
|
@ -245,4 +246,41 @@ final class ManagingTaxonsContext implements Context
|
|||
sprintf('Current taxon should have %s parent taxon', $taxon->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that taxon with this code already exists
|
||||
*/
|
||||
public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists()
|
||||
{
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage);
|
||||
|
||||
Assert::true(
|
||||
$currentPage->checkValidationMessageFor('code', 'Taxon with given code already exists.'),
|
||||
'Unique code violation message should appear on page, but it does not.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that :element is required
|
||||
*/
|
||||
public function iShouldBeNotifiedThatIsRequired($element)
|
||||
{
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage);
|
||||
|
||||
Assert::true(
|
||||
$currentPage->checkValidationMessageFor($element, sprintf('Please enter taxon %s.', $element)),
|
||||
sprintf('I should be notified that taxon %s should be required.', $element)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^there should still be only one taxon with code "([^"]*)"$/
|
||||
*/
|
||||
public function thereShouldStillBeOnlyOneTaxonWithCode($code)
|
||||
{
|
||||
Assert::true(
|
||||
$this->updatePage->hasResourceValues(['code' => $code]),
|
||||
sprintf('Taxon with code %s cannot be found.', $code)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ sylius_admin_taxon:
|
|||
resource: |
|
||||
alias: sylius.taxon
|
||||
section: admin
|
||||
templates: SyliusAdminBundle:Crud
|
||||
except: ['index', 'show', 'delete']
|
||||
templates: SyliusAdminBundle:Taxon
|
||||
except: ['index', 'show']
|
||||
redirect: update
|
||||
vars:
|
||||
all:
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@
|
|||
{% endmacro %}
|
||||
|
||||
{% macro renderChildren(taxons) %}
|
||||
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
|
||||
{% for taxon in taxons %}
|
||||
<div class="item">
|
||||
<i class="folder icon"></i>
|
||||
<div class="content">
|
||||
<div class="header">{{ taxon.name }}</div>
|
||||
{{ buttons.delete(path('sylius_admin_taxon_delete', { 'id': taxon.id }), 'sylius.ui.delete'|trans) }}
|
||||
{{ buttons.edit(path('sylius_admin_taxon_update', { 'id': taxon.id })) }}
|
||||
{% if not taxon.description %}
|
||||
<div class="description">{{ taxon.description }}</div>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
<div class="ui two column stackable grid">
|
||||
<div class="column">
|
||||
<div class="ui segment">
|
||||
{{ render(path('sylius_admin_taxon_index')) }}
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
{{ form_errors(form) }}
|
||||
<div class="one field">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
{% extends 'SyliusAdminBundle:Crud:create.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="ui two column grid">
|
||||
<div class="four wide column">
|
||||
{{ render(path('sylius_admin_taxon_index')) }}
|
||||
</div>
|
||||
<div class="twelve wide column">
|
||||
{{ parent() }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
{% import 'SyliusAdminBundle:Taxon/Macro:tree.html.twig' as tree %}
|
||||
|
||||
{{ tree.render(taxons) }}
|
||||
<div class="ui segment">
|
||||
{{ tree.render(taxons) }}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue