mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Cover the max code length validation in the Customer bundle
This commit is contained in:
parent
30c6be1def
commit
d51ef9fc38
5 changed files with 52 additions and 17 deletions
|
|
@ -1,25 +1,16 @@
|
|||
@managing_customer_groups
|
||||
Feature: Customer group validation
|
||||
Feature: Customer Group validation
|
||||
In order to avoid making mistakes when managing customer groups
|
||||
As an Administrator
|
||||
I want to be prevented from adding it without specifying required fields
|
||||
I want to be prevented from adding or editing it with invalid data
|
||||
|
||||
Background:
|
||||
Given I am logged in as an administrator
|
||||
|
||||
@ui @api
|
||||
Scenario: Trying to add a new customer group without a name
|
||||
When I want to create a new customer group
|
||||
And I try to add it
|
||||
Then I should be notified that name is required
|
||||
And I should be informed that this form contains errors
|
||||
|
||||
@ui @api
|
||||
Scenario: Trying to remove name from an existing customer group
|
||||
Given the store has a customer group "Retail"
|
||||
When I want to edit this customer group
|
||||
And I remove its name
|
||||
And I try to save my changes
|
||||
Then I should be notified that name is required
|
||||
And I should be informed that this form contains errors
|
||||
And this customer group should still be named "Retail"
|
||||
Scenario: Adding a new customer group with too long code
|
||||
Given I want to create a new customer group
|
||||
And I specify its name as "Retail"
|
||||
When I specify its code as 256 characters long string
|
||||
And I add it
|
||||
Then I should be notified that the code is too long
|
||||
|
|
|
|||
|
|
@ -47,6 +47,14 @@ final class ManagingCustomerGroupsContext implements Context
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :amount characters long string
|
||||
*/
|
||||
public function iSpecifyItsCodeAsCharactersLongString(int $amount): void
|
||||
{
|
||||
$this->iSpecifyItsCodeAs(str_repeat('a', $amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its name as :name
|
||||
* @When I remove its name
|
||||
|
|
@ -154,6 +162,17 @@ final class ManagingCustomerGroupsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the code is too long
|
||||
*/
|
||||
public function iShouldBeNotifiedThatTheCodeIsTooLong(): void
|
||||
{
|
||||
Assert::contains(
|
||||
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||
'Customer group code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be informed that this form contains errors
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -48,6 +48,14 @@ final class ManagingCustomerGroupsContext implements Context
|
|||
$this->createPage->specifyCode($code ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :amount characters long string
|
||||
*/
|
||||
public function iSpecifyItsCodeAsCharactersLongString(int $amount): void
|
||||
{
|
||||
$this->iSpecifyItsCodeAs(str_repeat('a', $amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its name as :name
|
||||
* @When I remove its name
|
||||
|
|
@ -169,6 +177,17 @@ final class ManagingCustomerGroupsContext implements Context
|
|||
Assert::same($this->createPage->getValidationMessage('code'), 'Customer group code has to be unique.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the code is too long
|
||||
*/
|
||||
public function iShouldBeNotifiedThatCustomerGroupCodeIsTooLong(): void
|
||||
{
|
||||
Assert::contains(
|
||||
$this->createPage->getValidationMessage('code'),
|
||||
'Customer group code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be informed that this form contains errors
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@
|
|||
<option name="pattern">/^[\w-]*$/</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
<constraint name="Length">
|
||||
<option name="max">255</option>
|
||||
<option name="maxMessage">sylius.customer_group.code.max_length</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
</property>
|
||||
<property name="name">
|
||||
<constraint name="NotBlank">
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ sylius:
|
|||
registered: This email is already registered, please login or use forgotten password.
|
||||
customer_group:
|
||||
code:
|
||||
max_length: Customer group code must not be longer than {{ limit }} characters.
|
||||
regex: Customer group code can only be comprised of letters, numbers, dashes and underscores.
|
||||
unique: Customer group code has to be unique.
|
||||
not_blank: Please enter a customer group code.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue