summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2017-11-01 22:00:53 +0100
committerGeorg Ehrke <developer@georgehrke.com>2017-11-07 13:18:38 +0100
commit3059191444bd538ff24d46e096a1ee13d0fc3898 (patch)
treea134a394044413f8936a67c13fa18fc614f7ecff /apps/dav/tests
parent0756fc0893700bc0a323f528c88a6d4c75c91e39 (diff)
downloadnextcloud-server-3059191444bd538ff24d46e096a1ee13d0fc3898.tar.gz
nextcloud-server-3059191444bd538ff24d46e096a1ee13d0fc3898.zip
ensure uid for calendar objects is unique
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php4
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php105
2 files changed, 101 insertions, 8 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
index a7bf4432c64..bcf6cb763ea 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
@@ -133,13 +133,15 @@ abstract class AbstractCalDavBackendTest extends TestCase {
protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') {
+ $randomPart = self::getUniqueID();
+
$calData = <<<EOD
BEGIN:VCALENDAR
VERSION:2.0
PRODID:ownCloud Calendar
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20130910T125139Z
-UID:47d15e3ec8
+UID:47d15e3ec8-$randomPart
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
SUMMARY:Test Event
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index fa298282d7e..b82d0bc0a16 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -266,18 +266,66 @@ EOD;
$this->assertCount(0, $calendarObjects);
}
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ * @expectedExceptionMessage Calendar object with uid already exists in this calendar collection.
+ */
+ public function testMultipleCalendarObjectsWithSameUID() {
+ $calendarId = $this->createTestCalendar();
+
+ $calData = <<<'EOD'
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:ownCloud 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;
+
+ $uri0 = static::getUniqueID('event');
+ $uri1 = static::getUniqueID('event');
+ $this->backend->createCalendarObject($calendarId, $uri0, $calData);
+ $this->backend->createCalendarObject($calendarId, $uri1, $calData);
+ }
+
public function testMultiCalendarObjects() {
$calendarId = $this->createTestCalendar();
// create an event
- $calData = <<<'EOD'
+ $calData = [];
+ $calData[] = <<<'EOD'
BEGIN:VCALENDAR
VERSION:2.0
PRODID:ownCloud Calendar
BEGIN:VEVENT
CREATED;VALUE=DATE-TIME:20130910T125139Z
-UID:47d15e3ec8
+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;
+
+ $calData[] = <<<'EOD'
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:ownCloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-2
LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
SUMMARY:Test Event
@@ -287,21 +335,39 @@ CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
EOD;
+
+ $calData[] = <<<'EOD'
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:ownCloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8-3
+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;
+
$uri0 = static::getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
- $this->backend->createCalendarObject($calendarId, $uri0, $calData);
+ $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
$uri1 = static::getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
- $this->backend->createCalendarObject($calendarId, $uri1, $calData);
+ $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
$uri2 = static::getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
- $this->backend->createCalendarObject($calendarId, $uri2, $calData);
+ $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
// get all the cards
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
@@ -317,9 +383,15 @@ EOD;
$this->assertArrayHasKey('etag', $card);
$this->assertArrayHasKey('size', $card);
$this->assertArrayHasKey('classification', $card);
- $this->assertEquals($calData, $card['calendardata']);
}
+ usort($calendarObjects, function($a, $b) {
+ return $a['id'] - $b['id'];
+ });
+
+ $this->assertEquals($calData[1], $calendarObjects[0]['calendardata']);
+ $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
+
// delete the card
$this->dispatcher->expects($this->at(0))
->method('dispatch')
@@ -362,7 +434,26 @@ EOD;
public function testGetCalendarObjectByUID() {
$calendarId = $this->createTestCalendar();
- $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
+ $uri = static::getUniqueID('calobj');
+ $calData = <<<'EOD'
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:ownCloud Calendar
+BEGIN:VEVENT
+CREATED;VALUE=DATE-TIME:20130910T125139Z
+UID:47d15e3ec8
+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;
+
+
+ $this->backend->createCalendarObject($calendarId, $uri, $calData);
$co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8');
$this->assertNotNull($co);