-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
273e76d
commit 1069f17
Showing
9 changed files
with
348 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
namespace DNADesign\Elemental\Tests\Behat\Context; | ||
|
||
use Behat\Mink\Element\NodeElement; | ||
use SilverStripe\BehatExtension\Context\SilverStripeContext; | ||
|
||
if (!class_exists(SilverStripeContext::class)) { | ||
return; | ||
} | ||
class FeatureContext extends SilverStripeContext | ||
{ | ||
/** | ||
* @Then I should see a list of blocks | ||
*/ | ||
public function iShouldSeeAListOfBlocks() | ||
{ | ||
assertNotEmpty($this->getBlocks()); | ||
} | ||
|
||
/** | ||
* @Then I should see block :position | ||
*/ | ||
public function iShouldSeeBlock($position) | ||
{ | ||
assertNotNull($this->getSpecificBlock($position)); | ||
// assert it is actually rendered | ||
} | ||
|
||
/** | ||
* @When I click on block :position | ||
*/ | ||
public function iClickOnBlock($position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); | ||
$block->click(); | ||
} | ||
|
||
/** | ||
* @When I click on the delete button for block :position | ||
*/ | ||
public function iClickOnTheDeleteButtonForBlock($position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); | ||
|
||
$button = $block->find('css', '.font-icon-trash-bin'); | ||
assertNotNull($button, 'Delete button not found'); | ||
$button->click(); | ||
} | ||
|
||
/** | ||
* @Then I should see :text as the icon for block :position | ||
*/ | ||
public function iShouldSeeAsTheIconForBlock($text, $position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
$icon = $block->find('css', '.element-editor-header__icon-container .i'); | ||
assertTrue($icon->hasClass($text)); | ||
} | ||
|
||
/** | ||
* @Then I should see :text as the title for block :position | ||
*/ | ||
public function iShouldSeeAsTheTitleForBlock($text, $position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
$title = $block->find('css', '.element-editor-header__title'); | ||
assertEquals($title->getText(), $text); | ||
} | ||
|
||
/** | ||
* @Then /^I should (not |)see the edit link for block :position/ | ||
* | ||
* @param string $text | ||
* @param string $position | ||
*/ | ||
public function iShouldSeeEditLinkForBlock($text, $position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
$editLink = $block->find('css', '.element-editor-header__actions-container .a'); | ||
assertTrue($icon->hasClass($text)); | ||
} | ||
|
||
|
||
/** | ||
* @Then I should see the delete button for block :position | ||
* | ||
* @param string $text | ||
* @param string $position | ||
*/ | ||
public function iShouldSeeDeleteButtonForBlock($position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
$button = $block->findAll('css', 'Delete'); | ||
assertNotNull($button, 'Delete button not found'); | ||
} | ||
|
||
/** | ||
* @When I hover over block :position | ||
* | ||
* @param int $position | ||
*/ | ||
public function iHoverOverBlock($position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); | ||
$block->mouseOver(); | ||
} | ||
|
||
/** | ||
* @When I hover over the icon of block :position | ||
* | ||
* @param int $position | ||
*/ | ||
public function iHoverOverTheIconOfBlock($position) | ||
{ | ||
$block = $this->getSpecificBlock($position); | ||
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); | ||
$icon = $block->find('css', '.element-editor-header .element-editor-header__info .element-editor-header__icon-container'); | ||
$icon->mouseOver(); | ||
} | ||
|
||
/** | ||
* Returns the blocks from the element editor | ||
* | ||
* @param string $modifier Optional CSS selector modifier | ||
* @return NodeElement[] | ||
*/ | ||
protected function getBlocks($modifier = '') | ||
{ | ||
// Wait for the list to be visible | ||
$this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0'); | ||
$blocks = $this->getSession() | ||
->getPage() | ||
->findAll('css', '.elemental-editor__list .element-editor__element' . $modifier); | ||
return $blocks; | ||
} | ||
/** | ||
* Returns the selected element | ||
* | ||
* @param int $position | ||
* @return NodeElement | ||
*/ | ||
protected function getSpecificBlock($position) | ||
{ | ||
$blocks = $this->getBlocks(); | ||
/** @var NodeElement $block */ | ||
if ($blocks[$position - 1] !== false) { | ||
return $blocks[$position - 1]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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; | ||
} | ||
/** | ||
* Context used to create fixtures in the SilverStripe ORM. | ||
*/ | ||
class FixtureContext extends BaseFixtureContext | ||
{ | ||
use StepHelper; | ||
protected function scaffoldDefaultFixtureFactory() | ||
{ | ||
$factory = parent::scaffoldDefaultFixtureFactory(); | ||
foreach (ClassInfo::subclassesFor(BaseElement::class) as $class) { | ||
$blueprint = Injector::inst()->create(FixtureBlueprint::class, $class); | ||
$factory->define($class, $blueprint); | ||
} | ||
return $factory; | ||
} | ||
/** | ||
* Create a page cothe "Blocks Page" :type has a "Block Title" content element with "Sample content" content | ||
* | ||
* @Given the :pageTitle :type has a :elementTitle content element with :elementContent content | ||
* | ||
* @param string $pageTitle | ||
* @param string $type | ||
* @param string $elementTitle | ||
* @param string $elementContent | ||
*/ | ||
public function theHasAContentElementWithContent($pageTitle, $type, $elementTitle, $elementContent) | ||
{ | ||
// 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); | ||
} | ||
// Ensure that an ElementalArea is created (see ElementalAreasExtension) | ||
$page->write(); | ||
|
||
// Create the element and assign it to the page's ElementalArea | ||
$element = $this->getFixtureFactory()->createObject(ElementContent::class, $elementTitle); | ||
$element->ParentID = $page->ElementalAreaID; | ||
$element->Content = $elementContent; | ||
$element->write(); | ||
|
||
$page->ElementalArea()->write(); | ||
} | ||
|
||
/** | ||
* @Given I add an extension :extension to the :class class | ||
*/ | ||
public function iAddAnExtensionToTheClass($extension, $class) | ||
{ | ||
$targetClass = $this->convertTypeToClass($class); | ||
$targetClass::add_extension(ElementalPageExtension::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
Name: testonly-enable-elemental | ||
--- | ||
Page: | ||
extensions: | ||
- DNADesign\Elemental\Extensions\ElementalPageExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
@javascript | ||
Feature: View types of elements in a report | ||
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 "<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" | ||
|
||
Scenario: I can see the icon, 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 | ||
|
||
Scenario: I can add elements to the page | ||
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 click "Create" in the "#Form_ItemEditForm_action_doSave" element | ||
Then I should see an ".message" element | ||
And 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 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 "My Sample Block" | ||
And the "HTML" HTML field should contain "My sample content" | ||
|
||
Given I fill in "New Block Title" for "Title" | ||
And I fill in "<p>New sample content</p>" for the "HTML" HTML field | ||
And I click "Publish" in the "#Form_ItemEditForm_action_doPublish" element | ||
And I go to "/admin/pages/edit/show/6" | ||
Then I should see "New Block Title" | ||
But I should not see "My Sample Block" | ||
|
||
@modal | ||
Scenario: I can delete a block | ||
Given 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 click "Create" in the "#Form_ItemEditForm_action_doSave" element | ||
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 should see the delete button for block 1 | ||
|
||
Then 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 until I see the ".element-editor__element" element | ||
Then I should see "Second Sample Block" | ||
But I should not see "My Sample Block Title" | ||
|
||
|
||
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 | ||
Then I should see text matching "Content" |