Skip to content

Commit

Permalink
IBX-6631: 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 8c7f28f commit 48730c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions eZ/Publish/API/Repository/Tests/TrashServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,31 @@ public function testDeleteThrowsNotFoundExceptionForNonExistingTrashItem()
));
}

public function testTrashProperlyAssignsRemovedLocationContentMapToTrashItem(): void
{
$repository = $this->getRepository();
$trashService = $repository->getTrashService();
$locationService = $repository->getLocationService();

$folder1 = $this->createFolder(['eng-GB' => 'Folder1'], 2);
$folder2 = $this->createFolder(['eng-GB' => 'Folder2'], $folder1->contentInfo->getMainLocationId());
$folder3 = $this->createFolder(['eng-GB' => 'Folder2'], $folder2->contentInfo->getMainLocationId());

$folderLocation = $locationService->loadLocation($folder1->contentInfo->getMainLocationId());

$trashItem = $trashService->trash($folderLocation);
$removedLocationContentMap = $trashItem->getRemovedLocationContentIdMap();

self::assertSame(
[
$folderLocation->id => $folder1->id,
$folder2->contentInfo->getMainLocationId() => $folder2->id,
$folder3->contentInfo->getMainLocationId() => $folder3->id,
],
$removedLocationContentMap,
);
}

/**
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function trashSubtree($locationId)
$locationRows = $this->locationGateway->getSubtreeContent($locationId);
$isLocationRemoved = false;
$parentLocationId = null;
$trashedLocationsContentMap = [];
$removedLocationsContentMap = [];

foreach ($locationRows as $locationRow) {
if ($locationRow['node_id'] == $locationId) {
Expand All @@ -118,7 +118,7 @@ public function trashSubtree($locationId)

if ($this->locationGateway->countLocationsByContentId($locationRow['contentobject_id']) == 1) {
$this->locationGateway->trashLocation($locationRow['node_id']);
$trashedLocationsContentMap[$locationRow['node_id']] = $locationRow['contentobject_id'];
$removedLocationsContentMap[(int)$locationRow['node_id']] = (int)$locationRow['contentobject_id'];
} else {
if ($locationRow['node_id'] == $locationId) {
$isLocationRemoved = true;
Expand Down Expand Up @@ -150,7 +150,7 @@ public function trashSubtree($locationId)
}

$trashItem = $this->loadTrashItem($locationId);
$trashItem->removedLocationContentIdMap = $trashedLocationsContentMap;
$trashItem->removedLocationContentIdMap = $removedLocationsContentMap;

return $trashItem;
}
Expand Down

0 comments on commit 48730c1

Please sign in to comment.