From d167d2f779fd372172742f2939241e9b78c2b0ed Mon Sep 17 00:00:00 2001 From: Raissa North Date: Tue, 21 Aug 2018 17:15:40 +1200 Subject: [PATCH 1/2] Refactor Behat tests --- tests/Behat/Context/FixtureContext.php | 32 +++++++- tests/Behat/config/enable-elemental.yml | 6 -- .../Behat/features/add-block-element.feature | 32 ++++++++ .../features/delete-block-element.feature | 31 ++++++++ .../Behat/features/edit-block-element.feature | 33 ++++++++ tests/Behat/features/element-editor.feature | 79 +++---------------- 6 files changed, 134 insertions(+), 79 deletions(-) delete mode 100644 tests/Behat/config/enable-elemental.yml create mode 100644 tests/Behat/features/add-block-element.feature create mode 100644 tests/Behat/features/delete-block-element.feature create mode 100644 tests/Behat/features/edit-block-element.feature diff --git a/tests/Behat/Context/FixtureContext.php b/tests/Behat/Context/FixtureContext.php index 5b18fb04..8ab3ad4b 100644 --- a/tests/Behat/Context/FixtureContext.php +++ b/tests/Behat/Context/FixtureContext.php @@ -23,11 +23,35 @@ class FixtureContext extends BaseFixtureContext { /** - * @Given I add an extension :extension to the :class class + * @Given /(?:the|a) "([^"]+)" "([^"]+)" (?:with|has) a "([^"]+)" content element with "([^"]+)" content/ + * + * @param string $pageTitle + * @param string $type + * @param string $elementTitle + * @param string $elementContent */ - public function iAddAnExtensionToTheClass($extension, $class) + public function theHasAContentElementWithContent($type, $pageTitle, $elementTitle, $elementContent) { - $targetClass = $this->convertTypeToClass($class); - $targetClass::add_extension(ElementalPageExtension::class); + // Create the page (ElementalArea is created on write and attached to it) + $targetClass = $this->convertTypeToClass($type); + + $page = $this->getFixtureFactory()->get($targetClass, $pageTitle); + if (!$page) { + $page = $this->getFixtureFactory()->createObject($targetClass, $pageTitle); + } + + $elementalArea = $page->ElementalArea(); + $elementalArea->Elements()->add($this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle)); + + // Create element + $element = $this->getFixtureFactory()->get(ElementContent::class, $elementTitle); + + if ($element) { + $element->HTML = $elementContent; + $element->write(); + } else { + $element = $this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle, $fields); + $element->write(); + } } } diff --git a/tests/Behat/config/enable-elemental.yml b/tests/Behat/config/enable-elemental.yml deleted file mode 100644 index fe51cc0b..00000000 --- a/tests/Behat/config/enable-elemental.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -Name: testonly-enable-elemental ---- -Page: - extensions: - - DNADesign\Elemental\Extensions\ElementalPageExtension diff --git a/tests/Behat/features/add-block-element.feature b/tests/Behat/features/add-block-element.feature new file mode 100644 index 00000000..c0585d82 --- /dev/null +++ b/tests/Behat/features/add-block-element.feature @@ -0,0 +1,32 @@ +@javascript +Feature: Add elements in the CMS + As a CMS user + I want to add elements in the CMS + So that I can use multiple elements on a page + + Background: + Given I am logged in with "ADMIN" permissions + And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content + And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + + # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, + # See https://github.com/dnadesign/silverstripe-elemental/issues/320 + And I go to "/admin/pages/edit/show/6" + And I wait until I see the ".element-editor__element" element + Then I should see "Alice's Block" + And I should see "Bob's Block" + + Scenario: I can add elements to the page + Given I wait until I see the ".element-editor__element" element + When I select "Content" from "elemental-editor_add-new-block-control_select-dropdown" + And I click "Add" in the ".elemental-editor__add-new-block-control" element + And I fill in "Eve's Block" for "Title" + And I fill in "

Some content III

" for the "HTML" HTML field + And I press the "Create" button + Then I should see a "Saved content block" message + + When I go to "/admin/pages/edit/show/6" + And I wait until I see the ".element-editor__element" element + And I wait 1 second + Then I should see "Eve's Block" diff --git a/tests/Behat/features/delete-block-element.feature b/tests/Behat/features/delete-block-element.feature new file mode 100644 index 00000000..12703165 --- /dev/null +++ b/tests/Behat/features/delete-block-element.feature @@ -0,0 +1,31 @@ +@javascript +Feature: Delete elements in the CMS + As a CMS user + I want to delete elements in the CMS + So that I can remove elements I have used on a page + + + Background: + Given I am logged in with "ADMIN" permissions + And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content + And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + + # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, + # See https://github.com/dnadesign/silverstripe-elemental/issues/320 + And I go to "/admin/pages/edit/show/6" + And I wait until I see the ".element-editor__element" element + Then I should see "Alice's Block" + And I should see "Bob's Block" + + @modal + Scenario: I can delete a block + Given I wait until I see the ".element-editor__element" element + When I should see the delete button for block 1 + And I click on the delete button for block 1 + And I see the text "Are you sure you want to delete this block?" in the alert + And I confirm the dialog + And I wait for 2 seconds + And I wait until I see the ".element-editor__element" element + Then I should see "Bob's Block" + But I should not see "Alice's Block" diff --git a/tests/Behat/features/edit-block-element.feature b/tests/Behat/features/edit-block-element.feature new file mode 100644 index 00000000..0f537900 --- /dev/null +++ b/tests/Behat/features/edit-block-element.feature @@ -0,0 +1,33 @@ +@javascript +Feature: Edit elements in the CMS + As a CMS user + I want to edit elements in the CMS + So that I can modify elements I have used on a page + + Background: + Given I am logged in with "ADMIN" permissions + And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content + And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, + # See https://github.com/dnadesign/silverstripe-elemental/issues/320 + And I go to "/admin/pages/edit/show/6" + And I wait until I see the ".element-editor__element" element + Then I should see "Alice's Block" + And I should see "Bob's Block" + + Scenario: I can edit a block + Given I wait until I see the ".element-editor__element" element + Then I should see block 1 + + Given I click on block 1 + Then I should see "Alice's Block" + And the "HTML" HTML field should contain "Some content" + + Given I fill in "Eve's Block" for "Title" + And I fill in "

New sample content

" for the "HTML" HTML field + And I press the "Publish" button + Then I should see a "Published content block" message + When I go to "/admin/pages/edit/show/6" + Then I should see "Eve's Block" + But I should not see "Alice's Block" diff --git a/tests/Behat/features/element-editor.feature b/tests/Behat/features/element-editor.feature index 2a53ff72..1b99fc04 100644 --- a/tests/Behat/features/element-editor.feature +++ b/tests/Behat/features/element-editor.feature @@ -1,85 +1,26 @@ @javascript -Feature: View types of elements in a report +Feature: View types of elements in the elemental editor As a CMS user I want to view a list of elements in the CMS So that I can see which elements I have used on a page Background: - Given I have a config file "enable-elemental.yml" Given I am logged in with "ADMIN" permissions - And I add an extension "DNADesign\\Elemental\\Extensions\\ElementalPageExtension" to the "Page" class - And I go to "/dev/build?flush" - And a "page" "Blocks Page" - And I go to "/admin/pages" - And I wait until I see the ".cms-tree" element - And I click on "Blocks Page" in the tree - And I wait until I see the ".elemental-editor__list" element - # Workaround until the FixtureFactory applies ElementalArea relations correctly; - # See https://github.com/silverstripe/silverstripe-behat-extension/issues/180 - And I select "Content" from "elemental-editor_add-new-block-control_select-dropdown" - And I click "Add" in the ".elemental-editor__add-new-block-control" element - And I fill in "My Sample Block" for "Title" - And I fill in "

My sample content

" for the "HTML" HTML field - And I click "Create" in the "#Form_ItemEditForm_action_doSave" element - # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, - # See https://github.com/dnadesign/silverstripe-elemental/issues/320 + And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content + And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content And I go to "/admin/pages/edit/show/6" And I wait until I see the ".element-editor__element" element - Then I should see "My Sample Block" + Then I should see "Alice's Block" + And I should see "Bob's Block" Scenario: I can see the title and summary of each element Given I wait until I see the ".element-editor__element" element Then I should see a list of blocks - And I should see "My Sample Block" as the title for block 1 - And I should see "My sample content" as the summary for block 1 - - - Scenario: I can add elements to the page - Given I wait until I see the ".element-editor__element" element - When I select "Content" from "elemental-editor_add-new-block-control_select-dropdown" - And I click "Add" in the ".elemental-editor__add-new-block-control" element - And I fill in "Additional Sample Block" for "Title" - And I fill in "

Additional sample content

" for the "HTML" HTML field - And I press the "Create" button - Then I should see a "Saved content block" message - - When I go to "/admin/pages/edit/show/6" - And I wait until I see the ".element-editor__element" element - And I wait 1 second - Then I should see "Additional Sample Block" - - Scenario: I can preview a block - Given I wait until I see the ".element-editor__element" element - Then I should see block 1 - - Given I click on block 1 - # Needs rewrite once the FormBuilder component is fully functional. - # Test checks only if placeholder text is rendered. - Then I should see "Imagine some fancy form builder here!" - - @modal - Scenario: I can archive a block - Given I wait until I see the ".element-editor__element" element - When I select "Content" from "elemental-editor_add-new-block-control_select-dropdown" - And I click "Add" in the ".elemental-editor__add-new-block-control" element - And I wait 1 second - And I fill in "Second Sample Block" for "Title" - And I fill in "

Additional sample content

" for the "HTML" HTML field - And I press the "Create" button - And I go to "/admin/pages/edit/show/6" - And I wait until I see the ".element-editor__element" element - And I wait 1 second - And I should see "Second Sample Block" - And I should see block 1 - And I press the "View actions" button - Then I should see the archive button for block 1 - When I press the "Archive" button - And I see the text "Are you sure you want to send this block to the archive?" in the alert - And I confirm the dialog - And I wait until I see the ".element-editor__element" element - Then I should see "Second Sample Block" - But I should not see "My Sample Block Title" - + And I should see "Alice's Block" as the title for block 1 + And I should see "Some content" as the summary for block 1 + And I should see "Bob's Block" as the title for block 2 + And I should see "Some content II" as the summary for block 2 Scenario: I can see the block type when I hover over an element's icon Given I wait until I see the ".element-editor__element" element From 2b07d5216e7fef15cea2007967a4f64f60e8f183 Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Wed, 29 Aug 2018 17:41:31 +1200 Subject: [PATCH 2/2] Fixing up tests with latest updates from behat-extensions --- .travis.yml | 1 + composer.json | 3 +- tests/Behat/Context/FixtureContext.php | 40 ++++++++++++++----- .../Behat/features/add-block-element.feature | 4 +- ....feature => archive-block-element.feature} | 20 +++++----- .../Behat/features/edit-block-element.feature | 13 +++--- tests/Behat/features/element-editor.feature | 25 +++++++++--- 7 files changed, 71 insertions(+), 35 deletions(-) rename tests/Behat/features/{delete-block-element.feature => archive-block-element.feature} (66%) diff --git a/.travis.yml b/.travis.yml index 2a6874f7..a40d38d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,7 @@ before_script: # Install composer dependencies - composer validate - composer require silverstripe/recipe-cms:"$RECIPE_VERSION" silverstripe/recipe-testing:^1 --no-update + - if [[ $BEHAT_TEST ]]; then composer require --no-update silverstripe/behat-extension:4.x-dev; fi; - if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.1.x-dev --no-update; fi - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile diff --git a/composer.json b/composer.json index 295458d8..45666e63 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,7 @@ "silverstripe/vendor-plugin": "^1" }, "require-dev": { - "phpunit/phpunit": "^5.7", - "squizlabs/php_codesniffer": "^3.0" + "silverstripe/recipe-testing": "1.x-dev" }, "suggest": { "silverstripe/elemental-blocks": "Adds a set of common SilverStripe content block types", diff --git a/tests/Behat/Context/FixtureContext.php b/tests/Behat/Context/FixtureContext.php index 8ab3ad4b..1d7ac72a 100644 --- a/tests/Behat/Context/FixtureContext.php +++ b/tests/Behat/Context/FixtureContext.php @@ -1,18 +1,8 @@ HTML = $elementContent; $element->write(); } else { - $element = $this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle, $fields); + $element = $this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle, [ + 'Title' => $elementTitle, + 'HTML' => $elementContent + ]); $element->write(); } } + + /** + * @Given content blocks are not in-line editable + * + * @param $elementTitle + */ + public function contentBlocksAreNotInLineEditable() + { + $contentBlockClass = ElementContent::class; + $config = <<getDestinationConfigFolder($file); + file_put_contents($path, $config); + + $this->activatedConfigFiles[] = $path; + + $this->getMainContext()->visit('/?flush'); + } } diff --git a/tests/Behat/features/add-block-element.feature b/tests/Behat/features/add-block-element.feature index c0585d82..0a811a34 100644 --- a/tests/Behat/features/add-block-element.feature +++ b/tests/Behat/features/add-block-element.feature @@ -5,11 +5,11 @@ Feature: Add elements in the CMS So that I can use multiple elements on a page Background: - Given I am logged in with "ADMIN" permissions - And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + Given I am logged in with "ADMIN" permissions # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, # See https://github.com/dnadesign/silverstripe-elemental/issues/320 And I go to "/admin/pages/edit/show/6" diff --git a/tests/Behat/features/delete-block-element.feature b/tests/Behat/features/archive-block-element.feature similarity index 66% rename from tests/Behat/features/delete-block-element.feature rename to tests/Behat/features/archive-block-element.feature index 12703165..88311e15 100644 --- a/tests/Behat/features/delete-block-element.feature +++ b/tests/Behat/features/archive-block-element.feature @@ -1,16 +1,16 @@ @javascript -Feature: Delete elements in the CMS +Feature: Archive elements in the CMS As a CMS user - I want to delete elements in the CMS + I want to archive elements in the CMS So that I can remove elements I have used on a page Background: - Given I am logged in with "ADMIN" permissions - And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + Given I am logged in with "ADMIN" permissions # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, # See https://github.com/dnadesign/silverstripe-elemental/issues/320 And I go to "/admin/pages/edit/show/6" @@ -19,13 +19,15 @@ Feature: Delete elements in the CMS And I should see "Bob's Block" @modal - Scenario: I can delete a block + Scenario: I can archive a block Given I wait until I see the ".element-editor__element" element - When I should see the delete button for block 1 - And I click on the delete button for block 1 - And I see the text "Are you sure you want to delete this block?" in the alert + When I press the "View actions" button + Then I should see the archive button for block 1 + When I press the "Archive" button + And I see the text "Are you sure you want to send this block to the archive?" in the alert And I confirm the dialog - And I wait for 2 seconds + # Sometimes behat can be quicker than the time it takes the JS to remove the row... + And I wait 1 second And I wait until I see the ".element-editor__element" element Then I should see "Bob's Block" But I should not see "Alice's Block" diff --git a/tests/Behat/features/edit-block-element.feature b/tests/Behat/features/edit-block-element.feature index 0f537900..178f5ca5 100644 --- a/tests/Behat/features/edit-block-element.feature +++ b/tests/Behat/features/edit-block-element.feature @@ -5,10 +5,11 @@ Feature: Edit elements in the CMS So that I can modify elements I have used on a page Background: - Given I am logged in with "ADMIN" permissions - And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + + Given I am logged in with "ADMIN" permissions # Remove with 'And I click "Blocks Page" in the ".breadcrumbs-wrapper" element' once the ElementalArea refreshes, # See https://github.com/dnadesign/silverstripe-elemental/issues/320 And I go to "/admin/pages/edit/show/6" @@ -16,8 +17,10 @@ Feature: Edit elements in the CMS Then I should see "Alice's Block" And I should see "Bob's Block" - Scenario: I can edit a block - Given I wait until I see the ".element-editor__element" element + Scenario: I can edit a non in-line editable block + Given content blocks are not in-line editable + And I go to "/admin/pages/edit/show/6" + And I wait until I see the ".element-editor__element" element Then I should see block 1 Given I click on block 1 @@ -29,5 +32,5 @@ Feature: Edit elements in the CMS And I press the "Publish" button Then I should see a "Published content block" message When I go to "/admin/pages/edit/show/6" - Then I should see "Eve's Block" + Then I should see "Eve's Block" But I should not see "Alice's Block" diff --git a/tests/Behat/features/element-editor.feature b/tests/Behat/features/element-editor.feature index 1b99fc04..485586bf 100644 --- a/tests/Behat/features/element-editor.feature +++ b/tests/Behat/features/element-editor.feature @@ -1,16 +1,17 @@ @javascript -Feature: View types of elements in the elemental editor +Feature: View types of elements in an area on a page As a CMS user - I want to view a list of elements in the CMS - So that I can see which elements I have used on a page + I want to view a list of elements that I have on a page + So that I can manage these elements individually Background: - Given I am logged in with "ADMIN" permissions - And I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class + Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class And a "page" "Blocks Page" with a "Alice's Block" content element with "Some content" content And the "page" "Blocks Page" has a "Bob's Block" content element with "Some content II" content + + Given I am logged in with "ADMIN" permissions And I go to "/admin/pages/edit/show/6" - And I wait until I see the ".element-editor__element" element + And I wait until I see the ".elemental-editor__list" element Then I should see "Alice's Block" And I should see "Bob's Block" @@ -22,6 +23,18 @@ Feature: View types of elements in the elemental editor And I should see "Bob's Block" as the title for block 2 And I should see "Some content II" as the summary for block 2 + Scenario: I can preview a block + Given I wait until I see the ".element-editor__element" element + Then I should see block 1 + Given I click on block 1 + # Needs rewrite once the FormBuilder component is fully functional. + # Test checks only if placeholder text is rendered. + Then I should see "Imagine some fancy form builder here!" + + Scenario: Opening the "more actions" menu will not expand a block + When I press the "View actions" button + Then I should not see "Imagine some fancy form builder here!" + Scenario: I can see the block type when I hover over an element's icon Given I wait until I see the ".element-editor__element" element When I hover over the icon of block 1