From 47c6c6b3b04054ff3416339fdd3b1cbcee9a4b4a Mon Sep 17 00:00:00 2001 From: venyii Date: Wed, 30 Jan 2019 16:33:53 +0100 Subject: [PATCH 1/2] Add missing Length constraint on product translation slug This previously caused database errors when trying to insert data. This may also occur when trying to save a product in the admin GUI. --- .../config/validation/ProductTranslation.xml | 5 ++ .../Resources/translations/validators.en.yml | 1 + tests/Controller/ProductApiTest.php | 29 ++++++++ ...translations_validation_fail_response.json | 69 +++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 tests/Responses/Expected/product/create_with_long_translations_validation_fail_response.json diff --git a/src/Sylius/Bundle/ProductBundle/Resources/config/validation/ProductTranslation.xml b/src/Sylius/Bundle/ProductBundle/Resources/config/validation/ProductTranslation.xml index 2ddda1479b0..ef490a61c11 100644 --- a/src/Sylius/Bundle/ProductBundle/Resources/config/validation/ProductTranslation.xml +++ b/src/Sylius/Bundle/ProductBundle/Resources/config/validation/ProductTranslation.xml @@ -40,6 +40,11 @@ + + + + + diff --git a/src/Sylius/Bundle/ProductBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/ProductBundle/Resources/translations/validators.en.yml index c6042f44924..add9f9304a8 100644 --- a/src/Sylius/Bundle/ProductBundle/Resources/translations/validators.en.yml +++ b/src/Sylius/Bundle/ProductBundle/Resources/translations/validators.en.yml @@ -6,6 +6,7 @@ sylius: slug: not_blank: Please enter product slug. unique: Product slug must be unique. + max_length: Product slug must not be longer than 1 character.|Product slug must not be longer than {{ limit }} characters. code: not_blank: Please enter product code. regex: Product code can only be comprised of letters, numbers, dashes and underscores. diff --git a/tests/Controller/ProductApiTest.php b/tests/Controller/ProductApiTest.php index aad77695a0f..87fb84e8201 100644 --- a/tests/Controller/ProductApiTest.php +++ b/tests/Controller/ProductApiTest.php @@ -153,6 +153,35 @@ public function it_allows_create_product_with_multiple_translations() $this->assertResponse($response, 'product/create_response', Response::HTTP_CREATED); } + /** + * @test + */ + public function it_does_not_allow_to_create_product_with_too_long_translations() + { + $this->loadFixturesFromFile('authentication/api_administrator.yml'); + $this->loadFixturesFromFile('resources/locales.yml'); + + $longString = str_repeat('s', 256); + + $data = +<<client->request('POST', '/api/v1/products/', [], [], static::$authorizedHeaderWithContentType, $data); + + $response = $this->client->getResponse(); + $this->assertResponse($response, 'product/create_with_long_translations_validation_fail_response', Response::HTTP_BAD_REQUEST); + } + /** * @test */ diff --git a/tests/Responses/Expected/product/create_with_long_translations_validation_fail_response.json b/tests/Responses/Expected/product/create_with_long_translations_validation_fail_response.json new file mode 100644 index 00000000000..a247c196eab --- /dev/null +++ b/tests/Responses/Expected/product/create_with_long_translations_validation_fail_response.json @@ -0,0 +1,69 @@ +{ + "code": 400, + "message": "Validation Failed", + "errors": { + "children": { + "enabled": {}, + "translations": { + "children": { + "en_US": { + "children": { + "name": { + "errors": [ + "Product name must not be longer than 255 characters." + ] + }, + "slug": { + "errors": [ + "Product slug must not be longer than 255 characters." + ] + }, + "description": {}, + "metaKeywords": {}, + "metaDescription": {}, + "shortDescription": {} + } + }, + "nl_NL": { + "children": { + "name": {}, + "slug": {}, + "description": {}, + "metaKeywords": {}, + "metaDescription": {}, + "shortDescription": {} + } + }, + "fr_FR": { + "children": { + "name": {}, + "slug": {}, + "description": {}, + "metaKeywords": {}, + "metaDescription": {}, + "shortDescription": {} + } + }, + "de_CH": { + "children": { + "name": {}, + "slug": {}, + "description": {}, + "metaKeywords": {}, + "metaDescription": {}, + "shortDescription": {} + } + } + } + }, + "attributes": {}, + "associations": {}, + "channels": {}, + "mainTaxon": {}, + "images": {}, + "code": {}, + "options": {}, + "productTaxons": {} + } + } +} From d7129477a60818fae698a66c3d8f79675efebf60 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 31 Jan 2019 11:12:51 +0100 Subject: [PATCH 2/2] Move bundle registration from Kernel class to "bundles.php" --- config/bundles.php | 1 + src/Kernel.php | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/config/bundles.php b/config/bundles.php index bd719d17cd9..875bd2e77c2 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -68,4 +68,5 @@ Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true], + Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true], ]; diff --git a/src/Kernel.php b/src/Kernel.php index 718752534e3..0f3e3f41991 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -56,10 +56,6 @@ public function registerBundles(): iterable yield new $class(); } } - - if (in_array($this->getEnvironment(), ['test', 'test_cached'])) { - yield new \Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin(); - } } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void