From d311ff12408e34c0d1b661276e0224b67a2e034d Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Thu, 3 Nov 2022 11:10:26 +0100 Subject: [PATCH] fixup! Attempt to fix CalendarImpl tests --- .../tests/unit/CalDAV/CalendarImplTest.php | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php index 27e4afd1ccf7a..b504e8b124915 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php @@ -34,6 +34,10 @@ use OCP\Calendar\Exceptions\CalendarException; use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Server; +use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\ITip\Message; +use Sabre\VObject\Reader; /** * @group DB @@ -136,29 +140,20 @@ public function testGetPermissionAll() { $this->assertEquals(31, $this->calendarImpl->getPermissions()); } - public function testHandleImipMssage(): void { + public function testHandleImipMessage(): void { /** @var CustomPrincipalPlugin|MockObject $authPlugin */ $authPlugin = $this->createMock(CustomPrincipalPlugin::class); $authPlugin->expects(self::once()) ->method('setCurrentPrincipal') ->with($this->calendar->getPrincipalURI()); - /** @var Plugin|MockObject $schedulingPlugin */ - $schedulingPlugin = $this->createMock(Plugin::class); - // FIXME: THis was expected to be called once but isn't - $schedulingPlugin->expects(self::once()) - ->method('setPathOfCalendarObjectChange') - ->with('fullcalendarname'); - /** @var \Sabre\DAVACL\Plugin|MockObject $schedulingPlugin */ $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); - // FIXME: The :ACCEPTED looks odd in the call $aclPlugin->expects(self::once()) ->method('getPrincipalByUri') - ->with('lewis@stardew-tent-living.com:ACCEPTED'); + ->with('mailto:lewis@stardew-tent-living.com'); - $server = - $this->createMock(Server::class); + $server = $this->createMock(Server::class); $server->expects($this->any()) ->method('getPlugin') ->willReturnMap([ @@ -172,6 +167,9 @@ public function testHandleImipMssage(): void { $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]) @@ -195,6 +193,12 @@ public function testHandleImipMssage(): void { END:VEVENT END:VCALENDAR EOF; + /** @var Plugin|MockObject $schedulingPlugin */ + $schedulingPlugin = $this->createMock(Plugin::class); + $iTipMessage = $this->getITipMessage($message); + $schedulingPlugin->expects(self::once()) + ->method('scheduleLocalDelivery') + ->with($iTipMessage); $calendarImpl->handleIMipMessage('filename.ics', $message); } @@ -255,4 +259,23 @@ public function testHandleImipMessageNoCalendarUri(): void { $this->expectException(CalendarException::class); $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; + } }