aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2025-01-08 11:48:53 +0100
committerGitHub <noreply@github.com>2025-01-08 11:48:53 +0100
commitdd0f7f0bbfb9c176fe4845458bdc62ec7b388d8f (patch)
tree9da570ba67309bbdcb19e280deeb491109aa9d61 /tests
parente7122a6864947ead88a022d0a6cf3a4c4209b6eb (diff)
parent42fa3abc3ef31d6bfebc29b76c8f55da45c1d16c (diff)
downloadnextcloud-server-dd0f7f0bbfb9c176fe4845458bdc62ec7b388d8f.tar.gz
nextcloud-server-dd0f7f0bbfb9c176fe4845458bdc62ec7b388d8f.zip
Merge pull request #49888 from nextcloud/feat/ocp/meetings-api-requirements
feat(ocp): calendar event builder api
Diffstat (limited to 'tests')
-rw-r--r--tests/data/ics/event-builder-complete.ics16
-rw-r--r--tests/data/ics/event-builder-complete.ics.license2
-rw-r--r--tests/data/ics/event-builder-without-attendees.ics13
-rw-r--r--tests/data/ics/event-builder-without-attendees.ics.license2
-rw-r--r--tests/lib/Calendar/CalendarEventBuilderTest.php146
-rw-r--r--tests/lib/Calendar/ManagerTest.php53
6 files changed, 216 insertions, 16 deletions
diff --git a/tests/data/ics/event-builder-complete.ics b/tests/data/ics/event-builder-complete.ics
new file mode 100644
index 00000000000..d96a3137356
--- /dev/null
+++ b/tests/data/ics/event-builder-complete.ics
@@ -0,0 +1,16 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject 4.5.6//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:event-uid-123
+DTSTAMP:20250105T000000Z
+SUMMARY:My event
+DTSTART:20250105T170958Z
+DTEND:20250105T171958Z
+DESCRIPTION:Foo bar baz
+ORGANIZER:mailto:organizer@domain.tld
+ATTENDEE:mailto:attendee1@domain.tld
+ATTENDEE:mailto:attendee2@domain.tld
+END:VEVENT
+END:VCALENDAR
diff --git a/tests/data/ics/event-builder-complete.ics.license b/tests/data/ics/event-builder-complete.ics.license
new file mode 100644
index 00000000000..f7f52efa96f
--- /dev/null
+++ b/tests/data/ics/event-builder-complete.ics.license
@@ -0,0 +1,2 @@
+SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/data/ics/event-builder-without-attendees.ics b/tests/data/ics/event-builder-without-attendees.ics
new file mode 100644
index 00000000000..95c4c44fa1f
--- /dev/null
+++ b/tests/data/ics/event-builder-without-attendees.ics
@@ -0,0 +1,13 @@
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject 4.5.6//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+UID:event-uid-123
+DTSTAMP:20250105T000000Z
+SUMMARY:My event
+DTSTART:20250105T170958Z
+DTEND:20250105T171958Z
+DESCRIPTION:Foo bar baz
+END:VEVENT
+END:VCALENDAR
diff --git a/tests/data/ics/event-builder-without-attendees.ics.license b/tests/data/ics/event-builder-without-attendees.ics.license
new file mode 100644
index 00000000000..f7f52efa96f
--- /dev/null
+++ b/tests/data/ics/event-builder-without-attendees.ics.license
@@ -0,0 +1,2 @@
+SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/tests/lib/Calendar/CalendarEventBuilderTest.php b/tests/lib/Calendar/CalendarEventBuilderTest.php
new file mode 100644
index 00000000000..48684d56093
--- /dev/null
+++ b/tests/lib/Calendar/CalendarEventBuilderTest.php
@@ -0,0 +1,146 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Calendar;
+
+use DateTimeImmutable;
+use InvalidArgumentException;
+use OC\Calendar\CalendarEventBuilder;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Calendar\ICreateFromString;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class CalendarEventBuilderTest extends TestCase {
+ private CalendarEventBuilder $calendarEventBuilder;
+ private ITimeFactory&MockObject $timeFactory;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->timeFactory->method('now')
+ ->willReturn(new DateTimeImmutable('20250105T000000Z'));
+
+ $this->calendarEventBuilder = new CalendarEventBuilder(
+ 'event-uid-123',
+ $this->timeFactory,
+ );
+ }
+
+ public function testToIcs(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('mailto:organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics');
+ $actual = $this->calendarEventBuilder->toIcs();
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testToIcsWithoutOrganizerAndAttendees(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+
+ $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-without-attendees.ics');
+ $actual = $this->calendarEventBuilder->toIcs();
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testToIcsWithoutMailtoPrefix(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee2@domain.tld');
+
+ $expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics');
+ $actual = $this->calendarEventBuilder->toIcs();
+ $this->assertEquals($expected, $actual);
+ }
+
+ public function testCreateInCalendar(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $expectedIcs = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-complete.ics');
+ $calendar = $this->createMock(ICreateFromString::class);
+ $calendar->expects(self::once())
+ ->method('createFromString')
+ ->with('event-uid-123.ics', $expectedIcs);
+
+ $actual = $this->calendarEventBuilder->createInCalendar($calendar);
+ $this->assertEquals('event-uid-123.ics', $actual);
+ }
+
+ public function testToIcsWithoutStartDate(): void {
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $this->expectException(InvalidArgumentException::class);
+ $this->expectExceptionMessageMatches('/start date/i');
+ $this->calendarEventBuilder->toIcs();
+ }
+
+ public function testToIcsWithoutEndDate(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $this->expectException(InvalidArgumentException::class);
+ $this->expectExceptionMessageMatches('/end date/i');
+ $this->calendarEventBuilder->toIcs();
+ }
+
+ public function testToIcsWithoutSummary(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $this->expectException(InvalidArgumentException::class);
+ $this->expectExceptionMessageMatches('/summary/i');
+ $this->calendarEventBuilder->toIcs();
+ }
+
+ public function testToIcsWithoutOrganizerWithAttendees(): void {
+ $this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
+ $this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
+ $this->calendarEventBuilder->setSummary('My event');
+ $this->calendarEventBuilder->setDescription('Foo bar baz');
+ $this->calendarEventBuilder->addAttendee('attendee1@domain.tld');
+ $this->calendarEventBuilder->addAttendee('mailto:attendee2@domain.tld');
+
+ $this->expectException(InvalidArgumentException::class);
+ $this->expectExceptionMessageMatches('/organizer/i');
+ $this->calendarEventBuilder->toIcs();
+ }
+}
diff --git a/tests/lib/Calendar/ManagerTest.php b/tests/lib/Calendar/ManagerTest.php
index f0ca278f352..a7aeed98046 100644
--- a/tests/lib/Calendar/ManagerTest.php
+++ b/tests/lib/Calendar/ManagerTest.php
@@ -14,6 +14,7 @@ use OCP\Calendar\ICalendarIsShared;
use OCP\Calendar\ICalendarIsWritable;
use OCP\Calendar\ICreateFromString;
use OCP\Calendar\IHandleImipMessage;
+use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@@ -44,6 +45,9 @@ class ManagerTest extends TestCase {
/** @var ITimeFactory&MockObject */
private $time;
+ /** @var ISecureRandom&MockObject */
+ private ISecureRandom $secureRandom;
+
private VCalendar $vCalendar1a;
protected function setUp(): void {
@@ -53,12 +57,14 @@ class ManagerTest extends TestCase {
$this->container = $this->createMock(ContainerInterface::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->time = $this->createMock(ITimeFactory::class);
+ $this->secureRandom = $this->createMock(ISecureRandom::class);
$this->manager = new Manager(
$this->coordinator,
$this->container,
$this->logger,
$this->time,
+ $this->secureRandom,
);
// construct calendar with a 1 hour event and same start/end time zones
@@ -260,7 +266,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -291,7 +298,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -321,7 +329,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -352,7 +361,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -384,7 +394,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -416,7 +427,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -448,7 +460,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -491,7 +504,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -534,7 +548,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->onlyMethods(['getCalendarsForPrincipal'])
->getMock();
@@ -612,7 +627,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -643,7 +659,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -680,7 +697,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -767,7 +785,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -800,7 +819,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -837,7 +857,8 @@ class ManagerTest extends TestCase {
$this->coordinator,
$this->container,
$this->logger,
- $this->time
+ $this->time,
+ $this->secureRandom,
])
->setMethods([
'getCalendarsForPrincipal'
@@ -866,7 +887,7 @@ class ManagerTest extends TestCase {
$result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize());
$this->assertTrue($result);
}
-
+
private function getVCalendarReply(): Document {
$data = <<<EOF
BEGIN:VCALENDAR