summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-10-11 10:54:11 +0200
committerJoas Schilling <coding@schilljs.com>2016-10-11 14:18:01 +0200
commit203c5f745ee58f4d5c5e8bc387e2675410010861 (patch)
tree8057b5c9475125259d7c9235865080f17a9274fe /tests
parent1b006b9d6e77ac78fcec63a6daef19f227f4067d (diff)
downloadnextcloud-server-203c5f745ee58f4d5c5e8bc387e2675410010861.tar.gz
nextcloud-server-203c5f745ee58f4d5c5e8bc387e2675410010861.zip
Make sure that comments, notifications and preferences are deleted
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/user/user.php73
1 files changed, 68 insertions, 5 deletions
diff --git a/tests/lib/user/user.php b/tests/lib/user/user.php
index a8d688d9c88..31b2f6769bc 100644
--- a/tests/lib/user/user.php
+++ b/tests/lib/user/user.php
@@ -435,7 +435,18 @@ class User extends \Test\TestCase {
$this->assertEquals(2, $hooksCalled);
}
- public function testDeleteHooks() {
+ public function dataDeleteHooks() {
+ return [
+ [true],
+ [false],
+ ];
+ }
+
+ /**
+ * @dataProvider dataDeleteHooks
+ * @param bool $result
+ */
+ public function testDeleteHooks($result) {
$hooksCalled = 0;
$test = $this;
@@ -444,7 +455,10 @@ class User extends \Test\TestCase {
*/
$backend = $this->getMock('\Test\Util\User\Dummy');
$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
@@ -454,12 +468,61 @@ class User 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());
+ $config = $this->getMockBuilder('OCP\IConfig')->getMock();
+ $commentsManager = $this->getMockBuilder('OCP\Comments\ICommentsManager')->getMock();
+ $notificationManager = $this->getMockBuilder('OCP\Notification\IManager')->getMock();
+
+ 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->getMockBuilder('OCP\Notification\INotification')->getMock();
+ $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(2, $hooksCalled);
}