1111
1212use OCA \Tables \Db \ContextMapper ;
1313use OCA \Tables \Db \ContextNavigationMapper ;
14+ use OCA \Tables \Db \Share ;
1415use OCA \Tables \Db \ShareMapper ;
1516use OCA \Tables \Db \TableMapper ;
1617use OCA \Tables \Db \ViewMapper ;
1718use OCA \Tables \ShareReview \ShareReviewSource ;
19+ use OCP \AppFramework \Db \DoesNotExistException ;
1820use OCP \Constants ;
1921use OCP \DB \Exception ;
2022use OCP \IL10N ;
@@ -225,16 +227,36 @@ public function testGetSharesReturnsEmptyOnDbException(): void {
225227 $ this ->assertSame ([], $ this ->source ->getShares ());
226228 }
227229
228- public function testDeleteShareSuccess (): void {
229- $ this ->shareMapper ->expects ($ this ->once ())->method ('deleteById ' )->with (7 )->willReturn (true );
230+ private function makeShare (int $ id , string $ nodeType ): Share {
231+ $ share = new Share ();
232+ $ share ->setId ($ id );
233+ $ share ->setNodeType ($ nodeType );
234+ return $ share ;
235+ }
236+
237+ public function testDeleteShareTableSuccessSkipsContextNavCleanup (): void {
238+ $ share = $ this ->makeShare (7 , 'table ' );
239+ $ this ->shareMapper ->expects ($ this ->once ())->method ('find ' )->with (7 )->willReturn ($ share );
240+ $ this ->shareMapper ->expects ($ this ->once ())->method ('delete ' )->with ($ share );
241+ $ this ->contextNavigationMapper ->expects ($ this ->never ())->method ('deleteByShareId ' );
242+ $ this ->logger ->expects ($ this ->once ())->method ('info ' );
243+
244+ $ this ->assertTrue ($ this ->source ->deleteShare ('7 ' ));
245+ }
246+
247+ public function testDeleteShareContextSuccessCleansUpContextNav (): void {
248+ $ share = $ this ->makeShare (7 , 'context ' );
249+ $ this ->shareMapper ->expects ($ this ->once ())->method ('find ' )->with (7 )->willReturn ($ share );
250+ $ this ->shareMapper ->expects ($ this ->once ())->method ('delete ' )->with ($ share );
230251 $ this ->contextNavigationMapper ->expects ($ this ->once ())->method ('deleteByShareId ' )->with (7 );
231252 $ this ->logger ->expects ($ this ->once ())->method ('info ' );
232253
233254 $ this ->assertTrue ($ this ->source ->deleteShare ('7 ' ));
234255 }
235256
236257 public function testDeleteShareNotFoundReturnsFalse (): void {
237- $ this ->shareMapper ->method ('deleteById ' )->willReturn (false );
258+ $ this ->shareMapper ->method ('find ' )->willThrowException (new DoesNotExistException ('not found ' ));
259+ $ this ->shareMapper ->expects ($ this ->never ())->method ('delete ' );
238260 $ this ->contextNavigationMapper ->expects ($ this ->never ())->method ('deleteByShareId ' );
239261 $ this ->logger ->expects ($ this ->once ())->method ('info ' );
240262 $ this ->logger ->expects ($ this ->once ())->method ('warning ' );
@@ -243,7 +265,9 @@ public function testDeleteShareNotFoundReturnsFalse(): void {
243265 }
244266
245267 public function testDeleteShareReturnsFalseOnDeleteException (): void {
246- $ this ->shareMapper ->method ('deleteById ' )->willThrowException ($ this ->createMock (Exception::class));
268+ $ share = $ this ->makeShare (7 , 'table ' );
269+ $ this ->shareMapper ->method ('find ' )->willReturn ($ share );
270+ $ this ->shareMapper ->method ('delete ' )->willThrowException ($ this ->createMock (Exception::class));
247271 $ this ->contextNavigationMapper ->expects ($ this ->never ())->method ('deleteByShareId ' );
248272 $ this ->logger ->expects ($ this ->once ())->method ('info ' );
249273 $ this ->logger ->expects ($ this ->once ())->method ('error ' );
@@ -252,7 +276,9 @@ public function testDeleteShareReturnsFalseOnDeleteException(): void {
252276 }
253277
254278 public function testDeleteShareReturnsTrueOnContextNavigationException (): void {
255- $ this ->shareMapper ->method ('deleteById ' )->willReturn (true );
279+ $ share = $ this ->makeShare (42 , 'context ' );
280+ $ this ->shareMapper ->method ('find ' )->willReturn ($ share );
281+ $ this ->shareMapper ->method ('delete ' );
256282 $ this ->contextNavigationMapper ->method ('deleteByShareId ' )->willThrowException ($ this ->createMock (Exception::class));
257283 $ this ->logger ->expects ($ this ->once ())->method ('info ' );
258284 $ this ->logger ->expects ($ this ->once ())->method ('error ' );
0 commit comments