summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/CalDAV/CalendarImplTest.php')
-rw-r--r--apps/dav/tests/unit/CalDAV/CalendarImplTest.php144
1 files changed, 108 insertions, 36 deletions
diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
index 6842bdadb53..cc0b963634c 100644
--- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php
@@ -31,10 +31,18 @@ use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\CalendarImpl;
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
use OCA\DAV\CalDAV\Schedule\Plugin;
+use OCA\DAV\Connector\Sabre\Server;
+use OCP\Calendar\Exceptions\CalendarException;
use PHPUnit\Framework\MockObject\MockObject;
+use Sabre\VObject\Component\VCalendar;
+use Sabre\VObject\Component\VEvent;
+use Sabre\VObject\ITip\Message;
+use Sabre\VObject\Reader;
+/**
+ * @group DB
+ */
class CalendarImplTest extends \Test\TestCase {
-
/** @var CalendarImpl */
private $calendarImpl;
@@ -69,7 +77,7 @@ class CalendarImplTest extends \Test\TestCase {
}
public function testGetDisplayname() {
- $this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123');
+ $this->assertEquals($this->calendarImpl->getDisplayName(), 'user readable name 123');
}
public function testGetDisplayColor() {
@@ -132,52 +140,104 @@ class CalendarImplTest extends \Test\TestCase {
}
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
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:lewis@stardew-tent-living.com
ORGANIZER:mailto:pierre@generalstore.com
UID:aUniqueUid
SEQUENCE:2
REQUEST-STATUS:2.0;Success
-%sEND:VEVENT
+END:VEVENT
END:VCALENDAR
EOF;
/** @var CustomPrincipalPlugin|MockObject $authPlugin */
- $authPlugin = $invitationResponseServer->server->getPlugin('auth');
+ $authPlugin = $this->createMock(CustomPrincipalPlugin::class);
$authPlugin->expects(self::once())
- ->method('setPrincipalUri')
+ ->method('setCurrentPrincipal')
->with($this->calendar->getPrincipalURI());
+ /** @var \Sabre\DAVACL\Plugin|MockObject $aclPlugin*/
+ $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class);
+
/** @var Plugin|MockObject $schedulingPlugin */
- $schedulingPlugin = $invitationResponseServer->server->getPlugin('caldav-schedule');
+ $schedulingPlugin = $this->createMock(Plugin::class);
+ $iTipMessage = $this->getITipMessage($message);
+ $iTipMessage->recipient = "mailto:lewis@stardew-tent-living.com";
$schedulingPlugin->expects(self::once())
- ->method('setPathOfCalendarObjectChange')
- ->with('fullcalendarname');
+ ->method('scheduleLocalDelivery')
+ ->with($iTipMessage);
+
+ $server = $this->createMock(Server::class);
+ $server->expects($this->any())
+ ->method('getPlugin')
+ ->willReturnMap([
+ ['auth', $authPlugin],
+ ['acl', $aclPlugin],
+ ['caldav-schedule', $schedulingPlugin]
+ ]);
+
+ $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer', 'isExternalAttendee']);
+ $invitationResponseServer->server = $server;
+ $invitationResponseServer->expects($this->any())
+ ->method('getServer')
+ ->willReturn($server);
+ $invitationResponseServer->expects(self::once())
+ ->method('isExternalAttendee')
+ ->willReturn(false);
+
+ $calendarImpl = $this->getMockBuilder(CalendarImpl::class)
+ ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend])
+ ->onlyMethods(['getInvitationResponseServer'])
+ ->getMock();
+ $calendarImpl->expects($this->once())
+ ->method('getInvitationResponseServer')
+ ->willReturn($invitationResponseServer);
+
+ $calendarImpl->handleIMipMessage('filename.ics', $message);
}
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)
- ]
- ])
- ]);
+ /** @var CustomPrincipalPlugin|MockObject $authPlugin */
+ $authPlugin = $this->createMock(CustomPrincipalPlugin::class);
+ $authPlugin->expects(self::once())
+ ->method('setCurrentPrincipal')
+ ->with($this->calendar->getPrincipalURI());
+ unset($this->calendarInfo['uri']);
+
+ /** @var Plugin|MockObject $schedulingPlugin */
+ $schedulingPlugin = $this->createMock(Plugin::class);
+
+ /** @var \Sabre\DAVACL\Plugin|MockObject $schedulingPlugin */
+ $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class);
+
+ $server =
+ $this->createMock(Server::class);
+ $server->expects($this->any())
+ ->method('getPlugin')
+ ->willReturnMap([
+ ['auth', $authPlugin],
+ ['acl', $aclPlugin],
+ ['caldav-schedule', $schedulingPlugin]
+ ]);
+
+ $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer']);
+ $invitationResponseServer->server = $server;
+ $invitationResponseServer->expects($this->any())
+ ->method('getServer')
+ ->willReturn($server);
+
+ $calendarImpl = $this->getMockBuilder(CalendarImpl::class)
+ ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend])
+ ->onlyMethods(['getInvitationResponseServer'])
+ ->getMock();
+ $calendarImpl->expects($this->once())
+ ->method('getInvitationResponseServer')
+ ->willReturn($invitationResponseServer);
$message = <<<EOF
BEGIN:VCALENDAR
@@ -185,23 +245,35 @@ PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
METHOD:REPLY
VERSION:2.0
BEGIN:VEVENT
-ATTENDEE;PARTSTAT=mailto:lewis@stardew-tent-living.com:ACCEPTED
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:lewis@stardew-tent-living.com
ORGANIZER:mailto:pierre@generalstore.com
UID:aUniqueUid
SEQUENCE:2
REQUEST-STATUS:2.0;Success
-%sEND:VEVENT
+END:VEVENT
END:VCALENDAR
EOF;
- /** @var CustomPrincipalPlugin|MockObject $authPlugin */
- $authPlugin = $invitationResponseServer->server->getPlugin('auth');
- $authPlugin->expects(self::once())
- ->method('setPrincipalUri')
- ->with($this->calendar->getPrincipalURI());
+ $this->expectException(CalendarException::class);
+ $calendarImpl->handleIMipMessage('filename.ics', $message);
+ }
- unset($this->calendarInfo['uri']);
- $this->expectException('CalendarException');
- $this->calendarImpl->handleIMipMessage('filename.ics', $message);
+ private function getITipMessage($calendarData): Message {
+ $iTipMessage = new Message();
+ /** @var VCalendar $vObject */
+ $vObject = Reader::read($calendarData);
+ /** @var VEvent $vEvent */
+ $vEvent = $vObject->{'VEVENT'};
+ $orgaizer = $vEvent->{'ORGANIZER'}->getValue();
+ $attendee = $vEvent->{'ATTENDEE'}->getValue();
+
+ $iTipMessage->method = $vObject->{'METHOD'}->getValue();
+ $iTipMessage->recipient = $orgaizer;
+ $iTipMessage->sender = $attendee;
+ $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : '';
+ $iTipMessage->component = 'VEVENT';
+ $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0;
+ $iTipMessage->message = $vObject;
+ return $iTipMessage;
}
}