From 159127435f8f4fddf205d4aaf955d2d9b45e0a36 Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Mon, 1 Nov 2021 10:46:30 +0100 Subject: [PATCH] Minor fixes to behats and contexts --- ..._catalog_promotions_in_proper_time_range.feature | 8 ++------ .../editing_catalog_promotion.feature | 4 ++-- .../Api/Admin/ManagingCatalogPromotionsContext.php | 8 ++++---- .../Behat/Context/Setup/CatalogPromotionContext.php | 13 +++++++++++++ .../Ui/Admin/ManagingCatalogPromotionsContext.php | 8 ++++---- .../Page/Admin/CatalogPromotion/CreatePage.php | 2 +- .../Form/Type/CatalogPromotionType.php | 2 -- .../Resources/translations/validators.en.yml | 2 +- ...talog_promotion_with_invalid_dates_response.json | 2 +- 9 files changed, 28 insertions(+), 21 deletions(-) diff --git a/features/promotion/applying_catalog_promotions/applying_catalog_promotions_in_proper_time_range.feature b/features/promotion/applying_catalog_promotions/applying_catalog_promotions_in_proper_time_range.feature index 67df7e844f60..047cdb987e4c 100644 --- a/features/promotion/applying_catalog_promotions/applying_catalog_promotions_in_proper_time_range.feature +++ b/features/promotion/applying_catalog_promotions/applying_catalog_promotions_in_proper_time_range.feature @@ -38,10 +38,6 @@ Feature: Applying catalog promotions in proper time range Scenario: Not applying catalog promotion if its end date has already passed after end date modification Given it is "2021-12-25" now And the catalog promotion "Winter sale" operates between "2021-12-20" and "2021-12-30" - And I am logged in as an administrator - When I want to modify a catalog promotion "Winter sale" - And I change its end date to "2021-12-23" - And I save my changes - And I am logged out - And I view product "T-Shirt" + And the end date of catalog promotion "Winter sale" was changed to "2021-12-23" + When I view product "T-Shirt" Then I should see the product price "$20.00" diff --git a/features/promotion/managing_catalog_promotions/editing_catalog_promotion.feature b/features/promotion/managing_catalog_promotions/editing_catalog_promotion.feature index 0c2c6a801298..d2f6f8b0a84d 100644 --- a/features/promotion/managing_catalog_promotions/editing_catalog_promotion.feature +++ b/features/promotion/managing_catalog_promotions/editing_catalog_promotion.feature @@ -80,6 +80,6 @@ Feature: Editing catalog promotion Scenario: Being unable to change end date to earlier then current date Given the catalog promotion "Christmas sale" operates between "2021-12-20" and "2021-12-30" When I want to modify a catalog promotion "Christmas sale" - And I try change its end date to "2021-12-15" + And I try to change its end date to "2021-12-15" And I save my changes - Then I should get information that the end date can not be before start date + Then I should get information that the end date cannot be set before start date diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php index 68f73931c2fb..640bf3a6f739 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php @@ -602,7 +602,7 @@ public function iViewDetailsOfTheCatalogPromotion(CatalogPromotionInterface $cat } /** - * @When I( try) change its end date to :endDate + * @When I( try to) change its end date to :endDate */ public function iChangeItsEndDateTo(string $endDate): void { @@ -1072,13 +1072,13 @@ public function itsNameShouldBe(string $name): void } /** - * @Then I should get information that the end date can not be before start date + * @Then I should get information that the end date cannot be set before start date */ - public function iShouldGetInformationThatTheEndDateCanNotBeBeforeStartDate(): void + public function iShouldGetInformationThatTheEndDateCannotBeSetBeforeStartDate(): void { Assert::contains( $this->responseChecker->getError($this->client->getLastResponse()), - 'endDate: End date can not be before start date.' + 'endDate: End date cannot be set before start date.' ); } diff --git a/src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php b/src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php index fc051015e8b6..ecec00cbef75 100644 --- a/src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php +++ b/src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php @@ -350,6 +350,19 @@ public function theCatalogPromotionStartsAt(CatalogPromotionInterface $catalogPr $this->eventBus->dispatch(new CatalogPromotionUpdated($catalogPromotion->getCode())); } + /** + * @Given the end date of catalog promotion :catalogPromotion was changed to :endDate + */ + public function theEndDateOfCatalogPromotionWasChangedTo( + CatalogPromotionInterface $catalogPromotion, + string $endDate + ): void { + $catalogPromotion->setEndDate(new \DateTime($endDate)); + + $this->entityManager->flush(); + $this->eventBus->dispatch(new CatalogPromotionUpdated($catalogPromotion->getCode())); + } + /** * @Given the catalog promotion :catalogPromotion is currently being processed */ diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php index bee01ce28b68..248cdd4567b0 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php @@ -189,7 +189,7 @@ public function iMakeItUnavailableInChannel(string $channelName): void } /** - * @When I( try) change its end date to :endDate + * @When I( try to) change its end date to :endDate */ public function iChangeItsEndDateTo(string $endDate): void { @@ -801,10 +801,10 @@ public function itShouldStartAtAndEndAt(string $startDate, string $endDate): voi } /** - * @Then I should get information that the end date can not be before start date + * @Then I should get information that the end date cannot be set before start date */ - public function iShouldGetInformationThatTheEndDateCanNotBeBeforeStartDate(): void + public function iShouldGetInformationThatTheEndDateCannotBeSetBeforeStartDate(): void { - Assert::same($this->createPage->getValidationMessage('endDate'), 'End date can not be before start date.'); + Assert::same($this->createPage->getValidationMessage('endDate'), 'End date cannot be set before start date.'); } } diff --git a/src/Sylius/Behat/Page/Admin/CatalogPromotion/CreatePage.php b/src/Sylius/Behat/Page/Admin/CatalogPromotion/CreatePage.php index d1edc566f2b1..6303548b675f 100644 --- a/src/Sylius/Behat/Page/Admin/CatalogPromotion/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/CatalogPromotion/CreatePage.php @@ -23,8 +23,8 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ - 'endDate' => '#sylius_catalog_promotion_endDate', 'code' => '#sylius_catalog_promotion_code', + 'endDate' => '#sylius_catalog_promotion_endDate', 'name' => '#sylius_catalog_promotion_name', ]); } diff --git a/src/Sylius/Bundle/PromotionBundle/Form/Type/CatalogPromotionType.php b/src/Sylius/Bundle/PromotionBundle/Form/Type/CatalogPromotionType.php index d778d2a1c7e8..f09331ade49f 100644 --- a/src/Sylius/Bundle/PromotionBundle/Form/Type/CatalogPromotionType.php +++ b/src/Sylius/Bundle/PromotionBundle/Form/Type/CatalogPromotionType.php @@ -13,11 +13,9 @@ namespace Sylius\Bundle\PromotionBundle\Form\Type; -use Sylius\Bundle\PromotionBundle\Form\DataTransformer\DefaultTimeDataTransformer; use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; -use Sylius\Component\Promotion\Model\CatalogPromotionInterface; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; diff --git a/src/Sylius/Bundle/PromotionBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/PromotionBundle/Resources/translations/validators.en.yml index 84b75b30caea..c6e5df8d552f 100644 --- a/src/Sylius/Bundle/PromotionBundle/Resources/translations/validators.en.yml +++ b/src/Sylius/Bundle/PromotionBundle/Resources/translations/validators.en.yml @@ -8,7 +8,7 @@ sylius: regex: Catalog promotion code can only be comprised of letters, numbers, dashes and underscores. not_blank: Please enter catalog promotion code. date: - greater_than_start_date: End date can not be before start date. + greater_than_start_date: End date cannot be set before start date. name: max_length: Catalog promotion name must not be longer than {{ limit }} characters. min_length: Catalog promotion name must be at least {{ limit }} characters long. diff --git a/tests/Api/Responses/Expected/admin/catalog_promotion/post_catalog_promotion_with_invalid_dates_response.json b/tests/Api/Responses/Expected/admin/catalog_promotion/post_catalog_promotion_with_invalid_dates_response.json index 4c24d1dde44b..9b4f3626081b 100644 --- a/tests/Api/Responses/Expected/admin/catalog_promotion/post_catalog_promotion_with_invalid_dates_response.json +++ b/tests/Api/Responses/Expected/admin/catalog_promotion/post_catalog_promotion_with_invalid_dates_response.json @@ -6,7 +6,7 @@ "violations": [ { "propertyPath": "endDate", - "message": "End date can not be before start date.", + "message": "End date cannot be set before start date.", "code": @string@ } ]