diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 9adec06b5..4ea5a08a7 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -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 \ No newline at end of file + 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 diff --git a/features/admin/adding_frequently_asked_question.feature b/features/admin/adding_frequently_asked_question.feature index a08c80272..b53a935c4 100644 --- a/features/admin/adding_frequently_asked_question.feature +++ b/features/admin/adding_frequently_asked_question.feature @@ -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 diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 60691f877..24ed99c65 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -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 diff --git a/src/Resources/config/services/form.yml b/src/Resources/config/services/form.yml index bc35522c5..21e0a333e 100644 --- a/src/Resources/config/services/form.yml +++ b/src/Resources/config/services/form.yml @@ -11,7 +11,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\TextBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag'] + - ['bitbag', 'bitbag_content'] tags: - { name: form.type } @@ -19,7 +19,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag'] + - ['bitbag', 'bitbag_content'] tags: - { name: form.type } @@ -27,7 +27,7 @@ services: class: BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType arguments: - "%bitbag.model.block_translation.class%" - - ['bitbag'] + - ['bitbag', 'bitbag_image'] tags: - { name: form.type } diff --git a/src/Resources/config/validation/Image.yml b/src/Resources/config/validation/BlockImage.yml similarity index 60% rename from src/Resources/config/validation/Image.yml rename to src/Resources/config/validation/BlockImage.yml index f68e2e373..0b04a068a 100644 --- a/src/Resources/config/validation/Image.yml +++ b/src/Resources/config/validation/BlockImage.yml @@ -1,6 +1,6 @@ -BitBag\CmsPlugin\Entity\Image: +BitBag\CmsPlugin\Entity\BlockImage: properties: file: - NotBlank: message: 'bitbag.cms.block.image.not_blank' - groups: ['bitbag'] \ No newline at end of file + groups: ['bitbag_image'] \ No newline at end of file diff --git a/src/Resources/config/validation/BlockTranslation.yml b/src/Resources/config/validation/BlockTranslation.yml index 1b96805d3..8cd89e89a 100644 --- a/src/Resources/config/validation/BlockTranslation.yml +++ b/src/Resources/config/validation/BlockTranslation.yml @@ -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] \ No newline at end of file + groups: ['bitbag'] \ No newline at end of file diff --git a/src/Resources/config/validation/FrequentlyAskedQuestion.yml b/src/Resources/config/validation/FrequentlyAskedQuestion.yml index c3fc89165..23b91c643 100755 --- a/src/Resources/config/validation/FrequentlyAskedQuestion.yml +++ b/src/Resources/config/validation/FrequentlyAskedQuestion.yml @@ -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: diff --git a/src/Resources/translations/validators.en.yml b/src/Resources/translations/validators.en.yml index 50bdbdce7..e7915da7d 100755 --- a/src/Resources/translations/validators.en.yml +++ b/src/Resources/translations/validators.en.yml @@ -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: @@ -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. \ No newline at end of file diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 004d039f8..e4f3793d7 100644 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -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 */ @@ -222,6 +234,7 @@ public function iRemoveThisImageBlock(): void /** * @When I add it + * @When I try to add it */ public function iAddIt(): void { @@ -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 */ diff --git a/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php b/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php index 78d44f303..fdff1bbf6 100644 --- a/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php +++ b/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php @@ -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 */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 92a8fc0c3..23651d518 100644 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -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); @@ -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);