mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
PR review fixes
This commit is contained in:
parent
6f4047f7f1
commit
7d36cdcd03
15 changed files with 89 additions and 40 deletions
|
|
@ -28,7 +28,7 @@ Feature: Adding a new product
|
|||
When I specify its code as "WHISKEY_GENTLEMEN"
|
||||
And I name it "Gentleman Jack" in "English (United States)"
|
||||
And I add the "Bottle size" option to it
|
||||
And I set its slug to "whiskey/gentelman-jack"
|
||||
And I set its slug to "whiskey/gentleman-jack"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the product "Gentleman Jack" should appear in the shop
|
||||
|
|
@ -38,7 +38,7 @@ Feature: Adding a new product
|
|||
Given I want to create a new configurable product
|
||||
When I specify its code as "WHISKEY_GENTLEMEN"
|
||||
And I name it "Gentleman Jack" in "English (United States)"
|
||||
And I set its slug to "whiskey/gentelman-jack"
|
||||
And I set its slug to "whiskey/gentleman-jack"
|
||||
And I add it
|
||||
Then I should be notified that it has been successfully created
|
||||
And the product "Gentleman Jack" should appear in the shop
|
||||
|
|
|
|||
|
|
@ -9,53 +9,53 @@ Feature: Editing product's slug
|
|||
And I am logged in as an administrator
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Creating product with autogenerated slug
|
||||
Scenario: Creating a product with an autogenerated slug
|
||||
Given I want to create a new simple product
|
||||
When I specify its code as "BOARD_MANSION_OF_MADNESS"
|
||||
And I name it "Mansion of Madness" in "English (United States)"
|
||||
And I set its price to "$100.00"
|
||||
And I add it
|
||||
Then slug of product "Mansion of Madness" should be "mansion-of-madness"
|
||||
Then the slug of the "Mansion of Madness" product should be "mansion-of-madness"
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Creating product with custom slug
|
||||
Scenario: Creating a product with a custom slug
|
||||
Given I want to create a new simple product
|
||||
When I specify its code as "BOARD_MANSION_OF_MADNESS"
|
||||
And I name it "Mansion of Madness" in "English (United States)"
|
||||
And I set its price to "$100.00"
|
||||
And I set its slug to "mom-board-game"
|
||||
And I add it
|
||||
Then slug of product "Mansion of Madness" should be "mom-board-game"
|
||||
Then the slug of the "Mansion of Madness" product should be "mom-board-game"
|
||||
|
||||
@ui
|
||||
Scenario: Seeing disabled slug field when editing product
|
||||
Scenario: Seeing disabled slug field when editing a product
|
||||
Given the store has a product "Mansion of Madness"
|
||||
When I want to modify this product
|
||||
Then the slug field should not be editable
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Prevent from editing slug while changing product name
|
||||
Scenario: Prevent from editing a slug while changing a product name
|
||||
Given the store has a product "Mansion of Madness"
|
||||
When I want to modify this product
|
||||
And I rename it to "Mansion of Madness: Second Edition" in "English (United States)"
|
||||
And I save my changes
|
||||
Then slug of product "Mansion of Madness: Second Edition" should still be "mansion-of-madness"
|
||||
Then the slug of the "Mansion of Madness: Second Edition" product should still be "mansion-of-madness"
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Automatically changing product's slug while editing product's name
|
||||
Scenario: Automatically changing a product's slug while editing a product's name
|
||||
Given the store has a product "Mansion of Madness"
|
||||
When I want to modify this product
|
||||
And I enable slug modification
|
||||
And I rename it to "Small World" in "English (United States)"
|
||||
And I save my changes
|
||||
Then slug of product "Small World" should be "small-world"
|
||||
Then the slug of the "Small World" product should be "small-world"
|
||||
|
||||
@ui @javascript
|
||||
Scenario: Manually changing product's slug while editing product's name
|
||||
Scenario: Manually changing a product's slug while editing a product's name
|
||||
Given the store has a product "Mansion of Madness"
|
||||
When I want to modify this product
|
||||
And I enable slug modification
|
||||
And I rename it to "Small World" in "English (United States)"
|
||||
And I set its slug to "small-world-board-game"
|
||||
And I save my changes
|
||||
Then slug of product "Small World" should be "small-world-board-game"
|
||||
Then the slug of the "Small World" product should be "small-world-board-game"
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ Feature: Products validation
|
|||
|
||||
@ui
|
||||
Scenario: Adding a new simple product without specifying its code
|
||||
Given I want to create a new simple product
|
||||
When I name it "Dice Brewing" in "English (United States)"
|
||||
When I want to create a new simple product
|
||||
And I name it "Dice Brewing" in "English (United States)"
|
||||
And I set its price to "$10.00"
|
||||
And I try to add it
|
||||
Then I should be notified that code is required
|
||||
|
|
@ -19,8 +19,8 @@ Feature: Products validation
|
|||
|
||||
@ui
|
||||
Scenario: Adding a new simple product without specifying its slug
|
||||
Given I want to create a new simple product
|
||||
When I specify its code as "BOARD_DICE_BREWING"
|
||||
When I want to create a new simple product
|
||||
And I specify its code as "BOARD_DICE_BREWING"
|
||||
And I name it "Dice Brewing" in "English (United States)"
|
||||
And I set its price to "$10.00"
|
||||
And I remove its slug
|
||||
|
|
@ -30,8 +30,8 @@ Feature: Products validation
|
|||
|
||||
@ui
|
||||
Scenario: Adding a new simple product without specifying its name
|
||||
Given I want to create a new simple product
|
||||
When I specify its code as "BOARD_DICE_BREWING"
|
||||
When I want to create a new simple product
|
||||
And I specify its code as "BOARD_DICE_BREWING"
|
||||
And I set its price to "$10.00"
|
||||
And I try to add it
|
||||
Then I should be notified that name is required
|
||||
|
|
@ -39,8 +39,8 @@ Feature: Products validation
|
|||
|
||||
@ui
|
||||
Scenario: Adding a new simple product without specifying its price
|
||||
Given I want to create a new simple product
|
||||
When I specify its code as "BOARD_DICE_BREWING"
|
||||
When I want to create a new simple product
|
||||
And I specify its code as "BOARD_DICE_BREWING"
|
||||
And I name it "Dice Brewing" in "English (United States)"
|
||||
And I try to add it
|
||||
Then I should be notified that price is required
|
||||
|
|
@ -48,16 +48,16 @@ Feature: Products validation
|
|||
|
||||
@ui
|
||||
Scenario: Adding a new configurable product without specifying its code
|
||||
Given I want to create a new configurable product
|
||||
When I name it "Dice Brewing" in "English (United States)"
|
||||
When I want to create a new configurable product
|
||||
And I name it "Dice Brewing" in "English (United States)"
|
||||
And I try to add it
|
||||
Then I should be notified that code is required
|
||||
And product with name "Dice Brewing" should not be added
|
||||
|
||||
@ui
|
||||
Scenario: Adding a new configurable product without specifying its name
|
||||
Given I want to create a new configurable product
|
||||
When I specify its code as "BOARD_DICE_BREWING"
|
||||
When I want to create a new configurable product
|
||||
And I specify its code as "BOARD_DICE_BREWING"
|
||||
And I try to add it
|
||||
Then I should be notified that name is required
|
||||
And product with code "BOARD_DICE_BREWING" should not be added
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ final class ManagingProductsContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @Given /^slug of (product "[^"]+") should(?:| still) be "([^"]+)"$/
|
||||
* @Then /^the slug of the ("[^"]+" product) should(?:| still) be "([^"]+)"$/
|
||||
*/
|
||||
public function productSlugShouldBe(ProductInterface $product, $slug)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Behat\Page\Admin\Product;
|
||||
|
||||
use Behat\Mink\Driver\Selenium2Driver;
|
||||
use Behat\Mink\Element\NodeElement;
|
||||
use Sylius\Behat\Behaviour\SpecifiesItsCode;
|
||||
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
|
||||
|
|
@ -31,6 +32,8 @@ class CreateConfigurableProductPage extends BaseCreatePage implements CreateConf
|
|||
$this->getDocument()->fillField(
|
||||
sprintf('sylius_product_translations_%s_name', $localeCode), $name
|
||||
);
|
||||
|
||||
$this->waitForSlugGenerationIfNecessary();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,6 +69,7 @@ class CreateConfigurableProductPage extends BaseCreatePage implements CreateConf
|
|||
'code' => '#sylius_product_code',
|
||||
'images' => '#sylius_product_images',
|
||||
'name' => '#sylius_product_translations_en_US_name',
|
||||
'slug' => '#sylius_product_translations_en_US_slug',
|
||||
'tab' => '.menu [data-tab="%name%"]',
|
||||
]);
|
||||
}
|
||||
|
|
@ -93,4 +97,13 @@ class CreateConfigurableProductPage extends BaseCreatePage implements CreateConf
|
|||
|
||||
return end($items);
|
||||
}
|
||||
|
||||
private function waitForSlugGenerationIfNecessary()
|
||||
{
|
||||
if ($this->getDriver() instanceof Selenium2Driver) {
|
||||
$this->getDocument()->waitFor(1000, function () {
|
||||
return '' !== $this->getElement('slug')->getValue();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,7 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd
|
|||
sprintf('sylius_product_translations_%s_name', $localeCode), $name
|
||||
);
|
||||
|
||||
$this->getDocument()->waitFor(10, function () {
|
||||
return '' !== $this->getElement('slug')->getValue();
|
||||
});
|
||||
$this->waitForSlugGenerationIfNecessary();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -176,4 +174,13 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd
|
|||
|
||||
return end($items);
|
||||
}
|
||||
|
||||
private function waitForSlugGenerationIfNecessary()
|
||||
{
|
||||
if ($this->getDriver() instanceof Selenium2Driver) {
|
||||
$this->getDocument()->waitFor(1000, function () {
|
||||
return '' !== $this->getElement('slug')->getValue();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProd
|
|||
$this->getDocument()->fillField(
|
||||
sprintf('sylius_product_translations_%s_name', $localeCode), $name
|
||||
);
|
||||
|
||||
$this->waitForSlugGenerationIfNecessary();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -312,4 +314,21 @@ class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProd
|
|||
|
||||
return reset($imageElements);
|
||||
}
|
||||
|
||||
private function waitForSlugGenerationIfNecessary()
|
||||
{
|
||||
if (!$this->getDriver() instanceof Selenium2Driver) {
|
||||
return;
|
||||
}
|
||||
|
||||
$slugElement = $this->getElement('slug');
|
||||
if ($slugElement->hasAttribute('readonly')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = $slugElement->getValue();
|
||||
$this->getDocument()->waitFor(1000, function () use ($slugElement, $value) {
|
||||
return $value !== $slugElement->getValue();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
sylius_admin_api_taxon:
|
||||
resource: "@SyliusAdminBundle/Resources/config/routing/api/taxon.yml"
|
||||
prefix: /taxons
|
||||
|
||||
sylius_admin_api_product:
|
||||
resource: "@SyliusAdminBundle/Resources/config/routing/api/product.yml"
|
||||
prefix: /products
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
sylius_admin_api_generate_product_slug:
|
||||
path: /generate-slug/
|
||||
methods: [GET]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_slug:generateAction
|
||||
|
|
@ -76,9 +76,3 @@ sylius_admin_product_create_simple:
|
|||
form: SyliusAdminBundle:Product:_form.html.twig
|
||||
route:
|
||||
name: sylius_admin_product_create_simple
|
||||
|
||||
sylius_product_generate_slug:
|
||||
path: /generate-slug/
|
||||
methods: [GET]
|
||||
defaults:
|
||||
_controller: sylius.controller.product_slug:generateAction
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<div class="{% if slugField.vars.required %}required {% endif %}field{% if slugField.vars.errors|length > 0 %} error{% endif %}">
|
||||
{{ form_label(slugField) }}
|
||||
{% if product.slug == null %}
|
||||
{{ form_widget(slugField, {'attr': {'data-url': path('sylius_product_generate_slug')}}) }}
|
||||
{{ form_widget(slugField, {'attr': {'data-url': path('sylius_admin_api_generate_product_slug')}}) }}
|
||||
{% else %}
|
||||
<div class="ui action input">
|
||||
{{ form_widget(slugField, {'attr': {'readonly': 'readonly', 'data-url': path('sylius_product_generate_slug')}}) }}
|
||||
{{ form_widget(slugField, {'attr': {'readonly': 'readonly', 'data-url': path('sylius_admin_api_generate_product_slug')}}) }}
|
||||
<span id="toggle-slug-modification" class="ui icon button">
|
||||
<i class="unlock icon"></i>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -81,3 +81,7 @@ th {
|
|||
font-size: 0.9em;
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
|
||||
.ui.input input[readonly] {
|
||||
color: #aaa;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace Sylius\Component\Product\Generator;
|
||||
|
||||
use Behat\Transliterator\Transliterator;
|
||||
|
||||
/**
|
||||
* @author Mateusz Zalewski <mateusz.zalewski@lakion.com>
|
||||
*/
|
||||
|
|
@ -21,6 +23,6 @@ final class SlugGenerator implements SlugGeneratorInterface
|
|||
*/
|
||||
public function generate($name)
|
||||
{
|
||||
return preg_replace('/[^a-z0-9\-]/', '', str_replace(' ', '-', strtolower($name)));
|
||||
return Transliterator::transliterate($name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
"require": {
|
||||
"php": "^5.6|^7.0",
|
||||
|
||||
"behat/transliterator": "^1.1",
|
||||
"sylius/attribute": "^1.0",
|
||||
"sylius/association": "^1.0",
|
||||
"sylius/resource": "^1.0",
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ final class SlugGeneratorSpec extends ObjectBehavior
|
|||
function it_generates_slug_without_punctuation_marks()
|
||||
{
|
||||
$this->generate('"Ticket to Ride: Europe"')->shouldReturn('ticket-to-ride-europe');
|
||||
$this->generate('Tzolk\'in: The Mayan Calendar')->shouldReturn('tzolkin-the-mayan-calendar');
|
||||
$this->generate('Tzolk\'in: The Mayan Calendar')->shouldReturn('tzolk-in-the-mayan-calendar');
|
||||
$this->generate('Game of Thrones: The Board Game')->shouldReturn('game-of-thrones-the-board-game');
|
||||
}
|
||||
|
||||
function it_generates_slug_without_special_signs()
|
||||
{
|
||||
$this->generate('Wsiąść do Pociągu: Europa')->shouldReturn('wsi-do-pocigu-europa');
|
||||
$this->generate('Wsiąść do Pociągu: Europa')->shouldReturn('wsiasc-do-pociagu-europa');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue