From b14c19281fe01dbb32b6f78b6df07daff072ba84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kr=C3=B3l?= Date: Sat, 11 Nov 2017 16:19:16 +0100 Subject: [PATCH] [Behat] Cleanup contexts --- features/adding_block_with_sections.feature | 19 --- features/adding_new_html_block.feature | 18 --- features/adding_new_image_block.feature | 21 ---- features/adding_new_text_block.feature | 20 --- features/admin/adding_block.feature | 45 +++++++ .../adding_frequently_asked_question.feature | 11 +- features/{ => admin}/adding_page.feature | 39 +++--- features/{ => admin}/adding_section.feature | 0 features/admin/managing_blocks.feature | 61 ++++++++++ .../managing_pages.feature} | 30 +++-- features/disabling_block.feature | 17 --- features/managing_blocks.feature | 30 ----- features/managing_pages.feature | 17 --- features/updating_html_block.feature | 18 --- features/updating_image_block.feature | 18 --- features/updating_text_block.feature | 18 --- src/Resources/views/Block/create.html.twig | 3 +- src/Resources/views/Block/index.html.twig | 2 +- src/Resources/views/Block/update.html.twig | 3 +- .../Behaviour/ContainsErrorInterface.php | 22 ++++ ...ntainsError.php => ContainsErrorTrait.php} | 2 +- tests/Behat/Context/Setup/BlockContext.php | 8 ++ tests/Behat/Context/Setup/SectionContext.php | 32 ++--- ...gingBlocksContext.php => BlockContext.php} | 115 +++++------------- .../Admin/FrequentlyAskedQuestionContext.php | 11 +- ...nagingPagesContext.php => PageContext.php} | 114 ++++++----------- .../Behat/Context/Ui/Admin/SectionContext.php | 2 +- tests/Behat/Page/Admin/Block/CreatePage.php | 13 +- .../Page/Admin/Block/CreatePageInterface.php | 9 +- tests/Behat/Page/Admin/Block/UpdatePage.php | 8 ++ .../Page/Admin/Block/UpdatePageInterface.php | 6 + .../FrequentlyAskedQuestion/CreatePage.php | 4 +- .../CreatePageInterface.php | 3 +- tests/Behat/Page/Admin/Page/CreatePage.php | 38 +++++- .../Page/Admin/Page/CreatePageInterface.php | 15 ++- tests/Behat/Page/Admin/Page/UpdatePage.php | 6 +- .../Page/Admin/Page/UpdatePageInterface.php | 2 +- tests/Behat/Page/Admin/Section/CreatePage.php | 6 +- .../Admin/Section/CreatePageInterface.php | 5 +- tests/Behat/Page/Admin/Section/UpdatePage.php | 20 ++- .../Admin/Section/UpdatePageInterface.php | 12 +- .../Resources/services/contexts/setup.yml | 1 - .../Behat/Resources/services/contexts/ui.yml | 6 +- .../Resources/suites/ui/managing_pages.yml | 1 + 44 files changed, 369 insertions(+), 482 deletions(-) delete mode 100644 features/adding_block_with_sections.feature delete mode 100644 features/adding_new_html_block.feature delete mode 100644 features/adding_new_image_block.feature delete mode 100644 features/adding_new_text_block.feature create mode 100644 features/admin/adding_block.feature rename features/{ => admin}/adding_frequently_asked_question.feature (77%) rename features/{ => admin}/adding_page.feature (54%) rename features/{ => admin}/adding_section.feature (100%) create mode 100644 features/admin/managing_blocks.feature rename features/{updating_page.feature => admin/managing_pages.feature} (61%) delete mode 100644 features/disabling_block.feature delete mode 100644 features/managing_blocks.feature delete mode 100644 features/managing_pages.feature delete mode 100644 features/updating_html_block.feature delete mode 100644 features/updating_image_block.feature delete mode 100644 features/updating_text_block.feature create mode 100644 tests/Behat/Behaviour/ContainsErrorInterface.php rename tests/Behat/Behaviour/{ContainsError.php => ContainsErrorTrait.php} (98%) rename tests/Behat/Context/Ui/Admin/{ManagingBlocksContext.php => BlockContext.php} (69%) rename tests/Behat/Context/Ui/Admin/{ManagingPagesContext.php => PageContext.php} (78%) diff --git a/features/adding_block_with_sections.feature b/features/adding_block_with_sections.feature deleted file mode 100644 index 1aa0fb1b9..000000000 --- a/features/adding_block_with_sections.feature +++ /dev/null @@ -1,19 +0,0 @@ -@managing_blocks -Feature: Adding block with sections - In order to display blocks under some sections - As an Administrator - I want to be able to add new blocks with existing sections - - Background: - Given the store operates on a single channel in "United States" - And I am logged in as an administrator - - @ui @javascript - Scenario: Seeing menu items - Given there is are existing sections named "Blog" and "Homepage" - When I go to the create "html" block page - And I fill the code with "store_description" - And I fill the content with "

We have the best candies in the internet!

" - And I add "Blog" and "Homepage" sections to it - And I add it - Then I should be notified that new text block was created \ No newline at end of file diff --git a/features/adding_new_html_block.feature b/features/adding_new_html_block.feature deleted file mode 100644 index 30ae9fe56..000000000 --- a/features/adding_new_html_block.feature +++ /dev/null @@ -1,18 +0,0 @@ -@managing_blocks -Feature: Adding image block - In order to manage dynamic text content - As an Administrator - I want to be able to add new text blocks - - Background: - Given I am logged in as an administrator - And the store operates on a single channel in "United States" - - @ui - Scenario: Seeing menu items - When I go to the create "html" block page - And I fill the code with "store_description" - And I fill the content with "

We have the best candies in the internet!

" - And I add it - Then I should be notified that new text block was created - And block with "html" type and "

We have the best candies in the internet!

