diff --git a/features/standard/UrlAliases.feature b/features/standard/UrlAliases.feature new file mode 100644 index 0000000000..0a811f187c --- /dev/null +++ b/features/standard/UrlAliases.feature @@ -0,0 +1,15 @@ +@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript +Feature: UrlAliases + + Background: + Given I am logged as admin + + @test + Scenario: Create an Url Alias + Given a "folder" Content item named "UrlAliases" exists in root + | name | short_name | + | UrlAliases | UrlAliases | + Given I'm on Content view Page for "UrlAliases" + When I switch to "URL" tab in Content structure + And I create a new direct Url Alias called "TestUrlAlias" in "English (United Kingdom)" language + Then there should be a "/testurlalias" Url Alias on the list with "Direct" type \ No newline at end of file diff --git a/src/bundle/Resources/config/services/test/components.yaml b/src/bundle/Resources/config/services/test/components.yaml index 101c17fbdf..b1dafa1df0 100644 --- a/src/bundle/Resources/config/services/test/components.yaml +++ b/src/bundle/Resources/config/services/test/components.yaml @@ -59,3 +59,6 @@ services: Ibexa\AdminUi\Behat\Component\FullView: ~ Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~ + + Ibexa\AdminUi\Behat\Component\CreateUrlAliasForm: ~ + diff --git a/src/lib/Behat/BrowserContext/ContentViewContext.php b/src/lib/Behat/BrowserContext/ContentViewContext.php index 69b4303f38..42c4eb9214 100644 --- a/src/lib/Behat/BrowserContext/ContentViewContext.php +++ b/src/lib/Behat/BrowserContext/ContentViewContext.php @@ -168,4 +168,23 @@ public function iSendContentToTrash(): void { $this->contentViewPage->sendToTrash(); } + + /** + * @When I create a new direct Url Alias called :path in :languageName language + */ + public function iCreateNewUrlAlias(string $path, string $languageName): void + { + $this->contentViewPage->createNewDirectUrlAlias($path, $languageName, false); + } + + /** + * @Then there should be a :path Url Alias on the list with :type type + */ + public function verifyUrlAliasExists(string $path, string $type): void + { + Assert::assertTrue( + $this->contentViewPage->isUrlAliasOnTheList($path, $type), + sprintf('Url alias "%s" with type "%s" not found', $path, $type) + ); + } } diff --git a/src/lib/Behat/Component/CreateUrlAliasForm.php b/src/lib/Behat/Component/CreateUrlAliasForm.php new file mode 100644 index 0000000000..f217c844d0 --- /dev/null +++ b/src/lib/Behat/Component/CreateUrlAliasForm.php @@ -0,0 +1,49 @@ +ibexaDropdown = $ibexaDropdown; + } + + public function verifyIsLoaded(): void + { + $this->getHTMLPage()->find($this->getLocator('title'))->assert()->textEquals('Create a new URL alias'); + } + + public function createNewUrlAlias(string $path, string $languageName, bool $isRedirecting): void + { + $this->getHTMLPage()->find($this->getLocator('pathInput'))->setValue($path); + $this->getHTMLPage()->find($this->getLocator('languageDropdown'))->click(); + $this->ibexaDropdown->verifyIsLoaded(); + $this->ibexaDropdown->selectOption($languageName); + $this->getHTMLPage()->find($this->getLocator('createButton'))->click(); + } + + protected function specifyLocators(): array + { + return [ + new VisibleCSSLocator('title', '#ibexa-modal--custom-url-alias .modal-title'), + new VisibleCSSLocator('createButton', '#custom_url_add_add'), + new VisibleCSSLocator('pathInput', '#custom_url_add_path'), + new VisibleCSSLocator('languageDropdown', '.ibexa-custom-url-from__item .ibexa-dropdown__selection-info'), + ]; + } +} diff --git a/src/lib/Behat/Page/ContentViewPage.php b/src/lib/Behat/Page/ContentViewPage.php index 52fe1183e0..f7dd411e75 100644 --- a/src/lib/Behat/Page/ContentViewPage.php +++ b/src/lib/Behat/Page/ContentViewPage.php @@ -13,11 +13,13 @@ use Ibexa\AdminUi\Behat\Component\ContentActionsMenu; use Ibexa\AdminUi\Behat\Component\ContentItemAdminPreview; use Ibexa\AdminUi\Behat\Component\ContentTypePicker; +use Ibexa\AdminUi\Behat\Component\CreateUrlAliasForm; use Ibexa\AdminUi\Behat\Component\DeleteContentDialog; use Ibexa\AdminUi\Behat\Component\Dialog; use Ibexa\AdminUi\Behat\Component\IbexaDropdown; use Ibexa\AdminUi\Behat\Component\LanguagePicker; use Ibexa\AdminUi\Behat\Component\SubItemsList; +use Ibexa\AdminUi\Behat\Component\Table\TableBuilder; use Ibexa\AdminUi\Behat\Component\TranslationDialog; use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget; use Ibexa\AdminUi\Behat\Component\UpperMenu; @@ -85,6 +87,10 @@ class ContentViewPage extends Page private DeleteContentDialog $deleteContentDialog; + private CreateUrlAliasForm $createUrlAliasForm; + + private TableBuilder $tableBuilder; + public function __construct( Session $session, Router $router, @@ -101,7 +107,9 @@ public function __construct( UniversalDiscoveryWidget $universalDiscoveryWidget, IbexaDropdown $ibexaDropdown, UpperMenu $upperMenu, - DeleteContentDialog $deleteContentDialog + DeleteContentDialog $deleteContentDialog, + CreateUrlAliasForm $createUrlAliasForm, + TableBuilder $tableBuilder ) { parent::__construct($session, $router); $this->contentActionsMenu = $contentActionsMenu; @@ -118,6 +126,8 @@ public function __construct( $this->ibexaDropdown = $ibexaDropdown; $this->upperMenu = $upperMenu; $this->deleteContentDialog = $deleteContentDialog; + $this->createUrlAliasForm = $createUrlAliasForm; + $this->tableBuilder = $tableBuilder; } public function startCreatingContent(string $contentTypeName, ?string $language = null) @@ -294,6 +304,19 @@ public function isBookmarked(): bool return $this->getHTMLPage()->find($this->getLocator('isBookmarked'))->isVisible(); } + public function createNewDirectUrlAlias(string $path, string $languageName, bool $isRedirecting): void + { + $this->getHTMLPage()->find($this->getLocator('addUrlAliasButton'))->click(); + $this->createUrlAliasForm->createNewUrlAlias($path, $languageName, $isRedirecting); + } + + public function isUrlAliasOnTheList(string $path, string $type): bool + { + $customUrlAliasesTable = $this->tableBuilder->newTable()->withParentLocator($this->getLocator('customUrlAliasesTable'))->build(); + + return $customUrlAliasesTable->hasElement(['URL' => $path, 'Type' => $type]); + } + protected function specifyLocators(): array { return [ @@ -308,6 +331,8 @@ protected function specifyLocators(): array new VisibleCSSLocator('ibexaDropdownPreview', '.ibexa-raw-content-title__language-form .ibexa-dropdown__selection-info'), new VisibleCSSLocator('moreTab', '.ibexa-tabs__tab--more'), new VisibleCSSLocator('popupMenuItem', '.ibexa-popup-menu__item .ibexa-popup-menu__item-content'), + new VisibleCSSLocator('addUrlAliasButton', '#ibexa-tab-location-view-urls [data-bs-target="#ibexa-modal--custom-url-alias"]'), + new VisibleCSSLocator('customUrlAliasesTable', '#ibexa-tab-location-view-urls .ibexa-table'), ]; }