Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Behat][WIP] Add validation scenarios #76

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,43 @@ Feature: Adding blocks
And I fill "Code, Content" fields
And I add "Blog" and "Homepage" sections to it
And I add it
Then I should be notified that the block has been created
Then I should be notified that the block has been created

@ui
Scenario: Trying to add text block with blank data
When I go to the create "text" block page
And I try to add it
Then I should be notified that "Code, Content" cannot be blank

@ui
Scenario: Trying to add html block with blank data
When I go to the create "html" block page
And I try to add it
Then I should be notified that "Code, Content" cannot be blank

@ui
Scenario: Trying to add image block with blank data
When I go to the create "image" block page
And I try to add it
Then I should be notified that "Code, Image" cannot be blank

@ui
Scenario: Trying to add text block with too long data
When I go to the create "text" block page
And I fill "Code, Name, Content" fields with 6000 characters
And I try to add it
Then I should be notified that "Code, Name" fields are too long

@ui
Scenario: Trying to add html block with too long data
When I go to the create "html" block page
And I fill "Code, Name, Content" fields with 6000 characters
And I try to add it
Then I should be notified that "Code, Name" fields are too long

@ui
Scenario: Trying to add image block with too long data
When I go to the create "image" block page
And I fill "Code, Name" fields with 6000 characters
And I try to add it
Then I should be notified that "Code, Name" fields are too long
9 changes: 8 additions & 1 deletion features/admin/adding_frequently_asked_question.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ Feature: Adding frequently asked question
Scenario: Adding new frequently asked question with blank data
When I go to the create faq page
And I add it
Then I should be notified that "Code, Position, Question, Answer" cannot be blank
Then I should be notified that "Code, Position, Question, Answer" fields cannot be blank

@ui
Scenario: Adding new frequently asked question with too long short data
When I go to the create faq page
And I fill "Question, Answer" fields with 1 character
And I add it
Then I should be notified that "Question, Answer" fields are too short

@ui
Scenario: Adding new frequently asked question with existing position
Expand Down
8 changes: 4 additions & 4 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Feature: Adding new page
Scenario: Adding new page with blank data
When I go to the create page page
And I add it
And I should be notified that "Code, Name, Slug, Content" fields can not be blank
And I should be notified that "Code, Name, Slug, Content" fields cannot be blank

@ui
Scenario: Trying to add a page with too short data
When I go to the create page page
And I fill "Code, Name, Slug, Meta keywords, Meta description, Content" with 1 character
And I fill "Code, Name, Slug, Meta keywords, Meta description, Content" fields with 1 character
And I try to add it
Then I should be notified that the "Code, Name, Slug, Meta keywords, Meta description, Content" fields are too short
Then I should be notified that "Code, Name, Slug, Meta keywords, Meta description, Content" fields are too short

@ui
Scenario: Trying to add a page with too long data
When I go to the create page page
And I fill "Code, Name, Slug, Meta keywords, Meta description" with 6000 characters
And I fill "Code, Name, Slug, Meta keywords, Meta description" fields with 6000 characters
And I try to add it
Then I should be notified that "Code, Name, Slug, Meta keywords, Meta description" fields are too long

Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/services/form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ services:
class: BitBag\CmsPlugin\Form\Type\Translation\TextBlockTranslationType
arguments:
- "%bitbag.model.block_translation.class%"
- ['bitbag']
- ['bitbag', 'bitbag_content']
tags:
- { name: form.type }

bitbag.form.type.translation.html_block:
class: BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType
arguments:
- "%bitbag.model.block_translation.class%"
- ['bitbag']
- ['bitbag', 'bitbag_content']
tags:
- { name: form.type }

