Skip to content
Merged
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
23 changes: 23 additions & 0 deletions features/standard/UrlAliases.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
Feature: UrlAliases

Background:
Given I am logged as admin

Scenario: Create a redirect Url Alias
Given a "folder" Content item named "UrlAliases" exists in root
| name | short_name |
| UrlAliases | UrlAliases |
And I'm on Content view Page for "UrlAliases"
And I switch to "URL" tab in Content structure
When I create a new Url Alias called "RedirectUrlAlias" in "English (United Kingdom)" language with redirect value set to "true"
Then there should be a "/redirecturlalias" Url Alias on the list with "Redirect" type

Scenario: Create a direct Url Alias
Given a "folder" Content item named "UrlAliases" exists in root
| name | short_name |
| UrlAliases | UrlAliases |
And I'm on Content view Page for "UrlAliases"
And I switch to "URL" tab in Content structure
When I create a new Url Alias called "DirectUrlAlias" in "English (United Kingdom)" language with redirect value set to "false"
Then there should be a "/directurlalias" Url Alias on the list with "Direct" type
3 changes: 3 additions & 0 deletions src/bundle/Resources/config/services/test/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ services:

Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~

Ibexa\AdminUi\Behat\Component\CreateUrlAliasModal: ~

Ibexa\AdminUi\Behat\Component\TrashSearch: ~

20 changes: 20 additions & 0 deletions src/lib/Behat/BrowserContext/ContentViewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,24 @@ public function iShouldSeeAlertAppears(string $alertMessage): void
$this->contentViewPage->verifyIsLoaded();
$this->contentViewPage->verifyMessage($alertMessage);
}

/**
* @When I create a new Url Alias called :path in :languageName language with redirect value set to :redirect
*/
public function iCreateNewUrlAlias(string $path, string $languageName, string $redirect_string): void
{
$redirect = filter_var($redirect_string, FILTER_VALIDATE_BOOLEAN);
$this->contentViewPage->createNewUrlAlias($path, $languageName, $redirect);
}

/**
* @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)
);
}
}
52 changes: 52 additions & 0 deletions src/lib/Behat/Component/CreateUrlAliasModal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace Ibexa\AdminUi\Behat\Component;

use Behat\Mink\Session;
use Ibexa\Behat\Browser\Component\Component;
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;

final class CreateUrlAliasModal extends Component
{
private IbexaDropdown $ibexaDropdown;

public function __construct(Session $session, IbexaDropdown $ibexaDropdown)
{
parent::__construct($session);
$this->ibexaDropdown = $ibexaDropdown;
}

public function verifyIsLoaded(): void
{
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('title'))->assert()->textEquals('Create a new URL alias');
}

public function createNewUrlAlias(string $path, string $languageName, bool $redirect): void
{
$this->getHTMLPage()->find($this->getLocator('pathInput'))->setValue($path);
$this->getHTMLPage()->find($this->getLocator('languageDropdown'))->click();
$this->ibexaDropdown->verifyIsLoaded();
$this->ibexaDropdown->selectOption($languageName);
$redirectToggleState = $this->getHTMLPage()->find($this->getLocator('redirectToggle'));
if ($redirect !== $redirectToggleState->hasClass('ibexa-toggle--is-checked')) {
$this->getHTMLPage()->find($this->getLocator('redirectToggle'))->click();
}
$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'),
new VisibleCSSLocator('redirectToggle', '.ibexa-custom-url-from__item .ibexa-toggle'),
];
}
}
30 changes: 29 additions & 1 deletion src/lib/Behat/Page/ContentViewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\CreateUrlAliasModal;
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;
Expand Down Expand Up @@ -85,6 +87,10 @@ class ContentViewPage extends Page

private DeleteContentDialog $deleteContentDialog;

private CreateUrlAliasModal $createUrlAliasModal;

private TableBuilder $tableBuilder;

public function __construct(
Session $session,
Router $router,
Expand All @@ -101,9 +107,12 @@ public function __construct(
UniversalDiscoveryWidget $universalDiscoveryWidget,
IbexaDropdown $ibexaDropdown,
UpperMenu $upperMenu,
DeleteContentDialog $deleteContentDialog
DeleteContentDialog $deleteContentDialog,
CreateUrlAliasModal $createUrlAliasModal,
TableBuilder $tableBuilder
) {
parent::__construct($session, $router);

$this->contentActionsMenu = $contentActionsMenu;
$this->subItemList = $subItemList;
$this->contentTypePicker = $contentTypePicker;
Expand All @@ -118,6 +127,8 @@ public function __construct(
$this->ibexaDropdown = $ibexaDropdown;
$this->upperMenu = $upperMenu;
$this->deleteContentDialog = $deleteContentDialog;
$this->createUrlAliasModal = $createUrlAliasModal;
$this->tableBuilder = $tableBuilder;
}

public function startCreatingContent(string $contentTypeName, ?string $language = null)
Expand Down Expand Up @@ -294,6 +305,21 @@ public function isBookmarked(): bool
return $this->getHTMLPage()->find($this->getLocator('isBookmarked'))->isVisible();
}

public function createNewUrlAlias(string $path, string $languageName, bool $redirect): void
{
$this->getHTMLPage()->find($this->getLocator('addUrlAliasButton'))->click();
$this->createUrlAliasModal->createNewUrlAlias($path, $languageName, $redirect);
}

public function isUrlAliasOnTheList(string $path, string $type): bool
{
/** @var \Ibexa\Behat\Browser\Locator\CSSLocator $locator */
$locator = $this->getLocator('customUrlAliasesTable');
$customUrlAliasesTable = $this->tableBuilder->newTable()->withParentLocator($locator)->build();

return $customUrlAliasesTable->hasElement(['URL' => $path, 'Type' => $type]);
}

protected function specifyLocators(): array
{
return [
Expand All @@ -308,6 +334,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'),
new VisibleCSSLocator('alertTitle', '.ibexa-alert__title'),
];
}
Expand Down
Loading