Skip to content
Draft
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
11 changes: 11 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recipesEndpoint": "",
"packages": [
{
"requirement": "dev-IBX-11423_cant-delete-product-urlalias-for-translations as 4.6.x-dev",
"repositoryUrl": "https://github.com/ibexa/core",
"package": "ibexa/core",
"shouldBeAddedAsVCS": false
}
]
}
4 changes: 2 additions & 2 deletions src/lib/Server/Controller/URLAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
*/
public function loadURLAlias($urlAliasId)
{
return $this->urlAliasService->load($urlAliasId);
return $this->urlAliasService->load($urlAliasId, true);
}

/**
Expand Down Expand Up @@ -175,7 +175,7 @@ public function deleteURLAlias($urlAliasId)
{
$this->urlAliasService->removeAliases(
[
$this->urlAliasService->load($urlAliasId),
$this->urlAliasService->load($urlAliasId, true),
]
);

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/IbexaTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Ibexa\Contracts\Rest\UriParser\UriParserInterface;
use Ibexa\Contracts\Test\Core\IbexaTestKernel as CoreIbexaTestKernel;
use Ibexa\Rest\Server\Controller\Root as RestRootController;
use Ibexa\Rest\Server\Controller\URLAlias as URLAliasController;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -45,6 +46,7 @@ protected static function getExposedServicesByClass(): iterable
{
yield from parent::getExposedServicesByClass();
yield RestRootController::class;
yield URLAliasController::class;
yield UriParserInterface::class;
}

Expand Down
133 changes: 133 additions & 0 deletions tests/integration/Server/Controller/URLAliasTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

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

namespace Ibexa\Tests\Integration\Rest\Server\Controller;

use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\URLAliasService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias;
use Ibexa\Contracts\Test\Core\IbexaKernelTestCase;
use Ibexa\Rest\Server\Controller\URLAlias as URLAliasController;
use Ibexa\Rest\Server\Values\NoContent;

/**
* @covers \Ibexa\Rest\Server\Controller\URLAlias::deleteURLAlias
* @covers \Ibexa\Rest\Server\Controller\URLAlias::loadURLAlias
*/
final class URLAliasTest extends IbexaKernelTestCase
{
/**
* Language outside the prioritized languages configured for the test SiteAccess.
*/
private const NON_PRIORITIZED_LANGUAGE_CODE = 'nor-NO';

private const LOCATION_ID = 2;

protected function setUp(): void
{
parent::setUp();

$ibexaTestCore = $this->getIbexaTestCore();
$ibexaTestCore->loadSchema();
$ibexaTestCore->loadFixtures();
$ibexaTestCore->setAdministratorUser();
}

/**
* Regression test for IBX-11423: a custom URL alias created in a language which is not
* in the prioritized languages list must be removable via DELETE /content/urlaliases/{id}.
*/
public function testDeleteCustomUrlAliasInNonPrioritizedLanguage(): void
{
$location = $this->getIbexaTestCore()->getLocationService()->loadLocation(self::LOCATION_ID);
$urlAlias = $this->createCustomUrlAliasInNonPrioritizedLanguage($location);

self::assertContains(
$urlAlias->id,
$this->getCustomAliasIds($location),
'Sanity check: the custom URL alias should exist before removal.'
);

$controller = $this->getIbexaTestCore()->getServiceByClassName(URLAliasController::class);
$result = $controller->deleteURLAlias($urlAlias->id);

self::assertInstanceOf(NoContent::class, $result);
self::assertNotContains(
$urlAlias->id,
$this->getCustomAliasIds($location),
'The custom URL alias in a non-prioritized language should have been removed.'
);
}

/**
* Regression test for IBX-11423: a custom URL alias created in a language which is not
* in the prioritized languages list must be loadable via GET /content/urlaliases/{id}.
*/
public function testLoadCustomUrlAliasInNonPrioritizedLanguage(): void
{
$location = $this->getIbexaTestCore()->getLocationService()->loadLocation(self::LOCATION_ID);
$urlAlias = $this->createCustomUrlAliasInNonPrioritizedLanguage($location);

$controller = $this->getIbexaTestCore()->getServiceByClassName(URLAliasController::class);
$loadedUrlAlias = $controller->loadURLAlias($urlAlias->id);

self::assertSame($urlAlias->id, $loadedUrlAlias->id);
self::assertSame([self::NON_PRIORITIZED_LANGUAGE_CODE], $loadedUrlAlias->languageCodes);
}

private function createCustomUrlAliasInNonPrioritizedLanguage(Location $location): URLAlias
{
$this->ensureLanguageExists(self::NON_PRIORITIZED_LANGUAGE_CODE, 'Norwegian');

return $this->getURLAliasService()->createUrlAlias(
$location,
'/ibx-11423/norwegian-custom-alias',
self::NON_PRIORITIZED_LANGUAGE_CODE,
false,
false
);
}

/**
* Lists custom aliases in all languages, regardless of the prioritized languages.
*
* @return list<string>
*/
private function getCustomAliasIds(Location $location): array
{
$aliases = $this->getURLAliasService()->listLocationAliases($location, true, null, true);

return array_values(array_map(
static fn (URLAlias $alias): string => $alias->id,
is_array($aliases) ? $aliases : iterator_to_array($aliases)
));
}

private function ensureLanguageExists(
string $languageCode,
string $name
): void {
$languageService = $this->getIbexaTestCore()->getLanguageService();

try {
$languageService->loadLanguage($languageCode);
} catch (NotFoundException $e) {
$languageCreateStruct = $languageService->newLanguageCreateStruct();
$languageCreateStruct->languageCode = $languageCode;
$languageCreateStruct->name = $name;

$languageService->createLanguage($languageCreateStruct);
}
}

private function getURLAliasService(): URLAliasService
{
return $this->getIbexaTestCore()->getServiceByClassName(URLAliasService::class);
}
}