diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-09-28 21:42:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-28 21:42:55 +0200 |
commit | ef0760f84f7da2adbb44851aa8ff4f6fdbdf4720 (patch) | |
tree | 05966304139d36a5b4c55cde947a3d7baa53d05a /apps/dav/tests/unit/DAV | |
parent | 2eaa2791b75f7c2c8c7892a5354f6e93fedaf396 (diff) | |
parent | 6c8bcb38f1124d0be7cee770ab67730d90dbd783 (diff) | |
download | nextcloud-server-ef0760f84f7da2adbb44851aa8ff4f6fdbdf4720.tar.gz nextcloud-server-ef0760f84f7da2adbb44851aa8ff4f6fdbdf4720.zip |
Merge pull request #1545 from nextcloud/delete-calendars-with-their-users
Delete calendars with their users
Diffstat (limited to 'apps/dav/tests/unit/DAV')
-rw-r--r-- | apps/dav/tests/unit/DAV/HookManagerTest.php | 88 |
1 files changed, 73 insertions, 15 deletions
diff --git a/apps/dav/tests/unit/DAV/HookManagerTest.php b/apps/dav/tests/unit/DAV/HookManagerTest.php index 0db66bf76c1..5b7d4700a5f 100644 --- a/apps/dav/tests/unit/DAV/HookManagerTest.php +++ b/apps/dav/tests/unit/DAV/HookManagerTest.php @@ -28,29 +28,45 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\SyncService; use OCA\DAV\HookManager; +use OCP\IL10N; +use OCP\IUser; use OCP\IUserManager; use Test\TestCase; class HookManagerTest extends TestCase { + /** @var IL10N */ + private $l10n; + + public function setUp() { + parent::setUp(); + $this->l10n = $this->createMock(IL10N::class); + $this->l10n + ->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function ($text, $parameters = []) { + return vsprintf($text, $parameters); + })); + } + 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 +75,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 +88,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 +123,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 +149,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 +160,46 @@ 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('getUsersOwnCalendars')->willReturn([ + ['id' => 'personal'] + ]); + $cal->expects($this->once())->method('deleteCalendar'); + $cal->expects($this->once())->method('deleteAllSharesByUser'); + + /** @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']); + } } |