mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Behat] Add browsing, delete feature
This commit is contained in:
parent
e4e6b93148
commit
313273c739
8 changed files with 197 additions and 7 deletions
16
features/taxonomy/managing_taxons/browsing_taxon.feature
Normal file
16
features/taxonomy/managing_taxons/browsing_taxon.feature
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
@managing_taxons
|
||||||
|
Feature: Browsing taxons
|
||||||
|
In order to see all taxons in the store
|
||||||
|
As an Administrator
|
||||||
|
I want to browse taxons
|
||||||
|
|
||||||
|
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: Browsing taxons in store
|
||||||
|
Given I want to see all taxons in store
|
||||||
|
Then I should see 2 taxons on the list
|
||||||
|
And I should see the taxon named "T-Shirts" in the list
|
||||||
16
features/taxonomy/managing_taxons/deleting_taxon.feature
Normal file
16
features/taxonomy/managing_taxons/deleting_taxon.feature
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
@managing_taxons
|
||||||
|
Feature: Deleting a taxon
|
||||||
|
In order to remove test, obsolete or incorrect taxons
|
||||||
|
As an Administrator
|
||||||
|
I want to be able to delete a taxon
|
||||||
|
|
||||||
|
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: Deleted taxon should disappear from the registry
|
||||||
|
When I delete taxon named "T-Shirts"
|
||||||
|
Then I should be notified that it has been successfully deleted
|
||||||
|
And the taxon named "T-Shirts" should no longer exist in the registry
|
||||||
|
|
@ -15,6 +15,7 @@ Feature: Taxon validation
|
||||||
And I name it "T-Shirts" in "English (United States)"
|
And I name it "T-Shirts" in "English (United States)"
|
||||||
And I try to add it
|
And I try to add it
|
||||||
Then I should be notified that code is required
|
Then I should be notified that code is required
|
||||||
|
And Taxon named "T-Shirts" should not be added
|
||||||
|
|
||||||
@ui
|
@ui
|
||||||
Scenario: Trying to add a taxon without specifying its name
|
Scenario: Trying to add a taxon without specifying its name
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ final class ManagingTaxonsContext implements Context
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Given I want to create a new taxon
|
* @Given I want to create a new taxon
|
||||||
|
* @Given I want to see all taxons in store
|
||||||
*/
|
*/
|
||||||
public function iWantToCreateANewTaxon()
|
public function iWantToCreateANewTaxon()
|
||||||
{
|
{
|
||||||
|
|
@ -168,6 +169,15 @@ final class ManagingTaxonsContext implements Context
|
||||||
// Intentionally left blank to fulfill context expectation
|
// Intentionally left blank to fulfill context expectation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When I delete taxon named :name
|
||||||
|
*/
|
||||||
|
public function iDeleteTaxonNamed($name)
|
||||||
|
{
|
||||||
|
$this->createPage->open();
|
||||||
|
$this->createPage->deleteTaxonOnPageByName($name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @When I add it
|
* @When I add it
|
||||||
* @When I try to add it
|
* @When I try to add it
|
||||||
|
|
@ -202,6 +212,14 @@ final class ManagingTaxonsContext implements Context
|
||||||
$this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME);
|
$this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then I should be notified that it has been successfully deleted
|
||||||
|
*/
|
||||||
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted()
|
||||||
|
{
|
||||||
|
$this->notificationChecker->checkDeletionNotification(self::RESOURCE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then /^the ("[^"]+" taxon) should appear in the registry$/
|
* @Then /^the ("[^"]+" taxon) should appear in the registry$/
|
||||||
*/
|
*/
|
||||||
|
|
@ -274,7 +292,7 @@ final class ManagingTaxonsContext implements Context
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then /^there should still be only one taxon with code "([^"]*)"$/
|
* @Then /^there should still be only one taxon with code "([^"]+)"$/
|
||||||
*/
|
*/
|
||||||
public function thereShouldStillBeOnlyOneTaxonWithCode($code)
|
public function thereShouldStillBeOnlyOneTaxonWithCode($code)
|
||||||
{
|
{
|
||||||
|
|
@ -283,4 +301,43 @@ final class ManagingTaxonsContext implements Context
|
||||||
sprintf('Taxon with code %s cannot be found.', $code)
|
sprintf('Taxon with code %s cannot be found.', $code)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then /^Taxon named "([^"]+)" should not be added$/
|
||||||
|
* @Then the taxon named :name should no longer exist in the registry
|
||||||
|
*/
|
||||||
|
public function taxonNamedShouldNotBeAdded($name)
|
||||||
|
{
|
||||||
|
Assert::eq(
|
||||||
|
0,
|
||||||
|
$this->createPage->countTaxonsByName($name),
|
||||||
|
sprintf('Taxon %s should not exist', $name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then /^I should see (\d+) taxons on the list$/
|
||||||
|
*/
|
||||||
|
public function iShouldSeeZonesInTheList($number)
|
||||||
|
{
|
||||||
|
$taxonsOnPage = $this->createPage->countTaxons();
|
||||||
|
|
||||||
|
Assert::eq(
|
||||||
|
$number,
|
||||||
|
$taxonsOnPage,
|
||||||
|
sprintf('On list should be %d taxons but get %d', $number, $taxonsOnPage)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then I should see the taxon named :name in the list
|
||||||
|
*/
|
||||||
|
public function iShouldSeeTheTaxonNamedInTheList($name)
|
||||||
|
{
|
||||||
|
Assert::eq(
|
||||||
|
1,
|
||||||
|
$this->createPage->countTaxonsByName($name),
|
||||||
|
sprintf('Taxon %s does not exist', $name)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,12 @@
|
||||||
|
|
||||||
namespace Sylius\Behat\Page\Admin\Taxon;
|
namespace Sylius\Behat\Page\Admin\Taxon;
|
||||||
|
|
||||||
|
use Behat\Mink\Element\NodeElement;
|
||||||
|
use Behat\Mink\Exception\ElementNotFoundException;
|
||||||
use Sylius\Behat\Behaviour\SpecifiesItsCode;
|
use Sylius\Behat\Behaviour\SpecifiesItsCode;
|
||||||
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
|
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
|
||||||
use Sylius\Component\Core\Model\TaxonInterface;
|
use Sylius\Component\Core\Model\TaxonInterface;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
|
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
|
||||||
|
|
@ -22,6 +25,30 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
{
|
{
|
||||||
use SpecifiesItsCode;
|
use SpecifiesItsCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function countTaxons()
|
||||||
|
{
|
||||||
|
return count($this->getLeafs());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function countTaxonsByName($name)
|
||||||
|
{
|
||||||
|
$matchedLeafsCounter = 0;
|
||||||
|
$leafs = $this->getLeafs();
|
||||||
|
foreach ($leafs as $leaf) {
|
||||||
|
if ($leaf->getText() === $name) {
|
||||||
|
$matchedLeafsCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $matchedLeafsCounter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -30,6 +57,21 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
$this->getElement('parent')->selectOption($taxon->getName(), false);
|
$this->getElement('parent')->selectOption($taxon->getName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function deleteTaxonOnPageByName($name)
|
||||||
|
{
|
||||||
|
$leafs = $this->getLeafs();
|
||||||
|
foreach ($leafs as $leaf) {
|
||||||
|
if ($leaf->getText() === $name) {
|
||||||
|
$leaf->pressButton('Delete');
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -38,6 +80,14 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description);
|
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function hasTaxonWithName($name)
|
||||||
|
{
|
||||||
|
return 0 !== $this->countTaxonsByName($name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,6 +115,20 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
||||||
'parent' => '#sylius_taxon_parent',
|
'parent' => '#sylius_taxon_parent',
|
||||||
'permalink' => '#sylius_taxon_translations_en_US_permalink',
|
'permalink' => '#sylius_taxon_translations_en_US_permalink',
|
||||||
'description' => '#sylius_taxon_translations_en_US_description',
|
'description' => '#sylius_taxon_translations_en_US_description',
|
||||||
|
'tree' => '.ui.list',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return NodeElement[]
|
||||||
|
*
|
||||||
|
* @throws ElementNotFoundException
|
||||||
|
*/
|
||||||
|
private function getLeafs()
|
||||||
|
{
|
||||||
|
$tree = $this->getElement('tree');
|
||||||
|
Assert::notNull($tree);
|
||||||
|
|
||||||
|
return $tree->findAll('css', '.item > .content > .header');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,23 @@ use Sylius\Component\Core\Model\TaxonInterface;
|
||||||
*/
|
*/
|
||||||
interface CreatePageInterface extends BaseCreatePageInterface
|
interface CreatePageInterface extends BaseCreatePageInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function countTaxons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function countTaxonsByName($name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function deleteTaxonOnPageByName($name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @param string $languageCode
|
* @param string $languageCode
|
||||||
|
|
@ -30,6 +47,13 @@ interface CreatePageInterface extends BaseCreatePageInterface
|
||||||
*/
|
*/
|
||||||
public function chooseParent(TaxonInterface $taxon);
|
public function chooseParent(TaxonInterface $taxon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasTaxonWithName($name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $languageCode
|
* @param string $languageCode
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ sylius_admin_taxon:
|
||||||
resource: |
|
resource: |
|
||||||
alias: sylius.taxon
|
alias: sylius.taxon
|
||||||
section: admin
|
section: admin
|
||||||
templates: SyliusAdminBundle:Taxon
|
templates: SyliusAdminBundle:Crud
|
||||||
except: ['index', 'show']
|
only: ['update', 'delete']
|
||||||
redirect: update
|
redirect: update
|
||||||
vars:
|
vars:
|
||||||
all:
|
all:
|
||||||
|
|
@ -14,7 +14,7 @@ sylius_admin_taxon:
|
||||||
type: sylius.resource
|
type: sylius.resource
|
||||||
|
|
||||||
sylius_admin_taxon_index:
|
sylius_admin_taxon_index:
|
||||||
path: /taxons/tree/
|
path: /taxons/
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
defaults:
|
defaults:
|
||||||
_controller: sylius.controller.taxon:indexAction
|
_controller: sylius.controller.taxon:indexAction
|
||||||
|
|
@ -24,3 +24,15 @@ sylius_admin_taxon_index:
|
||||||
repository:
|
repository:
|
||||||
method: findRootNodes
|
method: findRootNodes
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
|
|
||||||
|
sylius_admin_taxon_create:
|
||||||
|
path: /taxons/new
|
||||||
|
methods: [GET, POST]
|
||||||
|
defaults:
|
||||||
|
_controller: sylius.controller.taxon:createAction
|
||||||
|
_sylius:
|
||||||
|
template: SyliusAdminBundle:Taxon:create.html.twig
|
||||||
|
section: admin
|
||||||
|
vars:
|
||||||
|
templates:
|
||||||
|
form: SyliusAdminBundle:Taxon:_form.html.twig
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{% macro render(taxons) %}
|
{% macro render(taxons) %}
|
||||||
<div class="ui list">
|
<div class="ui list">
|
||||||
{{ _self.renderChildren(taxons) }}
|
{{ _self.renderLeaf(taxons) }}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro renderChildren(taxons) %}
|
{% macro renderLeaf(taxons) %}
|
||||||
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
|
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
|
||||||
{% for taxon in taxons %}
|
{% for taxon in taxons %}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<div class="description">{{ taxon.description }}</div>
|
<div class="description">{{ taxon.description }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="list">
|
<div class="list">
|
||||||
{{ _self.renderChildren(taxon.children) }}
|
{{ _self.renderLeaf(taxon.children) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue