Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

[Behat] Improve CommonActions and Authentication context Css selectors #653

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 80 additions & 21 deletions Features/Context/PlatformUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@
namespace EzSystems\PlatformUIBundle\Features\Context;

use EzSystems\BehatBundle\Context\Browser\Context;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\Core\Persistence\Legacy\Exception\TypeNotFound as TypeNotFoundException;

class PlatformUI extends Context
{
/**
* Default Platform URI.
*/
const PLATFORM_URI = 'ez';
/**
* Default Platform URI admin username.
*/
const PLATFORM_USERNAME = 'admin';
/**
* Default Platform admin user password.
*/
const PLATFORM_USERPASSWORD = 'publish';

/**
* Max. time to wait while loading elements (f.e. during rest calls).
Expand Down Expand Up @@ -60,18 +72,18 @@ class PlatformUI extends Context
protected $lastException;

/**
* User account name, admin by default.
* User account name.
*
* @var string
*/
protected $user = 'admin';
protected $user;

/**
* User account password, publish by default.
* User account password.
*
* @var string
*/
protected $password = 'publish';
protected $password;

/**
* Stores the status of the platform.
Expand All @@ -84,23 +96,25 @@ class PlatformUI extends Context
*/
protected $newPathsMap = array();

/**
* Ezpublish api Search service.
*/
protected $searchService;

/**
* Initialize class.
*
* @param string $uri
* @injectService $searchService @ezpublish.api.service.search
*/
public function __construct($uri = self::PLATFORM_URI, $user = null, $password = null)
public function __construct($searchService)
{
parent::__construct();
$this->platformUiUri = self::PLATFORM_URI;
$this->user = self::PLATFORM_USERNAME;
$this->password = self::PLATFORM_USERPASSWORD;
$this->searchService = $searchService;
$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;
}
if ($password != null) {
$this->password = $password;
}
}

/**
Expand Down Expand Up @@ -134,13 +148,6 @@ public function beforeStep()
$this->waitWhileLoading();
}

/**
* @AfterStep
*/
public function afterStep()
{
}

/**
* Setter for the new path of the content name.
*/
Expand Down Expand Up @@ -331,6 +338,57 @@ protected function clickElementByText($text, $selector, $textSelector = null, $b
}
}

/**
* Returns the path string of the content with the given name.
*
* @param string $contentName
*
* @return string
*/
protected function getContentLocationPath($contentName)
{
$criterion = new Criterion\ContentTypeIdentifier($contentName);
$query = new LocationQuery(
array(
'query' => $criterion,
)
);

$searchResult = null;
try {
$searchResult = $this->searchService->findLocations($query);
} catch (TypeNotFoundException $e) {
// do nothing if the content type identifier does not exist
}

if (!$searchResult) {
$criterions = array(
new Criterion\Field('title', Criterion\Operator::EQ, $contentName),
new Criterion\Field('short_title', Criterion\Operator::EQ, $contentName),
new Criterion\Field('name', Criterion\Operator::EQ, $contentName),
new Criterion\Field('short_name', Criterion\Operator::EQ, $contentName),
);
$query = new LocationQuery(
array(
'query' => new Criterion\LogicalOr($criterions),
)
);
$searchResult = $this->searchService->findLocations($query);
}

$pathString = null;
foreach ($searchResult->searchHits as $searchHit) {
$pathString = $searchHit->valueObject->pathString;
}

if (!$pathString) {
throw new \Exception("Content $contentName not found");
}
$pathString = rtrim($pathString, '/');

return $pathString;
}

/**
* Opens a content tree node based on the root of the tree or a given node.
*
Expand All @@ -355,8 +413,9 @@ protected function openTreeNode($text, $parentNode)
);
}
}
$nodeId = '/api/ezp/v2/content/locations' . $this->getContentLocationPath($text);
// find an '.ez-tree-node' element which contains an '.ez-tree-navigate' with text '$text'
$element = $this->getElementByText($text, '.ez-tree-node', '.ez-tree-navigate', $parentNode);
$element = $this->findWithWait(".ez-tree-node[data-node-id='$nodeId']", $parentNode);
if (!$element) {
throw new \Exception("The tree node '$text' was not found");
}
Expand Down
6 changes: 4 additions & 2 deletions Features/Context/SubContext/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function goToPlatformUiAndLogIn($username, $password)
$this->waitWhileLoading();
$this->fillFieldWithValue('username', $username);
$this->fillFieldWithValue('password', $password);
$this->iClickAtButton('Login');
$this->findWithWait('.ez-loginform-button')->click();
$this->iShouldBeLoggedIn();
$this->shouldBeLoggedIn = true;
}
Expand Down Expand Up @@ -69,7 +69,9 @@ public function iLogout()
$this->waitWhileLoading();
$el->click();
$this->waitWhileLoading();
$this->iClickAtLink('Logout');
$this
->findWithWait('.ez-view-usermenuitemfireeventview[data-event-name="logOut"] .ez-user-menu-item')
->click();
}

/**
Expand Down
Loading