diff --git a/apps/files/lib/Listener/SyncLivePhotosListener.php b/apps/files/lib/Listener/SyncLivePhotosListener.php index a3213310b486f..423924a50ad22 100644 --- a/apps/files/lib/Listener/SyncLivePhotosListener.php +++ b/apps/files/lib/Listener/SyncLivePhotosListener.php @@ -102,7 +102,7 @@ public function handleCacheEntriesRemovedEvent(CacheEntriesRemovedEvent $cacheEn $peerFile = $this->userFolder->getFirstNodeById($peerFileId); if ($peerFile === null) { - return; // Peer file not found. + continue; // Peer file not found. } $peerFile->delete(); } diff --git a/apps/files/tests/Listener/SyncLivePhotosListenerTest.php b/apps/files/tests/Listener/SyncLivePhotosListenerTest.php new file mode 100644 index 0000000000000..b57ec6cd9a512 --- /dev/null +++ b/apps/files/tests/Listener/SyncLivePhotosListenerTest.php @@ -0,0 +1,66 @@ +userFolder = $this->createMock(Folder::class); + $this->livePhotosService = $this->createMock(LivePhotosService::class); + + $this->listener = new SyncLivePhotosListener( + $this->userFolder, + $this->createMock(IFilesMetadataManager::class), + $this->livePhotosService, + $this->createMock(IRootFolder::class), + $this->createMock(View::class), + ); + } + + public function testCacheEntriesRemovedDeletesPeersAfterMissingOne(): void { + $entries = array_map(function (int $fileId): ICacheEvent { + $entry = $this->createMock(ICacheEvent::class); + $entry->method('getFileId')->willReturn($fileId); + return $entry; + }, [1, 2]); + + $this->livePhotosService->method('getLivePhotoPeerIds') + ->with([1, 2]) + ->willReturn([11, 12]); + + $peer = $this->createMock(File::class); + $peer->expects($this->once())->method('delete'); + + $this->userFolder->method('getFirstNodeById') + ->willReturnMap([ + [11, null], + [12, $peer], + ]); + + $this->listener->handle(new CacheEntriesRemovedEvent($entries)); + } +}