Skip to content

Commit

Permalink
fixup! Attempt to fix CalendarImpl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Nov 3, 2022
1 parent 187a707 commit d311ff1
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions apps/dav/tests/unit/CalDAV/CalendarImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('[email protected]:ACCEPTED');
->with('mailto:[email protected]');

$server =
$this->createMock(Server::class);
$server = $this->createMock(Server::class);
$server->expects($this->any())
->method('getPlugin')
->willReturnMap([
Expand All @@ -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])
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit d311ff1

Please sign in to comment.