This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
[Behat] WIP Improve structure and usability of PlatformUI behat Contexts #602
Open
miguelcleverti
wants to merge
8
commits into
ezsystems:master
Choose a base branch
from
miguelcleverti:BehatStructureUpdate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
604181f
[Behat] Separate CommonActions into meaningfull Contexts
3935983
[Behat] Remove not used method from platformUI context
f62f4dd
[Behat] gather contexts using annotions in the properties
5a37f9d
[Behat] Fix iSeeTitle() method in wrong Context
678d2a1
[Behat] Improve gatherContexts, use @var annotation instead of custom…
225ab8a
[Behat] Remove not used property
f204c59
[Behat] Fix kernel behat contexts namespace
e36e132
[Behat] Remove xPath Helper
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,29 @@ | |
*/ | ||
namespace EzSystems\PlatformUIBundle\Features\Context; | ||
|
||
use PHPUnit_Framework_Assert as Assertion; | ||
|
||
class ContentActions extends PlatformUI | ||
{ | ||
/** | ||
* @var EzSystems\PlatformUIBundle\Features\Context\SubContext\ContentEditContext | ||
*/ | ||
protected $contentEditContext; | ||
|
||
/** | ||
* @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext | ||
*/ | ||
protected $dashboardContext; | ||
|
||
/** | ||
*/ | ||
private function iSeeNotification($message) | ||
{ | ||
$this->sleep(); | ||
$result = $this->getElementByText($message, '.ez-notification-text'); | ||
Assertion::AssertNotNull($result); | ||
} | ||
|
||
/** | ||
* @Then I am notified that :name has been copied under :destiny | ||
*/ | ||
|
@@ -25,10 +46,11 @@ public function iSeeCopiedNotification($name, $destiny) | |
*/ | ||
public function moveInto($name, $destiny) | ||
{ | ||
$this->onFullView($name); | ||
$this->clickActionBar('Move'); | ||
$this->selectFromUniversalDiscovery("eZ Platform/$destiny"); | ||
$this->confirmSelection(); | ||
$this->contentEditContext->onFullView($name); | ||
$this->waitWhileLoading(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems that the |
||
$this->dashboardContext->clickActionBar('Move'); | ||
$this->dashboardContext->selectFromUniversalDiscovery("eZ Platform/$destiny"); | ||
$this->dashboardContext->confirmSelection(); | ||
$destinyName = explode('/', $destiny); | ||
$destinyName = end($destinyName); | ||
$this->iSeeMovedNotification($name, $destinyName); | ||
|
@@ -58,9 +80,9 @@ public function iSeeMovedNotification($name, $destiny) | |
*/ | ||
public function removeContent($name) | ||
{ | ||
$this->onFullView($name); | ||
$this->contentEditContext->onFullView($name); | ||
$this->waitWhileLoading(); | ||
$this->clickActionBar('Send to Trash'); | ||
$this->dashboardContext->clickActionBar('Send to Trash'); | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -9,14 +9,24 @@ | |
*/ | ||
namespace EzSystems\PlatformUIBundle\Features\Context; | ||
|
||
use EzSystems\BehatBundle\ObjectManager\FieldType; | ||
use Behat\Mink\WebAssert; | ||
use eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext as FieldType; | ||
|
||
class Fields extends PlatformUI | ||
{ | ||
const NOTIFICATION_CONTENT_PUBLISHED = 'Content has been published'; | ||
const NOTIFICATION_PUBLISH_ERROR = 'An error occured while publishing the draft'; | ||
|
||
/** | ||
* @var eZ\Bundle\EzPublishCoreBundle\Features\Context\FieldTypeContext | ||
*/ | ||
protected $fieldtypeContext; | ||
|
||
/** | ||
* @var EzSystems\PlatformUIBundle\Features\Context\SubContext\DashboardContext | ||
*/ | ||
protected $dashboardContext; | ||
|
||
protected function getFieldIdentCss($identifier, $contentId = '') | ||
{ | ||
return "ez-field-$contentId-$identifier"; | ||
|
@@ -49,12 +59,11 @@ protected function getEditLabelCss($type, $fieldIdentifier = '', $contentId = '' | |
|
||
protected function getThisFieldIdent() | ||
{ | ||
$fieldManager = $this->getFieldTypeManager(); | ||
$identifier = $fieldManager->getThisFieldTypeIdentifier(); | ||
$identifier = $this->fieldtypeContext->getThisFieldTypeIdentifier(); | ||
|
||
// check if we are editing a field for draft or published content | ||
if ($fieldManager->getFieldContentState() == FieldType::CONTENT_PUBLISHED) { | ||
$contentId = $fieldManager->getThisContentId(); | ||
if ($this->fieldtypeContext->getFieldContentState() == FieldType::CONTENT_PUBLISHED) { | ||
$contentId = $this->fieldtypeContext->getThisContentId(); | ||
} else { | ||
$contentId = ''; | ||
} | ||
|
@@ -67,14 +76,13 @@ protected function getThisFieldIdent() | |
*/ | ||
public function createAContentOfThisType() | ||
{ | ||
$fieldManager = $this->getFieldTypeManager(); | ||
$fieldManager->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED); | ||
$name = $fieldManager->getThisContentTypeName(); | ||
$this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_TYPE_PUBLISHED); | ||
$name = $this->fieldtypeContext->getThisContentTypeName(); | ||
|
||
$this->clickNavigationZone('Content'); | ||
$this->clickNavigationItem('Content structure'); | ||
$this->clickActionBar('Create'); | ||
$this->clickContentType($name); | ||
$this->dashboardContext->clickNavigationZone('Content'); | ||
$this->dashboardContext->clickNavigationItem('Content structure'); | ||
$this->dashboardContext->clickActionBar('Create'); | ||
$this->dashboardContext->clickContentType($name); | ||
$this->platformStatus = self::WAITING_FOR_PUBLISHING; | ||
} | ||
|
||
|
@@ -83,14 +91,13 @@ public function createAContentOfThisType() | |
*/ | ||
public function editThisContent() | ||
{ | ||
$fieldManager = $this->getFieldTypeManager(); | ||
$fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); | ||
$name = $fieldManager->getThisContentName(); | ||
$this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_PUBLISHED); | ||
$name = $this->fieldtypeContext->getThisContentName(); | ||
|
||
$this->clickNavigationZone('Content'); | ||
$this->clickNavigationItem('Content structure'); | ||
$this->clickOnTreePath($name); | ||
$this->clickActionBar('Edit'); | ||
$this->dashboardContext->clickNavigationZone('Content'); | ||
$this->dashboardContext->clickNavigationItem('Content structure'); | ||
$this->dashboardContext->clickOnTreePath($name); | ||
$this->dashboardContext->clickActionBar('Edit'); | ||
$this->platformStatus = self::WAITING_FOR_PUBLISHING; | ||
// assert | ||
$this->iSeeContentEditView(); | ||
|
@@ -147,7 +154,7 @@ public function uncheckFieldValue() | |
public function publishContent() | ||
{ | ||
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { | ||
$this->clickEditActionBar('Publish'); | ||
$this->dashboardContext->clickEditActionBar('Publish'); | ||
} else { | ||
throw new \Exception('Cannot publish content, application in wrong state'); | ||
} | ||
|
@@ -161,9 +168,8 @@ public function publishContent() | |
public function seeRequiredFieldtOfType($label) | ||
{ | ||
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { | ||
$fieldManager = $this->getFieldTypeManager(); | ||
// $type = ... | ||
//$name = $fieldManager->getThisFieldTypeName(); | ||
//$name = $fieldtypeContext->getThisFieldTypeName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleanup comments instead of updating them |
||
|
||
$verification = new WebAssert($this->getSession()); | ||
//$verification->elementTextContains('css', $this->getEditLabelCss($type, $name), $label . '*');. | ||
|
@@ -186,7 +192,7 @@ public function iSeeContentEditView() | |
*/ | ||
public function contentIsPublished() | ||
{ | ||
$this->iSeeNotification(self::NOTIFICATION_CONTENT_PUBLISHED); | ||
$this->dashboardContext->iSeeNotification(self::NOTIFICATION_CONTENT_PUBLISHED); | ||
} | ||
|
||
/** | ||
|
@@ -205,11 +211,11 @@ public function failsWithMessage($message) | |
public function seeFieldtOfType($type, $label = null) | ||
{ | ||
if ($this->platformStatus == self::WAITING_FOR_PUBLISHING) { | ||
$this->clickEditActionBar('Publish'); | ||
$this->dashboardContext->clickEditActionBar('Publish'); | ||
} | ||
$verification = new WebAssert($this->getSession()); | ||
// for view we need the internal field identifier... | ||
$internalName = $this->getFieldTypeManager()->getFieldTypeInternalIdentifier($type); | ||
$internalName = $this->fieldtypeContext->getFieldTypeInternalIdentifier($type); | ||
$verification->elementExists('css', ".ez-fieldview-$internalName .ez-fieldview-value-content"); | ||
|
||
if ($label != null) { | ||
|
@@ -222,13 +228,12 @@ public function seeFieldtOfType($type, $label = null) | |
*/ | ||
public function viewThisContent() | ||
{ | ||
$fieldManager = $this->getFieldTypeManager(); | ||
$fieldManager->setFieldContentState(FieldType::CONTENT_PUBLISHED); | ||
$name = $fieldManager->getThisContentName(); | ||
$this->fieldtypeContext->setFieldContentState(FieldType::CONTENT_PUBLISHED); | ||
$name = $this->fieldtypeContext->getThisContentName(); | ||
|
||
$this->clickNavigationZone('Content'); | ||
$this->clickNavigationItem('Content structure'); | ||
$this->clickOnTreePath($name); | ||
$this->dashboardContext->clickNavigationZone('Content'); | ||
$this->dashboardContext->clickNavigationItem('Content structure'); | ||
$this->dashboardContext->clickOnTreePath($name); | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -9,9 +9,11 @@ | |
*/ | ||
namespace EzSystems\PlatformUIBundle\Features\Context; | ||
|
||
use EzSystems\BehatBundle\Context\Browser\Context; | ||
use ReflectionClass; | ||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use Behat\MinkExtension\Context\RawMinkContext; | ||
|
||
class PlatformUI extends Context | ||
class PlatformUI extends RawMinkContext | ||
{ | ||
/** | ||
* Default Platform URI. | ||
|
@@ -44,9 +46,6 @@ class PlatformUI extends Context | |
const NOT_WAITING = 0; | ||
const WAITING_FOR_PUBLISHING = 1; | ||
|
||
use SubContext\Authentication; | ||
use SubContext\CommonActions; | ||
|
||
/** | ||
* PlatformUI relative URL path. | ||
* | ||
|
@@ -79,21 +78,13 @@ class PlatformUI extends Context | |
*/ | ||
protected $platformStatus = self::NOT_WAITING; | ||
|
||
/** | ||
* Mapping of the new paths of contents after being moved. | ||
*/ | ||
protected $newPathsMap = array(); | ||
|
||
/** | ||
* Initialize class. | ||
* | ||
* @param string $uri | ||
*/ | ||
public function __construct($uri = self::PLATFORM_URI, $user = null, $password = null) | ||
{ | ||
parent::__construct(); | ||
$this->pageIdentifierMap['roles'] = '/ez#/admin/pjax%2Frole'; | ||
$this->pageIdentifierMap['users'] = '/ez#/view/%2Fapi%2Fezp%2Fv2%2Fcontent%2Flocations%2F1%2F5/eng-GB'; | ||
$this->platformUiUri = $uri; | ||
if ($user != null) { | ||
$this->user = $user; | ||
|
@@ -103,6 +94,30 @@ public function __construct($uri = self::PLATFORM_URI, $user = null, $password = | |
} | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would need some doc.
|
||
* | ||
* Default gather contexts method. | ||
* Uses doc comment type hint to get the contexts and set them | ||
*/ | ||
public function gatherContexts(BeforeScenarioScope $scope) | ||
{ | ||
$refClass = new ReflectionClass($this); | ||
$refProperties = $refClass->getProperties(); | ||
foreach ($refProperties as $refProperty) { | ||
$propertyName = $refProperty->getName(); | ||
// get property type hint from doc comment | ||
preg_match_all('#@var\s(.*?)\n#s', $refProperty->getDocComment(), $matches); | ||
foreach ($matches[1] as $typeHint) { | ||
// checks if the type hint implements Behat Context | ||
$implements = @class_implements($typeHint); | ||
if (!empty($implements) && in_array('Behat\Behat\Context\Context', $implements)) { | ||
$this->$propertyName = $scope->getEnvironment()->getContext($typeHint); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @BeforeScenario | ||
*/ | ||
|
@@ -118,7 +133,6 @@ public function afterScenario() | |
{ | ||
$this->closeConfirmBox(); | ||
$this->closeEditView(); | ||
$this->iLogout(); | ||
} | ||
|
||
/** | ||
|
@@ -130,11 +144,41 @@ public function beforeStep() | |
$this->waitWhileLoading(); | ||
} | ||
|
||
/** | ||
* @AfterStep | ||
*/ | ||
public function afterStep() | ||
public function fillFieldWithValue($field, $value = '') | ||
{ | ||
$fieldNode = $this->spin( | ||
function () use ($field) { | ||
$fieldNode = $this->getSession()->getPage()->findField($field); | ||
if ($fieldNode == null) { | ||
throw new \Exception('Field not found'); | ||
} | ||
|
||
return $fieldNode; | ||
} | ||
); | ||
|
||
$this->spin( | ||
function () use ($fieldNode, $field, $value) { | ||
// make sure any autofocus elements don't mis-behave when setting value | ||
$fieldNode->blur(); | ||
usleep(10 * 1000); | ||
$fieldNode->focus(); | ||
usleep(10 * 1000); | ||
|
||
// setting value on pre-filled inputs can cause issues, clearing before | ||
$fieldNode->setValue(''); | ||
$fieldNode->setValue($value); | ||
|
||
// verication that the field was really filled in correctly | ||
$this->sleep(); | ||
$check = $this->getSession()->getPage()->findField($field)->getValue(); | ||
if ($check != $value) { | ||
throw new \Exception('Failed to set the field value: ' . $check); | ||
} | ||
|
||
return true; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -284,7 +328,7 @@ function () use ($selector, $baseElement, $checkVisibility) { | |
* @param string $selector CSS selector of the element | ||
* @param string $textSelector Extra CSS selector for text of the element | ||
* @param string $baseElement Element in which the search is based | ||
* @param int $iteration Iteration number, used to control number of executions | ||
* | ||
* @return array | ||
*/ | ||
protected function getElementByText($text, $selector, $textSelector = null, $baseElement = null) | ||
|
@@ -408,33 +452,4 @@ protected function closeEditView() | |
} catch (\Exception $e) { | ||
} | ||
} | ||
/** | ||
* Attaches a file to a input field on the HTML. | ||
* | ||
* @param string $file file name relative to mink definitions | ||
* @param string $selector CSS file upload element selector | ||
*/ | ||
protected function attachFile($fileName, $selector) | ||
{ | ||
if ($this->getMinkParameter('files_path')) { | ||
$fullPath = rtrim( | ||
realpath( | ||
$this->getMinkParameter('files_path') | ||
), | ||
DIRECTORY_SEPARATOR | ||
) . DIRECTORY_SEPARATOR . $fileName; | ||
|
||
if (is_file($fullPath)) { | ||
$fileInput = 'input[type="file"]' . $selector; | ||
$field = $this->getSession()->getPage()->find('css', $fileInput); | ||
|
||
if (null === $field) { | ||
throw new Exception("File input $selector is not found"); | ||
} | ||
$field->attachFile($fullPath); | ||
} | ||
} else { | ||
throw new Exception("File $fileName is not found at the given location: $fullPath"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance var not really necessary, if not for consistency maybe?