-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Attempt to fix CalendarImpl tests
- Loading branch information
1 parent
187a707
commit d311ff1
Showing
1 changed file
with
35 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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('[email protected]:ACCEPTED'); | ||
->with('mailto:[email protected]'); | ||
|
||
$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; | ||
} | ||
} |