Skip to content

Commit

Permalink
Merge pull request #1063 from ezsystems/EZP-29112
Browse files Browse the repository at this point in the history
EZP-29112 Implement scenarios for Site Access matching
  • Loading branch information
micszo authored Dec 2, 2019
2 parents 344ad13 + e158c2e commit 20b850c
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 27 deletions.
32 changes: 32 additions & 0 deletions src/lib/Behat/Helper/UtilityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,41 @@
use Behat\MinkExtension\Context\MinkContext;
use Exception;
use WebDriver\Exception\ElementNotVisible;
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
use eZ\Publish\Core\MVC\Symfony\Routing\SimplifiedRequest;

class UtilityContext extends MinkContext
{
/** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess\Router */
private $router;

/**
* @injectService $router @ezpublish.siteaccess_router
*/
public function __construct(Router $router)
{
$this->router = $router;
}

/**
* Return the full web address of a page, based on SiteAccess, page route and hosts configuration.
*
* @param string $siteAccessName name of SiteAccess the page is on
* @param string $route page address route
*
* @return string web address of the page
*/
public function reverseMatchRoute(string $siteAccessName, string $route): string
{
$matcher = $this->router->matchByName($siteAccessName)->matcher;
$matcher->setRequest(new SimplifiedRequest(['scheme' => 'http', 'host' => $this->getMinkParameter('base_url'), 'pathinfo' => $route]));
$request = $matcher->reverseMatch($siteAccessName)->getRequest();
$explodedHost = explode('//', $request->host);
$actualHost = $explodedHost[count($explodedHost) - 1];

return sprintf('%s://%s%s', $request->scheme, $actualHost, $request->pathinfo);
}

/**
* Waits until element is visible. If it does not appear throws exception.
*
Expand Down
5 changes: 2 additions & 3 deletions src/lib/Behat/PageObject/AdminUpdateItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

class AdminUpdateItemPage extends Page
{
/** @var string Route under which the Page is available */
protected $route = '/admin/contenttypegroup';

/** @var string Name by which Page is recognised */
public const PAGE_NAME = 'Admin Item Update';

Expand All @@ -33,6 +30,8 @@ class AdminUpdateItemPage extends Page
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->siteAccess = 'admin';
$this->route = '/contenttypegroup';
$this->adminUpdateForm = ElementFactory::createElement($this->context, AdminUpdateForm::ELEMENT_NAME);
$this->rightMenu = ElementFactory::createElement($this->context, RightMenu::ELEMENT_NAME);
$this->pageTitle = 'Editing';
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ContentItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ContentItemPage extends Page
public function __construct(UtilityContext $context, string $contentName)
{
parent::__construct($context);
$this->route = '/admin/content/location';
$this->siteAccess = 'admin';
$this->route = '/content/location';
$this->rightMenu = ElementFactory::createElement($context, RightMenu::ELEMENT_NAME);
$this->subItemList = ElementFactory::createElement($context, SubItemsList::ELEMENT_NAME);
$this->contentField = ElementFactory::createElement($context, ContentField::ELEMENT_NAME);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ContentPreviewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ContentPreviewPage extends Page
public function __construct(UtilityContext $context, string $contentName)
{
parent::__construct($context);
$this->route = '/admin/content';
$this->siteAccess = 'admin';
$this->route = '/content';
$this->pageTitle = 'Previewing: ' . $contentName;
$this->pageTitleLocator = '.ez-preview__nav .ez-preview__item--description';
$this->previewNav = ElementFactory::createElement($context, PreviewNav::ELEMENT_NAME);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ContentTypeGroupPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ContentTypeGroupPage extends Page
public function __construct(UtilityContext $context, string $groupName)
{
parent::__construct($context);
$this->route = '/admin/contenttypegroup/';
$this->siteAccess = 'admin';
$this->route = '/contenttypegroup/';
$this->groupName = $groupName;
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, sprintf('Content Types in %s', $this->groupName), IconLinkedListTable::ELEMENT_NAME);
$this->pageTitle = $groupName;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ContentTypeGroupsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class ContentTypeGroupsPage extends Page
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->route = '/admin/contenttypegroup/list';
$this->siteAccess = 'admin';
$this->route = '/contenttypegroup/list';
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME, LinkedListTable::ELEMENT_NAME);
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ContentTypePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function __construct(UtilityContext $context, string $contentTypeName)
{
parent::__construct($context);
$this->groupName = $contentTypeName;
$this->route = '/admin/contenttypegroup/';
$this->siteAccess = 'admin';
$this->route = '/contenttypegroup/';

$this->contentTypeAdminList = ElementFactory::createElement(
$this->context,
Expand Down
5 changes: 2 additions & 3 deletions src/lib/Behat/PageObject/ContentUpdateItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

class ContentUpdateItemPage extends Page
{
/** @var string Route under which the Page is available */
protected $route = '/admin/content';

/** @var string Name by which Page is recognised */
public const PAGE_NAME = 'Content Update';

Expand All @@ -33,6 +30,8 @@ class ContentUpdateItemPage extends Page
public function __construct(UtilityContext $context, string $contentItemName)
{
parent::__construct($context);
$this->siteAccess = 'admin';
$this->route = '/content';
$this->contentUpdateForm = ElementFactory::createElement($this->context, ContentUpdateForm::ELEMENT_NAME);
$this->rightMenu = ElementFactory::createElement($this->context, RightMenu::ELEMENT_NAME);
$this->pageTitleLocator = '.ez-content-edit-container h1';
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/DashboardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class DashboardPage extends Page
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->route = '/admin/dashboard';
$this->siteAccess = 'admin';
$this->route = '/dashboard';
$this->fields = [
'tableSelector' => '.card-body',
'tableTitle' => '.mb-3',
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/LanguagePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function __construct(UtilityContext $context, string $languageName)
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME . ' information', SimpleTable::ELEMENT_NAME);
$this->languageName = $languageName;
$this->route = '/admin/language/view';
$this->siteAccess = 'admin';
$this->route = '/language/view';
$this->pageTitle = sprintf('Language "%s"', $languageName);
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/LanguagesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME, LinkedListTable::ELEMENT_NAME);
$this->route = '/admin/language/list';
$this->siteAccess = 'admin';
$this->route = '/language/list';
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
12 changes: 9 additions & 3 deletions src/lib/Behat/PageObject/LoginPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/
namespace EzSystems\EzPlatformAdminUi\Behat\PageObject;

use EzSystems\EzPlatformAdminUi\Behat\Helper\UtilityContext;

class LoginPage extends Page
{
/** @var string Route under which the Page is available */
protected $route = '/admin/login';

/** @var string Name by which Page is recognised */
public const PAGE_NAME = 'Login';

Expand All @@ -19,6 +18,13 @@ class LoginPage extends Page
'password' => '#password',
];

public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->siteAccess = 'admin';
$this->route = '/login';
}

/**
* Performs login action.
*
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ObjectStateGroupPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ObjectStateGroupPage extends Page
public function __construct(UtilityContext $context, string $objectStateGroupName)
{
parent::__construct($context);
$this->route = '/admin/state/group/';
$this->siteAccess = 'admin';
$this->route = '/state/group/';
$this->objectStateGroupName = $objectStateGroupName;
$this->adminLists['Object State Group Information'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Object State Group Information', SimpleTable::ELEMENT_NAME);
$this->adminLists['Object States'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Object States', LinkedListTable::ELEMENT_NAME, $this->secondListContainerLocator);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ObjectStateGroupsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME, LinkedListTable::ELEMENT_NAME);
$this->route = '/admin/state/groups';
$this->siteAccess = 'admin';
$this->route = '/state/groups';
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/ObjectStatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function __construct(UtilityContext $context, string $objectStateName)
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME . ' Information', SimpleTable::ELEMENT_NAME);
$this->objectStateName = $objectStateName;
$this->route = '/admin/state/state';
$this->siteAccess = 'admin';
$this->route = '/state/state';
$this->pageTitle = sprintf('Object State: %s', $objectStateName);
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
11 changes: 10 additions & 1 deletion src/lib/Behat/PageObject/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ abstract class Page
/** @var string Route under which the Page is available */
protected $route;

/** @var string SiteAccess name */
public $siteAccess;

/** @var string title that we see directly below upper menu */
protected $pageTitle;

Expand Down Expand Up @@ -50,7 +53,13 @@ public function verifyIsLoaded(): void
*/
public function open(bool $verifyIfLoaded = true): void
{
$this->context->visit($this->route);
if (isset($this->siteAccess)) {
$url = $this->context->reverseMatchRoute($this->siteAccess, $this->route);
} else {
$url = $this->route;
}

$this->context->visit($url);

if ($verifyIfLoaded) {
$this->verifyIsLoaded();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/RolePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class RolePage extends Page
public function __construct(UtilityContext $context, string $roleName)
{
parent::__construct($context);
$this->route = '/admin/role/';
$this->siteAccess = 'admin';
$this->route = '/role/';
$this->roleName = $roleName;
$this->adminLists['Policies'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Policies', SimpleListTable::ELEMENT_NAME, $this->activeAdminListContainerLocator);
$this->adminLists['Assignments'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Users and Groups', SimpleListTable::ELEMENT_NAME, $this->activeAdminListContainerLocator);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/RolesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME, LinkedListTable::ELEMENT_NAME);
$this->route = '/admin/role/list';
$this->siteAccess = 'admin';
$this->route = '/role/list';
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/SectionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class SectionPage extends Page
public function __construct(UtilityContext $context, string $sectionName)
{
parent::__construct($context);
$this->route = '/admin/section/view/';
$this->siteAccess = 'admin';
$this->route = '/section/view/';
$this->sectionName = $sectionName;
$this->adminLists['Section information'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Section information', SimpleTable::ELEMENT_NAME);
$this->adminLists['Content items'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Content items', SimpleTable::ELEMENT_NAME, $this->secondListContainerLocator);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/SectionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->adminList = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, self::PAGE_NAME, LinkedListTable::ELEMENT_NAME);
$this->route = '/admin/section/list';
$this->siteAccess = 'admin';
$this->route = '/section/list';
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/SystemInfoPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function __construct(UtilityContext $context)
$this->adminLists['Bundles'] = ElementFactory::createElement($this->context, AdminList::ELEMENT_NAME, 'Bundles', SimpleTable::ELEMENT_NAME, '.ez-main-container .tab-pane.active');
$this->systemInfoTable = ElementFactory::createElement($context, SystemInfoTable::ELEMENT_NAME, '.ez-main-container .tab-pane.active .ez-table--list');
$this->navLinkTabs = ElementFactory::createElement($context, NavLinkTabs::ELEMENT_NAME);
$this->route = '/admin/systeminfo';
$this->siteAccess = 'admin';
$this->route = '/systeminfo';
$this->pageTitle = self::PAGE_NAME;
$this->pageTitleLocator = '.ez-header h1';
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Behat/PageObject/TrashPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class TrashPage extends Page
public function __construct(UtilityContext $context)
{
parent::__construct($context);
$this->route = '/admin/trash/list';
$this->siteAccess = 'admin';
$this->route = '/trash/list';
$this->trashTable = ElementFactory::createElement($this->context, TrashTable::ELEMENT_NAME, $this::ITEM_RESTORE_LIST_CONTAINER);
$this->dialog = ElementFactory::createElement($this->context, Dialog::ELEMENT_NAME);
$this->pageTitle = 'Trash';
Expand Down

0 comments on commit 20b850c

Please sign in to comment.