@@ -174,9 +174,7 @@ public function testChangeAvatarNotSupported() {
174174
175175 $ backend ->expects ($ this ->any ())
176176 ->method ('implementsActions ' )
177- ->will ($ this ->returnCallback (function ($ actions ) {
178- return false ;
179- }));
177+ ->willReturn (false );
180178
181179 $ user = new \OC \User \User ('foo ' , $ backend );
182180 $ this ->assertTrue ($ user ->canChangeAvatar ());
@@ -379,9 +377,7 @@ public function testSetDisplayNameNotSupported() {
379377
380378 $ backend ->expects ($ this ->any ())
381379 ->method ('implementsActions ' )
382- ->will ($ this ->returnCallback (function ($ actions ) {
383- return false ;
384- }));
380+ ->willReturn (false );
385381
386382 $ backend ->expects ($ this ->never ())
387383 ->method ('setDisplayName ' );
@@ -432,7 +428,19 @@ public function testSetPasswordHooks() {
432428 $ this ->assertEquals (2 , $ hooksCalled );
433429 }
434430
435- public function testDeleteHooks () {
431+ public function dataDeleteHooks () {
432+ return [
433+ [true , 2 ],
434+ [false , 1 ],
435+ ];
436+ }
437+
438+ /**
439+ * @dataProvider dataDeleteHooks
440+ * @param bool $result
441+ * @param int $expectedHooks
442+ */
443+ public function testDeleteHooks ($ result , $ expectedHooks ) {
436444 $ hooksCalled = 0 ;
437445 $ test = $ this ;
438446
@@ -441,7 +449,10 @@ public function testDeleteHooks() {
441449 */
442450 $ backend = $ this ->getMock ('\Test\Util\User\Dummy ' );
443451 $ backend ->expects ($ this ->once ())
444- ->method ('deleteUser ' );
452+ ->method ('deleteUser ' )
453+ ->willReturn ($ result );
454+ $ emitter = new PublicEmitter ();
455+ $ user = new \OC \User \User ('foo ' , $ backend , $ emitter );
445456
446457 /**
447458 * @param \OC\User\User $user
@@ -451,13 +462,62 @@ public function testDeleteHooks() {
451462 $ test ->assertEquals ('foo ' , $ user ->getUID ());
452463 };
453464
454- $ emitter = new PublicEmitter ();
455465 $ emitter ->listen ('\OC\User ' , 'preDelete ' , $ hook );
456466 $ emitter ->listen ('\OC\User ' , 'postDelete ' , $ hook );
457467
458- $ user = new \OC \User \User ('foo ' , $ backend , $ emitter );
459- $ this ->assertTrue ($ user ->delete ());
460- $ this ->assertEquals (2 , $ hooksCalled );
468+ $ config = $ this ->getMockBuilder ('OCP\IConfig ' )->getMock ();
469+ $ commentsManager = $ this ->getMockBuilder ('OCP\Comments\ICommentsManager ' )->getMock ();
470+ $ notificationManager = $ this ->getMockBuilder ('OCP\Notification\IManager ' )->getMock ();
471+
472+ if ($ result ) {
473+ $ config ->expects ($ this ->once ())
474+ ->method ('deleteAllUserValues ' )
475+ ->with ('foo ' );
476+
477+ $ commentsManager ->expects ($ this ->once ())
478+ ->method ('deleteReferencesOfActor ' )
479+ ->with ('users ' , 'foo ' );
480+ $ commentsManager ->expects ($ this ->once ())
481+ ->method ('deleteReadMarksFromUser ' )
482+ ->with ($ user );
483+
484+ $ notification = $ this ->getMockBuilder ('OCP\Notification\INotification ' )->getMock ();
485+ $ notification ->expects ($ this ->once ())
486+ ->method ('setUser ' )
487+ ->with ('foo ' );
488+
489+ $ notificationManager ->expects ($ this ->once ())
490+ ->method ('createNotification ' )
491+ ->willReturn ($ notification );
492+ $ notificationManager ->expects ($ this ->once ())
493+ ->method ('markProcessed ' )
494+ ->with ($ notification );
495+ } else {
496+ $ config ->expects ($ this ->never ())
497+ ->method ('deleteAllUserValues ' );
498+
499+ $ commentsManager ->expects ($ this ->never ())
500+ ->method ('deleteReferencesOfActor ' );
501+ $ commentsManager ->expects ($ this ->never ())
502+ ->method ('deleteReadMarksFromUser ' );
503+
504+ $ notificationManager ->expects ($ this ->never ())
505+ ->method ('createNotification ' );
506+ $ notificationManager ->expects ($ this ->never ())
507+ ->method ('markProcessed ' );
508+ }
509+
510+ $ this ->overwriteService ('NotificationManager ' , $ notificationManager );
511+ $ this ->overwriteService ('CommentsManager ' , $ commentsManager );
512+ $ this ->overwriteService ('AllConfig ' , $ config );
513+
514+ $ this ->assertSame ($ result , $ user ->delete ());
515+
516+ $ this ->restoreService ('AllConfig ' );
517+ $ this ->restoreService ('CommentsManager ' );
518+ $ this ->restoreService ('NotificationManager ' );
519+
520+ $ this ->assertEquals ($ expectedHooks , $ hooksCalled );
461521 }
462522
463523 public function testGetCloudId () {
0 commit comments