Skip to content

Commit

Permalink
IBX-3957: Added an integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 13, 2023
1 parent df28106 commit 2b9b4b7
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,57 @@ public function testDeleteCorruptedUrlAliases()
);
}

public function testRenamingParentContentDoesntBreakChildAlias(): void
{
$repository = $this->getRepository();
$locationService = $repository->getLocationService();
$urlAliasService = $repository->getURLAliasService();
$contentTypeService = $repository->getContentTypeService();
$contentService = $repository->getContentService();

$languageCode = 'eng-GB';
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder');

// 1. Create parent folder
$folderCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode);
$folderCreateStruct->setField('name', 'A');
$folderDraft = $contentService->createContent($folderCreateStruct, [
$locationService->newLocationCreateStruct(2),
]);
$folder = $contentService->publishVersion($folderDraft->getVersionInfo());
$folderLocation = $locationService->loadLocation($folder->contentInfo->getMainLocationId());

// 2. Create child folder
$childCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode);
$childCreateStruct->setField('title', 'B');
$childDraft = $contentService->createContent($folderCreateStruct, [
$locationService->newLocationCreateStruct($folderLocation->id),
]);
$child = $contentService->publishVersion($childDraft->getVersionInfo());
$childLocation = $locationService->loadLocation($child->contentInfo->getMainLocationId());

// 3. Create custom URL alias for child folder
$urlAliasService->createUrlAlias($childLocation, '/c/b', $languageCode);
$lookup = $urlAliasService->lookup('/c/b');

self::assertSame('/c/b', $lookup->path);

// 4. Rename "A" to "C"
$folderDraft = $contentService->createContentDraft($folder->contentInfo);
$folderUpdateStruct = $contentService->newContentUpdateStruct();
$folderUpdateStruct->setField('name', 'C');
$renamedFolder = $contentService->updateContent($folderDraft->getVersionInfo(), $folderUpdateStruct);
$contentService->publishVersion($renamedFolder->getVersionInfo());

// Loading aliases shouldn't throw a `BadStateException`
$urlAliasService->listLocationAliases($childLocation);

// Renamed content should have '/c2' path alias
$lookupRenamed = $urlAliasService->lookup('C2');

self::assertSame('/C2', $lookupRenamed->path);
}

/**
* Mutate 'ezpublish.persistence.slug_converter' Service configuration.
*
Expand Down

0 comments on commit 2b9b4b7

Please sign in to comment.