diff --git a/dependencies.json b/dependencies.json new file mode 100644 index 00000000..3ac6a616 --- /dev/null +++ b/dependencies.json @@ -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 + } + ] +} diff --git a/src/lib/Server/Controller/URLAlias.php b/src/lib/Server/Controller/URLAlias.php index 1b2f8385..6fb33760 100644 --- a/src/lib/Server/Controller/URLAlias.php +++ b/src/lib/Server/Controller/URLAlias.php @@ -62,7 +62,7 @@ public function __construct( */ public function loadURLAlias($urlAliasId) { - return $this->urlAliasService->load($urlAliasId); + return $this->urlAliasService->load($urlAliasId, true); } /** @@ -175,7 +175,7 @@ public function deleteURLAlias($urlAliasId) { $this->urlAliasService->removeAliases( [ - $this->urlAliasService->load($urlAliasId), + $this->urlAliasService->load($urlAliasId, true), ] ); diff --git a/tests/integration/IbexaTestKernel.php b/tests/integration/IbexaTestKernel.php index 41d2b1b8..9c6ae83d 100644 --- a/tests/integration/IbexaTestKernel.php +++ b/tests/integration/IbexaTestKernel.php @@ -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; @@ -45,6 +46,7 @@ protected static function getExposedServicesByClass(): iterable { yield from parent::getExposedServicesByClass(); yield RestRootController::class; + yield URLAliasController::class; yield UriParserInterface::class; } diff --git a/tests/integration/Server/Controller/URLAliasTest.php b/tests/integration/Server/Controller/URLAliasTest.php new file mode 100644 index 00000000..288e6063 --- /dev/null +++ b/tests/integration/Server/Controller/URLAliasTest.php @@ -0,0 +1,133 @@ +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 + */ + 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); + } +}