" content should exist in the store \ No newline at end of file diff --git a/features/adding_new_image_block.feature b/features/adding_new_image_block.feature deleted file mode 100644 index 690894270..000000000 --- a/features/adding_new_image_block.feature +++ /dev/null @@ -1,21 +0,0 @@ -@managing_blocks -Feature: Adding image block - In order to manage dynamic images - As an Administrator - I want to be able to add new image blocks - - Background: - Given the store operates on a single channel in "United States" - And I am logged in as an administrator - - @ui - Scenario: Seeing menu items - When I go to the create "image" block page - And I fill the code with "aston_martin_db_11" - And I fill the name with "Aston Marting DB 11 image" - And I fill the link with "/page/aston-martin-db-11-review" - And I upload the "aston_martin_db_11.jpg" image - And I add it - Then I should be notified that new image block was created - And image block with "aston_martin_db_11" code and "aston_martin_db_11.jpg" image should exist in the store - And this block should also have "Aston Marting DB 11 image" name and "/page/aston-martin-db-11-review" link \ No newline at end of file diff --git a/features/adding_new_text_block.feature b/features/adding_new_text_block.feature deleted file mode 100644 index 544e776ff..000000000 --- a/features/adding_new_text_block.feature +++ /dev/null @@ -1,20 +0,0 @@ -@managing_blocks -Feature: Adding image block - In order to manage dynamic text content - As an Administrator - I want to be able to add new text blocks - - Background: - Given I am logged in as an administrator - And the store operates on a single channel in "United States" - - @ui - Scenario: Seeing menu items - When I go to the create "text" block page - And I fill the code with "store_main_title" - And I fill the name with "Store title" - And I fill the content with "Welcome to the Candy Shop" - And I add it - Then I should be notified that new text block was created - And block with "text" type and "Welcome to the Candy Shop" content should exist in the store - And this block should also have "Store title" name \ No newline at end of file diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature new file mode 100644 index 000000000..9adec06b5 --- /dev/null +++ b/features/admin/adding_block.feature @@ -0,0 +1,45 @@ +@managing_blocks +Feature: Adding blocks + In order to present and manage dynamic content on my store pages + As an Administrator + I want to be able to add new blocks + + Background: + Given I am logged in as an administrator + And the store operates on a single channel in "United States" + + @ui + Scenario: Adding html block + When I go to the create "html" block page + And I fill the code with "store_description" + And I fill the content with "

We have the best candies on the internet!

