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 5b18fb04..1d7ac72a 100644 --- a/tests/Behat/Context/FixtureContext.php +++ b/tests/Behat/Context/FixtureContext.php @@ -1,18 +1,8 @@ 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, [ + '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/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..0a811a34 --- /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 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" + 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/archive-block-element.feature b/tests/Behat/features/archive-block-element.feature new file mode 100644 index 00000000..88311e15 --- /dev/null +++ b/tests/Behat/features/archive-block-element.feature @@ -0,0 +1,33 @@ +@javascript +Feature: Archive elements in the CMS + As a CMS user + I want to archive elements in the CMS + So that I can remove elements I have used on a page + + + Background: + 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" + 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 archive a block + Given I wait until I see the ".element-editor__element" element + 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 + # 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 new file mode 100644 index 00000000..178f5ca5 --- /dev/null +++ b/tests/Behat/features/edit-block-element.feature @@ -0,0 +1,36 @@ +@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 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" + 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 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 + 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..485586bf 100644 --- a/tests/Behat/features/element-editor.feature +++ b/tests/Behat/features/element-editor.feature @@ -1,85 +1,39 @@ @javascript -Feature: View types of elements in a report +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 have a config file "enable-elemental.yml" + 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 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 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" + 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" 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" + 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 preview a block Given I wait until I see the ".element-editor__element" element - Then I should see block 1 - + 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" + # 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