From 48730c11ce932de1ae3d0c6173b299d1c56ce353 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 13 Oct 2023 14:22:42 +0200 Subject: [PATCH] IBX-6631: Added an integration test --- .../API/Repository/Tests/TrashServiceTest.php | 25 +++++++++++++++++++ .../Legacy/Content/Location/Trash/Handler.php | 6 ++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/TrashServiceTest.php b/eZ/Publish/API/Repository/Tests/TrashServiceTest.php index 4a1f3ca67c..c4bbe2950a 100644 --- a/eZ/Publish/API/Repository/Tests/TrashServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/TrashServiceTest.php @@ -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 */ diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Trash/Handler.php b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Trash/Handler.php index 07fe1276df..d4affc5cdd 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Trash/Handler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Trash/Handler.php @@ -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) { @@ -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; @@ -150,7 +150,7 @@ public function trashSubtree($locationId) } $trashItem = $this->loadTrashItem($locationId); - $trashItem->removedLocationContentIdMap = $trashedLocationsContentMap; + $trashItem->removedLocationContentIdMap = $removedLocationsContentMap; return $trashItem; }