-
-
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.
Signed-off-by: Julius Härtl <[email protected]>
- Loading branch information
1 parent
bc740ad
commit 187a707
Showing
4 changed files
with
102 additions
and
41 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
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
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 |
---|---|---|
|
@@ -31,8 +31,13 @@ | |
use OCA\DAV\CalDAV\CalendarImpl; | ||
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; | ||
use OCA\DAV\CalDAV\Schedule\Plugin; | ||
use OCP\Calendar\Exceptions\CalendarException; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Sabre\DAV\Server; | ||
|
||
/** | ||
* @group DB | ||
*/ | ||
class CalendarImplTest extends \Test\TestCase { | ||
|
||
/** @var CalendarImpl */ | ||
|
@@ -131,15 +136,50 @@ public function testGetPermissionAll() { | |
$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) | ||
] | ||
]) | ||
]); | ||
public function testHandleImipMssage(): 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'); | ||
|
||
$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 | ||
|
@@ -156,28 +196,46 @@ public function testHandleImipMessage(): void { | |
END:VCALENDAR | ||
EOF; | ||
|
||
$calendarImpl->handleIMipMessage('filename.ics', $message); | ||
} | ||
|
||
public function testHandleImipMessageNoCalendarUri(): void { | ||
/** @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()); | ||
unset($this->calendarInfo['uri']); | ||
|
||
/** @var Plugin|MockObject $schedulingPlugin */ | ||
$schedulingPlugin = $invitationResponseServer->server->getPlugin('caldav-schedule'); | ||
$schedulingPlugin->expects(self::once()) | ||
->method('setPathOfCalendarObjectChange') | ||
->with('fullcalendarname'); | ||
} | ||
$schedulingPlugin = $this->createMock(Plugin::class); | ||
|
||
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 \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 | ||
|
@@ -194,14 +252,7 @@ public function testHandleImipMessageNoCalendarUri(): void { | |
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); | ||
$this->expectException(CalendarException::class); | ||
$calendarImpl->handleIMipMessage('filename.ics', $message); | ||
} | ||
} |
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