diff --git a/features/promotion/managing_coupons/coupon_validation.feature b/features/promotion/managing_coupons/coupon_validation.feature index cedbd27d7fe..5cf66c41f58 100644 --- a/features/promotion/managing_coupons/coupon_validation.feature +++ b/features/promotion/managing_coupons/coupon_validation.feature @@ -2,7 +2,7 @@ Feature: Coupon validation In order to avoid making mistakes when managing a coupon As an Administrator - I want to be prevented from adding it without specifying required fields + I want to be prevented from adding incorrect coupons Background: Given the store operates on a single channel in "United States" @@ -31,3 +31,14 @@ Feature: Coupon validation And I try to add it Then I should be notified that coupon usage limit must be at least one And there should be 0 coupon related to this promotion + + @ui + Scenario: Trying to add a new coupon with per customer usage limit below one + When I want to create a new coupon for this promotion + And I specify its code as "SANTA2016" + And I limit its usage to 30 times + And I limit its per customer usage to -1 times + And I make it valid until "26.03.2017" + And I try to add it + Then I should be notified that coupon usage limit per customer must be at least one + And there should be 0 coupon related to this promotion diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionCouponsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionCouponsContext.php index f6eb6db8fc1..0633e606f2f 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionCouponsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionCouponsContext.php @@ -166,7 +166,7 @@ public function iSpecifyItsAmountAs(?int $amount = null): void } /** - * @When I limit its per customer usage to :limit times + * @When /^I limit its per customer usage to ([^"]+) times$/ */ public function iLimitItsPerCustomerUsageLimitTo(int $limit) { @@ -398,6 +398,17 @@ public function iShouldBeNotifiedThatCouponUsageLimitMustBeAtLeast() Assert::same($currentPage->getValidationMessage('usage_limit'), 'Coupon usage limit must be at least 1.'); } + /** + * @Then I should be notified that coupon usage limit per customer must be at least one + */ + public function iShouldBeNotifiedThatCouponUsageLimitPerCustomerMustBeAtLeast(): void + { + /** @var CreatePageInterface|UpdatePageInterface $currentPage */ + $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); + + Assert::same($currentPage->getValidationMessage('per_customer_usage_limit'), 'Coupon usage limit per customer must be at least 1.'); + } + /** * @Then /^(this coupon) should no longer exist in the coupon registry$/ */ diff --git a/src/Sylius/Behat/Page/Admin/PromotionCoupon/CreatePage.php b/src/Sylius/Behat/Page/Admin/PromotionCoupon/CreatePage.php index ca94a117b19..7cb2efa92e7 100644 --- a/src/Sylius/Behat/Page/Admin/PromotionCoupon/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/PromotionCoupon/CreatePage.php @@ -43,7 +43,7 @@ protected function getDefinedElements(): array 'code' => '#sylius_promotion_coupon_code', 'expires_at' => '#sylius_promotion_coupon_expiresAt', 'usage_limit' => '#sylius_promotion_coupon_usageLimit', - 'usage_limit_per_customer' => '#sylius_promotion_coupon_usageLimit', + 'per_customer_usage_limit' => '#sylius_promotion_coupon_perCustomerUsageLimit', ]); } } diff --git a/src/Sylius/Behat/Page/Admin/PromotionCoupon/UpdatePage.php b/src/Sylius/Behat/Page/Admin/PromotionCoupon/UpdatePage.php index d68bed2eaac..83d5d73a830 100644 --- a/src/Sylius/Behat/Page/Admin/PromotionCoupon/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/PromotionCoupon/UpdatePage.php @@ -49,7 +49,7 @@ protected function getDefinedElements(): array 'code' => '#sylius_promotion_coupon_code', 'expires_at' => '#sylius_promotion_coupon_expiresAt', 'usage_limit' => '#sylius_promotion_coupon_usageLimit', - 'usage_limit_per_customer' => '#sylius_promotion_coupon_usageLimit', + 'per_customer_usage_limit' => '#sylius_promotion_coupon_perCustomerUsageLimit', ]); } } diff --git a/src/Sylius/Bundle/CoreBundle/Resources/config/validation/PromotionCoupon.xml b/src/Sylius/Bundle/CoreBundle/Resources/config/validation/PromotionCoupon.xml new file mode 100644 index 00000000000..ee2a62e2cdc --- /dev/null +++ b/src/Sylius/Bundle/CoreBundle/Resources/config/validation/PromotionCoupon.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CoreBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/CoreBundle/Resources/translations/validators.en.yml index 3612b8c3234..482317bd726 100644 --- a/src/Sylius/Bundle/CoreBundle/Resources/translations/validators.en.yml +++ b/src/Sylius/Bundle/CoreBundle/Resources/translations/validators.en.yml @@ -73,6 +73,9 @@ sylius: invalid: Depth must be a number. channel_pricing: all_defined: 'You must define price for every channel.' + promotion_coupon: + per_customer_usage_limit: + min: Coupon usage limit per customer must be at least {{ limit }}. product_translation: short_description: max: Short description must not be longer then {{ limit }} characters.