summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2016-11-03 19:31:20 +0100
committerGitHub <noreply@github.com>2016-11-03 19:31:20 +0100
commitf6ff624e3df023529a0a53cfb232178a973aef65 (patch)
treea8cad891107bbf958d1973e0ba4a50b4758fb00b /apps/dav/tests
parent9e27e2f04841f4549307fd507b3aaa2f5ba70add (diff)
parent7a0e003adee4e42e1801e35485b731a543f820e6 (diff)
downloadnextcloud-server-f6ff624e3df023529a0a53cfb232178a973aef65.tar.gz
nextcloud-server-f6ff624e3df023529a0a53cfb232178a973aef65.zip
Merge pull request #1733 from nextcloud/dav-events
Activities for calendars, events and todos
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php51
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/BackendTest.php332
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php50
-rw-r--r--apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php22
4 files changed, 418 insertions, 37 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
index 2559ecbbf89..d15be72c77b 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
@@ -22,18 +22,12 @@
namespace OCA\DAV\Tests\unit\CalDAV;
-use DateTime;
-use DateTimeZone;
use OCA\DAV\CalDAV\CalDavBackend;
-use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\Connector\Sabre\Principal;
-use OCP\IL10N;
-use OCP\IConfig;
+use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
-use Sabre\DAV\PropPatch;
-use Sabre\DAV\Xml\Property\Href;
-use Sabre\DAVACL\IACL;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -50,12 +44,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
protected $principal;
-
- /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
-
- /** var OCP\IConfig */
- protected $config;
+ /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
+ protected $dispatcher;
/** @var ISecureRandom */
private $random;
@@ -67,9 +59,8 @@ abstract class AbstractCalDavBackendTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->userManager = $this->getMockBuilder('OCP\IUserManager')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
@@ -83,21 +74,28 @@ abstract class AbstractCalDavBackendTest extends TestCase {
->willReturn([self::UNIT_TEST_GROUP]);
$db = \OC::$server->getDatabaseConnection();
- $this->config = \OC::$server->getConfig();
$this->random = \OC::$server->getSecureRandom();
- $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->config, $this->random);
- $this->tearDown();
+ $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->random, $this->dispatcher);
+
+ $this->cleanUpBackend();
}
public function tearDown() {
+ $this->cleanUpBackend();
parent::tearDown();
+ }
+ public function cleanUpBackend() {
if (is_null($this->backend)) {
return;
}
- $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
- foreach ($books as $book) {
- $this->backend->deleteCalendar($book['id']);
+ $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
+ foreach ($calendars as $calendar) {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
+
+ $this->backend->deleteCalendar($calendar['id']);
}
$subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
foreach ($subscriptions as $subscription) {
@@ -106,6 +104,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
}
protected function createTestCalendar() {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
+
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
]);
@@ -143,6 +145,11 @@ END:VEVENT
END:VCALENDAR
EOD;
$uri0 = $this->getUniqueID('event');
+
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
return $uri0;
diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
new file mode 100644
index 00000000000..3585d69bad3
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
@@ -0,0 +1,332 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity;
+
+use OCA\DAV\CalDAV\Activity\Backend;
+use OCA\DAV\CalDAV\Activity\Extension;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
+use OCP\IGroup;
+use OCP\IGroupManager;
+use OCP\IUser;
+use OCP\IUserSession;
+use Test\TestCase;
+
+class BackendTest extends TestCase {
+
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $activityManager;
+
+ /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $groupManager;
+
+ /** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userSession;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->activityManager = $this->createMock(IManager::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ }
+
+ /**
+ * @param array $methods
+ * @return Backend|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getBackend(array $methods = []) {
+ if (empty($methods)) {
+ return new Backend(
+ $this->activityManager,
+ $this->groupManager,
+ $this->userSession
+ );
+ } else {
+ return $this->getMockBuilder(Backend::class)
+ ->setConstructorArgs([
+ $this->activityManager,
+ $this->groupManager,
+ $this->userSession,
+ ])
+ ->setMethods($methods)
+ ->getMock();
+ }
+ }
+
+ public function dataCallTriggerCalendarActivity() {
+ return [
+ ['onCalendarAdd', [['data']], Extension::SUBJECT_ADD, [['data'], [], []]],
+ ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Extension::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
+ ['onCalendarDelete', [['data'], ['shares']], Extension::SUBJECT_DELETE, [['data'], ['shares'], []]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataCallTriggerCalendarActivity
+ *
+ * @param string $method
+ * @param array $payload
+ * @param string $expectedSubject
+ * @param array $expectedPayload
+ */
+ public function testCallTriggerCalendarActivity($method, array $payload, $expectedSubject, array $expectedPayload) {
+ $backend = $this->getBackend(['triggerCalendarActivity']);
+ $backend->expects($this->once())
+ ->method('triggerCalendarActivity')
+ ->willReturnCallback(function() use($expectedPayload, $expectedSubject) {
+ $arguments = func_get_args();
+ $this->assertSame($expectedSubject, array_shift($arguments));
+ $this->assertEquals($expectedPayload, $arguments);
+ });
+
+ call_user_func_array([$backend, $method], $payload);
+ }
+
+ public function dataTriggerCalendarActivity() {
+ return [
+ // Add calendar
+ [Extension::SUBJECT_ADD, [], [], [], '', '', null, []],
+ [Extension::SUBJECT_ADD, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], [], [], '', 'admin', null, ['admin']],
+ [Extension::SUBJECT_ADD, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], [], [], 'test2', 'test2', null, ['admin']],
+
+ // Update calendar
+ [Extension::SUBJECT_UPDATE, [], [], [], '', '', null, []],
+ // No visible change - owner only
+ [Extension::SUBJECT_UPDATE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], '', 'admin', null, ['admin']],
+ // Visible change
+ [Extension::SUBJECT_UPDATE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']],
+ [Extension::SUBJECT_UPDATE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']],
+
+ // Delete calendar
+ [Extension::SUBJECT_DELETE, [], [], [], '', '', null, []],
+ [Extension::SUBJECT_DELETE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], '', 'admin', [], ['admin']],
+ [Extension::SUBJECT_DELETE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']],
+ [Extension::SUBJECT_DELETE, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataTriggerCalendarActivity
+ * @param string $action
+ * @param array $data
+ * @param array $shares
+ * @param array $changedProperties
+ * @param string $currentUser
+ * @param string $author
+ * @param string[]|null $shareUsers
+ * @param string[] $users
+ */
+ public function testTriggerCalendarActivity($action, array $data, array $shares, array $changedProperties, $currentUser, $author, $shareUsers, array $users) {
+ $backend = $this->getBackend(['getUsersForShares']);
+
+ if ($shareUsers === null) {
+ $backend->expects($this->never())
+ ->method('getUsersForShares');
+ } else {
+ $backend->expects($this->once())
+ ->method('getUsersForShares')
+ ->with($shares)
+ ->willReturn($shareUsers);
+ }
+
+ if ($author !== '') {
+ if ($currentUser !== '') {
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn($this->getUserMock($currentUser));
+ } else {
+ $this->userSession->expects($this->once())
+ ->method('getUser')
+ ->willReturn(null);
+ }
+
+ $event = $this->createMock(IEvent::class);
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($event);
+
+ $event->expects($this->once())
+ ->method('setApp')
+ ->with('dav')
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setObject')
+ ->with(Extension::CALENDAR, $data['id'])
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setType')
+ ->with(Extension::CALENDAR)
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setAuthor')
+ ->with($author)
+ ->willReturnSelf();
+
+ $event->expects($this->exactly(sizeof($users)))
+ ->method('setAffectedUser')
+ ->willReturnSelf();
+ $event->expects($this->exactly(sizeof($users)))
+ ->method('setSubject')
+ ->willReturnSelf();
+ $this->activityManager->expects($this->exactly(sizeof($users)))
+ ->method('publish')
+ ->with($event);
+ } else {
+ $this->activityManager->expects($this->never())
+ ->method('generateEvent');
+ }
+
+ $this->invokePrivate($backend, 'triggerCalendarActivity', [$action, $data, $shares, $changedProperties]);
+ }
+
+ public function dataGetUsersForShares() {
+ return [
+ [
+ [],
+ [],
+ [],
+ ],
+ [
+ [
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user3'],
+ ],
+ [],
+ ['user1', 'user2', 'user3'],
+ ],
+ [
+ [
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
+ ],
+ ['group2' => null, 'group3' => null],
+ ['user1', 'user2'],
+ ],
+ [
+ [
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user1'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/users/user2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/groups/group2'],
+ ['{http://owncloud.org/ns}principal' => 'principal/groups/group3'],
+ ],
+ ['group2' => ['user1', 'user2', 'user3'], 'group3' => ['user2', 'user3', 'user4']],
+ ['user1', 'user2', 'user3', 'user4'],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetUsersForShares
+ * @param array $shares
+ * @param array $groups
+ * @param array $expected
+ */
+ public function testGetUsersForShares(array $shares, array $groups, array $expected) {
+ $backend = $this->getBackend();
+
+ $getGroups = [];
+ foreach ($groups as $gid => $members) {
+ if ($members === null) {
+ $getGroups[] = [$gid, null];
+ continue;
+ }
+
+ $group = $this->createMock(IGroup::class);
+ $group->expects($this->once())
+ ->method('getUsers')
+ ->willReturn($this->getUsers($members));
+
+ $getGroups[] = [$gid, $group];
+ }
+
+ $this->groupManager->expects($this->exactly(sizeof($getGroups)))
+ ->method('get')
+ ->willReturnMap($getGroups);
+
+ $users = $this->invokePrivate($backend, 'getUsersForShares', [$shares]);
+ sort($users);
+ $this->assertEquals($expected, $users);
+ }
+
+ /**
+ * @param string[] $users
+ * @return IUser[]|\PHPUnit_Framework_MockObject_MockObject[]
+ */
+ protected function getUsers(array $users) {
+ $list = [];
+ foreach ($users as $user) {
+ $list[] = $this->getUserMock($user);
+ }
+ return $list;
+ }
+
+ /**
+ * @param string $uid
+ * @return IUser|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected function getUserMock($uid) {
+ $user = $this->createMock(IUser::class);
+ $user->expects($this->once())
+ ->method('getUID')
+ ->willReturn($uid);
+ return $user;
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 8349d98cd94..b5e700e8bc4 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -51,6 +51,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
'{DAV:}displayname' => 'Unit test',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
]);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar');
$this->backend->updateCalendar($calendarId, $patch);
$patch->commit();
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
@@ -60,6 +63,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$this->assertEquals('Calendar used for unit testing', $books[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
// delete the address book
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books));
@@ -106,6 +112,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0], $l10n);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
$this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books));
@@ -138,6 +147,9 @@ END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData);
/** @var IACL $child */
@@ -151,6 +163,9 @@ EOD;
$this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl);
// delete the address book
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books));
@@ -179,6 +194,9 @@ END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData);
// get all the cards
@@ -214,11 +232,17 @@ DTEND;VALUE=DATE-TIME:20130912T140000Z
END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject');
$this->backend->updateCalendarObject($calendarId, $uri, $calData);
$calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
$this->assertEquals($calData, $calendarObject['calendardata']);
// delete the card
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects));
@@ -246,10 +270,19 @@ END:VEVENT
END:VCALENDAR
EOD;
$uri0 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
$uri1 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
$uri2 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri2, $calData);
// get all the cards
@@ -270,8 +303,17 @@ EOD;
}
// delete the card
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri0);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri1);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri2);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects));
@@ -335,6 +377,10 @@ EOD;
}
public function testPublications() {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
+
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
@@ -357,10 +403,8 @@ EOD;
$calendar->setPublishStatus(false);
$this->assertEquals(false, $calendar->getPublishStatus());
- $publicCalendarURI = md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId());
$this->setExpectedException('Sabre\DAV\Exception\NotFound');
- $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI);
-
+ $this->backend->getPublicCalendar($publicCalendarURI);
}
public function testSubscriptions() {
diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
index 6dfec6d7e1f..59fa4747a93 100644
--- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
+++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
@@ -9,6 +9,7 @@ use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\PublicCalendarRoot;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
/**
@@ -27,12 +28,11 @@ class PublicCalendarRootTest extends TestCase {
private $publicCalendarRoot;
/** @var IL10N */
private $l10n;
- /** @var IUserManager */
- private $userManager;
- /** @var Principal */
+ /** @var Principal|\PHPUnit_Framework_MockObject_MockObject */
private $principal;
- /** var IConfig */
- protected $config;
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
+
/** @var ISecureRandom */
private $random;
@@ -40,19 +40,17 @@ class PublicCalendarRootTest extends TestCase {
parent::setUp();
$db = \OC::$server->getDatabaseConnection();
- $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
- ->disableOriginalConstructor()
- ->getMock();
- $this->config = \OC::$server->getConfig();
- $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
+ $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
+ $this->userManager = $this->createMock(IUserManager::class);
$this->random = \OC::$server->getSecureRandom();
+ $dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->backend = new CalDavBackend(
$db,
$this->principal,
$this->userManager,
- $this->config,
- $this->random
+ $this->random,
+ $dispatcher
);
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend);