Skip to content

Commit

Permalink
Minor fixes to behats and contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Nov 3, 2021
1 parent be22726 commit c30820f
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ Feature: Editing catalog promotion
And this catalog promotion name should still be "Christmas sale"

@api @ui
Scenario: Being unable to change end date to earlier then current date
Scenario: Being unable to change end date to earlier then start 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.'
);
}

Expand Down
1 change: 0 additions & 1 deletion src/Sylius/Behat/Context/Setup/AdminSecurityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function iAmLoggedInAsAdministrator($email)

/**
* @Given I have been logged out from administration
* @When I am logged out
*/
public function iHaveBeenLoggedOutFromAdministration()
{
Expand Down
13 changes: 13 additions & 0 deletions src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"@context": "\/api\/v2\/contexts\/ConstraintViolationList",
"@type": "ConstraintViolationList",
"hydra:title": "An error occurred",
"hydra:description": "endDate: End date can not be before start date.",
"hydra:description": "endDate: End date cannot be set before start date.",
"violations": [
{
"propertyPath": "endDate",
"message": "End date can not be before start date.",
"message": "End date cannot be set before start date.",
"code": @string@
}
]
Expand Down

0 comments on commit c30820f

Please sign in to comment.