Make sure that comments, notifications and preferences are deleted

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-09-29 15:01:38 +02:00
parent 1fcd7848c6
commit 9107573020
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 70 additions and 11 deletions

View File

@ -174,9 +174,7 @@ class UserTest extends \Test\TestCase {
$backend->expects($this->any()) $backend->expects($this->any())
->method('implementsActions') ->method('implementsActions')
->will($this->returnCallback(function ($actions) { ->willReturn(false);
return false;
}));
$user = new \OC\User\User('foo', $backend); $user = new \OC\User\User('foo', $backend);
$this->assertTrue($user->canChangeAvatar()); $this->assertTrue($user->canChangeAvatar());
@ -379,9 +377,7 @@ class UserTest extends \Test\TestCase {
$backend->expects($this->any()) $backend->expects($this->any())
->method('implementsActions') ->method('implementsActions')
->will($this->returnCallback(function ($actions) { ->willReturn(false);
return false;
}));
$backend->expects($this->never()) $backend->expects($this->never())
->method('setDisplayName'); ->method('setDisplayName');
@ -432,7 +428,18 @@ class UserTest extends \Test\TestCase {
$this->assertEquals(2, $hooksCalled); $this->assertEquals(2, $hooksCalled);
} }
public function testDeleteHooks() { public function dataDeleteHooks() {
return [
[true],
[false],
];
}
/**
* @dataProvider dataDeleteHooks
* @param bool $result
*/
public function testDeleteHooks($result) {
$hooksCalled = 0; $hooksCalled = 0;
$test = $this; $test = $this;
@ -441,7 +448,10 @@ class UserTest extends \Test\TestCase {
*/ */
$backend = $this->getMock('\Test\Util\User\Dummy'); $backend = $this->getMock('\Test\Util\User\Dummy');
$backend->expects($this->once()) $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 * @param \OC\User\User $user
@ -451,12 +461,61 @@ class UserTest extends \Test\TestCase {
$test->assertEquals('foo', $user->getUID()); $test->assertEquals('foo', $user->getUID());
}; };
$emitter = new PublicEmitter();
$emitter->listen('\OC\User', 'preDelete', $hook); $emitter->listen('\OC\User', 'preDelete', $hook);
$emitter->listen('\OC\User', 'postDelete', $hook); $emitter->listen('\OC\User', 'postDelete', $hook);
$user = new \OC\User\User('foo', $backend, $emitter); $config = $this->getMockBuilder('OCP\IConfig')->getMock();
$this->assertTrue($user->delete()); $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); $this->assertEquals(2, $hooksCalled);
} }