Skip to content

Commit

Permalink
IBX-3957: Applied review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 24, 2023
1 parent 7b30902 commit bd4088e
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1605,50 +1605,45 @@ 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());
$folder = $this->createFolder([$languageCode => 'a'], 2);
$folderLocationId = $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());
$child = $this->createFolder([$languageCode => 'b'], $folderLocationId);
$childLocationId = $child->contentInfo->getMainLocationId();
$childLocation = $locationService->loadLocation($childLocationId);

// 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);
self::assertSame($childLocationId, $lookup->destination);

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

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

self::assertCount(1, $childLocationAliases);
self::assertSame('/c/b', $childLocationAliases[0]->path);

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

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

/**
Expand Down

0 comments on commit bd4088e

Please sign in to comment.