@@ -340,6 +340,53 @@ public function testDeleteWithoutDeletingFile(): void {
340340 $ service ->delete (1 , false );
341341 }
342342
343+ public function testDeleteWithNullNodeIdDoesNotCallFolderService (): void {
344+ $ file = new \OCA \Libresign \Db \File ();
345+ $ file ->setId (1 );
346+ $ file ->setNodeType ('single ' );
347+ $ file ->setParentFileId (null );
348+ $ file ->setNodeId (null );
349+ $ file ->setSignedNodeId (null );
350+
351+ $ this ->fileMapper ->method ('getById ' )->willReturn ($ file );
352+ $ this ->fileMapper ->expects ($ this ->once ())->method ('delete ' )->with ($ file );
353+
354+ $ this ->folderService ->expects ($ this ->never ())->method ('getFileByNodeId ' );
355+
356+ $ this ->signRequestMapper ->method ('getByFileId ' )->willReturn ([]);
357+ $ this ->fileElementService ->expects ($ this ->once ())->method ('deleteVisibleElements ' );
358+ $ this ->idDocsMapper ->expects ($ this ->once ())->method ('deleteByFileId ' );
359+
360+ $ service = $ this ->createFileService ();
361+
362+ $ service ->delete (1 , true );
363+ }
364+
365+ public function testDeleteIgnoresMissingPhysicalFile (): void {
366+ $ file = new \OCA \Libresign \Db \File ();
367+ $ file ->setId (1 );
368+ $ file ->setNodeId (100 );
369+ $ file ->setSignedNodeId (null );
370+ $ file ->setNodeType ('single ' );
371+ $ file ->setParentFileId (null );
372+
373+ $ this ->fileMapper ->method ('getById ' )->willReturn ($ file );
374+ $ this ->fileMapper ->expects ($ this ->once ())->method ('delete ' )->with ($ file );
375+
376+ $ this ->folderService ->expects ($ this ->once ())
377+ ->method ('getFileByNodeId ' )
378+ ->with (100 )
379+ ->willThrowException (new \OCP \Files \NotFoundException ());
380+
381+ $ this ->signRequestMapper ->method ('getByFileId ' )->willReturn ([]);
382+ $ this ->fileElementService ->expects ($ this ->once ())->method ('deleteVisibleElements ' );
383+ $ this ->idDocsMapper ->expects ($ this ->once ())->method ('deleteByFileId ' );
384+
385+ $ service = $ this ->createFileService ();
386+
387+ $ service ->delete (1 , true );
388+ }
389+
343390 #[DataProvider('providerTestVisibleElements ' )]
344391 public function testVisibleElements (bool $ showVisibleElementsFlag , bool $ expectedInResult ): void {
345392 $ file = new \OCA \Libresign \Db \File ();
0 commit comments