From 19e7e26ee28856d54887b6e13c31e082c3e3e1f0 Mon Sep 17 00:00:00 2001 From: Manuele Menozzi Date: Wed, 25 Mar 2020 09:21:14 +0100 Subject: [PATCH] Add toggleable to taxon and first behat scenario --- app/migrations/Version20200325075815.php | 35 +++++++++++++++++++ .../disable_or_enable_taxon.feature | 22 ++++++++++++ .../Ui/Admin/ManagingTaxonsContext.php | 16 +++++++++ .../Behat/Page/Admin/Taxon/UpdatePage.php | 11 ++++++ .../Page/Admin/Taxon/UpdatePageInterface.php | 4 +++ .../Resources/views/Taxon/_form.html.twig | 3 ++ .../TaxonomyBundle/Form/Type/TaxonType.php | 5 +++ .../config/doctrine/model/Taxon.orm.xml | 2 ++ .../Resources/translations/messages.en.yml | 1 + src/Sylius/Component/Taxonomy/Model/Taxon.php | 2 ++ .../Taxonomy/Model/TaxonInterface.php | 3 +- 11 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 app/migrations/Version20200325075815.php create mode 100644 features/taxonomy/managing_taxons/disable_or_enable_taxon.feature diff --git a/app/migrations/Version20200325075815.php b/app/migrations/Version20200325075815.php new file mode 100644 index 0000000000..02603777b4 --- /dev/null +++ b/app/migrations/Version20200325075815.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE sylius_taxon ADD enabled TINYINT(1) NOT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE sylius_taxon DROP enabled'); + } +} diff --git a/features/taxonomy/managing_taxons/disable_or_enable_taxon.feature b/features/taxonomy/managing_taxons/disable_or_enable_taxon.feature new file mode 100644 index 0000000000..73d6307f2c --- /dev/null +++ b/features/taxonomy/managing_taxons/disable_or_enable_taxon.feature @@ -0,0 +1,22 @@ +@managing_taxons +Feature: Toggle the taxon + In order to associate products to a taxon while it isn't published to customers + As an Administrator + I want to create a disabled taxon and toggle the taxon later + + Background: + Given the store is available in "English (United States)" + And the store classifies its products as "T-Shirts" and "Accessories" + And I am logged in as an administrator + + @ui + Scenario: Adding a disabled taxon + Given I want to create a new taxon + When I specify its code as "jeans" + And I name it "Jeans" in "English (United States)" + And I set its slug to "jeans" in "English (United States)" + And I disable it + And I add it + Then I should be notified that it has been successfully created + And the "Jeans" taxon should appear in the registry + And it should be marked as disabled diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php index 429dd822be..e63470a920 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -422,6 +422,22 @@ final class ManagingTaxonsContext implements Context Assert::same($this->createPage->getFirstTaxonOnTheList(), $taxonName); } + /** + * @When /^I disable it$/ + */ + public function iDisableIt(): void + { + $this->updatePage->disable(); + } + + /** + * @Then /^it should be marked as disabled$/ + */ + public function itShouldBeMarkedAsDisabled(): void + { + Assert::false($this->updatePage->isEnabled()); + } + /** * @return CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface */ diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php index 58c77f3ae8..0e3094057d 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php @@ -205,6 +205,16 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface }); } + public function disable(): void + { + $this->getElement('enabled')->uncheck(); + } + + public function isEnabled(): bool + { + return $this->getElement('enabled')->isChecked(); + } + protected function getElement(string $name, array $parameters = []): NodeElement { if (!isset($parameters['%language%'])) { @@ -230,6 +240,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface 'parent' => '#sylius_taxon_parent', 'slug' => '#sylius_taxon_translations_%language%_slug', 'toggle_taxon_slug_modification_button' => '[data-locale="%locale%"] .toggle-taxon-slug-modification', + 'enabled' => '#sylius_taxon_enabled', ]); } diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php index 991654321f..a026f8f65a 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php @@ -65,4 +65,8 @@ interface UpdatePageInterface extends BaseUpdatePageInterface public function getValidationMessageForImageAtPlace(int $place): string; public function activateLanguageTab(string $locale): void; + + public function disable(): void; + + public function isEnabled(): bool; } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig index be4581a6d7..4b6e7e20cc 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_form.html.twig @@ -10,6 +10,9 @@ {{ form_widget(form.parent, {'attr': {'style': 'display: none;'}}) }} {% endif %} +
+ {{ form_row(form.enabled) }} +
{{ translationFormWithSlug(form.translations, '@SyliusAdmin/Taxon/_slugField.html.twig', taxon) }} diff --git a/src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php b/src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php index d6efb2d133..87d08b47a6 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php +++ b/src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php @@ -16,6 +16,7 @@ namespace Sylius\Bundle\TaxonomyBundle\Form\Type; use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -29,6 +30,10 @@ final class TaxonType extends AbstractResourceType 'entry_type' => TaxonTranslationType::class, 'label' => 'sylius.form.taxon.name', ]) + ->add('enabled', CheckboxType::class, [ + 'required' => false, + 'label' => 'sylius.form.taxon.enabled', + ]) ->addEventSubscriber(new AddCodeFormSubscriber()) ->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { if (null === $event->getData()) { diff --git a/src/Sylius/Bundle/TaxonomyBundle/Resources/config/doctrine/model/Taxon.orm.xml b/src/Sylius/Bundle/TaxonomyBundle/Resources/config/doctrine/model/Taxon.orm.xml index 3b5a391a60..2d2c9b0c70 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/Resources/config/doctrine/model/Taxon.orm.xml +++ b/src/Sylius/Bundle/TaxonomyBundle/Resources/config/doctrine/model/Taxon.orm.xml @@ -56,6 +56,8 @@ + + diff --git a/src/Sylius/Bundle/TaxonomyBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/TaxonomyBundle/Resources/translations/messages.en.yml index a7d7c627ff..66064fb18f 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/TaxonomyBundle/Resources/translations/messages.en.yml @@ -8,5 +8,6 @@ sylius: name: Name parent: Parent slug: Slug + enabled: Enabled taxonomy: name: Name diff --git a/src/Sylius/Component/Taxonomy/Model/Taxon.php b/src/Sylius/Component/Taxonomy/Model/Taxon.php index 1cd1d2cb63..7324600624 100644 --- a/src/Sylius/Component/Taxonomy/Model/Taxon.php +++ b/src/Sylius/Component/Taxonomy/Model/Taxon.php @@ -15,6 +15,7 @@ namespace Sylius\Component\Taxonomy\Model; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Sylius\Component\Resource\Model\ToggleableTrait; use Sylius\Component\Resource\Model\TranslatableTrait; use Sylius\Component\Resource\Model\TranslationInterface; @@ -24,6 +25,7 @@ class Taxon implements TaxonInterface __construct as private initializeTranslationsCollection; getTranslation as private doGetTranslation; } + use ToggleableTrait; /** @var mixed */ protected $id; diff --git a/src/Sylius/Component/Taxonomy/Model/TaxonInterface.php b/src/Sylius/Component/Taxonomy/Model/TaxonInterface.php index ab7aff7ed8..d52d7b0868 100644 --- a/src/Sylius/Component/Taxonomy/Model/TaxonInterface.php +++ b/src/Sylius/Component/Taxonomy/Model/TaxonInterface.php @@ -17,10 +17,11 @@ use Doctrine\Common\Collections\Collection; use Sylius\Component\Resource\Model\CodeAwareInterface; use Sylius\Component\Resource\Model\ResourceInterface; use Sylius\Component\Resource\Model\SlugAwareInterface; +use Sylius\Component\Resource\Model\ToggleableInterface; use Sylius\Component\Resource\Model\TranslatableInterface; use Sylius\Component\Resource\Model\TranslationInterface; -interface TaxonInterface extends CodeAwareInterface, TranslatableInterface, ResourceInterface, SlugAwareInterface +interface TaxonInterface extends CodeAwareInterface, TranslatableInterface, ResourceInterface, SlugAwareInterface, ToggleableInterface { public function isRoot(): bool;