diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-09-22 11:24:33 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-09-27 18:30:10 +0200 |
commit | 97a47f49a14a9dd2b0edb12ac54649cf9f66584a (patch) | |
tree | e37ce9c68b773828cebfd6da8ff520382672c602 /apps/dav/tests | |
parent | 18c07f06929679cccf0b1dabe55bb549bae32ddd (diff) | |
download | nextcloud-server-97a47f49a14a9dd2b0edb12ac54649cf9f66584a.tar.gz nextcloud-server-97a47f49a14a9dd2b0edb12ac54649cf9f66584a.zip |
Adjust delete logic and ann unit tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/DAV/HookManagerTest.php | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php index 0db66bf76c1..05384813f02 100644 --- a/apps/dav/tests/unit/DAV/HookManagerTest.php +++ b/apps/dav/tests/unit/DAV/HookManagerTest.php @@ -28,29 +28,30 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\SyncService; use OCA\DAV\HookManager; +use OCP\IUser; use OCP\IUserManager; use Test\TestCase; class HookManagerTest extends TestCase { public function test() { - $user = $this->getMockBuilder('\OCP\IUser') + $user = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); $user->expects($this->once())->method('getUID')->willReturn('newUser'); /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */ - $userManager = $this->getMockBuilder('\OCP\IUserManager') + $userManager = $this->getMockBuilder(IUserManager::class) ->disableOriginalConstructor() ->getMock(); $userManager->expects($this->once())->method('get')->willReturn($user); /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */ - $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService') + $syncService = $this->getMockBuilder(SyncService::class) ->disableOriginalConstructor() ->getMock(); /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */ - $cal = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend') + $cal = $this->getMockBuilder(CalDavBackend::class) ->disableOriginalConstructor() ->getMock(); $cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); @@ -59,7 +60,7 @@ class HookManagerTest extends TestCase { 'personal', ['{DAV:}displayname' => 'Personal']); /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */ - $card = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') + $card = $this->getMockBuilder(CardDavBackend::class) ->disableOriginalConstructor() ->getMock(); $card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); @@ -72,31 +73,31 @@ class HookManagerTest extends TestCase { } public function testWithExisting() { - $user = $this->getMockBuilder('\OCP\IUser') + $user = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); $user->expects($this->once())->method('getUID')->willReturn('newUser'); /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */ - $userManager = $this->getMockBuilder('\OCP\IUserManager') + $userManager = $this->getMockBuilder(IUserManager::class) ->disableOriginalConstructor() ->getMock(); $userManager->expects($this->once())->method('get')->willReturn($user); /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */ - $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService') + $syncService = $this->getMockBuilder(SyncService::class) ->disableOriginalConstructor() ->getMock(); /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */ - $cal = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend') + $cal = $this->getMockBuilder(CalDavBackend::class) ->disableOriginalConstructor() ->getMock(); $cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(1); $cal->expects($this->never())->method('createCalendar'); /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */ - $card = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') + $card = $this->getMockBuilder(CardDavBackend::class) ->disableOriginalConstructor() ->getMock(); $card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1); @@ -107,24 +108,24 @@ class HookManagerTest extends TestCase { } public function testWithBirthdayCalendar() { - $user = $this->getMockBuilder('\OCP\IUser') + $user = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); $user->expects($this->once())->method('getUID')->willReturn('newUser'); /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */ - $userManager = $this->getMockBuilder('\OCP\IUserManager') + $userManager = $this->getMockBuilder(IUserManager::class) ->disableOriginalConstructor() ->getMock(); $userManager->expects($this->once())->method('get')->willReturn($user); /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */ - $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService') + $syncService = $this->getMockBuilder(SyncService::class) ->disableOriginalConstructor() ->getMock(); /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */ - $cal = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend') + $cal = $this->getMockBuilder(CalDavBackend::class) ->disableOriginalConstructor() ->getMock(); $cal->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); @@ -133,7 +134,7 @@ class HookManagerTest extends TestCase { 'personal', ['{DAV:}displayname' => 'Personal']); /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */ - $card = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') + $card = $this->getMockBuilder(CardDavBackend::class) ->disableOriginalConstructor() ->getMock(); $card->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); @@ -144,4 +145,45 @@ class HookManagerTest extends TestCase { $hm = new HookManager($userManager, $syncService, $cal, $card); $hm->postLogin(['uid' => 'newUser']); } + + public function testDeleteCalendar() { + $user = $this->getMockBuilder(IUser::class) + ->disableOriginalConstructor() + ->getMock(); + + /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */ + $userManager = $this->getMockBuilder(IUserManager::class) + ->disableOriginalConstructor() + ->getMock(); + $userManager->expects($this->once())->method('get')->willReturn($user); + + /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */ + $syncService = $this->getMockBuilder(SyncService::class) + ->disableOriginalConstructor() + ->getMock(); + $syncService->expects($this->once()) + ->method('deleteUser'); + + /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */ + $cal = $this->getMockBuilder(CalDavBackend::class) + ->disableOriginalConstructor() + ->getMock(); + $cal->expects($this->once())->method('getCalendarsForUser')->willReturn([ + ['id' => 'personal'] + ]); + $cal->expects($this->once())->method('deleteCalendar'); + + /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */ + $card = $this->getMockBuilder(CardDavBackend::class) + ->disableOriginalConstructor() + ->getMock(); + $card->expects($this->once())->method('getAddressBooksForUser')->willReturn([ + ['id' => 'personal'] + ]); + $card->expects($this->once())->method('deleteAddressBook'); + + $hm = new HookManager($userManager, $syncService, $cal, $card, $this->l10n); + $hm->preDeleteUser(['uid' => 'newUser']); + $hm->postDeleteUser(['uid' => 'newUser']); + } } |