mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Addressing] Add validation for zone type
This commit is contained in:
parent
c5dbbf85d4
commit
6607e993ff
5 changed files with 30 additions and 7 deletions
|
|
@ -99,3 +99,13 @@ Feature: Zone validation
|
||||||
And I try to add it
|
And I try to add it
|
||||||
Then I should be notified that "NA" is not a valid zone code
|
Then I should be notified that "NA" is not a valid zone code
|
||||||
And zone with name "America" should not be added
|
And zone with name "America" should not be added
|
||||||
|
|
||||||
|
@api @no-ui
|
||||||
|
Scenario: Trying to add a zone with wrong type
|
||||||
|
When I want to create a new zone consisting of wrong_type
|
||||||
|
And I name it "European Union"
|
||||||
|
And I specify its code as "EU"
|
||||||
|
And I add a country "France"
|
||||||
|
And I try to add it
|
||||||
|
Then I should be notified that "wrong_type" is not a valid zone type
|
||||||
|
And zone with name "European Union" should not be added
|
||||||
|
|
|
||||||
|
|
@ -485,6 +485,17 @@ final readonly class ManagingZonesContext implements Context
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Then I should be notified that :type is not a valid zone type
|
||||||
|
*/
|
||||||
|
public function iShouldBeNotifiedThatIsNotAValidZoneType(string $type): void
|
||||||
|
{
|
||||||
|
Assert::contains(
|
||||||
|
$this->responseChecker->getError($this->client->getLastResponse()),
|
||||||
|
sprintf('Type "%s" is invalid. Allowed types are:', $type),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function removeZoneMember(CountryInterface|ProvinceInterface|ZoneInterface $objectToRemove): void
|
private function removeZoneMember(CountryInterface|ProvinceInterface|ZoneInterface $objectToRemove): void
|
||||||
{
|
{
|
||||||
$members = $this->client->getContent()['members'];
|
$members = $this->client->getContent()['members'];
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,13 @@
|
||||||
<option name="groups">sylius</option>
|
<option name="groups">sylius</option>
|
||||||
</constraint>
|
</constraint>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="type">
|
||||||
|
<constraint name="Choice">
|
||||||
|
<option name="callback">getTypes</option>
|
||||||
|
<option name="message">sylius.zone.type.invalid</option>
|
||||||
|
<option name="groups">sylius</option>
|
||||||
|
</constraint>
|
||||||
|
</property>
|
||||||
<property name="scope">
|
<property name="scope">
|
||||||
<constraint name="NotBlank">
|
<constraint name="NotBlank">
|
||||||
<option name="message">sylius.zone.scope.not_blank</option>
|
<option name="message">sylius.zone.scope.not_blank</option>
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ sylius:
|
||||||
not_blank: Please enter zone code.
|
not_blank: Please enter zone code.
|
||||||
regex: Zone code can only be comprised of letters, numbers, dashes and underscores.
|
regex: Zone code can only be comprised of letters, numbers, dashes and underscores.
|
||||||
unique: Zone code must be unique.
|
unique: Zone code must be unique.
|
||||||
|
type:
|
||||||
|
invalid: "Type {{ value }} is invalid. Allowed types are: {{ choices }}."
|
||||||
members:
|
members:
|
||||||
min_count: Please add at least {{ limit }} zone member.
|
min_count: Please add at least {{ limit }} zone member.
|
||||||
name:
|
name:
|
||||||
|
|
|
||||||
|
|
@ -82,15 +82,8 @@ class Zone implements ZoneInterface, \Stringable
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function setType(?string $type): void
|
public function setType(?string $type): void
|
||||||
{
|
{
|
||||||
if (!in_array($type, static::getTypes(), true)) {
|
|
||||||
throw new \InvalidArgumentException('Wrong zone type supplied.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue