From e158c2e664d72fd35541122ff0920b21829702c7 Mon Sep 17 00:00:00 2001 From: m-tyrala Date: Fri, 29 Nov 2019 16:21:26 +0100 Subject: [PATCH] EZP-29112 Implement scenarios for Studio site access matching --- src/lib/Behat/Helper/UtilityContext.php | 32 +++++++++++++++++++ .../Behat/PageObject/AdminUpdateItemPage.php | 5 ++- src/lib/Behat/PageObject/ContentItemPage.php | 3 +- .../Behat/PageObject/ContentPreviewPage.php | 3 +- .../Behat/PageObject/ContentTypeGroupPage.php | 3 +- .../PageObject/ContentTypeGroupsPage.php | 3 +- src/lib/Behat/PageObject/ContentTypePage.php | 3 +- .../PageObject/ContentUpdateItemPage.php | 5 ++- src/lib/Behat/PageObject/DashboardPage.php | 3 +- src/lib/Behat/PageObject/LanguagePage.php | 3 +- src/lib/Behat/PageObject/LanguagesPage.php | 3 +- src/lib/Behat/PageObject/LoginPage.php | 12 +++++-- .../Behat/PageObject/ObjectStateGroupPage.php | 3 +- .../PageObject/ObjectStateGroupsPage.php | 3 +- src/lib/Behat/PageObject/ObjectStatePage.php | 3 +- src/lib/Behat/PageObject/Page.php | 11 ++++++- src/lib/Behat/PageObject/RolePage.php | 3 +- src/lib/Behat/PageObject/RolesPage.php | 3 +- src/lib/Behat/PageObject/SectionPage.php | 3 +- src/lib/Behat/PageObject/SectionsPage.php | 3 +- src/lib/Behat/PageObject/SystemInfoPage.php | 3 +- src/lib/Behat/PageObject/TrashPage.php | 3 +- 22 files changed, 89 insertions(+), 27 deletions(-) diff --git a/src/lib/Behat/Helper/UtilityContext.php b/src/lib/Behat/Helper/UtilityContext.php index 022b9a9d2e..de66e4fad1 100644 --- a/src/lib/Behat/Helper/UtilityContext.php +++ b/src/lib/Behat/Helper/UtilityContext.php @@ -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. * diff --git a/src/lib/Behat/PageObject/AdminUpdateItemPage.php b/src/lib/Behat/PageObject/AdminUpdateItemPage.php index 2273b11abb..af6ec08739 100644 --- a/src/lib/Behat/PageObject/AdminUpdateItemPage.php +++ b/src/lib/Behat/PageObject/AdminUpdateItemPage.php @@ -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'; @@ -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'; diff --git a/src/lib/Behat/PageObject/ContentItemPage.php b/src/lib/Behat/PageObject/ContentItemPage.php index f9f672a9ea..fde085675b 100644 --- a/src/lib/Behat/PageObject/ContentItemPage.php +++ b/src/lib/Behat/PageObject/ContentItemPage.php @@ -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); diff --git a/src/lib/Behat/PageObject/ContentPreviewPage.php b/src/lib/Behat/PageObject/ContentPreviewPage.php index 285510b6f6..0023a0dd07 100644 --- a/src/lib/Behat/PageObject/ContentPreviewPage.php +++ b/src/lib/Behat/PageObject/ContentPreviewPage.php @@ -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); diff --git a/src/lib/Behat/PageObject/ContentTypeGroupPage.php b/src/lib/Behat/PageObject/ContentTypeGroupPage.php index 62ad12b766..5b27f283ba 100644 --- a/src/lib/Behat/PageObject/ContentTypeGroupPage.php +++ b/src/lib/Behat/PageObject/ContentTypeGroupPage.php @@ -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; diff --git a/src/lib/Behat/PageObject/ContentTypeGroupsPage.php b/src/lib/Behat/PageObject/ContentTypeGroupsPage.php index 36f2aef7a3..57cc095345 100644 --- a/src/lib/Behat/PageObject/ContentTypeGroupsPage.php +++ b/src/lib/Behat/PageObject/ContentTypeGroupsPage.php @@ -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'; diff --git a/src/lib/Behat/PageObject/ContentTypePage.php b/src/lib/Behat/PageObject/ContentTypePage.php index a6fbea0370..9cb22cb9e0 100644 --- a/src/lib/Behat/PageObject/ContentTypePage.php +++ b/src/lib/Behat/PageObject/ContentTypePage.php @@ -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, diff --git a/src/lib/Behat/PageObject/ContentUpdateItemPage.php b/src/lib/Behat/PageObject/ContentUpdateItemPage.php index c53432bb4f..d2c8d32eb2 100644 --- a/src/lib/Behat/PageObject/ContentUpdateItemPage.php +++ b/src/lib/Behat/PageObject/ContentUpdateItemPage.php @@ -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'; @@ -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'; diff --git a/src/lib/Behat/PageObject/DashboardPage.php b/src/lib/Behat/PageObject/DashboardPage.php index ad2d62ce35..5c2a9ecbc3 100644 --- a/src/lib/Behat/PageObject/DashboardPage.php +++ b/src/lib/Behat/PageObject/DashboardPage.php @@ -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', diff --git a/src/lib/Behat/PageObject/LanguagePage.php b/src/lib/Behat/PageObject/LanguagePage.php index af74078a75..d51079aa6f 100644 --- a/src/lib/Behat/PageObject/LanguagePage.php +++ b/src/lib/Behat/PageObject/LanguagePage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/LanguagesPage.php b/src/lib/Behat/PageObject/LanguagesPage.php index 1ccd35ac20..d727a069a4 100644 --- a/src/lib/Behat/PageObject/LanguagesPage.php +++ b/src/lib/Behat/PageObject/LanguagesPage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/LoginPage.php b/src/lib/Behat/PageObject/LoginPage.php index 52e86fa205..8b435e41a4 100644 --- a/src/lib/Behat/PageObject/LoginPage.php +++ b/src/lib/Behat/PageObject/LoginPage.php @@ -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'; @@ -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. * diff --git a/src/lib/Behat/PageObject/ObjectStateGroupPage.php b/src/lib/Behat/PageObject/ObjectStateGroupPage.php index 71a435feac..ae1a200de0 100644 --- a/src/lib/Behat/PageObject/ObjectStateGroupPage.php +++ b/src/lib/Behat/PageObject/ObjectStateGroupPage.php @@ -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); diff --git a/src/lib/Behat/PageObject/ObjectStateGroupsPage.php b/src/lib/Behat/PageObject/ObjectStateGroupsPage.php index 9516a06479..0fe8d4e5b0 100644 --- a/src/lib/Behat/PageObject/ObjectStateGroupsPage.php +++ b/src/lib/Behat/PageObject/ObjectStateGroupsPage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/ObjectStatePage.php b/src/lib/Behat/PageObject/ObjectStatePage.php index a52165b567..f5fb45656b 100644 --- a/src/lib/Behat/PageObject/ObjectStatePage.php +++ b/src/lib/Behat/PageObject/ObjectStatePage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/Page.php b/src/lib/Behat/PageObject/Page.php index b58174da62..96bd9f712f 100644 --- a/src/lib/Behat/PageObject/Page.php +++ b/src/lib/Behat/PageObject/Page.php @@ -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; @@ -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(); diff --git a/src/lib/Behat/PageObject/RolePage.php b/src/lib/Behat/PageObject/RolePage.php index 58d62e65b3..6e17dcd845 100644 --- a/src/lib/Behat/PageObject/RolePage.php +++ b/src/lib/Behat/PageObject/RolePage.php @@ -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); diff --git a/src/lib/Behat/PageObject/RolesPage.php b/src/lib/Behat/PageObject/RolesPage.php index e81e36f1a0..a34a3cee69 100644 --- a/src/lib/Behat/PageObject/RolesPage.php +++ b/src/lib/Behat/PageObject/RolesPage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/SectionPage.php b/src/lib/Behat/PageObject/SectionPage.php index f49bccc271..7e48b3252e 100644 --- a/src/lib/Behat/PageObject/SectionPage.php +++ b/src/lib/Behat/PageObject/SectionPage.php @@ -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); diff --git a/src/lib/Behat/PageObject/SectionsPage.php b/src/lib/Behat/PageObject/SectionsPage.php index 56f60ae92c..b98b0e9416 100644 --- a/src/lib/Behat/PageObject/SectionsPage.php +++ b/src/lib/Behat/PageObject/SectionsPage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/SystemInfoPage.php b/src/lib/Behat/PageObject/SystemInfoPage.php index 0153923dd3..ef089958f9 100644 --- a/src/lib/Behat/PageObject/SystemInfoPage.php +++ b/src/lib/Behat/PageObject/SystemInfoPage.php @@ -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'; } diff --git a/src/lib/Behat/PageObject/TrashPage.php b/src/lib/Behat/PageObject/TrashPage.php index 61f7da6656..eba6790083 100644 --- a/src/lib/Behat/PageObject/TrashPage.php +++ b/src/lib/Behat/PageObject/TrashPage.php @@ -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';