diff --git a/features/taxonomy/managing_taxons/browsing_taxon.feature b/features/taxonomy/managing_taxons/browsing_taxon.feature new file mode 100644 index 0000000000..0258cb7d80 --- /dev/null +++ b/features/taxonomy/managing_taxons/browsing_taxon.feature @@ -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 diff --git a/features/taxonomy/managing_taxons/deleting_taxon.feature b/features/taxonomy/managing_taxons/deleting_taxon.feature new file mode 100644 index 0000000000..a364f97a1b --- /dev/null +++ b/features/taxonomy/managing_taxons/deleting_taxon.feature @@ -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 diff --git a/features/taxonomy/managing_taxons/taxon_validation.feature b/features/taxonomy/managing_taxons/taxon_validation.feature index d9ea927d09..e3145d4d3b 100644 --- a/features/taxonomy/managing_taxons/taxon_validation.feature +++ b/features/taxonomy/managing_taxons/taxon_validation.feature @@ -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 diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php index d7d9e290ee..c793ba99ff 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -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) + ); + } } diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php index 697ef686b5..85d63a5326 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php @@ -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 @@ -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'); + } } diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php index 45c7065357..626263a660 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php @@ -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 diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml index 5b4832bc97..380a891382 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/taxon.yml @@ -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 diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Macro/tree.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Macro/tree.html.twig index 094e81df6f..2f951f33fa 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Macro/tree.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/Macro/tree.html.twig @@ -1,10 +1,10 @@ {% macro render(taxons) %}
- {{ _self.renderChildren(taxons) }} + {{ _self.renderLeaf(taxons) }}
{% endmacro %} -{% macro renderChildren(taxons) %} +{% macro renderLeaf(taxons) %} {% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} {% for taxon in taxons %}
@@ -17,7 +17,7 @@
{{ taxon.description }}
{% endif %}
- {{ _self.renderChildren(taxon.children) }} + {{ _self.renderLeaf(taxon.children) }}