[Behat] Add browsing, delete feature

This commit is contained in:
Arminek 2016-04-26 01:06:38 +02:00
parent e4e6b93148
commit 313273c739
8 changed files with 197 additions and 7 deletions

View 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

View 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

View file

@ -15,6 +15,7 @@ Feature: Taxon validation
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
And Taxon named "T-Shirts" should not be added
@ui
Scenario: Trying to add a taxon without specifying its name

View file

@ -66,6 +66,7 @@ final class ManagingTaxonsContext implements Context
/**
* @Given I want to create a new taxon
* @Given I want to see all taxons in store
*/
public function iWantToCreateANewTaxon()
{
@ -168,6 +169,15 @@ final class ManagingTaxonsContext implements Context
// 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 try to add it
@ -202,6 +212,14 @@ final class ManagingTaxonsContext implements Context
$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$/
*/
@ -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)
{
@ -283,4 +301,43 @@ final class ManagingTaxonsContext implements Context
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)
);
}
}

View file

@ -11,9 +11,12 @@
namespace Sylius\Behat\Page\Admin\Taxon;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
@ -22,6 +25,30 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
{
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}
*/
@ -30,6 +57,21 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
$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}
*/
@ -38,6 +80,14 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description);
}
/**
* {@inheritdoc}
*/
public function hasTaxonWithName($name)
{
return 0 !== $this->countTaxonsByName($name);
}
/**
* {@inheritdoc}
*/
@ -65,6 +115,20 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
'parent' => '#sylius_taxon_parent',
'permalink' => '#sylius_taxon_translations_en_US_permalink',
'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');
}
}

View file

@ -19,6 +19,23 @@ use Sylius\Component\Core\Model\TaxonInterface;
*/
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 $languageCode
@ -30,6 +47,13 @@ interface CreatePageInterface extends BaseCreatePageInterface
*/
public function chooseParent(TaxonInterface $taxon);
/**
* @param string $name
*
* @return bool
*/
public function hasTaxonWithName($name);
/**
* @param string $name
* @param string $languageCode

View file

@ -2,8 +2,8 @@ sylius_admin_taxon:
resource: |
alias: sylius.taxon
section: admin
templates: SyliusAdminBundle:Taxon
except: ['index', 'show']
templates: SyliusAdminBundle:Crud
only: ['update', 'delete']
redirect: update
vars:
all:
@ -14,7 +14,7 @@ sylius_admin_taxon:
type: sylius.resource
sylius_admin_taxon_index:
path: /taxons/tree/
path: /taxons/
methods: [GET]
defaults:
_controller: sylius.controller.taxon:indexAction
@ -24,3 +24,15 @@ sylius_admin_taxon_index:
repository:
method: findRootNodes
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

View file

@ -1,10 +1,10 @@
{% macro render(taxons) %}
<div class="ui list">
{{ _self.renderChildren(taxons) }}
{{ _self.renderLeaf(taxons) }}
</div>
{% endmacro %}
{% macro renderChildren(taxons) %}
{% macro renderLeaf(taxons) %}
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %}
{% for taxon in taxons %}
<div class="item">
@ -17,7 +17,7 @@
<div class="description">{{ taxon.description }}</div>
{% endif %}
<div class="list">
{{ _self.renderChildren(taxon.children) }}
{{ _self.renderLeaf(taxon.children) }}
</div>
</div>
</div>