summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-04-19 14:30:35 +0200
committerLukas Reschke <lukas@owncloud.com>2016-04-19 14:30:35 +0200
commita86fd873d6102d4defeb4a7e4d4882685753a006 (patch)
tree46ce96beb6da4ba3379796d37fbacf8a30b502b4 /apps/dav
parent0c5f915377c77c1ca5f4cd886910ba2a93eb1ae6 (diff)
parent748134bd90ff5f3ad683e1cfce3fe317ede795c7 (diff)
downloadnextcloud-server-a86fd873d6102d4defeb4a7e4d4882685753a006.tar.gz
nextcloud-server-a86fd873d6102d4defeb4a7e4d4882685753a006.zip
Merge pull request #24076 from owncloud/fix-initial-calendar-and-addressbook-names
Fix displayname for initial calendars and address books
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/hookmanager.php36
-rw-r--r--apps/dav/tests/unit/dav/HookManagerTest.php71
2 files changed, 89 insertions, 18 deletions
diff --git a/apps/dav/lib/hookmanager.php b/apps/dav/lib/hookmanager.php
index 4a4704ff2a2..687e6718db3 100644
--- a/apps/dav/lib/hookmanager.php
+++ b/apps/dav/lib/hookmanager.php
@@ -100,26 +100,26 @@ class HookManager {
public function postLogin($params) {
$user = $this->userManager->get($params['uid']);
-
- $principal = 'principals/users/' . $user->getUID();
- $calendars = $this->calDav->getCalendarsForUser($principal);
- if (empty($calendars)) {
- try {
- $this->calDav->createCalendar($principal, 'personal', [
- 'displayname' => 'Personal']);
- } catch (\Exception $ex) {
- \OC::$server->getLogger()->logException($ex);
+ if (!is_null($user)) {
+ $principal = 'principals/users/' . $user->getUID();
+ $calendars = $this->calDav->getCalendarsForUser($principal);
+ if (empty($calendars)) {
+ try {
+ $this->calDav->createCalendar($principal, 'personal', [
+ '{DAV:}displayname' => 'Personal']);
+ } catch (\Exception $ex) {
+ \OC::$server->getLogger()->logException($ex);
+ }
}
- }
- $books = $this->cardDav->getAddressBooksForUser($principal);
- if (empty($books)) {
- try {
- $this->cardDav->createAddressBook($principal, 'contacts', [
- 'displayname' => 'Contacts']);
- } catch (\Exception $ex) {
- \OC::$server->getLogger()->logException($ex);
+ $books = $this->cardDav->getAddressBooksForUser($principal);
+ if (empty($books)) {
+ try {
+ $this->cardDav->createAddressBook($principal, 'contacts', [
+ '{DAV:}displayname' => 'Contacts']);
+ } catch (\Exception $ex) {
+ \OC::$server->getLogger()->logException($ex);
+ }
}
}
-
}
}
diff --git a/apps/dav/tests/unit/dav/HookManagerTest.php b/apps/dav/tests/unit/dav/HookManagerTest.php
new file mode 100644
index 00000000000..bec4c240ce8
--- /dev/null
+++ b/apps/dav/tests/unit/dav/HookManagerTest.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Tests\Unit\DAV;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\CardDAV\SyncService;
+use OCA\DAV\HookManager;
+use OCP\IUserManager;
+use Test\TestCase;
+
+class HookManagerTest extends TestCase {
+ public function test() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->expects($this->once())->method('getUID')->willReturn('newUser');
+
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */
+ $userManager = $this->getMockBuilder('\OCP\IUserManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userManager->expects($this->once())->method('get')->willReturn($user);
+
+ /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */
+ $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */
+ $cal = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $cal->expects($this->once())->method('getCalendarsForUser')->willReturn([]);
+ $cal->expects($this->once())->method('createCalendar')->with(
+ 'principals/users/newUser',
+ 'personal', ['{DAV:}displayname' => 'Personal']);
+
+ /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */
+ $card = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $card->expects($this->once())->method('getAddressBooksForUser')->willReturn([]);
+ $card->expects($this->once())->method('createAddressBook')->with(
+ 'principals/users/newUser',
+ 'contacts', ['{DAV:}displayname' => 'Contacts']);
+
+ $hm = new HookManager($userManager, $syncService, $cal, $card);
+ $hm->postLogin(['uid' => 'newUser']);
+ }
+}