Skip to content

Commit e08c1fb

Browse files
barbaragrbarbaragr
andauthored
[Behat] IBX-9747: Added scenario for creating URL Alias (#1606)
* Added scenario for creating URL Alias * Fixed errors * Step definition reduction * After cs-fix * removed .idea * Fixes after phpstan * Fixed unclosed '{' * Removed test tag * After cs-fix * Added dependencies * Fixed dependencies * Fixed CSSLocator type * Removed comment * Fixes after fix-cs * Fixes after review * Added Timeout after review * Fix after review * Delete dependencies.json --------- Co-authored-by: barbaragr <barbara.grajczyk@ez.no>
1 parent 152ca4d commit e08c1fb

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
2+
Feature: UrlAliases
3+
4+
Background:
5+
Given I am logged as admin
6+
7+
Scenario: Create a redirect Url Alias
8+
Given a "folder" Content item named "UrlAliases" exists in root
9+
| name | short_name |
10+
| UrlAliases | UrlAliases |
11+
And I'm on Content view Page for "UrlAliases"
12+
And I switch to "URL" tab in Content structure
13+
When I create a new Url Alias called "RedirectUrlAlias" in "English (United Kingdom)" language with redirect value set to "true"
14+
Then there should be a "/redirecturlalias" Url Alias on the list with "Redirect" type
15+
16+
Scenario: Create a direct Url Alias
17+
Given a "folder" Content item named "UrlAliases" exists in root
18+
| name | short_name |
19+
| UrlAliases | UrlAliases |
20+
And I'm on Content view Page for "UrlAliases"
21+
And I switch to "URL" tab in Content structure
22+
When I create a new Url Alias called "DirectUrlAlias" in "English (United Kingdom)" language with redirect value set to "false"
23+
Then there should be a "/directurlalias" Url Alias on the list with "Direct" type

src/bundle/Resources/config/services/test/components.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ services:
6060

6161
Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~
6262

63+
Ibexa\AdminUi\Behat\Component\CreateUrlAliasModal: ~
64+
6365
Ibexa\AdminUi\Behat\Component\TrashSearch: ~
66+

src/lib/Behat/BrowserContext/ContentViewContext.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,24 @@ public function iShouldSeeAlertAppears(string $alertMessage): void
177177
$this->contentViewPage->verifyIsLoaded();
178178
$this->contentViewPage->verifyMessage($alertMessage);
179179
}
180+
181+
/**
182+
* @When I create a new Url Alias called :path in :languageName language with redirect value set to :redirect
183+
*/
184+
public function iCreateNewUrlAlias(string $path, string $languageName, string $redirect_string): void
185+
{
186+
$redirect = filter_var($redirect_string, FILTER_VALIDATE_BOOLEAN);
187+
$this->contentViewPage->createNewUrlAlias($path, $languageName, $redirect);
188+
}
189+
190+
/**
191+
* @Then there should be a :path Url Alias on the list with :type type
192+
*/
193+
public function verifyUrlAliasExists(string $path, string $type): void
194+
{
195+
Assert::assertTrue(
196+
$this->contentViewPage->isUrlAliasOnTheList($path, $type),
197+
sprintf('Url alias "%s" with type "%s" not found', $path, $type)
198+
);
199+
}
180200
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
8+
namespace Ibexa\AdminUi\Behat\Component;
9+
10+
use Behat\Mink\Session;
11+
use Ibexa\Behat\Browser\Component\Component;
12+
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
13+
14+
final class CreateUrlAliasModal extends Component
15+
{
16+
private IbexaDropdown $ibexaDropdown;
17+
18+
public function __construct(Session $session, IbexaDropdown $ibexaDropdown)
19+
{
20+
parent::__construct($session);
21+
$this->ibexaDropdown = $ibexaDropdown;
22+
}
23+
24+
public function verifyIsLoaded(): void
25+
{
26+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('title'))->assert()->textEquals('Create a new URL alias');
27+
}
28+
29+
public function createNewUrlAlias(string $path, string $languageName, bool $redirect): void
30+
{
31+
$this->getHTMLPage()->find($this->getLocator('pathInput'))->setValue($path);
32+
$this->getHTMLPage()->find($this->getLocator('languageDropdown'))->click();
33+
$this->ibexaDropdown->verifyIsLoaded();
34+
$this->ibexaDropdown->selectOption($languageName);
35+
$redirectToggleState = $this->getHTMLPage()->find($this->getLocator('redirectToggle'));
36+
if ($redirect !== $redirectToggleState->hasClass('ibexa-toggle--is-checked')) {
37+
$this->getHTMLPage()->find($this->getLocator('redirectToggle'))->click();
38+
}
39+
$this->getHTMLPage()->find($this->getLocator('createButton'))->click();
40+
}
41+
42+
protected function specifyLocators(): array
43+
{
44+
return [
45+
new VisibleCSSLocator('title', '#ibexa-modal--custom-url-alias .modal-title'),
46+
new VisibleCSSLocator('createButton', '#custom_url_add_add'),
47+
new VisibleCSSLocator('pathInput', '#custom_url_add_path'),
48+
new VisibleCSSLocator('languageDropdown', '.ibexa-custom-url-from__item .ibexa-dropdown__selection-info'),
49+
new VisibleCSSLocator('redirectToggle', '.ibexa-custom-url-from__item .ibexa-toggle'),
50+
];
51+
}
52+
}

src/lib/Behat/Page/ContentViewPage.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
use Ibexa\AdminUi\Behat\Component\ContentActionsMenu;
1414
use Ibexa\AdminUi\Behat\Component\ContentItemAdminPreview;
1515
use Ibexa\AdminUi\Behat\Component\ContentTypePicker;
16+
use Ibexa\AdminUi\Behat\Component\CreateUrlAliasModal;
1617
use Ibexa\AdminUi\Behat\Component\DeleteContentDialog;
1718
use Ibexa\AdminUi\Behat\Component\Dialog;
1819
use Ibexa\AdminUi\Behat\Component\IbexaDropdown;
1920
use Ibexa\AdminUi\Behat\Component\LanguagePicker;
2021
use Ibexa\AdminUi\Behat\Component\SubItemsList;
22+
use Ibexa\AdminUi\Behat\Component\Table\TableBuilder;
2123
use Ibexa\AdminUi\Behat\Component\TranslationDialog;
2224
use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget;
2325
use Ibexa\AdminUi\Behat\Component\UpperMenu;
@@ -85,6 +87,10 @@ class ContentViewPage extends Page
8587

8688
private DeleteContentDialog $deleteContentDialog;
8789

90+
private CreateUrlAliasModal $createUrlAliasModal;
91+
92+
private TableBuilder $tableBuilder;
93+
8894
public function __construct(
8995
Session $session,
9096
Router $router,
@@ -101,9 +107,12 @@ public function __construct(
101107
UniversalDiscoveryWidget $universalDiscoveryWidget,
102108
IbexaDropdown $ibexaDropdown,
103109
UpperMenu $upperMenu,
104-
DeleteContentDialog $deleteContentDialog
110+
DeleteContentDialog $deleteContentDialog,
111+
CreateUrlAliasModal $createUrlAliasModal,
112+
TableBuilder $tableBuilder
105113
) {
106114
parent::__construct($session, $router);
115+
107116
$this->contentActionsMenu = $contentActionsMenu;
108117
$this->subItemList = $subItemList;
109118
$this->contentTypePicker = $contentTypePicker;
@@ -118,6 +127,8 @@ public function __construct(
118127
$this->ibexaDropdown = $ibexaDropdown;
119128
$this->upperMenu = $upperMenu;
120129
$this->deleteContentDialog = $deleteContentDialog;
130+
$this->createUrlAliasModal = $createUrlAliasModal;
131+
$this->tableBuilder = $tableBuilder;
121132
}
122133

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

308+
public function createNewUrlAlias(string $path, string $languageName, bool $redirect): void
309+
{
310+
$this->getHTMLPage()->find($this->getLocator('addUrlAliasButton'))->click();
311+
$this->createUrlAliasModal->createNewUrlAlias($path, $languageName, $redirect);
312+
}
313+
314+
public function isUrlAliasOnTheList(string $path, string $type): bool
315+
{
316+
/** @var \Ibexa\Behat\Browser\Locator\CSSLocator $locator */
317+
$locator = $this->getLocator('customUrlAliasesTable');
318+
$customUrlAliasesTable = $this->tableBuilder->newTable()->withParentLocator($locator)->build();
319+
320+
return $customUrlAliasesTable->hasElement(['URL' => $path, 'Type' => $type]);
321+
}
322+
297323
protected function specifyLocators(): array
298324
{
299325
return [
@@ -308,6 +334,8 @@ protected function specifyLocators(): array
308334
new VisibleCSSLocator('ibexaDropdownPreview', '.ibexa-raw-content-title__language-form .ibexa-dropdown__selection-info'),
309335
new VisibleCSSLocator('moreTab', '.ibexa-tabs__tab--more'),
310336
new VisibleCSSLocator('popupMenuItem', '.ibexa-popup-menu__item .ibexa-popup-menu__item-content'),
337+
new VisibleCSSLocator('addUrlAliasButton', '#ibexa-tab-location-view-urls [data-bs-target="#ibexa-modal--custom-url-alias"]'),
338+
new VisibleCSSLocator('customUrlAliasesTable', '#ibexa-tab-location-view-urls .ibexa-table'),
311339
new VisibleCSSLocator('alertTitle', '.ibexa-alert__title'),
312340
];
313341
}

0 commit comments

Comments
 (0)