[Behat][Admin][Taxon] Autogenerate slug based on selected parent

This commit is contained in:
Jan Goralski 2023-08-24 15:42:34 +02:00
parent 99cd870789
commit 2d5aa6864f
No known key found for this signature in database
GPG key ID: 95D91BA380F31EDD
4 changed files with 66 additions and 3 deletions

View file

@ -34,6 +34,16 @@ Feature: Editing taxon's slug
And I add it
Then this taxon slug should be "medieval-weapons/siege-engines"
@ui @javascript
Scenario: Creating a child taxon with autogenerated slug by setting the parent
Given the store has "Medieval weapons" taxonomy
When I want to create a new taxon
And I specify its code as "PIKES"
And I name it "Pikes" in "English (United States)"
And I set its parent taxon to "Medieval weapons"
And I add it
Then this taxon slug should be "medieval-weapons/pikes"
@ui
Scenario: Creating a taxon with a custom slug for parent
Given the store has "Medieval weapons" taxonomy
@ -51,13 +61,32 @@ Feature: Editing taxon's slug
Then the slug field should not be editable
@ui @javascript
Scenario: Prevent from editing a slug while changing a taxon name
Scenario: Prevent from editing the slug while changing a taxon name
Given the store has "Medieval weapons" taxonomy
When I want to modify the "Medieval weapons" taxon
And I rename it to "Renaissance weapons" in "English (United States)"
And I save my changes
Then the slug of the "Renaissance weapons" taxon should still be "medieval-weapons"
@ui @javascript
Scenario: Prevent from editing the slug while setting the taxon's parent
Given the store has "Medieval weapons" taxonomy
And the store has "Pikes" taxonomy
When I want to modify the "Pikes" taxon
And I set its parent taxon to "Medieval weapons"
And I save my changes
Then the slug of the "Pikes" taxon should still be "pikes"
@ui @javascript
Scenario: Prevent from editing the slug while changing the taxon's parent
Given the store has "Medieval weapons" taxonomy
Given the store has "Renaissance weapons" taxonomy
And the "Medieval weapons" taxon has child taxon "Pikes"
When I want to modify the "Pikes" taxon
And I change its parent taxon to "Renaissance weapons"
And I save my changes
Then the slug of the "Pikes" taxon should still be "medieval-weapons/pikes"
@ui @javascript
Scenario: Automatically changing a taxon's slug while editing a taxon's name
Given the store has "Medieval weapons" taxonomy
@ -78,3 +107,26 @@ Feature: Editing taxon's slug
Then the slug of the "Renaissance weapons" taxon should be "renaissance"
@ui @javascript
Scenario: Automatically changing a child taxon's slug when changing the parent
Given the store has "Renaissance weapons" taxonomy
And the store has "Medieval weapons" taxonomy
And the "Medieval weapons" taxon has child taxon "Pikes"
When I want to modify the "Pikes" taxon
And I enable slug modification
And I change its parent taxon to "Renaissance weapons"
And I save my changes
Then the slug of the "Pikes" taxon should be "renaissance-weapons/pikes"
@ui @javascript
Scenario: Manually changing a child taxon's slug when changing the parent
Given the store has "Renaissance weapons" taxonomy
And the store has "Medieval weapons" taxonomy
And the "Medieval weapons" taxon has child taxon "Pikes"
When I want to modify the "Pikes" taxon
And I enable slug modification
And I change its parent taxon to "Renaissance weapons"
And I set its slug to "pikes" in "English (United States)"
And I save my changes
Then the slug of the "Pikes" taxon should be "pikes"

View file

@ -120,7 +120,7 @@ final class TaxonomyContext implements Context
public function theTaxonHasChildrenTaxonAnd(TaxonInterface $taxon, string ...$taxonsNames): void
{
foreach ($taxonsNames as $taxonName) {
$taxon->addChild($this->createTaxon($taxonName));
$taxon->addChild($this->createChildTaxon($taxonName, $taxon));
}
$this->objectManager->persist($taxon);
@ -163,6 +163,15 @@ final class TaxonomyContext implements Context
return $taxon;
}
private function createChildTaxon(string $name, TaxonInterface $parent): TaxonInterface
{
$child = $this->createTaxon($name);
$child->setParent($parent);
$child->setSlug($this->taxonSlugGenerator->generate($child));
return $child;
}
/**
* @return TaxonInterface
*/

View file

@ -204,7 +204,7 @@ final class ManagingTaxonsContext implements Context
{
$this->updatePage->open(['id' => $taxon->getId()]);
Assert::true($this->updatePage->hasResourceValues(['slug' => $slug]));
Assert::same($this->updatePage->getSlug(), $slug);
}
/**

View file

@ -19,6 +19,7 @@ use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Behat\Service\AutocompleteHelper;
use Sylius\Behat\Service\DriverHelper;
use Sylius\Behat\Service\JQueryHelper;
use Sylius\Behat\Service\SlugGenerationHelper;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;
@ -32,6 +33,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
public function chooseParent(TaxonInterface $taxon): void
{
AutocompleteHelper::chooseValue($this->getSession(), $this->getElement('parent')->getParent(), $taxon->getName());
JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession());
}
public function describeItAs(string $description, string $languageCode): void