summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-09-30 00:34:19 +0200
committerGitHub <noreply@github.com>2016-09-30 00:34:19 +0200
commit85522ff1ed534dce30dd3713cebe9fb1a67fbdfe (patch)
tree95ec6e84810307185a57965d2a220fc09c79de09
parent938b0d5597c899e6f9a1026ae5593d750412c6bf (diff)
parent4d1acfd4ef7087b8dc7795396c75fd239a6245f4 (diff)
downloadnextcloud-server-85522ff1ed534dce30dd3713cebe9fb1a67fbdfe.tar.gz
nextcloud-server-85522ff1ed534dce30dd3713cebe9fb1a67fbdfe.zip
Merge pull request #1558 from nextcloud/remove-notifications-upon-user-deletion
Remove notifications upon user deletion
-rw-r--r--lib/private/User/User.php10
-rw-r--r--tests/lib/User/UserTest.php88
2 files changed, 83 insertions, 15 deletions
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index 94ac8c13621..68787ce60f8 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -214,10 +214,14 @@ class User implements IUser {
\OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid);
\OC::$server->getCommentsManager()->deleteReadMarksFromUser($this);
- }
- if ($this->emitter) {
- $this->emitter->emit('\OC\User', 'postDelete', array($this));
+ $notification = \OC::$server->getNotificationManager()->createNotification();
+ $notification->setUser($this->uid);
+ \OC::$server->getNotificationManager()->markProcessed($notification);
+
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\User', 'postDelete', array($this));
+ }
}
return !($result === false);
}
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index 69f75d07762..5eee5d60d04 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -11,6 +11,10 @@ namespace Test\User;
use OC\Hooks\PublicEmitter;
use OC\User\Database;
+use OCP\Comments\ICommentsManager;
+use OCP\IConfig;
+use OCP\Notification\IManager as INotificationManager;
+use OCP\Notification\INotification;
/**
* Class UserTest
@@ -175,9 +179,7 @@ class UserTest extends \Test\TestCase {
$backend->expects($this->any())
->method('implementsActions')
- ->will($this->returnCallback(function ($actions) {
- return false;
- }));
+ ->willReturn(false);
$user = new \OC\User\User('foo', $backend);
$this->assertTrue($user->canChangeAvatar());
@@ -380,9 +382,7 @@ class UserTest extends \Test\TestCase {
$backend->expects($this->any())
->method('implementsActions')
- ->will($this->returnCallback(function ($actions) {
- return false;
- }));
+ ->willReturn(false);
$backend->expects($this->never())
->method('setDisplayName');
@@ -433,7 +433,19 @@ class UserTest extends \Test\TestCase {
$this->assertEquals(2, $hooksCalled);
}
- public function testDeleteHooks() {
+ public function dataDeleteHooks() {
+ return [
+ [true, 2],
+ [false, 1],
+ ];
+ }
+
+ /**
+ * @dataProvider dataDeleteHooks
+ * @param bool $result
+ * @param int $expectedHooks
+ */
+ public function testDeleteHooks($result, $expectedHooks) {
$hooksCalled = 0;
$test = $this;
@@ -442,7 +454,10 @@ class UserTest extends \Test\TestCase {
*/
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$backend->expects($this->once())
- ->method('deleteUser');
+ ->method('deleteUser')
+ ->willReturn($result);
+ $emitter = new PublicEmitter();
+ $user = new \OC\User\User('foo', $backend, $emitter);
/**
* @param \OC\User\User $user
@@ -452,13 +467,62 @@ class UserTest extends \Test\TestCase {
$test->assertEquals('foo', $user->getUID());
};
- $emitter = new PublicEmitter();
$emitter->listen('\OC\User', 'preDelete', $hook);
$emitter->listen('\OC\User', 'postDelete', $hook);
- $user = new \OC\User\User('foo', $backend, $emitter);
- $this->assertTrue($user->delete());
- $this->assertEquals(2, $hooksCalled);
+ $config = $this->createMock(IConfig::class);
+ $commentsManager = $this->createMock(ICommentsManager::class);
+ $notificationManager = $this->createMock(INotificationManager::class);
+
+ if ($result) {
+ $config->expects($this->once())
+ ->method('deleteAllUserValues')
+ ->with('foo');
+
+ $commentsManager->expects($this->once())
+ ->method('deleteReferencesOfActor')
+ ->with('users', 'foo');
+ $commentsManager->expects($this->once())
+ ->method('deleteReadMarksFromUser')
+ ->with($user);
+
+ $notification = $this->createMock(INotification::class);
+ $notification->expects($this->once())
+ ->method('setUser')
+ ->with('foo');
+
+ $notificationManager->expects($this->once())
+ ->method('createNotification')
+ ->willReturn($notification);
+ $notificationManager->expects($this->once())
+ ->method('markProcessed')
+ ->with($notification);
+ } else {
+ $config->expects($this->never())
+ ->method('deleteAllUserValues');
+
+ $commentsManager->expects($this->never())
+ ->method('deleteReferencesOfActor');
+ $commentsManager->expects($this->never())
+ ->method('deleteReadMarksFromUser');
+
+ $notificationManager->expects($this->never())
+ ->method('createNotification');
+ $notificationManager->expects($this->never())
+ ->method('markProcessed');
+ }
+
+ $this->overwriteService('NotificationManager', $notificationManager);
+ $this->overwriteService('CommentsManager', $commentsManager);
+ $this->overwriteService('AllConfig', $config);
+
+ $this->assertSame($result, $user->delete());
+
+ $this->restoreService('AllConfig');
+ $this->restoreService('CommentsManager');
+ $this->restoreService('NotificationManager');
+
+ $this->assertEquals($expectedHooks, $hooksCalled);
}
public function testGetCloudId() {