bitbag.form.type.translation.image_block:
class: BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType
arguments:
- "%bitbag.model.block_translation.class%"
- ['bitbag']
- ['bitbag', 'bitbag_image']
tags:
- { name: form.type }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BitBag\CmsPlugin\Entity\Image:
BitBag\CmsPlugin\Entity\BlockImage:
properties:
file:
- NotBlank:
message: 'bitbag.cms.block.image.not_blank'
groups: ['bitbag']
groups: ['bitbag_image']
7 changes: 5 additions & 2 deletions src/Resources/config/validation/BlockTranslation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ BitBag\CmsPlugin\Entity\BlockTranslation:
max: 250
minMessage: bitbag.block.name.min_length
maxMessage: bitbag.block.name.max_length
groups: [bitbag]
groups: ['bitbag']
content:
- NotBlank:
message: bitbag.block.content.not_blank
groups: ['bitbag_content']
- Length:
min: 2
minMessage: bitbag.block.content.min_length
groups: [bitbag]
groups: ['bitbag']
2 changes: 0 additions & 2 deletions src/Resources/config/validation/FrequentlyAskedQuestion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ BitBag\CmsPlugin\Entity\FrequentlyAskedQuestion:
groups: ['bitbag']
- Length:
min: 2
max: 250
minMessage: 'bitbag.frequently_asked_question.code.min_length'
maxMessage: 'bitbag.frequently_asked_question.code.max_length'
groups: ['bitbag']
position:
- NotBlank:
Expand Down
25 changes: 13 additions & 12 deletions src/Resources/translations/validators.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ bitbag:
not_blank: Upload an image.
code:
unique: There is an existing block with this code.
not_blank: Code can not be blank.
not_blank: Code cannot be blank.
min_length: Code must be at least {{ limit }} characters long.
max_length: Code can not be longer than {{ limit }} characters.
name:
min_length: Name must be at least {{ limit }} characters long.
max_length: Name can not be longer than {{ limit }} characters.
content:
not_blank: Content cannot be blank.
min_length: Content must be at least {{ limit }} characters long.
page:
code:
unique: There is an existing page with this code.
not_blank: Code can not be blank.
not_blank: Code cannot be blank.
min_length: Code must be at least {{ limit }} characters long.
max_length: Code can not be longer than {{ limit }} characters.
name:
not_blank: Name can not be blank.
not_blank: Name cannot be blank.
min_length: Name must be at least {{ limit }} characters long.
max_length: Name can not be longer than {{ limit }} characters.
slug:
not_blank: Slug can not be blank.
not_blank: Slug cannot be blank.
min_length: Slug must be at least {{ limit }} characters long.
max_length: Slug can not be longer than {{ limit }} characters.
meta_keywords:
Expand All @@ -34,29 +35,29 @@ bitbag:
min_length: Meta description must be at least {{ limit }} characters long.
max_length: Meta description can not be longer than {{ limit }} characters.
content:
not_blank: Content can not be blank.
not_blank: Content cannot be blank.
min_length: Content must be at least {{ limit }} characters long.
frequently_asked_question:
code:
not_blank: Code can not be blank.
not_blank: Code cannot be blank.
min_length: Code must be at least {{ limit }} characters long.
max_length: Code can not be longer than {{ limit }} characters.
position:
unique: There is an existing faq with this position.
not_blank: Position can not be blank.
not_blank: Position cannot be blank.
question:
not_blank: Question can not be blank.
not_blank: Question cannot be blank.
min_length: Question must be at least {{ limit }} characters long.
max_length: Question can not be longer than {{ limit }} characters.
answer:
not_blank: Answer can not be blank.
min_length: Answer must be at least {{ limit }} characters long.
not_blank: Answer cannot be blank.
section:
code:
unique: There is an existing section with this code.
not_blank: Code can not be blank.
not_blank: Code cannot be blank.
min_length: Code must be at least {{ limit }} characters long.
max_length: Code can not be longer than {{ limit }} characters.
name:
not_blank: Name can not be blank.
not_blank: Name cannot be blank.
min_length: Name must be at least {{ limit }} characters long.
max_length: Name can not be longer than {{ limit }} characters.
43 changes: 43 additions & 0 deletions tests/Behat/Context/Ui/Admin/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ public function iFillFields(string $fields): void
}
}

/**
* @When /^I fill "([^"]*)" fields with (\d+) (?:character|characters)$/
*/
public function iFillFieldsWithCharacters(string $fields, int $length): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
$this->resolveCurrentPage()->fillField(trim($field), $this->randomStringGenerator->generate($length));
}
}

/**
* @When I fill the code with :code
*/
Expand Down Expand Up @@ -222,6 +234,7 @@ public function iRemoveThisImageBlock(): void

/**
* @When I add it
* @When I try to add it
*/
public function iAddIt(): void
{
Expand Down Expand Up @@ -277,6 +290,36 @@ public function iShouldBeNotifiedThatThisBlockWasRemoved(): void
);
}

/**
* @Then I should be notified that :fields cannot be blank
*/
public function iShouldBeNotifiedThatCannotBeBlank(string $fields): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf(
"%s cannot be blank.",
trim($field)
)));
}
}

/**
* @Then I should be notified that :fields fields are too long
*/
public function iShouldBeNotifiedThatFieldsAreTooLong(string $fields): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf(
"%s can not be longer than",
trim($field)
), false));
}
}

/**
* @Then I should be able to select between :firstBlockType, :secondBlockType and :thirdBlockType block types under Create button
*/
Expand Down
21 changes: 18 additions & 3 deletions tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,35 @@ public function iShouldBeNotifiedThatANewFaqHasBeenCreated(): void
}

/**
* @Then I should be notified that :fields cannot be blank
* @Then I should be notified that :fields fields cannot be blank
*/
public function iShouldBeNotifiedThatCannotBeBlank(string $fields): void
public function iShouldBeNotifiedThatFieldsCannotBeBlank(string $fields): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf(
"%s can not be blank.",
"%s cannot be blank.",
trim($field)
)));
}
}

/**
* @Then I should be notified that :fields fields are too short
*/
public function iShouldBeNotifiedThatFieldsAreTooShort(string $fields): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf(
"%s must be at least %d characters long.",
trim($field), 2
)));
}
}

/**
* @Then I should be notified that there is already an existing faq with selected position
*/
Expand Down
14 changes: 7 additions & 7 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ public function iFillTheContentWith(string $content): void
}

/**
* @When /^I fill "([^"]*)" with (\d+) (?:character|characters)$/
* @When /^I fill "([^"]*)" fields with (\d+) (?:character|characters)$/
*/
public function iFillWithCharacter(string $fields, int $length): void
public function iFillFieldsWithCharacters(string $fields, int $length): void
{
$fields = explode(',', $fields);

Expand Down Expand Up @@ -284,24 +284,24 @@ public function iShouldBeNotifiedThatThisPageHasBeenRemoved(): void
}

/**
* @Then I should be notified that :fields fields can not be blank
* @Then I should be notified that :fields fields cannot be blank
*/
public function iShouldBeNotifiedThatFieldsCanNotBeBlank(string $fields): void
public function iShouldBeNotifiedThatFieldsCannotBeBlank(string $fields): void
{
$fields = explode(',', $fields);

foreach ($fields as $field) {
Assert::true($this->resolveCurrentPage()->containsErrorWithMessage(sprintf(
"%s can not be blank.",
"%s cannot be blank.",
trim($field)
)));
}
}

/**
* @Then I should be notified that the :fields fields are too short
* @Then I should be notified that :fields fields are too short
*/
public function iShouldBeNotifiedThatTheFieldsAreTooShort(string $fields): void
public function iShouldBeNotifiedThatFieldsAreTooShort(string $fields): void
{
$fields = explode(',', $fields);

Expand Down