diff --git a/features/taxonomy/managing_taxons/editing_taxon.feature b/features/taxonomy/managing_taxons/editing_taxon.feature new file mode 100644 index 0000000000..760111f73d --- /dev/null +++ b/features/taxonomy/managing_taxons/editing_taxon.feature @@ -0,0 +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 + + 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: 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 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 diff --git a/src/Sylius/Behat/Context/Transform/TaxonContext.php b/src/Sylius/Behat/Context/Transform/TaxonContext.php index 8351b4a782..f709a131ed 100644 --- a/src/Sylius/Behat/Context/Transform/TaxonContext.php +++ b/src/Sylius/Behat/Context/Transform/TaxonContext.php @@ -38,6 +38,7 @@ final class TaxonContext implements Context * @Transform /^"([^"]+)" taxon$/ * @Transform /^"([^"]+)" as a parent taxon$/ * @Transform /^"([^"]+)" parent taxon$/ + * @Transform /^parent taxon to "([^"]+)"$/ */ public function getTaxonByName($taxonName) { diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php index f692e091db..52d151e4d2 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -72,6 +72,14 @@ final class ManagingTaxonsContext implements Context $this->createPage->open(); } + /** + * @Given /^I want to modify the ("[^"]+" taxon)$/ + */ + public function iWantToModifyATaxon(TaxonInterface $taxon) + { + $this->updatePage->open(['id' => $taxon->getId()]); + } + /** * @When I specify its code as :code */ @@ -82,13 +90,28 @@ final class ManagingTaxonsContext implements Context /** * @When I name it :name in :language - * @When I rename it to :name in :language */ public function iNameItIn($name, $language) { $this->createPage->nameIt($name, $language); } + /** + * @When I rename it to :name in :language + */ + public function iRenameItIn($name, $language) + { + $this->updatePage->nameIt($name, $language); + } + + /** + * @When I change its description to :description in :language + */ + public function iChangeItsDescriptionToIn($description, $language) + { + $this->updatePage->describeItAs($description, $language); + } + /** * @When I specify its permalink as :permalink in :language */ @@ -97,6 +120,14 @@ final class ManagingTaxonsContext implements Context $this->createPage->specifyPermalink($permalink, $language); } + /** + * @When I change its permalink to :permalink in :language + */ + public function iChangeItsPermalinkToIn($permalink, $language) + { + $this->updatePage->specifyPermalink($permalink, $language); + } + /** * @When I describe it as :description in :language */ @@ -113,6 +144,14 @@ final class ManagingTaxonsContext implements Context $this->createPage->chooseParent($taxon); } + /** + * @Given /^I change its (parent taxon to "[^"]+")$/ + */ + public function iChangeItsParentTaxonTo(TaxonInterface $taxon) + { + $this->updatePage->chooseParent($taxon); + } + /** * @When I add it * @When I try to add it @@ -122,6 +161,15 @@ final class ManagingTaxonsContext implements Context $this->createPage->create(); } + /** + * @When I save my changes + * @When I try to save my changes + */ + public function iSaveMyChanges() + { + $this->updatePage->saveChanges(); + } + /** * @Then I should be notified that it has been successfully created */ @@ -130,6 +178,14 @@ final class ManagingTaxonsContext implements Context $this->notificationChecker->checkCreationNotification(self::RESOURCE_NAME); } + /** + * @Then I should be notified that it has been successfully edited + */ + public function iShouldBeNotifiedAboutSuccessfulEdition() + { + $this->notificationChecker->checkEditionNotification(self::RESOURCE_NAME); + } + /** * @Then /^the ("[^"]+" taxon) should appear in the registry$/ */ @@ -165,4 +221,37 @@ final class ManagingTaxonsContext implements Context sprintf('Taxon %s should have %s parent taxon', $taxon->getName(), $parentTaxon->getName()) ); } + + /** + * @Then this taxon :element should be :value + */ + public function thisTaxonElementShouldBe($element, $value) + { + Assert::true( + $this->updatePage->hasResourceValues([$element => $value]), + sprintf('Taxon with %s should have %s value', $element, $value) + ); + } + + /** + * @Then the code field should be disabled + */ + public function theCodeFiledShouldBeDisabled() + { + Assert::true( + $this->updatePage->isCodeDisabled(), + 'Code field should be disabled but it is not' + ); + } + + /** + * @Then /^this taxon should (belongs to "[^"]+")$/ + */ + public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) + { + Assert::true( + $this->updatePage->hasResourceValues(['parent' => $taxon->getId()]), + sprintf('Current taxon should have %s parent taxon', $taxon->getName()) + ); + } } diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php index b4d7de1435..189833f6f7 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php @@ -11,13 +11,58 @@ namespace Sylius\Behat\Page\Admin\Taxon; +use Behat\Mink\Element\NodeElement; +use Sylius\Behat\Behaviour\ChecksCodeImmutability; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; +use Sylius\Component\Core\Model\TaxonInterface; /** * @author Arkadiusz Krakowiak */ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { + use ChecksCodeImmutability; + + /** + * {@inheritdoc} + */ + public function chooseParent(TaxonInterface $taxon) + { + $this->getElement('parent')->selectOption($taxon->getName(), false); + } + + /** + * {@inheritdoc} + */ + public function describeItAs($description, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_description', $languageCode), $description); + } + + /** + * {@inheritdoc} + */ + public function nameIt($name, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name); + } + + /** + * {@inheritdoc} + */ + public function specifyPermalink($permalink, $languageCode) + { + $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_permalink', $languageCode), $permalink); + } + + /** + * @return NodeElement + */ + protected function getCodeElement() + { + return $this->getElement('code'); + } + /** * {@inheritdoc} */ diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php index 7568b004ab..40a5bdd000 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php @@ -12,11 +12,38 @@ namespace Sylius\Behat\Page\Admin\Taxon; use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; +use Sylius\Component\Core\Model\TaxonInterface; /** * @author Arkadiusz Krakowiak */ interface UpdatePageInterface extends BaseUpdatePageInterface { + /** + * @param string $description + * @param string $languageCode + */ + public function describeItAs($description, $languageCode); + /** + * @param TaxonInterface $taxon + */ + public function chooseParent(TaxonInterface $taxon); + + /** + * @return bool + */ + public function isCodeDisabled(); + + /** + * @param string $name + * @param string $languageCode + */ + public function nameIt($name, $languageCode); + + /** + * @param string $permalink + * @param string $languageCode + */ + public function specifyPermalink($permalink, $languageCode); }