Skip to content

Commit

Permalink
Merge pull request #344 from creative-commoners/pulls/refactor-behat-…
Browse files Browse the repository at this point in the history
…tests-with-new-fixture-magic-added

Refactor Behat tests
  • Loading branch information
NightJar authored Aug 31, 2018
2 parents f076ee3 + 2b07d52 commit ce793da
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 89 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
70 changes: 56 additions & 14 deletions tests/Behat/Context/FixtureContext.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
<?php
namespace DNADesign\Elemental\Tests\Behat\Context;

use DNADesign\Elemental\Extensions\ElementalAreasExtension;
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Models\ElementContent;
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
use SilverStripe\BehatExtension\Utility\StepHelper;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\FixtureBlueprint;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\HasManyList;

if (!class_exists(BaseFixtureContext::class)) {
return;
Expand All @@ -23,11 +13,63 @@
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, [
'Title' => $elementTitle,
'HTML' => $elementContent
]);
$element->write();
}
}

/**
* @Given content blocks are not in-line editable
*
* @param $elementTitle
*/
public function contentBlocksAreNotInLineEditable()
{
$contentBlockClass = ElementContent::class;
$config = <<<YAML
---
Name: testonly-content-blocks-not-inline-editable
---
$contentBlockClass:
inline_editable: false
YAML;

$file = 'content-blocks-not-inline-editable.yml';
$path = $this->getDestinationConfigFolder($file);
file_put_contents($path, $config);

$this->activatedConfigFiles[] = $path;

$this->getMainContext()->visit('/?flush');
}
}
6 changes: 0 additions & 6 deletions tests/Behat/config/enable-elemental.yml

This file was deleted.

32 changes: 32 additions & 0 deletions tests/Behat/features/add-block-element.feature
Original file line number Diff line number Diff line change
@@ -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 "<p>Some content III</p>" 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"
33 changes: 33 additions & 0 deletions tests/Behat/features/archive-block-element.feature
Original file line number Diff line number Diff line change
@@ -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"
36 changes: 36 additions & 0 deletions tests/Behat/features/edit-block-element.feature
Original file line number Diff line number Diff line change
@@ -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 "<p>New sample content</p>" 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"
88 changes: 21 additions & 67 deletions tests/Behat/features/element-editor.feature
Original file line number Diff line number Diff line change
@@ -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 "<p>My sample content</p>" 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 "<p>Additional sample content</p>" 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 "<p>Additional sample content</p>" 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
Expand Down

0 comments on commit ce793da

Please sign in to comment.