diff options
Diffstat (limited to 'apps/dav/tests/unit/CalDAV/CalendarImplTest.php')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/CalendarImplTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php index af8c056cac7..6842bdadb53 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php @@ -25,9 +25,13 @@ */ namespace OCA\DAV\Tests\unit\CalDAV; +use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\CalDAV\CalendarImpl; +use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; +use OCA\DAV\CalDAV\Schedule\Plugin; +use PHPUnit\Framework\MockObject\MockObject; class CalendarImplTest extends \Test\TestCase { @@ -51,6 +55,7 @@ class CalendarImplTest extends \Test\TestCase { 'id' => 'fancy_id_123', '{DAV:}displayname' => 'user readable name 123', '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', + 'uri' => '/this/is/a/uri' ]; $this->backend = $this->createMock(CalDavBackend::class); @@ -125,4 +130,78 @@ class CalendarImplTest extends \Test\TestCase { $this->assertEquals(31, $this->calendarImpl->getPermissions()); } + + public function testHandleImipMessage(): void { + $invitationResponseServer = $this->createConfiguredMock(InvitationResponseServer::class, [ + 'server' => $this->createConfiguredMock(CalDavBackend::class, [ + 'getPlugin' => [ + 'auth' => $this->createMock(CustomPrincipalPlugin::class), + 'schedule' => $this->createMock(Plugin::class) + ] + ]) + ]); + + $message = <<<EOF +BEGIN:VCALENDAR +PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ATTENDEE;PARTSTAT=mailto:lewis@stardew-tent-living.com:ACCEPTED +ORGANIZER:mailto:pierre@generalstore.com +UID:aUniqueUid +SEQUENCE:2 +REQUEST-STATUS:2.0;Success +%sEND:VEVENT +END:VCALENDAR +EOF; + + /** @var CustomPrincipalPlugin|MockObject $authPlugin */ + $authPlugin = $invitationResponseServer->server->getPlugin('auth'); + $authPlugin->expects(self::once()) + ->method('setPrincipalUri') + ->with($this->calendar->getPrincipalURI()); + + /** @var Plugin|MockObject $schedulingPlugin */ + $schedulingPlugin = $invitationResponseServer->server->getPlugin('caldav-schedule'); + $schedulingPlugin->expects(self::once()) + ->method('setPathOfCalendarObjectChange') + ->with('fullcalendarname'); + } + + public function testHandleImipMessageNoCalendarUri(): void { + $invitationResponseServer = $this->createConfiguredMock(InvitationResponseServer::class, [ + 'server' => $this->createConfiguredMock(CalDavBackend::class, [ + 'getPlugin' => [ + 'auth' => $this->createMock(CustomPrincipalPlugin::class), + 'schedule' => $this->createMock(Plugin::class) + ] + ]) + ]); + + $message = <<<EOF +BEGIN:VCALENDAR +PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN +METHOD:REPLY +VERSION:2.0 +BEGIN:VEVENT +ATTENDEE;PARTSTAT=mailto:lewis@stardew-tent-living.com:ACCEPTED +ORGANIZER:mailto:pierre@generalstore.com +UID:aUniqueUid +SEQUENCE:2 +REQUEST-STATUS:2.0;Success +%sEND:VEVENT +END:VCALENDAR +EOF; + + /** @var CustomPrincipalPlugin|MockObject $authPlugin */ + $authPlugin = $invitationResponseServer->server->getPlugin('auth'); + $authPlugin->expects(self::once()) + ->method('setPrincipalUri') + ->with($this->calendar->getPrincipalURI()); + + unset($this->calendarInfo['uri']); + $this->expectException('CalendarException'); + $this->calendarImpl->handleIMipMessage('filename.ics', $message); + } } |