Skip to content

Commit

Permalink
Merge branch '1.3' into 1.4
Browse files Browse the repository at this point in the history
* 1.3:
  Move bundle registration from Kernel class to "bundles.php"
  Add missing Length constraint on product translation slug
  • Loading branch information
pamil committed Jan 31, 2019
2 parents 3791ebc + eac0674 commit 2a343ac
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/bundles.php
Expand Up @@ -69,4 +69,5 @@
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],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
Sylius\Behat\Application\SyliusTestPlugin\SyliusTestPlugin::class => ['test' => true, 'test_cached' => true],
];
4 changes: 0 additions & 4 deletions src/Kernel.php
Expand Up @@ -58,10 +58,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
Expand Down
Expand Up @@ -40,6 +40,11 @@
<option name="message">sylius.product.slug.not_blank</option>
<option name="groups">sylius</option>
</constraint>
<constraint name="Length">
<option name="max">255</option>
<option name="maxMessage">sylius.product.slug.max_length</option>
<option name="groups">sylius</option>
</constraint>
</property>
</class>
</constraint-mapping>
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions tests/Controller/ProductApiTest.php
Expand Up @@ -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 =
<<<EOT
{
"code": "MUG_TH",
"translations": {
"en_US": {
"name": "{$longString}",
"slug": "{$longString}"
}
}
}
EOT;

$this->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
*/
Expand Down
@@ -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": {}
}
}
}

0 comments on commit 2a343ac

Please sign in to comment.