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 Promotion bundle
This commit is contained in:
parent
1e1345dff4
commit
62a3f919c5
12 changed files with 158 additions and 1 deletions
|
|
@ -18,6 +18,16 @@ Feature: Validating a catalog promotion creation
|
|||
Then I should be notified that code and name are required
|
||||
And there should be an empty list of catalog promotions
|
||||
|
||||
@api @ui
|
||||
Scenario: Trying to create a catalog promotion with too long code
|
||||
Given I want to create a new catalog promotion
|
||||
And I name it "Winter sale"
|
||||
And I specify its label as "Winter -50%" in "English (United States)"
|
||||
And I describe it as "This promotion gives a 50% discount on all products" in "English (United States)"
|
||||
When I specify its code as 256 characters long string
|
||||
And I try to add it
|
||||
Then I should be notified that the code is too long
|
||||
|
||||
@api @ui
|
||||
Scenario: Trying to create a catalog promotion with taken code
|
||||
Given there is a catalog promotion with "sale" code and "Summer sale" name
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@ Feature: Coupon validation
|
|||
Then I should be notified that code is required
|
||||
And there should be 0 coupons related to this promotion
|
||||
|
||||
@ui @api
|
||||
Scenario: Trying to add a new coupon with too long code
|
||||
Given I want to create a new coupon for this promotion
|
||||
And I limit its usage to 30 times
|
||||
And I limit its per customer usage to 40 times
|
||||
And I make it valid until "26.03.2017"
|
||||
When I specify its code as 256 characters long string
|
||||
And I try to add it
|
||||
Then I should be notified that the code is too long
|
||||
|
||||
@ui @api
|
||||
Scenario: Trying to add a new coupon with usage limit below one
|
||||
When I want to create a new coupon for this promotion
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ Feature: Promotion validation
|
|||
Then I should be notified that code is required
|
||||
And promotion with name "No-VAT promotion" should not be added
|
||||
|
||||
@api @ui
|
||||
Scenario: Trying to add a new promotion with too long code
|
||||
Given I want to create a new promotion
|
||||
And I name it "No-VAT promotion"
|
||||
When I specify its code as 256 characters long string
|
||||
And I try to add it
|
||||
Then I should be notified that the code is too long
|
||||
|
||||
@api @ui
|
||||
Scenario: Trying to add a new promotion without specifying its name
|
||||
When I want to create a new promotion
|
||||
|
|
|
|||
|
|
@ -93,6 +93,14 @@ final class ManagingCatalogPromotionsContext implements Context
|
|||
$this->client->addRequestData($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :amount characters long string
|
||||
*/
|
||||
public function iSpecifyItsCodeAsCharactersLongString(int $amount): void
|
||||
{
|
||||
$this->iSpecifyItsAs('code', str_repeat('a', $amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set its priority to :priority
|
||||
*/
|
||||
|
|
@ -1535,6 +1543,17 @@ final class ManagingCatalogPromotionsContext 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()),
|
||||
'Catalog promotion code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should see a catalog promotion with name :name
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -105,6 +105,14 @@ final class ManagingPromotionCouponsContext implements Context
|
|||
$this->client->addRequestData('code', $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 limit its usage to :times time(s)
|
||||
* @When I change its usage limit to :times
|
||||
|
|
@ -510,6 +518,17 @@ final class ManagingPromotionCouponsContext 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()),
|
||||
'Coupon code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that only coupon based promotions can have coupons
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -103,6 +103,14 @@ final class ManagingPromotionsContext implements Context
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :amount characters long string
|
||||
*/
|
||||
public function iSpecifyItsCodeAsCharactersLongString(int $amount): void
|
||||
{
|
||||
$this->iSpecifyItsAs('code', str_repeat('a', $amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I set it as not applies to discounted by catalog promotion items
|
||||
*/
|
||||
|
|
@ -744,6 +752,17 @@ final class ManagingPromotionsContext 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()),
|
||||
'Promotion code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then there should still be only one promotion with :element :value
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -101,6 +101,14 @@ final class ManagingCatalogPromotionsContext implements Context
|
|||
$this->createPage->specifyCode($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I specify its code as :amount characters long string
|
||||
*/
|
||||
public function iSpecifyItsCodeAsCharactersLongString(int $amount): void
|
||||
{
|
||||
$this->createPage->specifyCode(str_repeat('a', $amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* @When I name it :name
|
||||
*/
|
||||
|
|
@ -1196,6 +1204,17 @@ final class ManagingCatalogPromotionsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the code is too long
|
||||
*/
|
||||
public function iShouldBeNotifiedThatTheCodeIsTooLong(): void
|
||||
{
|
||||
Assert::contains(
|
||||
$this->createPage->getValidationMessage('code'),
|
||||
'Catalog promotion code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then its priority should be :priority
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -122,6 +122,14 @@ final class ManagingPromotionCouponsContext 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 limit its usage to :limit time(s)
|
||||
*/
|
||||
|
|
@ -447,6 +455,20 @@ final class ManagingPromotionCouponsContext implements Context
|
|||
Assert::same($currentPage->getValidationMessage('usage_limit'), 'Coupon usage limit must be at least 1.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the code is too long
|
||||
*/
|
||||
public function iShouldBeNotifiedThatTheCouponIsTooLong(): void
|
||||
{
|
||||
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
|
||||
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
|
||||
|
||||
Assert::contains(
|
||||
$currentPage->getValidationMessage('code'),
|
||||
'Coupon code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that coupon usage limit per customer must be at least one
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -68,6 +68,14 @@ final class ManagingPromotionsContext 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 name it :name
|
||||
* @When I do not name it
|
||||
|
|
@ -588,6 +596,17 @@ final class ManagingPromotionsContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that the code is too long
|
||||
*/
|
||||
public function iShouldBeNotifiedThatTheCodeIsTooLong(): void
|
||||
{
|
||||
Assert::contains(
|
||||
$this->createPage->getValidationMessage('code'),
|
||||
'Promotion code must not be longer than',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then I should be notified that a percentage discount value must be between 0% and 100%
|
||||
* @Then I should be notified that a percentage discount value must be at least 0%
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@
|
|||
<option name="pattern">/^[\w-]*$/</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
<constraint name="Length">
|
||||
<option name="max">255</option>
|
||||
<option name="maxMessage">sylius.catalog_promotion.code.max_length</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
</property>
|
||||
<property name="name">
|
||||
<constraint name="NotBlank">
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@
|
|||
<option name="pattern">/^[\w-]*$/</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
<constraint name="Length">
|
||||
<option name="max">255</option>
|
||||
<option name="maxMessage">sylius.promotion.code.max_length</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
</property>
|
||||
<property name="name">
|
||||
<constraint name="NotBlank">
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
sylius:
|
||||
catalog_promotion:
|
||||
code:
|
||||
max_length: Catalog promotion code must not be longer than {{ limit }} characters.
|
||||
unique: The catalog promotion with given code already exists.
|
||||
regex: Catalog promotion code can only be comprised of letters, numbers, dashes and underscores.
|
||||
not_blank: Please enter catalog promotion code.
|
||||
|
|
@ -30,6 +31,7 @@ sylius:
|
|||
invalid: Catalog promotion scope type is invalid. Available types are {{ available_scope_types }}.
|
||||
promotion:
|
||||
code:
|
||||
max_length: Promotion code must not be longer than {{ limit }} characters.
|
||||
unique: The promotion with given code already exists.
|
||||
regex: Promotion code can only be comprised of letters, numbers, dashes and underscores.
|
||||
not_blank: Please enter promotion code.
|
||||
|
|
@ -51,7 +53,7 @@ sylius:
|
|||
invalid_type: Promotion rule type is invalid. Available rule types are {{ available_rule_types }}.
|
||||
promotion_coupon:
|
||||
code:
|
||||
max_length: Coupon code must not be longer than 1 character.|Coupon code must not be longer than {{ limit }} characters.
|
||||
max_length: Coupon code must not be longer than {{ limit }} characters.
|
||||
min_length: Coupon code must be at least 1 character long.|Coupon code must be at least {{ limit }} characters long.
|
||||
not_blank: Please enter coupon code.
|
||||
regex: Coupon code can only be comprised of letters, numbers, dashes and underscores.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue