summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/CalDAV')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php6
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/BackendTest.php19
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php109
-rw-r--r--apps/dav/tests/unit/CalDAV/CalendarImplTest.php126
-rw-r--r--apps/dav/tests/unit/CalDAV/CalendarManagerTest.php81
-rw-r--r--apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php5
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php19
7 files changed, 361 insertions, 4 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index 90bf860b24d..2a01bd425c0 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -28,6 +28,7 @@ namespace OCA\DAV\Tests\unit\CalDAV;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Connector\Sabre\Principal;
use OCP\IGroupManager;
+use OCP\ILogger;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
@@ -57,6 +58,8 @@ abstract class AbstractCalDavBackend extends TestCase {
/** @var ISecureRandom */
private $random;
+ /** @var ILogger */
+ private $logger;
const UNIT_TEST_USER = 'principals/users/caldav-unit-test';
const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1';
@@ -84,7 +87,8 @@ abstract class AbstractCalDavBackend extends TestCase {
$db = \OC::$server->getDatabaseConnection();
$this->random = \OC::$server->getSecureRandom();
- $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->groupManager, $this->random, $this->dispatcher);
+ $this->logger = $this->createMock(ILogger::class);
+ $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->groupManager, $this->random, $this->logger, $this->dispatcher);
$this->cleanUpBackend();
}
diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
index 16b2b8a616e..3b4e0038b59 100644
--- a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
@@ -79,6 +79,7 @@ class BackendTest extends TestCase {
['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]],
['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]],
+ ['onCalendarPublication', [['data'], true], Calendar::SUBJECT_PUBLISH, [['data'], [], []]],
];
}
@@ -163,6 +164,24 @@ class BackendTest extends TestCase {
'uri' => 'this-uri',
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], 'test2', 'test2', ['user1'], ['user1', 'admin']],
+
+ // Publish calendar
+ [Calendar::SUBJECT_PUBLISH, [], [], [], '', '', null, []],
+ [Calendar::SUBJECT_PUBLISH, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ 'uri' => 'this-uri',
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], '', 'admin', [], ['admin']],
+
+ // Unpublish calendar
+ [Calendar::SUBJECT_UNPUBLISH, [], [], [], '', '', null, []],
+ [Calendar::SUBJECT_UNPUBLISH, [
+ 'principaluri' => 'principal/user/admin',
+ 'id' => 42,
+ 'uri' => 'this-uri',
+ '{DAV:}displayname' => 'Name of calendar',
+ ], ['shares'], [], '', 'admin', [], ['admin']],
];
}
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 74820792c32..0b8978a0409 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -725,4 +725,113 @@ EOD;
]);
$this->assertEquals(count($search5), 0);
}
+
+ /**
+ * @dataProvider searchDataProvider
+ */
+ public function testSearch($isShared, $count) {
+ $calendarId = $this->createTestCalendar();
+
+ $uris = [];
+ $calData = [];
+
+ $uris[] = static::getUniqueID('calobj');
+ $calData[] = <<<EOD
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:Nextcloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-1
+LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
+DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
+SUMMARY:Test Event
+DTSTART;VALUE=DATE-TIME:20130912T130000Z
+DTEND;VALUE=DATE-TIME:20130912T140000Z
+CLASS:PUBLIC
+END:VEVENT
+END:VCALENDAR
+EOD;
+
+ $uris[] = static::getUniqueID('calobj');
+ $calData[] = <<<EOD
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:Nextcloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-2
+LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
+DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
+SUMMARY:123
+LOCATION:Test
+DTSTART;VALUE=DATE-TIME:20130912T130000Z
+DTEND;VALUE=DATE-TIME:20130912T140000Z
+CLASS:PUBLIC
+END:VEVENT
+END:VCALENDAR
+EOD;
+
+ $uris[] = static::getUniqueID('calobj');
+ $calData[] = <<<EOD
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:Nextcloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-3
+LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
+DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
+SUMMARY:123
+ATTENDEE;CN=test:mailto:foo@bar.com
+DTSTART;VALUE=DATE-TIME:20130912T130000Z
+DTEND;VALUE=DATE-TIME:20130912T140000Z
+CLASS:PRIVATE
+END:VEVENT
+END:VCALENDAR
+EOD;
+
+ $uris[] = static::getUniqueID('calobj');
+ $calData[] = <<<EOD
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:Nextcloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-4
+LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
+DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
+SUMMARY:123
+ATTENDEE;CN=foobar:mailto:test@bar.com
+DTSTART;VALUE=DATE-TIME:20130912T130000Z
+DTEND;VALUE=DATE-TIME:20130912T140000Z
+CLASS:CONFIDENTIAL
+END:VEVENT
+END:VCALENDAR
+EOD;
+
+ $uriCount = count($uris);
+ for ($i=0; $i < $uriCount; $i++) {
+ $this->backend->createCalendarObject($calendarId,
+ $uris[$i], $calData[$i]);
+ }
+
+ $calendarInfo = [
+ 'id' => $calendarId,
+ 'principaluri' => 'user1',
+ '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1',
+ ];
+
+ $result = $this->backend->search($calendarInfo, 'Test',
+ ['SUMMARY', 'LOCATION', 'ATTENDEE'], [], null, null);
+
+ $this->assertCount($count, $result);
+ }
+
+ public function searchDataProvider() {
+ return [
+ [false, 4],
+ [true, 2],
+ ];
+ }
}
diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
new file mode 100644
index 00000000000..ca3256773b3
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.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;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\Calendar;
+use OCA\DAV\CalDAV\CalendarImpl;
+
+class CalendarImplTest extends \Test\TestCase {
+
+ /** @var CalendarImpl */
+ private $calendarImpl;
+
+ /** @var Calendar | \PHPUnit_Framework_MockObject_MockObject */
+ private $calendar;
+
+ /** @var array */
+ private $calendarInfo;
+
+ /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
+ private $backend;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->calendar = $this->createMock(Calendar::class);
+ $this->calendarInfo = [
+ 'id' => 'fancy_id_123',
+ '{DAV:}displayname' => 'user readable name 123',
+ '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
+ ];
+ $this->backend = $this->createMock(CalDavBackend::class);
+
+ $this->calendarImpl = new CalendarImpl($this->calendar,
+ $this->calendarInfo, $this->backend);
+ }
+
+
+ public function testGetKey() {
+ $this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123');
+ }
+
+ public function testGetDisplayname() {
+ $this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123');
+ }
+
+ public function testGetDisplayColor() {
+ $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC');
+ }
+
+ public function testSearch() {
+ $this->backend->expects($this->once())
+ ->method('search')
+ ->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337)
+ ->will($this->returnValue(['SEARCHRESULTS']));
+
+ $result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337);
+ $this->assertEquals($result, ['SEARCHRESULTS']);
+ }
+
+ public function testGetPermissionRead() {
+ $this->calendar->expects($this->once())
+ ->method('getACL')
+ ->with()
+ ->will($this->returnValue([
+ ['privilege' => '{DAV:}read']
+ ]));
+
+ $this->assertEquals(1, $this->calendarImpl->getPermissions());
+ }
+
+ public function testGetPermissionWrite() {
+ $this->calendar->expects($this->once())
+ ->method('getACL')
+ ->with()
+ ->will($this->returnValue([
+ ['privilege' => '{DAV:}write']
+ ]));
+
+ $this->assertEquals(6, $this->calendarImpl->getPermissions());
+ }
+
+ public function testGetPermissionReadWrite() {
+ $this->calendar->expects($this->once())
+ ->method('getACL')
+ ->with()
+ ->will($this->returnValue([
+ ['privilege' => '{DAV:}read'],
+ ['privilege' => '{DAV:}write']
+ ]));
+
+ $this->assertEquals(7, $this->calendarImpl->getPermissions());
+ }
+
+ public function testGetPermissionAll() {
+ $this->calendar->expects($this->once())
+ ->method('getACL')
+ ->with()
+ ->will($this->returnValue([
+ ['privilege' => '{DAV:}all']
+ ]));
+
+ $this->assertEquals(31, $this->calendarImpl->getPermissions());
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php b/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php
new file mode 100644
index 00000000000..db8c536da53
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.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;
+
+use OC\Calendar\Manager;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\CalendarImpl;
+use OCA\DAV\CalDAV\CalendarManager;
+use OCP\Calendar\IManager;
+use OCP\IL10N;
+
+class CalendarManagerTest extends \Test\TestCase {
+
+ /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
+ private $backend;
+
+ /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */
+ private $l10n;
+
+ /** @var CalendarManager */
+ private $manager;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->backend = $this->createMock(CalDavBackend::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->manager = new CalendarManager($this->backend,
+ $this->l10n);
+ }
+
+ public function testSetupCalendarProvider() {
+ $this->backend->expects($this->once())
+ ->method('getCalendarsForUser')
+ ->with('principals/users/user123')
+ ->will($this->returnValue([
+ ['id' => 123, 'uri' => 'blablub1'],
+ ['id' => 456, 'uri' => 'blablub2'],
+ ]));
+
+ /** @var IManager | \PHPUnit_Framework_MockObject_MockObject $calendarManager */
+ $calendarManager = $this->createMock(Manager::class);
+ $calendarManager->expects($this->at(0))
+ ->method('registerCalendar')
+ ->will($this->returnCallback(function() {
+ $parameter = func_get_arg(0);
+ $this->assertInstanceOf(CalendarImpl::class, $parameter);
+ $this->assertEquals(123, $parameter->getKey());
+ }));
+
+ $calendarManager->expects($this->at(1))
+ ->method('registerCalendar')
+ ->will($this->returnCallback(function() {
+ $parameter = func_get_arg(0);
+ $this->assertInstanceOf(CalendarImpl::class, $parameter);
+ $this->assertEquals(456, $parameter->getKey());
+ }));
+
+ $this->manager->setupCalendarProvider($calendarManager, 'user123');
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
index fef85074182..c10b333e28d 100644
--- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
+++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php
@@ -35,6 +35,7 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\PublicCalendarRoot;
+use OCP\ILogger;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -67,6 +68,8 @@ class PublicCalendarRootTest extends TestCase {
/** @var ISecureRandom */
private $random;
+ /** @var ILogger */
+ private $logger;
public function setUp() {
parent::setUp();
@@ -76,6 +79,7 @@ class PublicCalendarRootTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->random = \OC::$server->getSecureRandom();
+ $this->logger = $this->createMock(ILogger::class);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->principal->expects($this->any())->method('getGroupMembership')
@@ -88,6 +92,7 @@ class PublicCalendarRootTest extends TestCase {
$this->userManager,
$this->groupManager,
$this->random,
+ $this->logger,
$dispatcher
);
$this->l10n = $this->getMockBuilder(IL10N::class)
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
index ee52cab2814..3f89002ab98 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
@@ -29,6 +29,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
use OC\Mail\Mailer;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Defaults;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -46,6 +47,7 @@ class IMipPluginTest extends TestCase {
public function testDelivery() {
$mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setFrom')->willReturn($mailMessage);
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
$mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
@@ -68,8 +70,13 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
+ $defaults = $this->createMock(Defaults::class);
+ $defaults->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('Instance Name 123'));
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -98,6 +105,7 @@ class IMipPluginTest extends TestCase {
public function testFailedDelivery() {
$mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setFrom')->willReturn($mailMessage);
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
$mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
@@ -120,8 +128,10 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
+ $defaults = $this->createMock(Defaults::class);
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -153,6 +163,7 @@ class IMipPluginTest extends TestCase {
*/
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {
$mailMessage = $this->createMock(IMessage::class);
+ $mailMessage->method('setFrom')->willReturn($mailMessage);
$mailMessage->method('setReplyTo')->willReturn($mailMessage);
$mailMessage->method('setTo')->willReturn($mailMessage);
/** @var Mailer | \PHPUnit_Framework_MockObject_MockObject $mailer */
@@ -179,8 +190,10 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
+ $defaults = $this->createMock(Defaults::class);
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, 'user123');
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();