Skip to content

Commit 2006057

Browse files
barbaragrbarbaragr
authored andcommitted
Added scenario for creating URL Alias
1 parent 74ba24d commit 2006057

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

features/standard/UrlAliases.feature

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
2+
Feature: UrlAliases
3+
4+
Background:
5+
Given I am logged as admin
6+
7+
@test
8+
Scenario: Create an Url Alias
9+
Given a "folder" Content item named "UrlAliases" exists in root
10+
| name | short_name |
11+
| UrlAliases | UrlAliases |
12+
Given I'm on Content view Page for "UrlAliases"
13+
When I switch to "URL" tab in Content structure
14+
And I create a new direct Url Alias called "TestUrlAlias" in "English (United Kingdom)" language
15+
Then there should be a "/testurlalias" 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
@@ -59,3 +59,6 @@ services:
5959
Ibexa\AdminUi\Behat\Component\FullView: ~
6060

6161
Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~
62+
63+
Ibexa\AdminUi\Behat\Component\CreateUrlAliasForm: ~
64+

src/lib/Behat/BrowserContext/ContentViewContext.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,23 @@ public function iSendContentToTrash(): void
168168
{
169169
$this->contentViewPage->sendToTrash();
170170
}
171+
172+
/**
173+
* @When I create a new direct Url Alias called :path in :languageName language
174+
*/
175+
public function iCreateNewUrlAlias(string $path, string $languageName): void
176+
{
177+
$this->contentViewPage->createNewDirectUrlAlias($path, $languageName, false);
178+
}
179+
180+
/**
181+
* @Then there should be a :path Url Alias on the list with :type type
182+
*/
183+
public function verifyUrlAliasExists(string $path, string $type): void
184+
{
185+
Assert::assertTrue(
186+
$this->contentViewPage->isUrlAliasOnTheList($path, $type),
187+
sprintf('Url alias "%s" with type "%s" not found', $path, $type)
188+
);
189+
}
171190
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 CreateUrlAliasForm extends Component
15+
{
16+
use \Ibexa\Behat\Core\Debug\InteractiveDebuggerTrait;
17+
18+
private IbexaDropdown $ibexaDropdown;
19+
20+
public function __construct(Session $session, IbexaDropdown $ibexaDropdown)
21+
{
22+
parent::__construct($session);
23+
$this->ibexaDropdown = $ibexaDropdown;
24+
}
25+
26+
public function verifyIsLoaded(): void
27+
{
28+
$this->getHTMLPage()->find($this->getLocator('title'))->assert()->textEquals('Create a new URL alias');
29+
}
30+
31+
public function createNewUrlAlias(string $path, string $languageName, bool $isRedirecting): void
32+
{
33+
$this->getHTMLPage()->find($this->getLocator('pathInput'))->setValue($path);
34+
$this->getHTMLPage()->find($this->getLocator('languageDropdown'))->click();
35+
$this->ibexaDropdown->verifyIsLoaded();
36+
$this->ibexaDropdown->selectOption($languageName);
37+
$this->getHTMLPage()->find($this->getLocator('createButton'))->click();
38+
}
39+
40+
protected function specifyLocators(): array
41+
{
42+
return [
43+
new VisibleCSSLocator('title', '#ibexa-modal--custom-url-alias .modal-title'),
44+
new VisibleCSSLocator('createButton', '#custom_url_add_add'),
45+
new VisibleCSSLocator('pathInput', '#custom_url_add_path'),
46+
new VisibleCSSLocator('languageDropdown', '.ibexa-custom-url-from__item .ibexa-dropdown__selection-info'),
47+
];
48+
}
49+
}

src/lib/Behat/Page/ContentViewPage.php

Lines changed: 26 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\CreateUrlAliasForm;
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 CreateUrlAliasForm $createUrlAliasForm;
91+
92+
private TableBuilder $tableBuilder;
93+
8894
public function __construct(
8995
Session $session,
9096
Router $router,
@@ -101,7 +107,9 @@ public function __construct(
101107
UniversalDiscoveryWidget $universalDiscoveryWidget,
102108
IbexaDropdown $ibexaDropdown,
103109
UpperMenu $upperMenu,
104-
DeleteContentDialog $deleteContentDialog
110+
DeleteContentDialog $deleteContentDialog,
111+
CreateUrlAliasForm $createUrlAliasForm,
112+
TableBuilder $tableBuilder
105113
) {
106114
parent::__construct($session, $router);
107115
$this->contentActionsMenu = $contentActionsMenu;
@@ -118,6 +126,8 @@ public function __construct(
118126
$this->ibexaDropdown = $ibexaDropdown;
119127
$this->upperMenu = $upperMenu;
120128
$this->deleteContentDialog = $deleteContentDialog;
129+
$this->createUrlAliasForm = $createUrlAliasForm;
130+
$this->tableBuilder = $tableBuilder;
121131
}
122132

123133
public function startCreatingContent(string $contentTypeName, ?string $language = null)
@@ -294,6 +304,19 @@ public function isBookmarked(): bool
294304
return $this->getHTMLPage()->find($this->getLocator('isBookmarked'))->isVisible();
295305
}
296306

307+
public function createNewDirectUrlAlias(string $path, string $languageName, bool $isRedirecting): void
308+
{
309+
$this->getHTMLPage()->find($this->getLocator('addUrlAliasButton'))->click();
310+
$this->createUrlAliasForm->createNewUrlAlias($path, $languageName, $isRedirecting);
311+
}
312+
313+
public function isUrlAliasOnTheList(string $path, string $type): bool
314+
{
315+
$customUrlAliasesTable = $this->tableBuilder->newTable()->withParentLocator($this->getLocator('customUrlAliasesTable'))->build();
316+
317+
return $customUrlAliasesTable->hasElement(['URL' => $path, 'Type' => $type]);
318+
}
319+
297320
protected function specifyLocators(): array
298321
{
299322
return [
@@ -308,6 +331,8 @@ protected function specifyLocators(): array
308331
new VisibleCSSLocator('ibexaDropdownPreview', '.ibexa-raw-content-title__language-form .ibexa-dropdown__selection-info'),
309332
new VisibleCSSLocator('moreTab', '.ibexa-tabs__tab--more'),
310333
new VisibleCSSLocator('popupMenuItem', '.ibexa-popup-menu__item .ibexa-popup-menu__item-content'),
334+
new VisibleCSSLocator('addUrlAliasButton', '#ibexa-tab-location-view-urls [data-bs-target="#ibexa-modal--custom-url-alias"]'),
335+
new VisibleCSSLocator('customUrlAliasesTable', '#ibexa-tab-location-view-urls .ibexa-table'),
311336
];
312337
}
313338

0 commit comments

Comments
 (0)