" + And I add it + Then I should be notified that the block has been created + + @ui + Scenario: Adding text block + When I go to the create "text" block page + And I fill the code with "store_main_title" + And I fill the name with "Store title" + And I fill the content with "Welcome to the Candy Shop" + And I add it + Then I should be notified that the block has been created + + @ui + Scenario: Adding image block + When I go to the create "image" block page + And I fill the code with "aston_martin_db_11" + And I fill the name with "Aston Marting DB 11 image" + And I fill the link with "/page/aston-martin-db-11-review" + And I upload the "aston_martin_db_11.jpg" image + And I add it + Then I should be notified that the block has been created + + @ui @javascript + Scenario: Adding block with sections + Given there are existing sections named "Blog" and "Homepage" + When I go to the create "html" block page + 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 diff --git a/features/adding_frequently_asked_question.feature b/features/admin/adding_frequently_asked_question.feature similarity index 77% rename from features/adding_frequently_asked_question.feature rename to features/admin/adding_frequently_asked_question.feature index 2c0dcd196..a08c80272 100644 --- a/features/adding_frequently_asked_question.feature +++ b/features/admin/adding_frequently_asked_question.feature @@ -9,7 +9,7 @@ Feature: Adding frequently asked question And the store operates on a single channel in "United States" @ui - Scenario: Adding new frequently asked question with valid data + Scenario: Adding frequently asked When I go to the create faq page And I fill code with "each_order_payment" And I set the position to 1 @@ -19,18 +19,15 @@ Feature: Adding frequently asked question Then I should be notified that a new faq has been created @ui - Scenario: Adding new frequently asked question with invalid data + 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" can not be blank + Then I should be notified that "Code, Position, Question, Answer" cannot be blank @ui Scenario: Adding new frequently asked question with existing position Given there is an existing faq with 1 position When I go to the create faq page - And I fill code with "delivery_zones" And I set the position to 1 - And I fill the question with "Do you send packages to Russia?" - And I set the answer to "Yes" - And I add it + And I try to add it Then I should be notified that there is already an existing faq with selected position \ No newline at end of file diff --git a/features/adding_page.feature b/features/admin/adding_page.feature similarity index 54% rename from features/adding_page.feature rename to features/admin/adding_page.feature index ee2086bf5..60691f877 100644 --- a/features/adding_page.feature +++ b/features/admin/adding_page.feature @@ -9,46 +9,43 @@ Feature: Adding new page And I am logged in as an administrator @ui @javascript - Scenario: Adding new page for en_US translation - When I go to the create new page page + Scenario: Adding page + When I go to the create page page And I fill the code with "top_5_outfits_for_this_summer" And I fill the name with "Top 5 outfits for this summer" - And I fill the meta keywords with "TOP 5 summer outfit trends, outfits, ralph lauren" - And I fill the meta description with "This summer is going to be hot. Here's what you must wear to look great on vacation." + And I fill the meta keywords with "TOP 5 summer outfit trends, outfits, Ralph Lauren" + And I fill the meta description with "This summer is going to be hot like a pizza." And I fill the content with "The best looks, trends, inspiration, and shopping picks for summer style." And I add it - Then I should be notified that new page was created - And this page should have "top_5_outfits_for_this_summer" code - And it should have "Top 5 outfits for this summer" name - And it should have "top-5-outfits-for-this-summer" slug - And it should have "TOP 5 summer outfit trends, outfits, ralph lauren" meta keywords - And it should have "The best looks, trends, inspiration, and shopping picks for summer style." content + Then I should be notified that the page has been created @ui - Scenario: Adding new page with empty data - When I go to the create new page 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 @ui Scenario: Trying to add a page with too short data - When I go to the create new page page + When I go to the create page page And I fill "Code, Name, Slug, Meta keywords, Meta description, Content" 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 @ui - Scenario: Trying to add a new page with too long data - When I go to the create new page page + 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 try to add it Then I should be notified that "Code, Name, Slug, Meta keywords, Meta description" fields are too long - @todo - Scenario: Adding new page with sections - Given there is are existing sections named "Blog" and "Homepage" - When I go to the create new page page - And I fill "Code, Name, Slug, Meta keywords, Meta description" with 5 characters + @ui @javascript + Scenario: Adding page with sections + Given there are existing sections named "Blog" and "Homepage" + When I go to the create page page + And I fill the code with "best_day_ever" + And I fill the name with "Best day ever" And I add "Blog" and "Homepage" sections to it + And I fill the content with "This was the best day of my life" And I add it - Then I should be notified that new page has been created \ No newline at end of file + Then I should be notified that the page has been created \ No newline at end of file diff --git a/features/adding_section.feature b/features/admin/adding_section.feature similarity index 100% rename from features/adding_section.feature rename to features/admin/adding_section.feature diff --git a/features/admin/managing_blocks.feature b/features/admin/managing_blocks.feature new file mode 100644 index 000000000..5174325cc --- /dev/null +++ b/features/admin/managing_blocks.feature @@ -0,0 +1,61 @@ +@managing_blocks +Feature: Managing cms blocks + In order to present dynamic content in my store + As an Administrator + I want to be able to manage existing blocks + + Background: + Given the store operates on a single channel in "United States" + Given I am logged in as an administrator + + @ui + Scenario: Seeing menu items + Given there is a cms text block with "store_phone_number" code and "123456789" content + When I go to the update "store_phone_number" block page + And I fill the content with "987654321" + And I update it + Then I should be notified that the block has been successfully updated + + @ui + Scenario: Updating html block + Given there is a cms html block with "store_email" code and "mikolaj.krol@bitbag.pl" content + When I go to the update "store_email" block page + And I fill the content with "mikolaj.krol@bitbag.pl" + And I update it + Then I should be notified that the block has been successfully updated + + @ui + Scenario: Updating image block + Given there is a cms block with "porsche_911_singer" code and "porsche_911_singer_1.jpg" image + When I go to the update "porsche_911_singer" block page + And I upload the "porsche_911_singer_2.jpg" image + And I update it + Then I should be notified that the block has been successfully updated + + @ui + Scenario: Disabling block + Given there is a cms block with "bitbag_quote" code + When I go to the update "bitbag_quote" block page + And I disable it + And I update it + Then I should be notified that the block has been successfully updated + + @ui + Scenario: Seeing dynamic blocks in the admin panel + Given there are 2 dynamic content blocks with "image" type + And there are 3 dynamic content blocks with "text" type + When I go to the cms blocks page + Then I should see 2 dynamic content blocks with "image" type + And I should see 3 dynamic content blocks with "text" type + + @ui + Scenario: Removing single block + Given there is a dynamic content block with "image" type + When I go to the cms blocks page + And I remove this image block + Then I should be notified that this block was removed + + @ui + Scenario: Being able to chose which block type to create + When I go to the cms blocks page + Then I should be able to select between "Text block", "HTML block" and "Image block" block types under Create button \ No newline at end of file diff --git a/features/updating_page.feature b/features/admin/managing_pages.feature similarity index 61% rename from features/updating_page.feature rename to features/admin/managing_pages.feature index b6ff9f2e2..fc38c3e14 100644 --- a/features/updating_page.feature +++ b/features/admin/managing_pages.feature @@ -1,19 +1,27 @@ @managing_pages -Feature: Updating cms page - In order to manage dynamic images +Feature: Managing cms pages + In order to present custom pages in my online store As an Administrator - I want to be able to edit existing image pages + I want to be able to display and remove existing pages Background: Given the store operates on a single channel in "United States" - And I am logged in as an administrator - And there is a cms page with "How to tie a tie" name + Given I am logged in as an administrator + + @ui + Scenario: Removing single page + Given there are 3 pages + When I go to the cms pages page + And I remove last page + Then I should be notified that this page has been removed + And only 2 pages should exist in the store + + @ui + Scenario: Updating page + Given there is a cms page with "How to tie a tie" name And it has "tie a tie, 100 ways to tie a tie" meta keywords And it has "After reading this tut you will never get stuck while trying to tie a tie." meta description And it has "Learn how to tie a tie with the Windsor, Half Windsor, Four in Hand and Pratt necktie knots by following step-by-step video." content - - @ui - Scenario: Seeing menu items When I go to the update "how_to_tie_a_tie" page page And I fill the name with "Top 5 outfits for this summer" And I fill the slug with "top-5-outfits-for-this-summer" @@ -21,8 +29,4 @@ Feature: Updating cms page And I fill the meta description with "This summer is going to be hot. Here's what you must wear to look great on vacation." And I fill the content with "The best looks, trends, inspiration, and shopping picks for summer style." And I update it - Then I should be notified that the page was updated - And it should have "Top 5 outfits for this summer" name - And it should have "top-5-outfits-for-this-summer" slug - And it should have "TOP 5 summer outfit trends, outfits, ralph lauren" meta keywords - And it should have "The best looks, trends, inspiration, and shopping picks for summer style." content \ No newline at end of file + Then I should be notified that the page was updated \ No newline at end of file diff --git a/features/disabling_block.feature b/features/disabling_block.feature deleted file mode 100644 index d3a0c57b7..000000000 --- a/features/disabling_block.feature +++ /dev/null @@ -1,17 +0,0 @@ -@managing_blocks -Feature: Adding image block - In order to manage dynamic text content - As an Administrator - I want to be able to disable existing blocks - - Background: - Given I am logged in as an administrator - And the store operates on a single channel in "United States" - And there is a cms text block with "bitbag_quote" code and "We develop eCommerce. With pleasure" content - - @ui - Scenario: Seeing menu items - When I go to the update "bitbag_quote" block page - And I disable it - And I update it - Then block with "bitbag_quote" should not appear in the store \ No newline at end of file diff --git a/features/managing_blocks.feature b/features/managing_blocks.feature deleted file mode 100644 index d5480ba78..000000000 --- a/features/managing_blocks.feature +++ /dev/null @@ -1,30 +0,0 @@ -@managing_blocks -Feature: Managing cms blocks - In order to present some dynamic data in the store - As an Administrator - I want to be able to display and remove existing blocks. - - Background: - Given the store operates on a single channel in "United States" - Given I am logged in as an administrator - - @ui - Scenario: Seeing dynamic blocks in admin panel - Given there are 2 dynamic content blocks with "image" type - And there are 3 dynamic content blocks with "text" type - When I go to the cms blocks page - Then I should see 2 dynamic content blocks with "image" type - And I should see 3 dynamic content blocks with "text" type - - @ui - Scenario: Removing single block - Given there is a dynamic content block with "image" type - When I go to the cms blocks page - And I remove this image block - Then I should be notified that this block was removed - And no dynamic content blocks should appear in the store - - @ui - Scenario: Being able to chose which block to create - When I go to the cms blocks page - Then I should be able to select between "Text block", "HTML block" and "Image block" block types under Create button \ No newline at end of file diff --git a/features/managing_pages.feature b/features/managing_pages.feature deleted file mode 100644 index 289005192..000000000 --- a/features/managing_pages.feature +++ /dev/null @@ -1,17 +0,0 @@ -@managing_pages -Feature: Managing cms pages - In order to present custom pages in my online store - As an Administrator - I want to be able to display and remove existing pages. - - Background: - Given the store operates on a single channel in "United States" - Given I am logged in as an administrator - - @ui - Scenario: Removing single page - Given there are 3 pages - When I go to the cms pages page - And I remove last page - Then I should be notified that this page was removed - And 2 pages should exist in the store \ No newline at end of file diff --git a/features/updating_html_block.feature b/features/updating_html_block.feature deleted file mode 100644 index 68f6bc37c..000000000 --- a/features/updating_html_block.feature +++ /dev/null @@ -1,18 +0,0 @@ -@managing_blocks -Feature: Updating image block - In order to manage dynamic images - As an Administrator - I want to be able to edit existing image blocks - - Background: - Given the store operates on a single channel in "United States" - And I am logged in as an administrator - And there is a cms html block with "store_email" code and "mikolaj.krol@bitbag.pl" content - - @ui - Scenario: Seeing menu items - When I go to the update "store_email" block page - And I fill the content with "mikolaj.krol@bitbag.pl" - And I update it - Then I should be notified that the block was successfully updated - And block with "store_email" code and "mikolaj.krol@bitbag.pl" content should exist in the store \ No newline at end of file diff --git a/features/updating_image_block.feature b/features/updating_image_block.feature deleted file mode 100644 index b144950ea..000000000 --- a/features/updating_image_block.feature +++ /dev/null @@ -1,18 +0,0 @@ -@managing_blocks -Feature: Updating image block - In order to manage dynamic images - As an Administrator - I want to be able to edit existing image blocks - - Background: - Given the store operates on a single channel in "United States" - And I am logged in as an administrator - And there is a cms block with "porsche_911_singer" code and "porsche_911_singer_1.jpg" image - - @ui - Scenario: Seeing menu items - When I go to the update "porsche_911_singer" block page - And I upload the "porsche_911_singer_2.jpg" image - And I update it - Then I should be notified that the block was successfully updated - And image block with "porsche_911_singer" code and "porsche_911_singer_2.jpg" image should exist in the store diff --git a/features/updating_text_block.feature b/features/updating_text_block.feature deleted file mode 100644 index ef23b078a..000000000 --- a/features/updating_text_block.feature +++ /dev/null @@ -1,18 +0,0 @@ -@managing_blocks -Feature: Updating image block - In order to manage dynamic images - As an Administrator - I want to be able to edit existing image blocks - - Background: - Given the store operates on a single channel in "United States" - And I am logged in as an administrator - And there is a cms text block with "store_phone_number" code and "123456789" content - - @ui - Scenario: Seeing menu items - When I go to the update "store_phone_number" block page - And I fill the content with "987654321" - And I update it - Then I should be notified that the block was successfully updated - And block with "store_phone_number" code and "987654321" content should exist in the store \ No newline at end of file diff --git a/src/Resources/views/Block/create.html.twig b/src/Resources/views/Block/create.html.twig index 02ec42dc0..eb2d11231 100644 --- a/src/Resources/views/Block/create.html.twig +++ b/src/Resources/views/Block/create.html.twig @@ -5,7 +5,7 @@ {% set header = configuration.vars.header|default(metadata.applicationName~'.ui.new_'~metadata.name) %} {% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.create' %} -{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} +{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} {% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} @@ -33,5 +33,4 @@ {{ sonata_block_render_event(event_prefix ~ '.javascripts') }} - {% endblock %} \ No newline at end of file diff --git a/src/Resources/views/Block/index.html.twig b/src/Resources/views/Block/index.html.twig index 67fffe49b..60f6dcab6 100644 --- a/src/Resources/views/Block/index.html.twig +++ b/src/Resources/views/Block/index.html.twig @@ -8,7 +8,7 @@ {% set header = configuration.vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %} -{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} +{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} {% block content %} {{ sonata_block_render_event(event_prefix ~ '.before_header', {'resources': resources}) }} diff --git a/src/Resources/views/Block/update.html.twig b/src/Resources/views/Block/update.html.twig index c442f5e90..2b5fd0a1e 100644 --- a/src/Resources/views/Block/update.html.twig +++ b/src/Resources/views/Block/update.html.twig @@ -6,7 +6,7 @@ {% set header = configuration.vars.header|default(metadata.applicationName~'.ui.edit_'~metadata.name) %} {% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.update' %} -{% block title %}{{ parent() }} {{ header|trans }}{% endblock %} +{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} {% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} @@ -34,5 +34,4 @@ {{ sonata_block_render_event(event_prefix ~ '.javascripts') }} - {% endblock %} diff --git a/tests/Behat/Behaviour/ContainsErrorInterface.php b/tests/Behat/Behaviour/ContainsErrorInterface.php new file mode 100644 index 000000000..a736f99af --- /dev/null +++ b/tests/Behat/Behaviour/ContainsErrorInterface.php @@ -0,0 +1,22 @@ + + */ +interface ContainsErrorInterface +{ + public function containsErrorWithMessage(string $message, bool $strict = true): bool; +} \ No newline at end of file diff --git a/tests/Behat/Behaviour/ContainsError.php b/tests/Behat/Behaviour/ContainsErrorTrait.php similarity index 98% rename from tests/Behat/Behaviour/ContainsError.php rename to tests/Behat/Behaviour/ContainsErrorTrait.php index 215591c7e..442e233e1 100644 --- a/tests/Behat/Behaviour/ContainsError.php +++ b/tests/Behat/Behaviour/ContainsErrorTrait.php @@ -18,7 +18,7 @@ /** * @author Mikołaj Król */ -trait ContainsError +trait ContainsErrorTrait { use DocumentAccessor; diff --git a/tests/Behat/Context/Setup/BlockContext.php b/tests/Behat/Context/Setup/BlockContext.php index fb310cedd..b8c9a3b5f 100644 --- a/tests/Behat/Context/Setup/BlockContext.php +++ b/tests/Behat/Context/Setup/BlockContext.php @@ -119,6 +119,14 @@ public function thereIsADynamicContentBlockWithType(string $type): void $this->createBlock($type); } + /** + * @Given there is a cms block with :code code + */ + public function thereIsATextCmsBlockWithCode(string $code): void + { + $this->createBlock(BlockInterface::TEXT_BLOCK_TYPE, null, $code); + } + /** * @Given there is a cms text block with :code code and :content content */ diff --git a/tests/Behat/Context/Setup/SectionContext.php b/tests/Behat/Context/Setup/SectionContext.php index e80a77a10..ff6266034 100644 --- a/tests/Behat/Context/Setup/SectionContext.php +++ b/tests/Behat/Context/Setup/SectionContext.php @@ -15,7 +15,6 @@ use Behat\Behat\Context\Context; use BitBag\CmsPlugin\Entity\SectionInterface; use BitBag\CmsPlugin\Repository\SectionRepositoryInterface; -use Doctrine\ORM\EntityManagerInterface; use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Tests\BitBag\CmsPlugin\Behat\Service\RandomStringGeneratorInterface; @@ -46,48 +45,35 @@ final class SectionContext implements Context private $sectionRepository; /** - * @var EntityManagerInterface - */ - private $entityManager; - - /** - * SectionContext constructor. * @param RandomStringGeneratorInterface $randomStringGenerator * @param SharedStorageInterface $sharedStorage * @param FactoryInterface $sectionFactory * @param SectionRepositoryInterface $sectionRepository - * @param EntityManagerInterface $entityManager */ public function __construct( RandomStringGeneratorInterface $randomStringGenerator, SharedStorageInterface $sharedStorage, FactoryInterface $sectionFactory, - SectionRepositoryInterface $sectionRepository, - EntityManagerInterface $entityManager + SectionRepositoryInterface $sectionRepository ) { $this->randomStringGenerator = $randomStringGenerator; $this->sharedStorage = $sharedStorage; $this->sectionFactory = $sectionFactory; $this->sectionRepository = $sectionRepository; - $this->entityManager = $entityManager; } /** - * @Given there is are existing sections named :firstNameSection and :secondNameSection + * @Given there are existing sections named :firstNameSection and :secondNameSection */ - public function thereIsAnExistingFaqWithPosition(string $firstNameSection, string $secondNameSection): void + public function thereAreExistingSections(...$sectionNames): void { - /** @var SectionInterface $firstSection */ - $firstSection = $this->createSection(); - /** @var SectionInterface $secondSection */ - $secondSection = $this->createSection(); + foreach ($sectionNames as $sectionName) { + $section = $this->createSection(); + $section->setName($sectionName); - $firstSection->setName($firstNameSection); - - $secondSection->setName($secondNameSection); - - $this->entityManager->flush(); + $this->sectionRepository->add($section); + } } /** @@ -103,8 +89,6 @@ private function createSection(): SectionInterface $section->setCode($this->randomStringGenerator->generate()); $section->setName($this->randomStringGenerator->generate()); - $this->sectionRepository->add($section); - return $section; } } diff --git a/tests/Behat/Context/Ui/Admin/ManagingBlocksContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php similarity index 69% rename from tests/Behat/Context/Ui/Admin/ManagingBlocksContext.php rename to tests/Behat/Context/Ui/Admin/BlockContext.php index f6b5b9461..004d039f8 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingBlocksContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -16,7 +16,6 @@ use BitBag\CmsPlugin\Entity\BlockInterface; use BitBag\CmsPlugin\Exception\TemplateTypeNotFound; use BitBag\CmsPlugin\Repository\BlockRepositoryInterface; -use Doctrine\ORM\EntityManagerInterface; use Sylius\Behat\NotificationType; use Sylius\Behat\Page\SymfonyPageInterface; use Sylius\Behat\Service\NotificationCheckerInterface; @@ -25,12 +24,13 @@ use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Block\CreatePageInterface; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Block\IndexPageInterface; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Block\UpdatePageInterface; +use Tests\BitBag\CmsPlugin\Behat\Service\RandomStringGeneratorInterface; use Webmozart\Assert\Assert; /** * @author Mikołaj Król */ -final class ManagingBlocksContext implements Context +final class BlockContext implements Context { /** * @var IndexPageInterface @@ -63,14 +63,14 @@ final class ManagingBlocksContext implements Context private $sharedStorage; /** - * @var BlockRepositoryInterface + * @var RandomStringGeneratorInterface */ - private $blockRepository; + private $randomStringGenerator; /** - * @var EntityManagerInterface + * @var BlockRepositoryInterface */ - private $entityManager; + private $blockRepository; /** * @param IndexPageInterface $indexPage @@ -79,8 +79,8 @@ final class ManagingBlocksContext implements Context * @param CurrentPageResolverInterface $currentPageResolver * @param NotificationCheckerInterface $notificationChecker * @param SharedStorageInterface $sharedStorage + * @param RandomStringGeneratorInterface $randomStringGenerator * @param BlockRepositoryInterface $blockRepository - * @param EntityManagerInterface $entityManager */ public function __construct( IndexPageInterface $indexPage, @@ -89,8 +89,8 @@ public function __construct( CurrentPageResolverInterface $currentPageResolver, NotificationCheckerInterface $notificationChecker, SharedStorageInterface $sharedStorage, - BlockRepositoryInterface $blockRepository, - EntityManagerInterface $entityManager + RandomStringGeneratorInterface $randomStringGenerator, + BlockRepositoryInterface $blockRepository ) { $this->createPage = $createPage; @@ -99,8 +99,8 @@ public function __construct( $this->currentPageResolver = $currentPageResolver; $this->notificationChecker = $notificationChecker; $this->sharedStorage = $sharedStorage; + $this->randomStringGenerator = $randomStringGenerator; $this->blockRepository = $blockRepository; - $this->entityManager = $entityManager; } /** @@ -148,6 +148,18 @@ public function iGoToTheUpdateBlockPage(string $code) $this->updatePage->open(['id' => $id]); } + /** + * @When I fill :fields fields + */ + public function iFillFields(string $fields): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + $this->resolveCurrentPage()->fillField(trim($field), $this->randomStringGenerator->generate(5)); + } + } + /** * @When I fill the code with :code */ @@ -224,14 +236,6 @@ public function iUpdateIt(): void $this->updatePage->saveChanges(); } - /** - * @Then no dynamic content blocks should appear in the store - */ - public function noDynamicContentBlocksShouldAppearInTheStore(): void - { - Assert::eq(0, count($this->blockRepository->findAll())); - } - /** * @Then I should see :number dynamic content blocks with :type type */ @@ -241,10 +245,9 @@ public function iShouldSeeDynamicContentBlocksWithType(int $number, string $type } /** - * @Then I should be notified that new image block was created - * @Then I should be notified that new text block was created + * @Then I should be notified that the block has been created */ - public function iShouldBeNotifiedThatNewImageBlockWasCreated(): void + public function iShouldBeNotifiedThatNewImageBlockHasBeenCreated(): void { $this->notificationChecker->checkNotification( "Block has been successfully created.", @@ -253,9 +256,9 @@ public function iShouldBeNotifiedThatNewImageBlockWasCreated(): void } /** - * @Then I should be notified that the block was successfully updated + * @Then I should be notified that the block has been successfully updated */ - public function iShouldBeNotifiedThatTheBlockWasSuccessfullyUpdated(): void + public function iShouldBeNotifiedThatTheBlockHasBeenSuccessfullyUpdated(): void { $this->notificationChecker->checkNotification( "Block has been successfully updated.", @@ -274,58 +277,6 @@ public function iShouldBeNotifiedThatThisBlockWasRemoved(): void ); } - /** - * @Then block with :code code and :content content should exist in the store - */ - public function blockWithCodeAndContentShouldBeInTheStore(string $code, string $content): void - { - $block = $this->blockRepository->findEnabledByCodeAndContent($code, $content); - - Assert::isInstanceOf($block, BlockInterface::class); - } - - /** - * @Then block with :type type and :content content should exist in the store - */ - public function blockWithTypeAndContentShouldBeInTheStore(string $type, string $content): void - { - $block = $this->blockRepository->findOneByTypeAndContent($type, $content); - - $this->sharedStorage->set('block', $block); - - Assert::isInstanceOf($block, BlockInterface::class); - } - - /** - * @Then this block should also have :name name and :link link - * @Then this block should also have :name name - */ - public function thisBlockShouldAlsoHaveNameAndLink(string $name, string $link = null): void - { - /** @var BlockInterface $block */ - $block = $this->sharedStorage->get('block'); - - Assert::eq($name, $block->getName()); - Assert::eq($link, $block->getLink()); - } - - /** - * @Then image block with :code code and :image image should exist in the store - */ - public function imageBlockWithTypeAndImageShouldBeInTheStore(string $code, string $image): void - { - $block = $this->blockRepository->findOneBy(['code' => $code]); - $blockImage = $block->getImage(); - $this->entityManager->refresh($blockImage); - $this->sharedStorage->set('block', $block); - - Assert::eq(BlockInterface::IMAGE_BLOCK_TYPE, $block->getType()); - Assert::eq( - file_get_contents(__DIR__ . '/../../../../Application/web/media/image/' . $block->getImage()->getPath()), - file_get_contents(__DIR__ . '/../../../Resources/images/' . $image) - ); - } - /** * @Then I should be able to select between :firstBlockType, :secondBlockType and :thirdBlockType block types under Create button */ @@ -341,19 +292,11 @@ public function iShouldBeAbleToSelectBetweenAndBlockTypesUnderCreateButton(strin } /** - * @Then block with :code should not appear in the store - */ - public function blockWithShouldNotAppearInTheStore(string $code): void - { - Assert::null($this->blockRepository->findEnabledByCode($code)); - } - - /** - * @When I add :arg1 and :arg2 sections to it + * @When I add :firstSection and :secondSection sections to it */ - public function iAddAndSectionsToIt(string ...$sectionsNames): void + public function iAddAndSectionsToIt(string ...$sectionNames): void { - $this->resolveCurrentPage()->associateSections($sectionsNames); + $this->resolveCurrentPage()->associateSections($sectionNames); } /** diff --git a/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php b/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php index 9715384de..78d44f303 100644 --- a/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php +++ b/tests/Behat/Context/Ui/Admin/FrequentlyAskedQuestionContext.php @@ -17,7 +17,7 @@ use Sylius\Behat\Page\SymfonyPageInterface; use Sylius\Behat\Service\NotificationCheckerInterface; use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\FrequentlyAskedQuestion\CreatePageInterface; use Webmozart\Assert\Assert; @@ -101,6 +101,7 @@ public function iSetTheAnswerTo(string $answer): void /** * @When I add it + * @When I try to add it */ public function iAddIt(): void { @@ -119,9 +120,9 @@ public function iShouldBeNotifiedThatANewFaqHasBeenCreated(): void } /** - * @Then I should be notified that :fields can not be blank + * @Then I should be notified that :fields cannot be blank */ - public function iShouldBeNotifiedThatCanNotBeBlank(string $fields): void + public function iShouldBeNotifiedThatCannotBeBlank(string $fields): void { $fields = explode(',', $fields); @@ -145,7 +146,7 @@ public function iShouldBeNotifiedThatThereIsAlreadyAnExistingFaqWithSelectedPosi } /** - * @return SymfonyPageInterface|CreatePageInterface|ContainsError + * @return SymfonyPageInterface|CreatePageInterface|ContainsErrorTrait */ private function resolveCurrentPage(): SymfonyPageInterface { @@ -153,4 +154,4 @@ private function resolveCurrentPage(): SymfonyPageInterface $this->createPage, ]); } -} \ No newline at end of file +} diff --git a/tests/Behat/Context/Ui/Admin/ManagingPagesContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php similarity index 78% rename from tests/Behat/Context/Ui/Admin/ManagingPagesContext.php rename to tests/Behat/Context/Ui/Admin/PageContext.php index 617b5d5f1..92a8fc0c3 100644 --- a/tests/Behat/Context/Ui/Admin/ManagingPagesContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -13,7 +13,6 @@ namespace Tests\BitBag\CmsPlugin\Behat\Context\Ui\Admin; use Behat\Behat\Context\Context; -use BitBag\CmsPlugin\Entity\PageInterface; use BitBag\CmsPlugin\Repository\PageRepositoryInterface; use Doctrine\ORM\EntityManagerInterface; use Sylius\Behat\NotificationType; @@ -21,7 +20,7 @@ use Sylius\Behat\Service\NotificationCheckerInterface; use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; use Sylius\Behat\Service\SharedStorageInterface; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Page\CreatePageInterface; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Page\IndexPageInterface; use Tests\BitBag\CmsPlugin\Behat\Page\Admin\Page\UpdatePageInterface; @@ -31,7 +30,7 @@ /** * @author Mikołaj Król */ -final class ManagingPagesContext implements Context +final class PageContext implements Context { /** * @var IndexPageInterface @@ -121,9 +120,9 @@ public function iGoToTheCmsPagesPage(): void } /** - * @When I go to the create new page page + * @When I go to the create page page */ - public function iGoToTheCreateNewPagePage(): void + public function iGoToTheCreatePagePage(): void { $this->createPage->open(); } @@ -160,14 +159,6 @@ public function iFillTheNameWith(string $name): void $this->resolveCurrentPage()->fillName($name); } - /** - * @When I fill the link with :link - */ - public function iFillTheLinkWith(string $link): void - { - $this->resolveCurrentPage()->fillLink($link); - } - /** * @When I fill the slug with :slug */ @@ -212,6 +203,26 @@ public function iFillWithCharacter(string $fields, int $length): void } } + /** + * @When I fill :fields fields + */ + public function iFillFields(string $fields): void + { + $fields = explode(',', $fields); + + foreach ($fields as $field) { + $this->resolveCurrentPage()->fillField(trim($field), $this->randomStringGenerator->generate(5)); + } + } + + /** + * @When I add :firstSection and :secondSection sections to it + */ + public function iAddAndSectionsToIt(string ...$sectionNames): void + { + $this->resolveCurrentPage()->associateSections($sectionNames); + } + /** * @When I add it * @When I try to add it @@ -240,7 +251,7 @@ public function iRemoveLastPage(): void } /** - * @Then I should be notified that new page was created + * @Then I should be notified that the page has been created */ public function iShouldBeNotifiedThatNewPageWasCreated(): void { @@ -262,9 +273,9 @@ public function iShouldBeNotifiedThatThePageWasUpdated(): void } /** - * @Then I should be notified that this page was removed + * @Then I should be notified that this page has been removed */ - public function iShouldBeNotifiedThatThisPageWasRemoved(): void + public function iShouldBeNotifiedThatThisPageHasBeenRemoved(): void { $this->notificationChecker->checkNotification( "Page has been successfully deleted.", @@ -318,74 +329,21 @@ public function iShouldBeNotifiedThatFieldsAreTooLong(string $fields): void } /** - * @Then this page should have :code code - */ - public function thisPageShouldHaveCode(string $code): void - { - Assert::eq($code, $this->getPage()->getCode()); - } - - /** - * @Then it should have :name name - */ - public function itShouldHaveName(string $name): void - { - Assert::eq($this->getPage()->getName(), $name); - } - - /** - * @Then it should have :slug slug - */ - public function itShouldHaveSlug(string $slug): void - { - Assert::eq($this->getPage()->getSlug(), $slug); - } - - /** - * @Then it should have :metaKeywords meta keywords + * @Then only :number pages should exist in the store */ - public function itShouldHaveMetaKeywords(string $metaKeywords): void + public function onlyPagesShouldExistInTheStore(int $number): void { - Assert::eq($metaKeywords, $this->getPage()->getMetaKeywords()); } /** - * @Then it should have :content content - */ - public function itShouldHaveContent(string $content): void - { - Assert::eq($content, $this->getPage()->getContent()); - } - - /** - * @Then :number pages should exist in the store - */ - public function pagesShouldExistInTheStore(int $number): void - { - Assert::eq((int)$number, count($this->pageRepository->findAll())); - } - - /** - * @return CreatePageInterface|UpdatePageInterface|ContainsError|SymfonyPageInterface + * @return CreatePageInterface|UpdatePageInterface|IndexPageInterface|SymfonyPageInterface */ private function resolveCurrentPage(): SymfonyPageInterface { - return $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); - } - - /** - * @return null|PageInterface - */ - private function getPage(): ?PageInterface - { - $code = $this->sharedStorage->get('page_code'); - /** @var null|PageInterface $page */ - $page = $this->pageRepository->findOneBy(['code' => $code]); - - $this->entityManager->refresh($page->getTranslation()); - - Assert::notNull($page); - - return $page; + return $this->currentPageResolver->getCurrentPageWithForm([ + $this->createPage, + $this->updatePage, + $this->indexPage, + ]); } -} \ No newline at end of file +} diff --git a/tests/Behat/Context/Ui/Admin/SectionContext.php b/tests/Behat/Context/Ui/Admin/SectionContext.php index 6b6168c87..0e34ef991 100644 --- a/tests/Behat/Context/Ui/Admin/SectionContext.php +++ b/tests/Behat/Context/Ui/Admin/SectionContext.php @@ -96,4 +96,4 @@ public function iShouldBeNotifiedThatNewSectionHasBeenCreated() NotificationType::success() ); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index f0c193ca3..d66c072b4 100644 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -14,6 +14,7 @@ use Behat\Mink\Driver\Selenium2Driver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; use Webmozart\Assert\Assert; /** @@ -21,6 +22,16 @@ */ final class CreatePage extends BaseCreatePage implements CreatePageInterface { + use ContainsErrorTrait; + + /** + * {@inheritDoc} + */ + public function fillField(string $field, string $value): void + { + $this->getDocument()->fillField($field, $value); + } + /** * {@inheritdoc} */ @@ -103,7 +114,7 @@ public function associateSections(array $sectionsNames): void /** * {@inheritdoc} */ - protected function getDefinedElements() + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'association_dropdown_section' => '.field > label:contains("Sections") ~ .sylius-autocomplete', diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 339efbea2..b963bae6e 100644 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -13,12 +13,19 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\Block; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorInterface; /** * @author Mikołaj Król */ -interface CreatePageInterface extends BaseCreatePageInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { + /** + * @param string $label + * @param string $value + */ + public function fillField(string $label, string $value); + /** * @param string $code */ diff --git a/tests/Behat/Page/Admin/Block/UpdatePage.php b/tests/Behat/Page/Admin/Block/UpdatePage.php index 4bd10e994..6e0181920 100644 --- a/tests/Behat/Page/Admin/Block/UpdatePage.php +++ b/tests/Behat/Page/Admin/Block/UpdatePage.php @@ -20,6 +20,14 @@ */ final class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { + /** + * {@inheritDoc} + */ + public function fillField(string $field, string $value): void + { + $this->getDocument()->fillField($field, $value); + } + /** * {@inheritdoc} */ diff --git a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php index 1f936432f..3bd501b3a 100644 --- a/tests/Behat/Page/Admin/Block/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/UpdatePageInterface.php @@ -19,6 +19,12 @@ */ interface UpdatePageInterface extends BaseUpdatePageInterface { + /** + * @param string $field + * @param string $value + */ + public function fillField(string $field, string $value): void; + /** * @param string $image */ diff --git a/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePage.php b/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePage.php index e2cf71f6d..459129195 100644 --- a/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePage.php +++ b/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePage.php @@ -13,14 +13,14 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\FrequentlyAskedQuestion; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; /** * @author Mikołaj Król */ final class CreatePage extends BaseCreatePage implements CreatePageInterface { - use ContainsError; + use ContainsErrorTrait; /** * {@inheritdoc} diff --git a/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePageInterface.php b/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePageInterface.php index 790145238..415fa88fa 100644 --- a/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/FrequentlyAskedQuestion/CreatePageInterface.php @@ -13,11 +13,12 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\FrequentlyAskedQuestion; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorInterface; /** * @author Mikołaj Król */ -interface CreatePageInterface extends BaseCreatePageInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { /** * @param string $code diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 8aa9273b8..ecd81ce77 100644 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -15,14 +15,23 @@ use Behat\Mink\Driver\Selenium2Driver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\SlugGenerationHelper; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; +use Webmozart\Assert\Assert; /** * @author Mikołaj Król */ final class CreatePage extends BaseCreatePage implements CreatePageInterface { - use ContainsError; + use ContainsErrorTrait; + + /** + * {@inheritDoc} + */ + public function fillField(string $field, string $value): void + { + $this->getDocument()->fillField($field, $value); + } /** * {@inheritDoc} @@ -79,9 +88,26 @@ public function fillContent(string $content): void /** * {@inheritDoc} */ - public function fillField(string $field, string $value): void + public function associateSections(array $sectionsNames): void { - $this->getDocument()->fillField($field, $value); + Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); + + $dropdown = $this->getElement('association_dropdown_section'); + $dropdown->click(); + + foreach ($sectionsNames as $sectionName) { + $dropdown->waitFor(5, function () use ($sectionName) { + return $this->hasElement('association_dropdown_section_item', [ + '%item%' => $sectionName, + ]); + }); + + $item = $this->getElement('association_dropdown_section_item', [ + '%item%' => $sectionName, + ]); + + $item->click(); + } } /** @@ -91,6 +117,8 @@ protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ 'slug' => '#bitbag_plugin_page_translations_en_US_slug', + 'association_dropdown_section' => '.field > label:contains("Sections") ~ .sylius-autocomplete', + 'association_dropdown_section_item' => '.field > label:contains("Sections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")', ]); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 2e9106632..dc77cbe45 100644 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -13,12 +13,19 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\Page; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorInterface; /** * @author Mikołaj Król */ -interface CreatePageInterface extends BaseCreatePageInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { + /** + * @param string $field + * @param string $value + */ + public function fillField(string $field, string $value): void; + /** * @param string $code */ @@ -43,15 +50,13 @@ public function fillMetaKeywords(string $metaKeywords): void; * @param string $metaDescription */ public function fillMetaDescription(string $metaDescription): void; - /** * @param string $content */ public function fillContent(string $content): void; /** - * @param string $field - * @param string $value + * @param array $sectionsNames */ - public function fillField(string $field, string $value): void; + public function associateSections(array $sectionsNames): void; } \ No newline at end of file diff --git a/tests/Behat/Page/Admin/Page/UpdatePage.php b/tests/Behat/Page/Admin/Page/UpdatePage.php index 9ea421f2a..86944cf98 100644 --- a/tests/Behat/Page/Admin/Page/UpdatePage.php +++ b/tests/Behat/Page/Admin/Page/UpdatePage.php @@ -15,14 +15,14 @@ use Behat\Mink\Driver\Selenium2Driver; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Sylius\Behat\Service\SlugGenerationHelper; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; /** * @author Mikołaj Król */ final class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { - use ContainsError; + use ContainsErrorTrait; /** * @param string $name @@ -85,4 +85,4 @@ protected function getDefinedElements(): array 'slug' => '#bitbag_plugin_page_translations_en_US_slug', ]); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php index 6586a32b5..2a824cd7f 100644 --- a/tests/Behat/Page/Admin/Page/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/UpdatePageInterface.php @@ -49,4 +49,4 @@ public function fillContent(string $content): void; * @param string $value */ public function fillField(string $field, string $value): void; -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Section/CreatePage.php b/tests/Behat/Page/Admin/Section/CreatePage.php index d6627f565..c47f072f4 100644 --- a/tests/Behat/Page/Admin/Section/CreatePage.php +++ b/tests/Behat/Page/Admin/Section/CreatePage.php @@ -13,14 +13,14 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\Section; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; /** * @author Patryk Drapik */ final class CreatePage extends BaseCreatePage implements CreatePageInterface { - use ContainsError; + use ContainsErrorTrait; /** * {@inheritDoc} @@ -45,4 +45,4 @@ public function fillField(string $field, string $value): void { $this->getDocument()->fillField($field, $value); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Section/CreatePageInterface.php b/tests/Behat/Page/Admin/Section/CreatePageInterface.php index 04a74d5cc..475959f3f 100644 --- a/tests/Behat/Page/Admin/Section/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Section/CreatePageInterface.php @@ -13,11 +13,12 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\Section; use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorInterface; /** * @author Patryk Drapik */ -interface CreatePageInterface extends BaseCreatePageInterface +interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface { /** * @param string $code @@ -34,4 +35,4 @@ public function fillName(string $name): void; * @param string $value */ public function fillField(string $field, string $value): void; -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Section/UpdatePage.php b/tests/Behat/Page/Admin/Section/UpdatePage.php index c67e56414..fb72fde82 100644 --- a/tests/Behat/Page/Admin/Section/UpdatePage.php +++ b/tests/Behat/Page/Admin/Section/UpdatePage.php @@ -13,30 +13,28 @@ namespace Tests\BitBag\CmsPlugin\Behat\Page\Admin\Section; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; -use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsError; +use Tests\BitBag\CmsPlugin\Behat\Behaviour\ContainsErrorTrait; /** * @author Patryk Drapik */ final class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { - use ContainsError; + use ContainsErrorTrait; /** - * @param string $name + * {@inheritdoc} */ - public function fillName(string $name): void + public function fillField(string $field, string $value): void { - $this->getDocument()->fillField('Name', $name); - + $this->getDocument()->fillField($field, $value); } /** - * @param string $field - * @param string $value + * {@inheritdoc} */ - public function fillField(string $field, string $value): void + public function fillName(string $name): void { - $this->getDocument()->fillField($field, $value); + $this->getDocument()->fillField('Name', $name); } -} \ No newline at end of file +} diff --git a/tests/Behat/Page/Admin/Section/UpdatePageInterface.php b/tests/Behat/Page/Admin/Section/UpdatePageInterface.php index 11ab58c26..3bbfadf1f 100644 --- a/tests/Behat/Page/Admin/Section/UpdatePageInterface.php +++ b/tests/Behat/Page/Admin/Section/UpdatePageInterface.php @@ -19,14 +19,14 @@ */ interface UpdatePageInterface extends BaseUpdatePageInterface { - /** - * @param string $name - */ - public function fillName(string $name): void; - /** * @param string $field * @param string $value */ public function fillField(string $field, string $value): void; -} \ No newline at end of file + + /** + * @param string $name + */ + public function fillName(string $name): void; +} diff --git a/tests/Behat/Resources/services/contexts/setup.yml b/tests/Behat/Resources/services/contexts/setup.yml index 338a3a81f..c9cec911c 100644 --- a/tests/Behat/Resources/services/contexts/setup.yml +++ b/tests/Behat/Resources/services/contexts/setup.yml @@ -38,6 +38,5 @@ services: - "@sylius.behat.shared_storage" - "@__symfony__.bitbag.factory.section" - "@__symfony__.bitbag.repository.section" - - "@__symfony__.bitbag.manager.section" tags: - { name: fob.context_service } \ No newline at end of file diff --git a/tests/Behat/Resources/services/contexts/ui.yml b/tests/Behat/Resources/services/contexts/ui.yml index 1710e90cf..b2a401727 100644 --- a/tests/Behat/Resources/services/contexts/ui.yml +++ b/tests/Behat/Resources/services/contexts/ui.yml @@ -1,6 +1,6 @@ services: bitbag.behat.context.ui.admin.managing_blocks: - class: Tests\BitBag\CmsPlugin\Behat\Context\Ui\Admin\ManagingBlocksContext + class: Tests\BitBag\CmsPlugin\Behat\Context\Ui\Admin\BlockContext arguments: - "@bitbag.behat.page.admin.block.index" - "@bitbag.behat.page.admin.block.create" @@ -8,13 +8,13 @@ services: - "@sylius.behat.current_page_resolver" - "@sylius.behat.notification_checker" - "@sylius.behat.shared_storage" + - "@bitbag.behat.random_string_generator" - "@__symfony__.bitbag.repository.block" - - "@__symfony__.bitbag.manager.block" tags: - { name: fob.context_service } bitbag.behat.context.ui.admin.managing_pages: - class: Tests\BitBag\CmsPlugin\Behat\Context\Ui\Admin\ManagingPagesContext + class: Tests\BitBag\CmsPlugin\Behat\Context\Ui\Admin\PageContext arguments: - "@bitbag.behat.page.admin.page.index" - "@bitbag.behat.page.admin.page.create" diff --git a/tests/Behat/Resources/suites/ui/managing_pages.yml b/tests/Behat/Resources/suites/ui/managing_pages.yml index f127b256a..433acd22a 100644 --- a/tests/Behat/Resources/suites/ui/managing_pages.yml +++ b/tests/Behat/Resources/suites/ui/managing_pages.yml @@ -8,6 +8,7 @@ default: - sylius.behat.context.setup.admin_security - sylius.behat.context.setup.product - bitbag.behat.context.setup.page + - bitbag.behat.context.setup.section - bitbag.behat.context.ui.admin.managing_pages filters: