@@ -257,7 +257,7 @@ |
||
| 257 | 257 | $iTipMessage->sender = $attendee; |
| 258 | 258 | $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
| 259 | 259 | $iTipMessage->component = 'VEVENT'; |
| 260 | - $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 260 | + $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int) $vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 261 | 261 | $iTipMessage->message = $vObject; |
| 262 | 262 | return $iTipMessage; |
| 263 | 263 | } |
@@ -23,108 +23,108 @@ discard block |
||
| 23 | 23 | use Sabre\VObject\Reader; |
| 24 | 24 | |
| 25 | 25 | class CalendarImplTest extends \Test\TestCase { |
| 26 | - private Calendar&MockObject $calendar; |
|
| 27 | - private array $calendarInfo; |
|
| 28 | - private CalDavBackend&MockObject $backend; |
|
| 29 | - private CalendarImpl $calendarImpl; |
|
| 30 | - private array $mockExportCollection; |
|
| 31 | - |
|
| 32 | - protected function setUp(): void { |
|
| 33 | - parent::setUp(); |
|
| 34 | - |
|
| 35 | - $this->calendar = $this->createMock(Calendar::class); |
|
| 36 | - $this->calendarInfo = [ |
|
| 37 | - 'id' => 1, |
|
| 38 | - '{DAV:}displayname' => 'user readable name 123', |
|
| 39 | - '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', |
|
| 40 | - 'uri' => '/this/is/a/uri', |
|
| 41 | - 'principaluri' => 'principal/users/foobar' |
|
| 42 | - ]; |
|
| 43 | - $this->backend = $this->createMock(CalDavBackend::class); |
|
| 44 | - |
|
| 45 | - $this->calendarImpl = new CalendarImpl( |
|
| 46 | - $this->calendar, |
|
| 47 | - $this->calendarInfo, |
|
| 48 | - $this->backend |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - public function testGetKey(): void { |
|
| 54 | - $this->assertEquals($this->calendarImpl->getKey(), 1); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function testGetDisplayname(): void { |
|
| 58 | - $this->assertEquals($this->calendarImpl->getDisplayName(), 'user readable name 123'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function testGetDisplayColor(): void { |
|
| 62 | - $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function testSearch(): void { |
|
| 66 | - $this->backend->expects($this->once()) |
|
| 67 | - ->method('search') |
|
| 68 | - ->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337) |
|
| 69 | - ->willReturn(['SEARCHRESULTS']); |
|
| 70 | - |
|
| 71 | - $result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337); |
|
| 72 | - $this->assertEquals($result, ['SEARCHRESULTS']); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function testGetPermissionRead(): void { |
|
| 76 | - $this->calendar->expects($this->once()) |
|
| 77 | - ->method('getACL') |
|
| 78 | - ->with() |
|
| 79 | - ->willReturn([ |
|
| 80 | - ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], |
|
| 81 | - ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], |
|
| 82 | - ['privilege' => '{DAV:}write', 'principal' => 'principal/users/other'], |
|
| 83 | - ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 84 | - ]); |
|
| 85 | - |
|
| 86 | - $this->assertEquals(1, $this->calendarImpl->getPermissions()); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function testGetPermissionWrite(): void { |
|
| 90 | - $this->calendar->expects($this->once()) |
|
| 91 | - ->method('getACL') |
|
| 92 | - ->with() |
|
| 93 | - ->willReturn([ |
|
| 94 | - ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], |
|
| 95 | - ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], |
|
| 96 | - ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 97 | - ]); |
|
| 98 | - |
|
| 99 | - $this->assertEquals(6, $this->calendarImpl->getPermissions()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function testGetPermissionReadWrite(): void { |
|
| 103 | - $this->calendar->expects($this->once()) |
|
| 104 | - ->method('getACL') |
|
| 105 | - ->with() |
|
| 106 | - ->willReturn([ |
|
| 107 | - ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], |
|
| 108 | - ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], |
|
| 109 | - ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 110 | - ]); |
|
| 111 | - |
|
| 112 | - $this->assertEquals(7, $this->calendarImpl->getPermissions()); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function testGetPermissionAll(): void { |
|
| 116 | - $this->calendar->expects($this->once()) |
|
| 117 | - ->method('getACL') |
|
| 118 | - ->with() |
|
| 119 | - ->willReturn([ |
|
| 120 | - ['privilege' => '{DAV:}all', 'principal' => 'principal/users/foobar'], |
|
| 121 | - ]); |
|
| 122 | - |
|
| 123 | - $this->assertEquals(31, $this->calendarImpl->getPermissions()); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function testHandleImipMessage(): void { |
|
| 127 | - $message = <<<EOF |
|
| 26 | + private Calendar&MockObject $calendar; |
|
| 27 | + private array $calendarInfo; |
|
| 28 | + private CalDavBackend&MockObject $backend; |
|
| 29 | + private CalendarImpl $calendarImpl; |
|
| 30 | + private array $mockExportCollection; |
|
| 31 | + |
|
| 32 | + protected function setUp(): void { |
|
| 33 | + parent::setUp(); |
|
| 34 | + |
|
| 35 | + $this->calendar = $this->createMock(Calendar::class); |
|
| 36 | + $this->calendarInfo = [ |
|
| 37 | + 'id' => 1, |
|
| 38 | + '{DAV:}displayname' => 'user readable name 123', |
|
| 39 | + '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', |
|
| 40 | + 'uri' => '/this/is/a/uri', |
|
| 41 | + 'principaluri' => 'principal/users/foobar' |
|
| 42 | + ]; |
|
| 43 | + $this->backend = $this->createMock(CalDavBackend::class); |
|
| 44 | + |
|
| 45 | + $this->calendarImpl = new CalendarImpl( |
|
| 46 | + $this->calendar, |
|
| 47 | + $this->calendarInfo, |
|
| 48 | + $this->backend |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + public function testGetKey(): void { |
|
| 54 | + $this->assertEquals($this->calendarImpl->getKey(), 1); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function testGetDisplayname(): void { |
|
| 58 | + $this->assertEquals($this->calendarImpl->getDisplayName(), 'user readable name 123'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function testGetDisplayColor(): void { |
|
| 62 | + $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function testSearch(): void { |
|
| 66 | + $this->backend->expects($this->once()) |
|
| 67 | + ->method('search') |
|
| 68 | + ->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337) |
|
| 69 | + ->willReturn(['SEARCHRESULTS']); |
|
| 70 | + |
|
| 71 | + $result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337); |
|
| 72 | + $this->assertEquals($result, ['SEARCHRESULTS']); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function testGetPermissionRead(): void { |
|
| 76 | + $this->calendar->expects($this->once()) |
|
| 77 | + ->method('getACL') |
|
| 78 | + ->with() |
|
| 79 | + ->willReturn([ |
|
| 80 | + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], |
|
| 81 | + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], |
|
| 82 | + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/other'], |
|
| 83 | + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 84 | + ]); |
|
| 85 | + |
|
| 86 | + $this->assertEquals(1, $this->calendarImpl->getPermissions()); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function testGetPermissionWrite(): void { |
|
| 90 | + $this->calendar->expects($this->once()) |
|
| 91 | + ->method('getACL') |
|
| 92 | + ->with() |
|
| 93 | + ->willReturn([ |
|
| 94 | + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], |
|
| 95 | + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/other'], |
|
| 96 | + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 97 | + ]); |
|
| 98 | + |
|
| 99 | + $this->assertEquals(6, $this->calendarImpl->getPermissions()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function testGetPermissionReadWrite(): void { |
|
| 103 | + $this->calendar->expects($this->once()) |
|
| 104 | + ->method('getACL') |
|
| 105 | + ->with() |
|
| 106 | + ->willReturn([ |
|
| 107 | + ['privilege' => '{DAV:}write', 'principal' => 'principal/users/foobar'], |
|
| 108 | + ['privilege' => '{DAV:}read', 'principal' => 'principal/users/foobar'], |
|
| 109 | + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/other'], |
|
| 110 | + ]); |
|
| 111 | + |
|
| 112 | + $this->assertEquals(7, $this->calendarImpl->getPermissions()); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function testGetPermissionAll(): void { |
|
| 116 | + $this->calendar->expects($this->once()) |
|
| 117 | + ->method('getACL') |
|
| 118 | + ->with() |
|
| 119 | + ->willReturn([ |
|
| 120 | + ['privilege' => '{DAV:}all', 'principal' => 'principal/users/foobar'], |
|
| 121 | + ]); |
|
| 122 | + |
|
| 123 | + $this->assertEquals(31, $this->calendarImpl->getPermissions()); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function testHandleImipMessage(): void { |
|
| 127 | + $message = <<<EOF |
|
| 128 | 128 | BEGIN:VCALENDAR |
| 129 | 129 | PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN |
| 130 | 130 | METHOD:REPLY |
@@ -139,92 +139,92 @@ discard block |
||
| 139 | 139 | END:VCALENDAR |
| 140 | 140 | EOF; |
| 141 | 141 | |
| 142 | - /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
|
| 143 | - $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
|
| 144 | - $authPlugin->expects(self::once()) |
|
| 145 | - ->method('setCurrentPrincipal') |
|
| 146 | - ->with($this->calendar->getPrincipalURI()); |
|
| 147 | - |
|
| 148 | - /** @var \Sabre\DAVACL\Plugin|MockObject $aclPlugin */ |
|
| 149 | - $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
|
| 150 | - |
|
| 151 | - /** @var Plugin|MockObject $schedulingPlugin */ |
|
| 152 | - $schedulingPlugin = $this->createMock(Plugin::class); |
|
| 153 | - $iTipMessage = $this->getITipMessage($message); |
|
| 154 | - $iTipMessage->recipient = 'mailto:[email protected]'; |
|
| 155 | - |
|
| 156 | - $server = $this->createMock(Server::class); |
|
| 157 | - $server->expects($this->any()) |
|
| 158 | - ->method('getPlugin') |
|
| 159 | - ->willReturnMap([ |
|
| 160 | - ['auth', $authPlugin], |
|
| 161 | - ['acl', $aclPlugin], |
|
| 162 | - ['caldav-schedule', $schedulingPlugin] |
|
| 163 | - ]); |
|
| 164 | - $server->expects(self::once()) |
|
| 165 | - ->method('emit'); |
|
| 166 | - |
|
| 167 | - $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer', 'isExternalAttendee']); |
|
| 168 | - $invitationResponseServer->server = $server; |
|
| 169 | - $invitationResponseServer->expects($this->any()) |
|
| 170 | - ->method('getServer') |
|
| 171 | - ->willReturn($server); |
|
| 172 | - $invitationResponseServer->expects(self::once()) |
|
| 173 | - ->method('isExternalAttendee') |
|
| 174 | - ->willReturn(false); |
|
| 175 | - |
|
| 176 | - $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
|
| 177 | - ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
|
| 178 | - ->onlyMethods(['getInvitationResponseServer']) |
|
| 179 | - ->getMock(); |
|
| 180 | - $calendarImpl->expects($this->once()) |
|
| 181 | - ->method('getInvitationResponseServer') |
|
| 182 | - ->willReturn($invitationResponseServer); |
|
| 183 | - |
|
| 184 | - $calendarImpl->handleIMipMessage('filename.ics', $message); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - public function testHandleImipMessageNoCalendarUri(): void { |
|
| 188 | - /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
|
| 189 | - $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
|
| 190 | - $authPlugin->expects(self::once()) |
|
| 191 | - ->method('setCurrentPrincipal') |
|
| 192 | - ->with($this->calendar->getPrincipalURI()); |
|
| 193 | - unset($this->calendarInfo['uri']); |
|
| 194 | - |
|
| 195 | - /** @var Plugin|MockObject $schedulingPlugin */ |
|
| 196 | - $schedulingPlugin = $this->createMock(Plugin::class); |
|
| 197 | - |
|
| 198 | - /** @var \Sabre\DAVACL\Plugin|MockObject $schedulingPlugin */ |
|
| 199 | - $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
|
| 200 | - |
|
| 201 | - $server = |
|
| 202 | - $this->createMock(Server::class); |
|
| 203 | - $server->expects($this->any()) |
|
| 204 | - ->method('getPlugin') |
|
| 205 | - ->willReturnMap([ |
|
| 206 | - ['auth', $authPlugin], |
|
| 207 | - ['acl', $aclPlugin], |
|
| 208 | - ['caldav-schedule', $schedulingPlugin] |
|
| 209 | - ]); |
|
| 210 | - $server->expects(self::never()) |
|
| 211 | - ->method('emit'); |
|
| 212 | - |
|
| 213 | - $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer']); |
|
| 214 | - $invitationResponseServer->server = $server; |
|
| 215 | - $invitationResponseServer->expects($this->any()) |
|
| 216 | - ->method('getServer') |
|
| 217 | - ->willReturn($server); |
|
| 218 | - |
|
| 219 | - $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
|
| 220 | - ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
|
| 221 | - ->onlyMethods(['getInvitationResponseServer']) |
|
| 222 | - ->getMock(); |
|
| 223 | - $calendarImpl->expects($this->once()) |
|
| 224 | - ->method('getInvitationResponseServer') |
|
| 225 | - ->willReturn($invitationResponseServer); |
|
| 226 | - |
|
| 227 | - $message = <<<EOF |
|
| 142 | + /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
|
| 143 | + $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
|
| 144 | + $authPlugin->expects(self::once()) |
|
| 145 | + ->method('setCurrentPrincipal') |
|
| 146 | + ->with($this->calendar->getPrincipalURI()); |
|
| 147 | + |
|
| 148 | + /** @var \Sabre\DAVACL\Plugin|MockObject $aclPlugin */ |
|
| 149 | + $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
|
| 150 | + |
|
| 151 | + /** @var Plugin|MockObject $schedulingPlugin */ |
|
| 152 | + $schedulingPlugin = $this->createMock(Plugin::class); |
|
| 153 | + $iTipMessage = $this->getITipMessage($message); |
|
| 154 | + $iTipMessage->recipient = 'mailto:[email protected]'; |
|
| 155 | + |
|
| 156 | + $server = $this->createMock(Server::class); |
|
| 157 | + $server->expects($this->any()) |
|
| 158 | + ->method('getPlugin') |
|
| 159 | + ->willReturnMap([ |
|
| 160 | + ['auth', $authPlugin], |
|
| 161 | + ['acl', $aclPlugin], |
|
| 162 | + ['caldav-schedule', $schedulingPlugin] |
|
| 163 | + ]); |
|
| 164 | + $server->expects(self::once()) |
|
| 165 | + ->method('emit'); |
|
| 166 | + |
|
| 167 | + $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer', 'isExternalAttendee']); |
|
| 168 | + $invitationResponseServer->server = $server; |
|
| 169 | + $invitationResponseServer->expects($this->any()) |
|
| 170 | + ->method('getServer') |
|
| 171 | + ->willReturn($server); |
|
| 172 | + $invitationResponseServer->expects(self::once()) |
|
| 173 | + ->method('isExternalAttendee') |
|
| 174 | + ->willReturn(false); |
|
| 175 | + |
|
| 176 | + $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
|
| 177 | + ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
|
| 178 | + ->onlyMethods(['getInvitationResponseServer']) |
|
| 179 | + ->getMock(); |
|
| 180 | + $calendarImpl->expects($this->once()) |
|
| 181 | + ->method('getInvitationResponseServer') |
|
| 182 | + ->willReturn($invitationResponseServer); |
|
| 183 | + |
|
| 184 | + $calendarImpl->handleIMipMessage('filename.ics', $message); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + public function testHandleImipMessageNoCalendarUri(): void { |
|
| 188 | + /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
|
| 189 | + $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
|
| 190 | + $authPlugin->expects(self::once()) |
|
| 191 | + ->method('setCurrentPrincipal') |
|
| 192 | + ->with($this->calendar->getPrincipalURI()); |
|
| 193 | + unset($this->calendarInfo['uri']); |
|
| 194 | + |
|
| 195 | + /** @var Plugin|MockObject $schedulingPlugin */ |
|
| 196 | + $schedulingPlugin = $this->createMock(Plugin::class); |
|
| 197 | + |
|
| 198 | + /** @var \Sabre\DAVACL\Plugin|MockObject $schedulingPlugin */ |
|
| 199 | + $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
|
| 200 | + |
|
| 201 | + $server = |
|
| 202 | + $this->createMock(Server::class); |
|
| 203 | + $server->expects($this->any()) |
|
| 204 | + ->method('getPlugin') |
|
| 205 | + ->willReturnMap([ |
|
| 206 | + ['auth', $authPlugin], |
|
| 207 | + ['acl', $aclPlugin], |
|
| 208 | + ['caldav-schedule', $schedulingPlugin] |
|
| 209 | + ]); |
|
| 210 | + $server->expects(self::never()) |
|
| 211 | + ->method('emit'); |
|
| 212 | + |
|
| 213 | + $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer']); |
|
| 214 | + $invitationResponseServer->server = $server; |
|
| 215 | + $invitationResponseServer->expects($this->any()) |
|
| 216 | + ->method('getServer') |
|
| 217 | + ->willReturn($server); |
|
| 218 | + |
|
| 219 | + $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
|
| 220 | + ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
|
| 221 | + ->onlyMethods(['getInvitationResponseServer']) |
|
| 222 | + ->getMock(); |
|
| 223 | + $calendarImpl->expects($this->once()) |
|
| 224 | + ->method('getInvitationResponseServer') |
|
| 225 | + ->willReturn($invitationResponseServer); |
|
| 226 | + |
|
| 227 | + $message = <<<EOF |
|
| 228 | 228 | BEGIN:VCALENDAR |
| 229 | 229 | PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN |
| 230 | 230 | METHOD:REPLY |
@@ -239,70 +239,70 @@ discard block |
||
| 239 | 239 | END:VCALENDAR |
| 240 | 240 | EOF; |
| 241 | 241 | |
| 242 | - $this->expectException(CalendarException::class); |
|
| 243 | - $calendarImpl->handleIMipMessage('filename.ics', $message); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - private function getITipMessage($calendarData): Message { |
|
| 247 | - $iTipMessage = new Message(); |
|
| 248 | - /** @var VCalendar $vObject */ |
|
| 249 | - $vObject = Reader::read($calendarData); |
|
| 250 | - /** @var VEvent $vEvent */ |
|
| 251 | - $vEvent = $vObject->{'VEVENT'}; |
|
| 252 | - $orgaizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 253 | - $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 254 | - |
|
| 255 | - $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 256 | - $iTipMessage->recipient = $orgaizer; |
|
| 257 | - $iTipMessage->sender = $attendee; |
|
| 258 | - $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 259 | - $iTipMessage->component = 'VEVENT'; |
|
| 260 | - $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 261 | - $iTipMessage->message = $vObject; |
|
| 262 | - return $iTipMessage; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - protected function mockExportGenerator(): Generator { |
|
| 266 | - foreach ($this->mockExportCollection as $entry) { |
|
| 267 | - yield $entry; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - public function testExport(): void { |
|
| 272 | - // Arrange |
|
| 273 | - // construct calendar with a 1 hour event and same start/end time zones |
|
| 274 | - $vCalendar = new VCalendar(); |
|
| 275 | - /** @var VEvent $vEvent */ |
|
| 276 | - $vEvent = $vCalendar->add('VEVENT', []); |
|
| 277 | - $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
| 278 | - $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
| 279 | - $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
| 280 | - $vEvent->add('SUMMARY', 'Test Recurrence Event'); |
|
| 281 | - $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'Organizer']); |
|
| 282 | - $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
| 283 | - 'CN' => 'Attendee One', |
|
| 284 | - 'CUTYPE' => 'INDIVIDUAL', |
|
| 285 | - 'PARTSTAT' => 'NEEDS-ACTION', |
|
| 286 | - 'ROLE' => 'REQ-PARTICIPANT', |
|
| 287 | - 'RSVP' => 'TRUE' |
|
| 288 | - ]); |
|
| 289 | - // construct data store return |
|
| 290 | - $this->mockExportCollection[] = [ |
|
| 291 | - 'id' => 1, |
|
| 292 | - 'calendardata' => $vCalendar->serialize() |
|
| 293 | - ]; |
|
| 294 | - $this->backend->expects($this->once()) |
|
| 295 | - ->method('exportCalendar') |
|
| 296 | - ->with(1, $this->backend::CALENDAR_TYPE_CALENDAR, null) |
|
| 297 | - ->willReturn($this->mockExportGenerator()); |
|
| 298 | - |
|
| 299 | - // Act |
|
| 300 | - foreach ($this->calendarImpl->export(null) as $entry) { |
|
| 301 | - $exported[] = $entry; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // Assert |
|
| 305 | - $this->assertCount(1, $exported, 'Invalid exported items count'); |
|
| 306 | - } |
|
| 242 | + $this->expectException(CalendarException::class); |
|
| 243 | + $calendarImpl->handleIMipMessage('filename.ics', $message); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + private function getITipMessage($calendarData): Message { |
|
| 247 | + $iTipMessage = new Message(); |
|
| 248 | + /** @var VCalendar $vObject */ |
|
| 249 | + $vObject = Reader::read($calendarData); |
|
| 250 | + /** @var VEvent $vEvent */ |
|
| 251 | + $vEvent = $vObject->{'VEVENT'}; |
|
| 252 | + $orgaizer = $vEvent->{'ORGANIZER'}->getValue(); |
|
| 253 | + $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
|
| 254 | + |
|
| 255 | + $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
|
| 256 | + $iTipMessage->recipient = $orgaizer; |
|
| 257 | + $iTipMessage->sender = $attendee; |
|
| 258 | + $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
|
| 259 | + $iTipMessage->component = 'VEVENT'; |
|
| 260 | + $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
|
| 261 | + $iTipMessage->message = $vObject; |
|
| 262 | + return $iTipMessage; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + protected function mockExportGenerator(): Generator { |
|
| 266 | + foreach ($this->mockExportCollection as $entry) { |
|
| 267 | + yield $entry; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + public function testExport(): void { |
|
| 272 | + // Arrange |
|
| 273 | + // construct calendar with a 1 hour event and same start/end time zones |
|
| 274 | + $vCalendar = new VCalendar(); |
|
| 275 | + /** @var VEvent $vEvent */ |
|
| 276 | + $vEvent = $vCalendar->add('VEVENT', []); |
|
| 277 | + $vEvent->UID->setValue('96a0e6b1-d886-4a55-a60d-152b31401dcc'); |
|
| 278 | + $vEvent->add('DTSTART', '20240701T080000', ['TZID' => 'America/Toronto']); |
|
| 279 | + $vEvent->add('DTEND', '20240701T090000', ['TZID' => 'America/Toronto']); |
|
| 280 | + $vEvent->add('SUMMARY', 'Test Recurrence Event'); |
|
| 281 | + $vEvent->add('ORGANIZER', 'mailto:[email protected]', ['CN' => 'Organizer']); |
|
| 282 | + $vEvent->add('ATTENDEE', 'mailto:[email protected]', [ |
|
| 283 | + 'CN' => 'Attendee One', |
|
| 284 | + 'CUTYPE' => 'INDIVIDUAL', |
|
| 285 | + 'PARTSTAT' => 'NEEDS-ACTION', |
|
| 286 | + 'ROLE' => 'REQ-PARTICIPANT', |
|
| 287 | + 'RSVP' => 'TRUE' |
|
| 288 | + ]); |
|
| 289 | + // construct data store return |
|
| 290 | + $this->mockExportCollection[] = [ |
|
| 291 | + 'id' => 1, |
|
| 292 | + 'calendardata' => $vCalendar->serialize() |
|
| 293 | + ]; |
|
| 294 | + $this->backend->expects($this->once()) |
|
| 295 | + ->method('exportCalendar') |
|
| 296 | + ->with(1, $this->backend::CALENDAR_TYPE_CALENDAR, null) |
|
| 297 | + ->willReturn($this->mockExportGenerator()); |
|
| 298 | + |
|
| 299 | + // Act |
|
| 300 | + foreach ($this->calendarImpl->export(null) as $entry) { |
|
| 301 | + $exported[] = $entry; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // Assert |
|
| 305 | + $this->assertCount(1, $exported, 'Invalid exported items count'); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | } |
@@ -14,20 +14,20 @@ |
||
| 14 | 14 | use Test\TestCase; |
| 15 | 15 | |
| 16 | 16 | class AvatarNodeTest extends TestCase { |
| 17 | - public function testGetName(): void { |
|
| 18 | - /** @var IAvatar&MockObject $a */ |
|
| 19 | - $a = $this->createMock(IAvatar::class); |
|
| 20 | - $n = new AvatarNode(1024, 'png', $a); |
|
| 21 | - $this->assertEquals('1024.png', $n->getName()); |
|
| 22 | - } |
|
| 17 | + public function testGetName(): void { |
|
| 18 | + /** @var IAvatar&MockObject $a */ |
|
| 19 | + $a = $this->createMock(IAvatar::class); |
|
| 20 | + $n = new AvatarNode(1024, 'png', $a); |
|
| 21 | + $this->assertEquals('1024.png', $n->getName()); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function testGetContentType(): void { |
|
| 25 | - /** @var IAvatar&MockObject $a */ |
|
| 26 | - $a = $this->createMock(IAvatar::class); |
|
| 27 | - $n = new AvatarNode(1024, 'png', $a); |
|
| 28 | - $this->assertEquals('image/png', $n->getContentType()); |
|
| 24 | + public function testGetContentType(): void { |
|
| 25 | + /** @var IAvatar&MockObject $a */ |
|
| 26 | + $a = $this->createMock(IAvatar::class); |
|
| 27 | + $n = new AvatarNode(1024, 'png', $a); |
|
| 28 | + $this->assertEquals('image/png', $n->getContentType()); |
|
| 29 | 29 | |
| 30 | - $n = new AvatarNode(1024, 'jpeg', $a); |
|
| 31 | - $this->assertEquals('image/jpeg', $n->getContentType()); |
|
| 32 | - } |
|
| 30 | + $n = new AvatarNode(1024, 'jpeg', $a); |
|
| 31 | + $this->assertEquals('image/jpeg', $n->getContentType()); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -18,88 +18,88 @@ |
||
| 18 | 18 | use Test\TestCase; |
| 19 | 19 | |
| 20 | 20 | class AvatarHomeTest extends TestCase { |
| 21 | - private AvatarHome $home; |
|
| 22 | - private IAvatarManager&MockObject $avatarManager; |
|
| 23 | - |
|
| 24 | - protected function setUp(): void { |
|
| 25 | - parent::setUp(); |
|
| 26 | - $this->avatarManager = $this->createMock(IAvatarManager::class); |
|
| 27 | - $this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @dataProvider providesForbiddenMethods |
|
| 32 | - */ |
|
| 33 | - public function testForbiddenMethods($method): void { |
|
| 34 | - $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
| 35 | - |
|
| 36 | - $this->home->$method(''); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public static function providesForbiddenMethods(): array { |
|
| 40 | - return [ |
|
| 41 | - ['createFile'], |
|
| 42 | - ['createDirectory'], |
|
| 43 | - ['delete'], |
|
| 44 | - ['setName'] |
|
| 45 | - ]; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function testGetName(): void { |
|
| 49 | - $n = $this->home->getName(); |
|
| 50 | - self::assertEquals('admin', $n); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public static function providesTestGetChild(): array { |
|
| 54 | - return [ |
|
| 55 | - [MethodNotAllowed::class, false, ''], |
|
| 56 | - [MethodNotAllowed::class, false, 'bla.foo'], |
|
| 57 | - [MethodNotAllowed::class, false, 'bla.png'], |
|
| 58 | - [NotFound::class, false, '512.png'], |
|
| 59 | - [null, true, '512.png'], |
|
| 60 | - ]; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @dataProvider providesTestGetChild |
|
| 65 | - */ |
|
| 66 | - public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void { |
|
| 67 | - if ($expectedException !== null) { |
|
| 68 | - $this->expectException($expectedException); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $avatar = $this->createMock(IAvatar::class); |
|
| 72 | - $avatar->method('exists')->willReturn($hasAvatar); |
|
| 73 | - |
|
| 74 | - $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 75 | - $avatarNode = $this->home->getChild($path); |
|
| 76 | - $this->assertInstanceOf(AvatarNode::class, $avatarNode); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function testGetChildren(): void { |
|
| 80 | - $avatarNodes = $this->home->getChildren(); |
|
| 81 | - self::assertEquals(0, count($avatarNodes)); |
|
| 82 | - |
|
| 83 | - $avatar = $this->createMock(IAvatar::class); |
|
| 84 | - $avatar->expects($this->once())->method('exists')->willReturn(true); |
|
| 85 | - $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 86 | - $avatarNodes = $this->home->getChildren(); |
|
| 87 | - self::assertEquals(1, count($avatarNodes)); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @dataProvider providesTestGetChild |
|
| 92 | - */ |
|
| 93 | - public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void { |
|
| 94 | - $avatar = $this->createMock(IAvatar::class); |
|
| 95 | - $avatar->method('exists')->willReturn($hasAvatar); |
|
| 96 | - |
|
| 97 | - $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 98 | - $childExists = $this->home->childExists($path); |
|
| 99 | - $this->assertEquals($hasAvatar, $childExists); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function testGetLastModified(): void { |
|
| 103 | - self::assertNull($this->home->getLastModified()); |
|
| 104 | - } |
|
| 21 | + private AvatarHome $home; |
|
| 22 | + private IAvatarManager&MockObject $avatarManager; |
|
| 23 | + |
|
| 24 | + protected function setUp(): void { |
|
| 25 | + parent::setUp(); |
|
| 26 | + $this->avatarManager = $this->createMock(IAvatarManager::class); |
|
| 27 | + $this->home = new AvatarHome(['uri' => 'principals/users/admin'], $this->avatarManager); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @dataProvider providesForbiddenMethods |
|
| 32 | + */ |
|
| 33 | + public function testForbiddenMethods($method): void { |
|
| 34 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
| 35 | + |
|
| 36 | + $this->home->$method(''); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public static function providesForbiddenMethods(): array { |
|
| 40 | + return [ |
|
| 41 | + ['createFile'], |
|
| 42 | + ['createDirectory'], |
|
| 43 | + ['delete'], |
|
| 44 | + ['setName'] |
|
| 45 | + ]; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function testGetName(): void { |
|
| 49 | + $n = $this->home->getName(); |
|
| 50 | + self::assertEquals('admin', $n); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public static function providesTestGetChild(): array { |
|
| 54 | + return [ |
|
| 55 | + [MethodNotAllowed::class, false, ''], |
|
| 56 | + [MethodNotAllowed::class, false, 'bla.foo'], |
|
| 57 | + [MethodNotAllowed::class, false, 'bla.png'], |
|
| 58 | + [NotFound::class, false, '512.png'], |
|
| 59 | + [null, true, '512.png'], |
|
| 60 | + ]; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @dataProvider providesTestGetChild |
|
| 65 | + */ |
|
| 66 | + public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void { |
|
| 67 | + if ($expectedException !== null) { |
|
| 68 | + $this->expectException($expectedException); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $avatar = $this->createMock(IAvatar::class); |
|
| 72 | + $avatar->method('exists')->willReturn($hasAvatar); |
|
| 73 | + |
|
| 74 | + $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 75 | + $avatarNode = $this->home->getChild($path); |
|
| 76 | + $this->assertInstanceOf(AvatarNode::class, $avatarNode); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function testGetChildren(): void { |
|
| 80 | + $avatarNodes = $this->home->getChildren(); |
|
| 81 | + self::assertEquals(0, count($avatarNodes)); |
|
| 82 | + |
|
| 83 | + $avatar = $this->createMock(IAvatar::class); |
|
| 84 | + $avatar->expects($this->once())->method('exists')->willReturn(true); |
|
| 85 | + $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 86 | + $avatarNodes = $this->home->getChildren(); |
|
| 87 | + self::assertEquals(1, count($avatarNodes)); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @dataProvider providesTestGetChild |
|
| 92 | + */ |
|
| 93 | + public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void { |
|
| 94 | + $avatar = $this->createMock(IAvatar::class); |
|
| 95 | + $avatar->method('exists')->willReturn($hasAvatar); |
|
| 96 | + |
|
| 97 | + $this->avatarManager->expects($this->any())->method('getAvatar')->with('admin')->willReturn($avatar); |
|
| 98 | + $childExists = $this->home->childExists($path); |
|
| 99 | + $this->assertEquals($hasAvatar, $childExists); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function testGetLastModified(): void { |
|
| 103 | + self::assertNull($this->home->getLastModified()); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -16,55 +16,55 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | class PublicCalendarTest extends CalendarTest { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @dataProvider providesConfidentialClassificationData |
|
| 21 | - */ |
|
| 22 | - public function testPrivateClassification(int $expectedChildren, bool $isShared): void { |
|
| 23 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 24 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
| 25 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 26 | - |
|
| 27 | - /** @var CalDavBackend&MockObject $backend */ |
|
| 28 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 29 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 30 | - $calObject0, $calObject1, $calObject2 |
|
| 31 | - ]); |
|
| 32 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 33 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 34 | - ->willReturn([ |
|
| 35 | - $calObject0, $calObject1, $calObject2 |
|
| 36 | - ]); |
|
| 37 | - $backend->expects($this->any())->method('getCalendarObject') |
|
| 38 | - ->willReturn($calObject2)->with(666, 'event-2'); |
|
| 39 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 40 | - |
|
| 41 | - $calendarInfo = [ |
|
| 42 | - '{http://owncloud.org/ns}owner-principal' => 'user2', |
|
| 43 | - 'principaluri' => 'user2', |
|
| 44 | - 'id' => 666, |
|
| 45 | - 'uri' => 'cal', |
|
| 46 | - ]; |
|
| 47 | - /** @var IConfig&MockObject $config */ |
|
| 48 | - $config = $this->createMock(IConfig::class); |
|
| 49 | - /** @var LoggerInterface&MockObject $logger */ |
|
| 50 | - $logger = $this->createMock(LoggerInterface::class); |
|
| 51 | - $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); |
|
| 52 | - $children = $c->getChildren(); |
|
| 53 | - $this->assertEquals(2, count($children)); |
|
| 54 | - $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
| 55 | - $this->assertEquals(2, count($children)); |
|
| 56 | - |
|
| 57 | - $this->assertFalse($c->childExists('event-2')); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @dataProvider providesConfidentialClassificationData |
|
| 62 | - */ |
|
| 63 | - public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { |
|
| 64 | - $start = '20160609'; |
|
| 65 | - $end = '20160610'; |
|
| 66 | - |
|
| 67 | - $calData = <<<EOD |
|
| 19 | + /** |
|
| 20 | + * @dataProvider providesConfidentialClassificationData |
|
| 21 | + */ |
|
| 22 | + public function testPrivateClassification(int $expectedChildren, bool $isShared): void { |
|
| 23 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 24 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
| 25 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 26 | + |
|
| 27 | + /** @var CalDavBackend&MockObject $backend */ |
|
| 28 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 29 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 30 | + $calObject0, $calObject1, $calObject2 |
|
| 31 | + ]); |
|
| 32 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 33 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 34 | + ->willReturn([ |
|
| 35 | + $calObject0, $calObject1, $calObject2 |
|
| 36 | + ]); |
|
| 37 | + $backend->expects($this->any())->method('getCalendarObject') |
|
| 38 | + ->willReturn($calObject2)->with(666, 'event-2'); |
|
| 39 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 40 | + |
|
| 41 | + $calendarInfo = [ |
|
| 42 | + '{http://owncloud.org/ns}owner-principal' => 'user2', |
|
| 43 | + 'principaluri' => 'user2', |
|
| 44 | + 'id' => 666, |
|
| 45 | + 'uri' => 'cal', |
|
| 46 | + ]; |
|
| 47 | + /** @var IConfig&MockObject $config */ |
|
| 48 | + $config = $this->createMock(IConfig::class); |
|
| 49 | + /** @var LoggerInterface&MockObject $logger */ |
|
| 50 | + $logger = $this->createMock(LoggerInterface::class); |
|
| 51 | + $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); |
|
| 52 | + $children = $c->getChildren(); |
|
| 53 | + $this->assertEquals(2, count($children)); |
|
| 54 | + $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
| 55 | + $this->assertEquals(2, count($children)); |
|
| 56 | + |
|
| 57 | + $this->assertFalse($c->childExists('event-2')); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @dataProvider providesConfidentialClassificationData |
|
| 62 | + */ |
|
| 63 | + public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { |
|
| 64 | + $start = '20160609'; |
|
| 65 | + $end = '20160610'; |
|
| 66 | + |
|
| 67 | + $calData = <<<EOD |
|
| 68 | 68 | BEGIN:VCALENDAR |
| 69 | 69 | PRODID:-//ownCloud calendar v1.2.2 |
| 70 | 70 | BEGIN:VEVENT |
@@ -106,50 +106,50 @@ discard block |
||
| 106 | 106 | END:VCALENDAR |
| 107 | 107 | EOD; |
| 108 | 108 | |
| 109 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 110 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
| 111 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 112 | - |
|
| 113 | - /** @var CalDavBackend&MockObject $backend */ |
|
| 114 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 115 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 116 | - $calObject0, $calObject1, $calObject2 |
|
| 117 | - ]); |
|
| 118 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 119 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 120 | - ->willReturn([ |
|
| 121 | - $calObject0, $calObject1, $calObject2 |
|
| 122 | - ]); |
|
| 123 | - $backend->expects($this->any())->method('getCalendarObject') |
|
| 124 | - ->willReturn($calObject1)->with(666, 'event-1'); |
|
| 125 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 126 | - |
|
| 127 | - $calendarInfo = [ |
|
| 128 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 129 | - 'principaluri' => 'user2', |
|
| 130 | - 'id' => 666, |
|
| 131 | - 'uri' => 'cal', |
|
| 132 | - ]; |
|
| 133 | - /** @var IConfig&MockObject $config */ |
|
| 134 | - $config = $this->createMock(IConfig::class); |
|
| 135 | - /** @var LoggerInterface&MockObject $logger */ |
|
| 136 | - $logger = $this->createMock(LoggerInterface::class); |
|
| 137 | - $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); |
|
| 138 | - |
|
| 139 | - $this->assertEquals(count($c->getChildren()), 2); |
|
| 140 | - |
|
| 141 | - // test private event |
|
| 142 | - $privateEvent = $c->getChild('event-1'); |
|
| 143 | - $calData = $privateEvent->get(); |
|
| 144 | - $event = Reader::read($calData); |
|
| 145 | - |
|
| 146 | - $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
| 147 | - $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
| 148 | - |
|
| 149 | - $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 150 | - $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
| 151 | - $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
| 152 | - $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
| 153 | - $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
| 154 | - } |
|
| 109 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 110 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
| 111 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 112 | + |
|
| 113 | + /** @var CalDavBackend&MockObject $backend */ |
|
| 114 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 115 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 116 | + $calObject0, $calObject1, $calObject2 |
|
| 117 | + ]); |
|
| 118 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 119 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 120 | + ->willReturn([ |
|
| 121 | + $calObject0, $calObject1, $calObject2 |
|
| 122 | + ]); |
|
| 123 | + $backend->expects($this->any())->method('getCalendarObject') |
|
| 124 | + ->willReturn($calObject1)->with(666, 'event-1'); |
|
| 125 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 126 | + |
|
| 127 | + $calendarInfo = [ |
|
| 128 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 129 | + 'principaluri' => 'user2', |
|
| 130 | + 'id' => 666, |
|
| 131 | + 'uri' => 'cal', |
|
| 132 | + ]; |
|
| 133 | + /** @var IConfig&MockObject $config */ |
|
| 134 | + $config = $this->createMock(IConfig::class); |
|
| 135 | + /** @var LoggerInterface&MockObject $logger */ |
|
| 136 | + $logger = $this->createMock(LoggerInterface::class); |
|
| 137 | + $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); |
|
| 138 | + |
|
| 139 | + $this->assertEquals(count($c->getChildren()), 2); |
|
| 140 | + |
|
| 141 | + // test private event |
|
| 142 | + $privateEvent = $c->getChild('event-1'); |
|
| 143 | + $calData = $privateEvent->get(); |
|
| 144 | + $event = Reader::read($calData); |
|
| 145 | + |
|
| 146 | + $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
| 147 | + $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
| 148 | + |
|
| 149 | + $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 150 | + $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
| 151 | + $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
| 152 | + $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
| 153 | + $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -21,122 +21,122 @@ |
||
| 21 | 21 | use Test\TestCase; |
| 22 | 22 | |
| 23 | 23 | class TimezoneServiceTest extends TestCase { |
| 24 | - private IConfig&MockObject $config; |
|
| 25 | - private PropertyMapper&MockObject $propertyMapper; |
|
| 26 | - private IManager&MockObject $calendarManager; |
|
| 27 | - private TimezoneService $service; |
|
| 28 | - |
|
| 29 | - protected function setUp(): void { |
|
| 30 | - parent::setUp(); |
|
| 31 | - |
|
| 32 | - $this->config = $this->createMock(IConfig::class); |
|
| 33 | - $this->propertyMapper = $this->createMock(PropertyMapper::class); |
|
| 34 | - $this->calendarManager = $this->createMock(IManager::class); |
|
| 35 | - |
|
| 36 | - $this->service = new TimezoneService( |
|
| 37 | - $this->config, |
|
| 38 | - $this->propertyMapper, |
|
| 39 | - $this->calendarManager, |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function testGetUserTimezoneFromSettings(): void { |
|
| 44 | - $this->config->expects(self::once()) |
|
| 45 | - ->method('getUserValue') |
|
| 46 | - ->with('test123', 'core', 'timezone', '') |
|
| 47 | - ->willReturn('Europe/Warsaw'); |
|
| 48 | - |
|
| 49 | - $timezone = $this->service->getUserTimezone('test123'); |
|
| 50 | - |
|
| 51 | - self::assertSame('Europe/Warsaw', $timezone); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function testGetUserTimezoneFromAvailability(): void { |
|
| 55 | - $this->config->expects(self::once()) |
|
| 56 | - ->method('getUserValue') |
|
| 57 | - ->with('test123', 'core', 'timezone', '') |
|
| 58 | - ->willReturn(''); |
|
| 59 | - $property = new Property(); |
|
| 60 | - $property->setPropertyvalue('BEGIN:VCALENDAR |
|
| 24 | + private IConfig&MockObject $config; |
|
| 25 | + private PropertyMapper&MockObject $propertyMapper; |
|
| 26 | + private IManager&MockObject $calendarManager; |
|
| 27 | + private TimezoneService $service; |
|
| 28 | + |
|
| 29 | + protected function setUp(): void { |
|
| 30 | + parent::setUp(); |
|
| 31 | + |
|
| 32 | + $this->config = $this->createMock(IConfig::class); |
|
| 33 | + $this->propertyMapper = $this->createMock(PropertyMapper::class); |
|
| 34 | + $this->calendarManager = $this->createMock(IManager::class); |
|
| 35 | + |
|
| 36 | + $this->service = new TimezoneService( |
|
| 37 | + $this->config, |
|
| 38 | + $this->propertyMapper, |
|
| 39 | + $this->calendarManager, |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function testGetUserTimezoneFromSettings(): void { |
|
| 44 | + $this->config->expects(self::once()) |
|
| 45 | + ->method('getUserValue') |
|
| 46 | + ->with('test123', 'core', 'timezone', '') |
|
| 47 | + ->willReturn('Europe/Warsaw'); |
|
| 48 | + |
|
| 49 | + $timezone = $this->service->getUserTimezone('test123'); |
|
| 50 | + |
|
| 51 | + self::assertSame('Europe/Warsaw', $timezone); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function testGetUserTimezoneFromAvailability(): void { |
|
| 55 | + $this->config->expects(self::once()) |
|
| 56 | + ->method('getUserValue') |
|
| 57 | + ->with('test123', 'core', 'timezone', '') |
|
| 58 | + ->willReturn(''); |
|
| 59 | + $property = new Property(); |
|
| 60 | + $property->setPropertyvalue('BEGIN:VCALENDAR |
|
| 61 | 61 | PRODID:Nextcloud DAV app |
| 62 | 62 | BEGIN:VTIMEZONE |
| 63 | 63 | TZID:Europe/Vienna |
| 64 | 64 | END:VTIMEZONE |
| 65 | 65 | END:VCALENDAR'); |
| 66 | - $this->propertyMapper->expects(self::once()) |
|
| 67 | - ->method('findPropertyByPathAndName') |
|
| 68 | - ->willReturn([ |
|
| 69 | - $property, |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - $timezone = $this->service->getUserTimezone('test123'); |
|
| 73 | - |
|
| 74 | - self::assertNotNull($timezone); |
|
| 75 | - self::assertEquals('Europe/Vienna', $timezone); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function testGetUserTimezoneFromPersonalCalendar(): void { |
|
| 79 | - $this->config->expects(self::exactly(2)) |
|
| 80 | - ->method('getUserValue') |
|
| 81 | - ->willReturnMap([ |
|
| 82 | - ['test123', 'core', 'timezone', '', ''], |
|
| 83 | - ['test123', 'dav', 'defaultCalendar', '', 'personal-1'], |
|
| 84 | - ]); |
|
| 85 | - $other = $this->createMock(ICalendar::class); |
|
| 86 | - $other->method('getUri')->willReturn('other'); |
|
| 87 | - $personal = $this->createMock(CalendarImpl::class); |
|
| 88 | - $personal->method('getUri')->willReturn('personal-1'); |
|
| 89 | - $tz = new DateTimeZone('Europe/Berlin'); |
|
| 90 | - $vtz = $this->createMock(VTimeZone::class); |
|
| 91 | - $vtz->method('getTimeZone')->willReturn($tz); |
|
| 92 | - $personal->method('getSchedulingTimezone')->willReturn($vtz); |
|
| 93 | - $this->calendarManager->expects(self::once()) |
|
| 94 | - ->method('getCalendarsForPrincipal') |
|
| 95 | - ->with('principals/users/test123') |
|
| 96 | - ->willReturn([ |
|
| 97 | - $other, |
|
| 98 | - $personal, |
|
| 99 | - ]); |
|
| 100 | - |
|
| 101 | - $timezone = $this->service->getUserTimezone('test123'); |
|
| 102 | - |
|
| 103 | - self::assertNotNull($timezone); |
|
| 104 | - self::assertEquals('Europe/Berlin', $timezone); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function testGetUserTimezoneFromAny(): void { |
|
| 108 | - $this->config->expects(self::exactly(2)) |
|
| 109 | - ->method('getUserValue') |
|
| 110 | - ->willReturnMap([ |
|
| 111 | - ['test123', 'core', 'timezone', '', ''], |
|
| 112 | - ['test123', 'dav', 'defaultCalendar', '', 'personal-1'], |
|
| 113 | - ]); |
|
| 114 | - $other = $this->createMock(ICalendar::class); |
|
| 115 | - $other->method('getUri')->willReturn('other'); |
|
| 116 | - $personal = $this->createMock(CalendarImpl::class); |
|
| 117 | - $personal->method('getUri')->willReturn('personal-2'); |
|
| 118 | - $tz = new DateTimeZone('Europe/Prague'); |
|
| 119 | - $vtz = $this->createMock(VTimeZone::class); |
|
| 120 | - $vtz->method('getTimeZone')->willReturn($tz); |
|
| 121 | - $personal->method('getSchedulingTimezone')->willReturn($vtz); |
|
| 122 | - $this->calendarManager->expects(self::once()) |
|
| 123 | - ->method('getCalendarsForPrincipal') |
|
| 124 | - ->with('principals/users/test123') |
|
| 125 | - ->willReturn([ |
|
| 126 | - $other, |
|
| 127 | - $personal, |
|
| 128 | - ]); |
|
| 129 | - |
|
| 130 | - $timezone = $this->service->getUserTimezone('test123'); |
|
| 131 | - |
|
| 132 | - self::assertNotNull($timezone); |
|
| 133 | - self::assertEquals('Europe/Prague', $timezone); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function testGetUserTimezoneNoneFound(): void { |
|
| 137 | - $timezone = $this->service->getUserTimezone('test123'); |
|
| 138 | - |
|
| 139 | - self::assertNull($timezone); |
|
| 140 | - } |
|
| 66 | + $this->propertyMapper->expects(self::once()) |
|
| 67 | + ->method('findPropertyByPathAndName') |
|
| 68 | + ->willReturn([ |
|
| 69 | + $property, |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + $timezone = $this->service->getUserTimezone('test123'); |
|
| 73 | + |
|
| 74 | + self::assertNotNull($timezone); |
|
| 75 | + self::assertEquals('Europe/Vienna', $timezone); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function testGetUserTimezoneFromPersonalCalendar(): void { |
|
| 79 | + $this->config->expects(self::exactly(2)) |
|
| 80 | + ->method('getUserValue') |
|
| 81 | + ->willReturnMap([ |
|
| 82 | + ['test123', 'core', 'timezone', '', ''], |
|
| 83 | + ['test123', 'dav', 'defaultCalendar', '', 'personal-1'], |
|
| 84 | + ]); |
|
| 85 | + $other = $this->createMock(ICalendar::class); |
|
| 86 | + $other->method('getUri')->willReturn('other'); |
|
| 87 | + $personal = $this->createMock(CalendarImpl::class); |
|
| 88 | + $personal->method('getUri')->willReturn('personal-1'); |
|
| 89 | + $tz = new DateTimeZone('Europe/Berlin'); |
|
| 90 | + $vtz = $this->createMock(VTimeZone::class); |
|
| 91 | + $vtz->method('getTimeZone')->willReturn($tz); |
|
| 92 | + $personal->method('getSchedulingTimezone')->willReturn($vtz); |
|
| 93 | + $this->calendarManager->expects(self::once()) |
|
| 94 | + ->method('getCalendarsForPrincipal') |
|
| 95 | + ->with('principals/users/test123') |
|
| 96 | + ->willReturn([ |
|
| 97 | + $other, |
|
| 98 | + $personal, |
|
| 99 | + ]); |
|
| 100 | + |
|
| 101 | + $timezone = $this->service->getUserTimezone('test123'); |
|
| 102 | + |
|
| 103 | + self::assertNotNull($timezone); |
|
| 104 | + self::assertEquals('Europe/Berlin', $timezone); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function testGetUserTimezoneFromAny(): void { |
|
| 108 | + $this->config->expects(self::exactly(2)) |
|
| 109 | + ->method('getUserValue') |
|
| 110 | + ->willReturnMap([ |
|
| 111 | + ['test123', 'core', 'timezone', '', ''], |
|
| 112 | + ['test123', 'dav', 'defaultCalendar', '', 'personal-1'], |
|
| 113 | + ]); |
|
| 114 | + $other = $this->createMock(ICalendar::class); |
|
| 115 | + $other->method('getUri')->willReturn('other'); |
|
| 116 | + $personal = $this->createMock(CalendarImpl::class); |
|
| 117 | + $personal->method('getUri')->willReturn('personal-2'); |
|
| 118 | + $tz = new DateTimeZone('Europe/Prague'); |
|
| 119 | + $vtz = $this->createMock(VTimeZone::class); |
|
| 120 | + $vtz->method('getTimeZone')->willReturn($tz); |
|
| 121 | + $personal->method('getSchedulingTimezone')->willReturn($vtz); |
|
| 122 | + $this->calendarManager->expects(self::once()) |
|
| 123 | + ->method('getCalendarsForPrincipal') |
|
| 124 | + ->with('principals/users/test123') |
|
| 125 | + ->willReturn([ |
|
| 126 | + $other, |
|
| 127 | + $personal, |
|
| 128 | + ]); |
|
| 129 | + |
|
| 130 | + $timezone = $this->service->getUserTimezone('test123'); |
|
| 131 | + |
|
| 132 | + self::assertNotNull($timezone); |
|
| 133 | + self::assertEquals('Europe/Prague', $timezone); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function testGetUserTimezoneNoneFound(): void { |
|
| 137 | + $timezone = $this->service->getUserTimezone('test123'); |
|
| 138 | + |
|
| 139 | + self::assertNull($timezone); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | } |
@@ -12,92 +12,92 @@ |
||
| 12 | 12 | use Test\TestCase; |
| 13 | 13 | |
| 14 | 14 | class ExternalCalendarTest extends TestCase { |
| 15 | - private ExternalCalendar&MockObject $abstractExternalCalendar; |
|
| 16 | - |
|
| 17 | - protected function setUp(): void { |
|
| 18 | - parent::setUp(); |
|
| 19 | - |
|
| 20 | - $this->abstractExternalCalendar = |
|
| 21 | - $this->getMockForAbstractClass(ExternalCalendar::class, ['example-app-id', 'calendar-uri-in-backend']); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function testGetName():void { |
|
| 25 | - // Check that the correct name is returned |
|
| 26 | - $this->assertEquals('app-generated--example-app-id--calendar-uri-in-backend', |
|
| 27 | - $this->abstractExternalCalendar->getName()); |
|
| 28 | - |
|
| 29 | - // Check that the method is final and can't be overridden by other classes |
|
| 30 | - $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'getName'); |
|
| 31 | - $this->assertTrue($reflectionMethod->isFinal()); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function testSetName():void { |
|
| 35 | - // Check that the method is final and can't be overridden by other classes |
|
| 36 | - $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'setName'); |
|
| 37 | - $this->assertTrue($reflectionMethod->isFinal()); |
|
| 38 | - |
|
| 39 | - $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
| 40 | - $this->expectExceptionMessage('Renaming calendars is not yet supported'); |
|
| 41 | - |
|
| 42 | - $this->abstractExternalCalendar->setName('other-name'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function createDirectory(): void { |
|
| 46 | - // Check that the method is final and can't be overridden by other classes |
|
| 47 | - $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'createDirectory'); |
|
| 48 | - $this->assertTrue($reflectionMethod->isFinal()); |
|
| 49 | - |
|
| 50 | - $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
| 51 | - $this->expectExceptionMessage('Creating collections in calendar objects is not allowed'); |
|
| 52 | - |
|
| 53 | - $this->abstractExternalCalendar->createDirectory('other-name'); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function testIsAppGeneratedCalendar():void { |
|
| 57 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('personal')); |
|
| 58 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('work')); |
|
| 59 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('contact_birthdays')); |
|
| 60 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('company')); |
|
| 61 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('app-generated')); |
|
| 62 | - $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('app-generated--example')); |
|
| 63 | - |
|
| 64 | - $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--deck--board-1')); |
|
| 65 | - $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--example--foo-2')); |
|
| 66 | - $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--example--foo--2')); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @dataProvider splitAppGeneratedCalendarUriDataProvider |
|
| 71 | - */ |
|
| 72 | - public function testSplitAppGeneratedCalendarUriInvalid(string $name):void { |
|
| 73 | - $this->expectException(\InvalidArgumentException::class); |
|
| 74 | - $this->expectExceptionMessage('Provided calendar uri was not app-generated'); |
|
| 75 | - |
|
| 76 | - ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public static function splitAppGeneratedCalendarUriDataProvider():array { |
|
| 80 | - return [ |
|
| 81 | - ['personal'], |
|
| 82 | - ['foo_shared_by_admin'], |
|
| 83 | - ['contact_birthdays'], |
|
| 84 | - ]; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function testSplitAppGeneratedCalendarUri():void { |
|
| 88 | - $this->assertEquals(['deck', 'board-1'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--deck--board-1')); |
|
| 89 | - $this->assertEquals(['example', 'foo-2'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--example--foo-2')); |
|
| 90 | - $this->assertEquals(['example', 'foo--2'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--example--foo--2')); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function testDoesViolateReservedName():void { |
|
| 94 | - $this->assertFalse(ExternalCalendar::doesViolateReservedName('personal')); |
|
| 95 | - $this->assertFalse(ExternalCalendar::doesViolateReservedName('work')); |
|
| 96 | - $this->assertFalse(ExternalCalendar::doesViolateReservedName('contact_birthdays')); |
|
| 97 | - $this->assertFalse(ExternalCalendar::doesViolateReservedName('company')); |
|
| 98 | - |
|
| 99 | - $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated')); |
|
| 100 | - $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated-calendar')); |
|
| 101 | - $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated--deck-123')); |
|
| 102 | - } |
|
| 15 | + private ExternalCalendar&MockObject $abstractExternalCalendar; |
|
| 16 | + |
|
| 17 | + protected function setUp(): void { |
|
| 18 | + parent::setUp(); |
|
| 19 | + |
|
| 20 | + $this->abstractExternalCalendar = |
|
| 21 | + $this->getMockForAbstractClass(ExternalCalendar::class, ['example-app-id', 'calendar-uri-in-backend']); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function testGetName():void { |
|
| 25 | + // Check that the correct name is returned |
|
| 26 | + $this->assertEquals('app-generated--example-app-id--calendar-uri-in-backend', |
|
| 27 | + $this->abstractExternalCalendar->getName()); |
|
| 28 | + |
|
| 29 | + // Check that the method is final and can't be overridden by other classes |
|
| 30 | + $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'getName'); |
|
| 31 | + $this->assertTrue($reflectionMethod->isFinal()); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function testSetName():void { |
|
| 35 | + // Check that the method is final and can't be overridden by other classes |
|
| 36 | + $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'setName'); |
|
| 37 | + $this->assertTrue($reflectionMethod->isFinal()); |
|
| 38 | + |
|
| 39 | + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
| 40 | + $this->expectExceptionMessage('Renaming calendars is not yet supported'); |
|
| 41 | + |
|
| 42 | + $this->abstractExternalCalendar->setName('other-name'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function createDirectory(): void { |
|
| 46 | + // Check that the method is final and can't be overridden by other classes |
|
| 47 | + $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'createDirectory'); |
|
| 48 | + $this->assertTrue($reflectionMethod->isFinal()); |
|
| 49 | + |
|
| 50 | + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
| 51 | + $this->expectExceptionMessage('Creating collections in calendar objects is not allowed'); |
|
| 52 | + |
|
| 53 | + $this->abstractExternalCalendar->createDirectory('other-name'); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function testIsAppGeneratedCalendar():void { |
|
| 57 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('personal')); |
|
| 58 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('work')); |
|
| 59 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('contact_birthdays')); |
|
| 60 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('company')); |
|
| 61 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('app-generated')); |
|
| 62 | + $this->assertFalse(ExternalCalendar::isAppGeneratedCalendar('app-generated--example')); |
|
| 63 | + |
|
| 64 | + $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--deck--board-1')); |
|
| 65 | + $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--example--foo-2')); |
|
| 66 | + $this->assertTrue(ExternalCalendar::isAppGeneratedCalendar('app-generated--example--foo--2')); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @dataProvider splitAppGeneratedCalendarUriDataProvider |
|
| 71 | + */ |
|
| 72 | + public function testSplitAppGeneratedCalendarUriInvalid(string $name):void { |
|
| 73 | + $this->expectException(\InvalidArgumentException::class); |
|
| 74 | + $this->expectExceptionMessage('Provided calendar uri was not app-generated'); |
|
| 75 | + |
|
| 76 | + ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public static function splitAppGeneratedCalendarUriDataProvider():array { |
|
| 80 | + return [ |
|
| 81 | + ['personal'], |
|
| 82 | + ['foo_shared_by_admin'], |
|
| 83 | + ['contact_birthdays'], |
|
| 84 | + ]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function testSplitAppGeneratedCalendarUri():void { |
|
| 88 | + $this->assertEquals(['deck', 'board-1'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--deck--board-1')); |
|
| 89 | + $this->assertEquals(['example', 'foo-2'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--example--foo-2')); |
|
| 90 | + $this->assertEquals(['example', 'foo--2'], ExternalCalendar::splitAppGeneratedCalendarUri('app-generated--example--foo--2')); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function testDoesViolateReservedName():void { |
|
| 94 | + $this->assertFalse(ExternalCalendar::doesViolateReservedName('personal')); |
|
| 95 | + $this->assertFalse(ExternalCalendar::doesViolateReservedName('work')); |
|
| 96 | + $this->assertFalse(ExternalCalendar::doesViolateReservedName('contact_birthdays')); |
|
| 97 | + $this->assertFalse(ExternalCalendar::doesViolateReservedName('company')); |
|
| 98 | + |
|
| 99 | + $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated')); |
|
| 100 | + $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated-calendar')); |
|
| 101 | + $this->assertTrue(ExternalCalendar::doesViolateReservedName('app-generated--deck-123')); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -27,419 +27,419 @@ |
||
| 27 | 27 | use Test\TestCase; |
| 28 | 28 | |
| 29 | 29 | class StatusServiceTest extends TestCase { |
| 30 | - private ITimeFactory&MockObject $timeFactory; |
|
| 31 | - private IManager&MockObject $calendarManager; |
|
| 32 | - private IUserManager&MockObject $userManager; |
|
| 33 | - private UserStatusService&MockObject $userStatusService; |
|
| 34 | - private IAvailabilityCoordinator&MockObject $availabilityCoordinator; |
|
| 35 | - private ICacheFactory&MockObject $cacheFactory; |
|
| 36 | - private LoggerInterface&MockObject $logger; |
|
| 37 | - private ICache&MockObject $cache; |
|
| 38 | - private StatusService $service; |
|
| 39 | - |
|
| 40 | - protected function setUp(): void { |
|
| 41 | - parent::setUp(); |
|
| 42 | - |
|
| 43 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 44 | - $this->calendarManager = $this->createMock(IManager::class); |
|
| 45 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 46 | - $this->userStatusService = $this->createMock(UserStatusService::class); |
|
| 47 | - $this->availabilityCoordinator = $this->createMock(IAvailabilityCoordinator::class); |
|
| 48 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 49 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 50 | - $this->cache = $this->createMock(ICache::class); |
|
| 51 | - $this->cacheFactory->expects(self::once()) |
|
| 52 | - ->method('createLocal') |
|
| 53 | - ->with('CalendarStatusService') |
|
| 54 | - ->willReturn($this->cache); |
|
| 55 | - |
|
| 56 | - $this->service = new StatusService($this->timeFactory, |
|
| 57 | - $this->calendarManager, |
|
| 58 | - $this->userManager, |
|
| 59 | - $this->userStatusService, |
|
| 60 | - $this->availabilityCoordinator, |
|
| 61 | - $this->cacheFactory, |
|
| 62 | - $this->logger, |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function testNoUser(): void { |
|
| 67 | - $this->userManager->expects(self::once()) |
|
| 68 | - ->method('get') |
|
| 69 | - ->willReturn(null); |
|
| 70 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 71 | - ->method('getCurrentOutOfOfficeData'); |
|
| 72 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 73 | - ->method('isInEffect'); |
|
| 74 | - $this->logger->expects(self::never()) |
|
| 75 | - ->method('debug'); |
|
| 76 | - $this->cache->expects(self::never()) |
|
| 77 | - ->method('get'); |
|
| 78 | - $this->cache->expects(self::never()) |
|
| 79 | - ->method('set'); |
|
| 80 | - $this->calendarManager->expects(self::never()) |
|
| 81 | - ->method('getCalendarsForPrincipal'); |
|
| 82 | - $this->calendarManager->expects(self::never()) |
|
| 83 | - ->method('newQuery'); |
|
| 84 | - $this->timeFactory->expects(self::never()) |
|
| 85 | - ->method('getDateTime'); |
|
| 86 | - $this->calendarManager->expects(self::never()) |
|
| 87 | - ->method('searchForPrincipal'); |
|
| 88 | - $this->userStatusService->expects(self::never()) |
|
| 89 | - ->method('revertUserStatus'); |
|
| 90 | - $this->userStatusService->expects(self::never()) |
|
| 91 | - ->method('setUserStatus'); |
|
| 92 | - $this->userStatusService->expects(self::never()) |
|
| 93 | - ->method('findByUserId'); |
|
| 94 | - |
|
| 95 | - $this->service->processCalendarStatus('admin'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function testOOOInEffect(): void { |
|
| 99 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 100 | - 'getUID' => 'admin', |
|
| 101 | - ]); |
|
| 102 | - |
|
| 103 | - $this->userManager->expects(self::once()) |
|
| 104 | - ->method('get') |
|
| 105 | - ->willReturn($user); |
|
| 106 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 107 | - ->method('getCurrentOutOfOfficeData') |
|
| 108 | - ->willReturn($this->createMock(IOutOfOfficeData::class)); |
|
| 109 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 110 | - ->method('isInEffect') |
|
| 111 | - ->willReturn(true); |
|
| 112 | - $this->logger->expects(self::once()) |
|
| 113 | - ->method('debug'); |
|
| 114 | - $this->cache->expects(self::never()) |
|
| 115 | - ->method('get'); |
|
| 116 | - $this->cache->expects(self::never()) |
|
| 117 | - ->method('set'); |
|
| 118 | - $this->calendarManager->expects(self::never()) |
|
| 119 | - ->method('getCalendarsForPrincipal'); |
|
| 120 | - $this->calendarManager->expects(self::never()) |
|
| 121 | - ->method('newQuery'); |
|
| 122 | - $this->timeFactory->expects(self::never()) |
|
| 123 | - ->method('getDateTime'); |
|
| 124 | - $this->calendarManager->expects(self::never()) |
|
| 125 | - ->method('searchForPrincipal'); |
|
| 126 | - $this->userStatusService->expects(self::never()) |
|
| 127 | - ->method('revertUserStatus'); |
|
| 128 | - $this->userStatusService->expects(self::never()) |
|
| 129 | - ->method('setUserStatus'); |
|
| 130 | - $this->userStatusService->expects(self::never()) |
|
| 131 | - ->method('findByUserId'); |
|
| 132 | - |
|
| 133 | - $this->service->processCalendarStatus('admin'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function testNoCalendars(): void { |
|
| 137 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 138 | - 'getUID' => 'admin', |
|
| 139 | - ]); |
|
| 140 | - |
|
| 141 | - $this->userManager->expects(self::once()) |
|
| 142 | - ->method('get') |
|
| 143 | - ->willReturn($user); |
|
| 144 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 145 | - ->method('getCurrentOutOfOfficeData') |
|
| 146 | - ->willReturn(null); |
|
| 147 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 148 | - ->method('isInEffect'); |
|
| 149 | - $this->cache->expects(self::once()) |
|
| 150 | - ->method('get') |
|
| 151 | - ->willReturn(null); |
|
| 152 | - $this->cache->expects(self::once()) |
|
| 153 | - ->method('set'); |
|
| 154 | - $this->calendarManager->expects(self::once()) |
|
| 155 | - ->method('getCalendarsForPrincipal') |
|
| 156 | - ->willReturn([]); |
|
| 157 | - $this->calendarManager->expects(self::never()) |
|
| 158 | - ->method('newQuery'); |
|
| 159 | - $this->timeFactory->expects(self::never()) |
|
| 160 | - ->method('getDateTime'); |
|
| 161 | - $this->calendarManager->expects(self::never()) |
|
| 162 | - ->method('searchForPrincipal'); |
|
| 163 | - $this->userStatusService->expects(self::once()) |
|
| 164 | - ->method('revertUserStatus'); |
|
| 165 | - $this->logger->expects(self::once()) |
|
| 166 | - ->method('debug'); |
|
| 167 | - $this->userStatusService->expects(self::never()) |
|
| 168 | - ->method('setUserStatus'); |
|
| 169 | - $this->userStatusService->expects(self::never()) |
|
| 170 | - ->method('findByUserId'); |
|
| 171 | - |
|
| 172 | - $this->service->processCalendarStatus('admin'); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - public function testNoCalendarEvents(): void { |
|
| 176 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 177 | - 'getUID' => 'admin', |
|
| 178 | - ]); |
|
| 179 | - |
|
| 180 | - $this->userManager->expects(self::once()) |
|
| 181 | - ->method('get') |
|
| 182 | - ->willReturn($user); |
|
| 183 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 184 | - ->method('getCurrentOutOfOfficeData') |
|
| 185 | - ->willReturn(null); |
|
| 186 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 187 | - ->method('isInEffect'); |
|
| 188 | - $this->cache->expects(self::once()) |
|
| 189 | - ->method('get') |
|
| 190 | - ->willReturn(null); |
|
| 191 | - $this->cache->expects(self::once()) |
|
| 192 | - ->method('set'); |
|
| 193 | - $this->calendarManager->expects(self::once()) |
|
| 194 | - ->method('getCalendarsForPrincipal') |
|
| 195 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 196 | - $this->calendarManager->expects(self::once()) |
|
| 197 | - ->method('newQuery') |
|
| 198 | - ->willReturn(new CalendarQuery('admin')); |
|
| 199 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 200 | - ->method('getDateTime') |
|
| 201 | - ->willReturn(new \DateTime()); |
|
| 202 | - $this->calendarManager->expects(self::once()) |
|
| 203 | - ->method('searchForPrincipal') |
|
| 204 | - ->willReturn([]); |
|
| 205 | - $this->userStatusService->expects(self::once()) |
|
| 206 | - ->method('revertUserStatus'); |
|
| 207 | - $this->logger->expects(self::once()) |
|
| 208 | - ->method('debug'); |
|
| 209 | - $this->userStatusService->expects(self::never()) |
|
| 210 | - ->method('setUserStatus'); |
|
| 211 | - $this->userStatusService->expects(self::never()) |
|
| 212 | - ->method('findByUserId'); |
|
| 213 | - |
|
| 214 | - $this->service->processCalendarStatus('admin'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - public function testCalendarNoEventObjects(): void { |
|
| 218 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 219 | - 'getUID' => 'admin', |
|
| 220 | - ]); |
|
| 221 | - |
|
| 222 | - $this->userManager->expects(self::once()) |
|
| 223 | - ->method('get') |
|
| 224 | - ->willReturn($user); |
|
| 225 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 226 | - ->method('getCurrentOutOfOfficeData') |
|
| 227 | - ->willReturn(null); |
|
| 228 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 229 | - ->method('isInEffect'); |
|
| 230 | - $this->cache->expects(self::once()) |
|
| 231 | - ->method('get') |
|
| 232 | - ->willReturn(null); |
|
| 233 | - $this->cache->expects(self::once()) |
|
| 234 | - ->method('set'); |
|
| 235 | - $this->calendarManager->expects(self::once()) |
|
| 236 | - ->method('getCalendarsForPrincipal') |
|
| 237 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 238 | - $this->calendarManager->expects(self::once()) |
|
| 239 | - ->method('newQuery') |
|
| 240 | - ->willReturn(new CalendarQuery('admin')); |
|
| 241 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 242 | - ->method('getDateTime') |
|
| 243 | - ->willReturn(new \DateTime()); |
|
| 244 | - $this->userStatusService->expects(self::once()) |
|
| 245 | - ->method('findByUserId') |
|
| 246 | - ->willThrowException(new DoesNotExistException('')); |
|
| 247 | - $this->calendarManager->expects(self::once()) |
|
| 248 | - ->method('searchForPrincipal') |
|
| 249 | - ->willReturn([['objects' => []]]); |
|
| 250 | - $this->userStatusService->expects(self::once()) |
|
| 251 | - ->method('revertUserStatus'); |
|
| 252 | - $this->logger->expects(self::once()) |
|
| 253 | - ->method('debug'); |
|
| 254 | - $this->userStatusService->expects(self::never()) |
|
| 255 | - ->method('setUserStatus'); |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - $this->service->processCalendarStatus('admin'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - public function testCalendarEvent(): void { |
|
| 262 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 263 | - 'getUID' => 'admin', |
|
| 264 | - ]); |
|
| 265 | - |
|
| 266 | - $this->userManager->expects(self::once()) |
|
| 267 | - ->method('get') |
|
| 268 | - ->willReturn($user); |
|
| 269 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 270 | - ->method('getCurrentOutOfOfficeData') |
|
| 271 | - ->willReturn(null); |
|
| 272 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 273 | - ->method('isInEffect'); |
|
| 274 | - $this->cache->expects(self::once()) |
|
| 275 | - ->method('get') |
|
| 276 | - ->willReturn(null); |
|
| 277 | - $this->cache->expects(self::once()) |
|
| 278 | - ->method('set'); |
|
| 279 | - $this->calendarManager->expects(self::once()) |
|
| 280 | - ->method('getCalendarsForPrincipal') |
|
| 281 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 282 | - $this->calendarManager->expects(self::once()) |
|
| 283 | - ->method('newQuery') |
|
| 284 | - ->willReturn(new CalendarQuery('admin')); |
|
| 285 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 286 | - ->method('getDateTime') |
|
| 287 | - ->willReturn(new \DateTime()); |
|
| 288 | - $this->userStatusService->expects(self::once()) |
|
| 289 | - ->method('findByUserId') |
|
| 290 | - ->willThrowException(new DoesNotExistException('')); |
|
| 291 | - $this->calendarManager->expects(self::once()) |
|
| 292 | - ->method('searchForPrincipal') |
|
| 293 | - ->willReturn([['objects' => [[]]]]); |
|
| 294 | - $this->userStatusService->expects(self::never()) |
|
| 295 | - ->method('revertUserStatus'); |
|
| 296 | - $this->logger->expects(self::once()) |
|
| 297 | - ->method('debug'); |
|
| 298 | - $this->userStatusService->expects(self::once()) |
|
| 299 | - ->method('setUserStatus'); |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - $this->service->processCalendarStatus('admin'); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - public function testCallStatus(): void { |
|
| 306 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 307 | - 'getUID' => 'admin', |
|
| 308 | - ]); |
|
| 309 | - |
|
| 310 | - $this->userManager->expects(self::once()) |
|
| 311 | - ->method('get') |
|
| 312 | - ->willReturn($user); |
|
| 313 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 314 | - ->method('getCurrentOutOfOfficeData') |
|
| 315 | - ->willReturn(null); |
|
| 316 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 317 | - ->method('isInEffect'); |
|
| 318 | - $this->cache->expects(self::once()) |
|
| 319 | - ->method('get') |
|
| 320 | - ->willReturn(null); |
|
| 321 | - $this->cache->expects(self::once()) |
|
| 322 | - ->method('set'); |
|
| 323 | - $this->calendarManager->expects(self::once()) |
|
| 324 | - ->method('getCalendarsForPrincipal') |
|
| 325 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 326 | - $this->calendarManager->expects(self::once()) |
|
| 327 | - ->method('newQuery') |
|
| 328 | - ->willReturn(new CalendarQuery('admin')); |
|
| 329 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 330 | - ->method('getDateTime') |
|
| 331 | - ->willReturn(new \DateTime()); |
|
| 332 | - $this->calendarManager->expects(self::once()) |
|
| 333 | - ->method('searchForPrincipal') |
|
| 334 | - ->willReturn([['objects' => [[]]]]); |
|
| 335 | - $userStatus = new UserStatus(); |
|
| 336 | - $userStatus->setMessageId(IUserStatus::MESSAGE_CALL); |
|
| 337 | - $userStatus->setStatusTimestamp(123456); |
|
| 338 | - $this->userStatusService->expects(self::once()) |
|
| 339 | - ->method('findByUserId') |
|
| 340 | - ->willReturn($userStatus); |
|
| 341 | - $this->logger->expects(self::once()) |
|
| 342 | - ->method('debug'); |
|
| 343 | - $this->userStatusService->expects(self::never()) |
|
| 344 | - ->method('revertUserStatus'); |
|
| 345 | - $this->userStatusService->expects(self::never()) |
|
| 346 | - ->method('setUserStatus'); |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - $this->service->processCalendarStatus('admin'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - public function testInvisibleStatus(): void { |
|
| 353 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 354 | - 'getUID' => 'admin', |
|
| 355 | - ]); |
|
| 356 | - |
|
| 357 | - $this->userManager->expects(self::once()) |
|
| 358 | - ->method('get') |
|
| 359 | - ->willReturn($user); |
|
| 360 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 361 | - ->method('getCurrentOutOfOfficeData') |
|
| 362 | - ->willReturn(null); |
|
| 363 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 364 | - ->method('isInEffect'); |
|
| 365 | - $this->cache->expects(self::once()) |
|
| 366 | - ->method('get') |
|
| 367 | - ->willReturn(null); |
|
| 368 | - $this->cache->expects(self::once()) |
|
| 369 | - ->method('set'); |
|
| 370 | - $this->calendarManager->expects(self::once()) |
|
| 371 | - ->method('getCalendarsForPrincipal') |
|
| 372 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 373 | - $this->calendarManager->expects(self::once()) |
|
| 374 | - ->method('newQuery') |
|
| 375 | - ->willReturn(new CalendarQuery('admin')); |
|
| 376 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 377 | - ->method('getDateTime') |
|
| 378 | - ->willReturn(new \DateTime()); |
|
| 379 | - $this->calendarManager->expects(self::once()) |
|
| 380 | - ->method('searchForPrincipal') |
|
| 381 | - ->willReturn([['objects' => [[]]]]); |
|
| 382 | - $userStatus = new UserStatus(); |
|
| 383 | - $userStatus->setStatus(IUserStatus::INVISIBLE); |
|
| 384 | - $userStatus->setStatusTimestamp(123456); |
|
| 385 | - $this->userStatusService->expects(self::once()) |
|
| 386 | - ->method('findByUserId') |
|
| 387 | - ->willReturn($userStatus); |
|
| 388 | - $this->logger->expects(self::once()) |
|
| 389 | - ->method('debug'); |
|
| 390 | - $this->userStatusService->expects(self::never()) |
|
| 391 | - ->method('revertUserStatus'); |
|
| 392 | - $this->userStatusService->expects(self::never()) |
|
| 393 | - ->method('setUserStatus'); |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - $this->service->processCalendarStatus('admin'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - public function testDNDStatus(): void { |
|
| 400 | - $user = $this->createConfiguredMock(IUser::class, [ |
|
| 401 | - 'getUID' => 'admin', |
|
| 402 | - ]); |
|
| 403 | - |
|
| 404 | - $this->userManager->expects(self::once()) |
|
| 405 | - ->method('get') |
|
| 406 | - ->willReturn($user); |
|
| 407 | - $this->availabilityCoordinator->expects(self::once()) |
|
| 408 | - ->method('getCurrentOutOfOfficeData') |
|
| 409 | - ->willReturn(null); |
|
| 410 | - $this->availabilityCoordinator->expects(self::never()) |
|
| 411 | - ->method('isInEffect'); |
|
| 412 | - $this->cache->expects(self::once()) |
|
| 413 | - ->method('get') |
|
| 414 | - ->willReturn(null); |
|
| 415 | - $this->cache->expects(self::once()) |
|
| 416 | - ->method('set'); |
|
| 417 | - $this->calendarManager->expects(self::once()) |
|
| 418 | - ->method('getCalendarsForPrincipal') |
|
| 419 | - ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 420 | - $this->calendarManager->expects(self::once()) |
|
| 421 | - ->method('newQuery') |
|
| 422 | - ->willReturn(new CalendarQuery('admin')); |
|
| 423 | - $this->timeFactory->expects(self::exactly(2)) |
|
| 424 | - ->method('getDateTime') |
|
| 425 | - ->willReturn(new \DateTime()); |
|
| 426 | - $this->calendarManager->expects(self::once()) |
|
| 427 | - ->method('searchForPrincipal') |
|
| 428 | - ->willReturn([['objects' => [[]]]]); |
|
| 429 | - $userStatus = new UserStatus(); |
|
| 430 | - $userStatus->setStatus(IUserStatus::DND); |
|
| 431 | - $userStatus->setStatusTimestamp(123456); |
|
| 432 | - $this->userStatusService->expects(self::once()) |
|
| 433 | - ->method('findByUserId') |
|
| 434 | - ->willReturn($userStatus); |
|
| 435 | - $this->logger->expects(self::once()) |
|
| 436 | - ->method('debug'); |
|
| 437 | - $this->userStatusService->expects(self::never()) |
|
| 438 | - ->method('revertUserStatus'); |
|
| 439 | - $this->userStatusService->expects(self::never()) |
|
| 440 | - ->method('setUserStatus'); |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - $this->service->processCalendarStatus('admin'); |
|
| 444 | - } |
|
| 30 | + private ITimeFactory&MockObject $timeFactory; |
|
| 31 | + private IManager&MockObject $calendarManager; |
|
| 32 | + private IUserManager&MockObject $userManager; |
|
| 33 | + private UserStatusService&MockObject $userStatusService; |
|
| 34 | + private IAvailabilityCoordinator&MockObject $availabilityCoordinator; |
|
| 35 | + private ICacheFactory&MockObject $cacheFactory; |
|
| 36 | + private LoggerInterface&MockObject $logger; |
|
| 37 | + private ICache&MockObject $cache; |
|
| 38 | + private StatusService $service; |
|
| 39 | + |
|
| 40 | + protected function setUp(): void { |
|
| 41 | + parent::setUp(); |
|
| 42 | + |
|
| 43 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
| 44 | + $this->calendarManager = $this->createMock(IManager::class); |
|
| 45 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 46 | + $this->userStatusService = $this->createMock(UserStatusService::class); |
|
| 47 | + $this->availabilityCoordinator = $this->createMock(IAvailabilityCoordinator::class); |
|
| 48 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 49 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 50 | + $this->cache = $this->createMock(ICache::class); |
|
| 51 | + $this->cacheFactory->expects(self::once()) |
|
| 52 | + ->method('createLocal') |
|
| 53 | + ->with('CalendarStatusService') |
|
| 54 | + ->willReturn($this->cache); |
|
| 55 | + |
|
| 56 | + $this->service = new StatusService($this->timeFactory, |
|
| 57 | + $this->calendarManager, |
|
| 58 | + $this->userManager, |
|
| 59 | + $this->userStatusService, |
|
| 60 | + $this->availabilityCoordinator, |
|
| 61 | + $this->cacheFactory, |
|
| 62 | + $this->logger, |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function testNoUser(): void { |
|
| 67 | + $this->userManager->expects(self::once()) |
|
| 68 | + ->method('get') |
|
| 69 | + ->willReturn(null); |
|
| 70 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 71 | + ->method('getCurrentOutOfOfficeData'); |
|
| 72 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 73 | + ->method('isInEffect'); |
|
| 74 | + $this->logger->expects(self::never()) |
|
| 75 | + ->method('debug'); |
|
| 76 | + $this->cache->expects(self::never()) |
|
| 77 | + ->method('get'); |
|
| 78 | + $this->cache->expects(self::never()) |
|
| 79 | + ->method('set'); |
|
| 80 | + $this->calendarManager->expects(self::never()) |
|
| 81 | + ->method('getCalendarsForPrincipal'); |
|
| 82 | + $this->calendarManager->expects(self::never()) |
|
| 83 | + ->method('newQuery'); |
|
| 84 | + $this->timeFactory->expects(self::never()) |
|
| 85 | + ->method('getDateTime'); |
|
| 86 | + $this->calendarManager->expects(self::never()) |
|
| 87 | + ->method('searchForPrincipal'); |
|
| 88 | + $this->userStatusService->expects(self::never()) |
|
| 89 | + ->method('revertUserStatus'); |
|
| 90 | + $this->userStatusService->expects(self::never()) |
|
| 91 | + ->method('setUserStatus'); |
|
| 92 | + $this->userStatusService->expects(self::never()) |
|
| 93 | + ->method('findByUserId'); |
|
| 94 | + |
|
| 95 | + $this->service->processCalendarStatus('admin'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function testOOOInEffect(): void { |
|
| 99 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 100 | + 'getUID' => 'admin', |
|
| 101 | + ]); |
|
| 102 | + |
|
| 103 | + $this->userManager->expects(self::once()) |
|
| 104 | + ->method('get') |
|
| 105 | + ->willReturn($user); |
|
| 106 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 107 | + ->method('getCurrentOutOfOfficeData') |
|
| 108 | + ->willReturn($this->createMock(IOutOfOfficeData::class)); |
|
| 109 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 110 | + ->method('isInEffect') |
|
| 111 | + ->willReturn(true); |
|
| 112 | + $this->logger->expects(self::once()) |
|
| 113 | + ->method('debug'); |
|
| 114 | + $this->cache->expects(self::never()) |
|
| 115 | + ->method('get'); |
|
| 116 | + $this->cache->expects(self::never()) |
|
| 117 | + ->method('set'); |
|
| 118 | + $this->calendarManager->expects(self::never()) |
|
| 119 | + ->method('getCalendarsForPrincipal'); |
|
| 120 | + $this->calendarManager->expects(self::never()) |
|
| 121 | + ->method('newQuery'); |
|
| 122 | + $this->timeFactory->expects(self::never()) |
|
| 123 | + ->method('getDateTime'); |
|
| 124 | + $this->calendarManager->expects(self::never()) |
|
| 125 | + ->method('searchForPrincipal'); |
|
| 126 | + $this->userStatusService->expects(self::never()) |
|
| 127 | + ->method('revertUserStatus'); |
|
| 128 | + $this->userStatusService->expects(self::never()) |
|
| 129 | + ->method('setUserStatus'); |
|
| 130 | + $this->userStatusService->expects(self::never()) |
|
| 131 | + ->method('findByUserId'); |
|
| 132 | + |
|
| 133 | + $this->service->processCalendarStatus('admin'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function testNoCalendars(): void { |
|
| 137 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 138 | + 'getUID' => 'admin', |
|
| 139 | + ]); |
|
| 140 | + |
|
| 141 | + $this->userManager->expects(self::once()) |
|
| 142 | + ->method('get') |
|
| 143 | + ->willReturn($user); |
|
| 144 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 145 | + ->method('getCurrentOutOfOfficeData') |
|
| 146 | + ->willReturn(null); |
|
| 147 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 148 | + ->method('isInEffect'); |
|
| 149 | + $this->cache->expects(self::once()) |
|
| 150 | + ->method('get') |
|
| 151 | + ->willReturn(null); |
|
| 152 | + $this->cache->expects(self::once()) |
|
| 153 | + ->method('set'); |
|
| 154 | + $this->calendarManager->expects(self::once()) |
|
| 155 | + ->method('getCalendarsForPrincipal') |
|
| 156 | + ->willReturn([]); |
|
| 157 | + $this->calendarManager->expects(self::never()) |
|
| 158 | + ->method('newQuery'); |
|
| 159 | + $this->timeFactory->expects(self::never()) |
|
| 160 | + ->method('getDateTime'); |
|
| 161 | + $this->calendarManager->expects(self::never()) |
|
| 162 | + ->method('searchForPrincipal'); |
|
| 163 | + $this->userStatusService->expects(self::once()) |
|
| 164 | + ->method('revertUserStatus'); |
|
| 165 | + $this->logger->expects(self::once()) |
|
| 166 | + ->method('debug'); |
|
| 167 | + $this->userStatusService->expects(self::never()) |
|
| 168 | + ->method('setUserStatus'); |
|
| 169 | + $this->userStatusService->expects(self::never()) |
|
| 170 | + ->method('findByUserId'); |
|
| 171 | + |
|
| 172 | + $this->service->processCalendarStatus('admin'); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + public function testNoCalendarEvents(): void { |
|
| 176 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 177 | + 'getUID' => 'admin', |
|
| 178 | + ]); |
|
| 179 | + |
|
| 180 | + $this->userManager->expects(self::once()) |
|
| 181 | + ->method('get') |
|
| 182 | + ->willReturn($user); |
|
| 183 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 184 | + ->method('getCurrentOutOfOfficeData') |
|
| 185 | + ->willReturn(null); |
|
| 186 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 187 | + ->method('isInEffect'); |
|
| 188 | + $this->cache->expects(self::once()) |
|
| 189 | + ->method('get') |
|
| 190 | + ->willReturn(null); |
|
| 191 | + $this->cache->expects(self::once()) |
|
| 192 | + ->method('set'); |
|
| 193 | + $this->calendarManager->expects(self::once()) |
|
| 194 | + ->method('getCalendarsForPrincipal') |
|
| 195 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 196 | + $this->calendarManager->expects(self::once()) |
|
| 197 | + ->method('newQuery') |
|
| 198 | + ->willReturn(new CalendarQuery('admin')); |
|
| 199 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 200 | + ->method('getDateTime') |
|
| 201 | + ->willReturn(new \DateTime()); |
|
| 202 | + $this->calendarManager->expects(self::once()) |
|
| 203 | + ->method('searchForPrincipal') |
|
| 204 | + ->willReturn([]); |
|
| 205 | + $this->userStatusService->expects(self::once()) |
|
| 206 | + ->method('revertUserStatus'); |
|
| 207 | + $this->logger->expects(self::once()) |
|
| 208 | + ->method('debug'); |
|
| 209 | + $this->userStatusService->expects(self::never()) |
|
| 210 | + ->method('setUserStatus'); |
|
| 211 | + $this->userStatusService->expects(self::never()) |
|
| 212 | + ->method('findByUserId'); |
|
| 213 | + |
|
| 214 | + $this->service->processCalendarStatus('admin'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + public function testCalendarNoEventObjects(): void { |
|
| 218 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 219 | + 'getUID' => 'admin', |
|
| 220 | + ]); |
|
| 221 | + |
|
| 222 | + $this->userManager->expects(self::once()) |
|
| 223 | + ->method('get') |
|
| 224 | + ->willReturn($user); |
|
| 225 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 226 | + ->method('getCurrentOutOfOfficeData') |
|
| 227 | + ->willReturn(null); |
|
| 228 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 229 | + ->method('isInEffect'); |
|
| 230 | + $this->cache->expects(self::once()) |
|
| 231 | + ->method('get') |
|
| 232 | + ->willReturn(null); |
|
| 233 | + $this->cache->expects(self::once()) |
|
| 234 | + ->method('set'); |
|
| 235 | + $this->calendarManager->expects(self::once()) |
|
| 236 | + ->method('getCalendarsForPrincipal') |
|
| 237 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 238 | + $this->calendarManager->expects(self::once()) |
|
| 239 | + ->method('newQuery') |
|
| 240 | + ->willReturn(new CalendarQuery('admin')); |
|
| 241 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 242 | + ->method('getDateTime') |
|
| 243 | + ->willReturn(new \DateTime()); |
|
| 244 | + $this->userStatusService->expects(self::once()) |
|
| 245 | + ->method('findByUserId') |
|
| 246 | + ->willThrowException(new DoesNotExistException('')); |
|
| 247 | + $this->calendarManager->expects(self::once()) |
|
| 248 | + ->method('searchForPrincipal') |
|
| 249 | + ->willReturn([['objects' => []]]); |
|
| 250 | + $this->userStatusService->expects(self::once()) |
|
| 251 | + ->method('revertUserStatus'); |
|
| 252 | + $this->logger->expects(self::once()) |
|
| 253 | + ->method('debug'); |
|
| 254 | + $this->userStatusService->expects(self::never()) |
|
| 255 | + ->method('setUserStatus'); |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + $this->service->processCalendarStatus('admin'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + public function testCalendarEvent(): void { |
|
| 262 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 263 | + 'getUID' => 'admin', |
|
| 264 | + ]); |
|
| 265 | + |
|
| 266 | + $this->userManager->expects(self::once()) |
|
| 267 | + ->method('get') |
|
| 268 | + ->willReturn($user); |
|
| 269 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 270 | + ->method('getCurrentOutOfOfficeData') |
|
| 271 | + ->willReturn(null); |
|
| 272 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 273 | + ->method('isInEffect'); |
|
| 274 | + $this->cache->expects(self::once()) |
|
| 275 | + ->method('get') |
|
| 276 | + ->willReturn(null); |
|
| 277 | + $this->cache->expects(self::once()) |
|
| 278 | + ->method('set'); |
|
| 279 | + $this->calendarManager->expects(self::once()) |
|
| 280 | + ->method('getCalendarsForPrincipal') |
|
| 281 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 282 | + $this->calendarManager->expects(self::once()) |
|
| 283 | + ->method('newQuery') |
|
| 284 | + ->willReturn(new CalendarQuery('admin')); |
|
| 285 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 286 | + ->method('getDateTime') |
|
| 287 | + ->willReturn(new \DateTime()); |
|
| 288 | + $this->userStatusService->expects(self::once()) |
|
| 289 | + ->method('findByUserId') |
|
| 290 | + ->willThrowException(new DoesNotExistException('')); |
|
| 291 | + $this->calendarManager->expects(self::once()) |
|
| 292 | + ->method('searchForPrincipal') |
|
| 293 | + ->willReturn([['objects' => [[]]]]); |
|
| 294 | + $this->userStatusService->expects(self::never()) |
|
| 295 | + ->method('revertUserStatus'); |
|
| 296 | + $this->logger->expects(self::once()) |
|
| 297 | + ->method('debug'); |
|
| 298 | + $this->userStatusService->expects(self::once()) |
|
| 299 | + ->method('setUserStatus'); |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + $this->service->processCalendarStatus('admin'); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + public function testCallStatus(): void { |
|
| 306 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 307 | + 'getUID' => 'admin', |
|
| 308 | + ]); |
|
| 309 | + |
|
| 310 | + $this->userManager->expects(self::once()) |
|
| 311 | + ->method('get') |
|
| 312 | + ->willReturn($user); |
|
| 313 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 314 | + ->method('getCurrentOutOfOfficeData') |
|
| 315 | + ->willReturn(null); |
|
| 316 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 317 | + ->method('isInEffect'); |
|
| 318 | + $this->cache->expects(self::once()) |
|
| 319 | + ->method('get') |
|
| 320 | + ->willReturn(null); |
|
| 321 | + $this->cache->expects(self::once()) |
|
| 322 | + ->method('set'); |
|
| 323 | + $this->calendarManager->expects(self::once()) |
|
| 324 | + ->method('getCalendarsForPrincipal') |
|
| 325 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 326 | + $this->calendarManager->expects(self::once()) |
|
| 327 | + ->method('newQuery') |
|
| 328 | + ->willReturn(new CalendarQuery('admin')); |
|
| 329 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 330 | + ->method('getDateTime') |
|
| 331 | + ->willReturn(new \DateTime()); |
|
| 332 | + $this->calendarManager->expects(self::once()) |
|
| 333 | + ->method('searchForPrincipal') |
|
| 334 | + ->willReturn([['objects' => [[]]]]); |
|
| 335 | + $userStatus = new UserStatus(); |
|
| 336 | + $userStatus->setMessageId(IUserStatus::MESSAGE_CALL); |
|
| 337 | + $userStatus->setStatusTimestamp(123456); |
|
| 338 | + $this->userStatusService->expects(self::once()) |
|
| 339 | + ->method('findByUserId') |
|
| 340 | + ->willReturn($userStatus); |
|
| 341 | + $this->logger->expects(self::once()) |
|
| 342 | + ->method('debug'); |
|
| 343 | + $this->userStatusService->expects(self::never()) |
|
| 344 | + ->method('revertUserStatus'); |
|
| 345 | + $this->userStatusService->expects(self::never()) |
|
| 346 | + ->method('setUserStatus'); |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + $this->service->processCalendarStatus('admin'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + public function testInvisibleStatus(): void { |
|
| 353 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 354 | + 'getUID' => 'admin', |
|
| 355 | + ]); |
|
| 356 | + |
|
| 357 | + $this->userManager->expects(self::once()) |
|
| 358 | + ->method('get') |
|
| 359 | + ->willReturn($user); |
|
| 360 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 361 | + ->method('getCurrentOutOfOfficeData') |
|
| 362 | + ->willReturn(null); |
|
| 363 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 364 | + ->method('isInEffect'); |
|
| 365 | + $this->cache->expects(self::once()) |
|
| 366 | + ->method('get') |
|
| 367 | + ->willReturn(null); |
|
| 368 | + $this->cache->expects(self::once()) |
|
| 369 | + ->method('set'); |
|
| 370 | + $this->calendarManager->expects(self::once()) |
|
| 371 | + ->method('getCalendarsForPrincipal') |
|
| 372 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 373 | + $this->calendarManager->expects(self::once()) |
|
| 374 | + ->method('newQuery') |
|
| 375 | + ->willReturn(new CalendarQuery('admin')); |
|
| 376 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 377 | + ->method('getDateTime') |
|
| 378 | + ->willReturn(new \DateTime()); |
|
| 379 | + $this->calendarManager->expects(self::once()) |
|
| 380 | + ->method('searchForPrincipal') |
|
| 381 | + ->willReturn([['objects' => [[]]]]); |
|
| 382 | + $userStatus = new UserStatus(); |
|
| 383 | + $userStatus->setStatus(IUserStatus::INVISIBLE); |
|
| 384 | + $userStatus->setStatusTimestamp(123456); |
|
| 385 | + $this->userStatusService->expects(self::once()) |
|
| 386 | + ->method('findByUserId') |
|
| 387 | + ->willReturn($userStatus); |
|
| 388 | + $this->logger->expects(self::once()) |
|
| 389 | + ->method('debug'); |
|
| 390 | + $this->userStatusService->expects(self::never()) |
|
| 391 | + ->method('revertUserStatus'); |
|
| 392 | + $this->userStatusService->expects(self::never()) |
|
| 393 | + ->method('setUserStatus'); |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + $this->service->processCalendarStatus('admin'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + public function testDNDStatus(): void { |
|
| 400 | + $user = $this->createConfiguredMock(IUser::class, [ |
|
| 401 | + 'getUID' => 'admin', |
|
| 402 | + ]); |
|
| 403 | + |
|
| 404 | + $this->userManager->expects(self::once()) |
|
| 405 | + ->method('get') |
|
| 406 | + ->willReturn($user); |
|
| 407 | + $this->availabilityCoordinator->expects(self::once()) |
|
| 408 | + ->method('getCurrentOutOfOfficeData') |
|
| 409 | + ->willReturn(null); |
|
| 410 | + $this->availabilityCoordinator->expects(self::never()) |
|
| 411 | + ->method('isInEffect'); |
|
| 412 | + $this->cache->expects(self::once()) |
|
| 413 | + ->method('get') |
|
| 414 | + ->willReturn(null); |
|
| 415 | + $this->cache->expects(self::once()) |
|
| 416 | + ->method('set'); |
|
| 417 | + $this->calendarManager->expects(self::once()) |
|
| 418 | + ->method('getCalendarsForPrincipal') |
|
| 419 | + ->willReturn([$this->createMock(CalendarImpl::class)]); |
|
| 420 | + $this->calendarManager->expects(self::once()) |
|
| 421 | + ->method('newQuery') |
|
| 422 | + ->willReturn(new CalendarQuery('admin')); |
|
| 423 | + $this->timeFactory->expects(self::exactly(2)) |
|
| 424 | + ->method('getDateTime') |
|
| 425 | + ->willReturn(new \DateTime()); |
|
| 426 | + $this->calendarManager->expects(self::once()) |
|
| 427 | + ->method('searchForPrincipal') |
|
| 428 | + ->willReturn([['objects' => [[]]]]); |
|
| 429 | + $userStatus = new UserStatus(); |
|
| 430 | + $userStatus->setStatus(IUserStatus::DND); |
|
| 431 | + $userStatus->setStatusTimestamp(123456); |
|
| 432 | + $this->userStatusService->expects(self::once()) |
|
| 433 | + ->method('findByUserId') |
|
| 434 | + ->willReturn($userStatus); |
|
| 435 | + $this->logger->expects(self::once()) |
|
| 436 | + ->method('debug'); |
|
| 437 | + $this->userStatusService->expects(self::never()) |
|
| 438 | + ->method('revertUserStatus'); |
|
| 439 | + $this->userStatusService->expects(self::never()) |
|
| 440 | + ->method('setUserStatus'); |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + $this->service->processCalendarStatus('admin'); |
|
| 444 | + } |
|
| 445 | 445 | } |
@@ -32,110 +32,110 @@ |
||
| 32 | 32 | * @package OCA\DAV\Tests\unit\CalDAV |
| 33 | 33 | */ |
| 34 | 34 | class PublicCalendarRootTest extends TestCase { |
| 35 | - public const UNIT_TEST_USER = ''; |
|
| 36 | - private CalDavBackend $backend; |
|
| 37 | - private PublicCalendarRoot $publicCalendarRoot; |
|
| 38 | - private IL10N&MockObject $l10n; |
|
| 39 | - private Principal&MockObject $principal; |
|
| 40 | - protected IUserManager&MockObject $userManager; |
|
| 41 | - protected IGroupManager&MockObject $groupManager; |
|
| 42 | - protected IConfig&MockObject $config; |
|
| 43 | - private ISecureRandom $random; |
|
| 44 | - private LoggerInterface&MockObject $logger; |
|
| 45 | - |
|
| 46 | - protected function setUp(): void { |
|
| 47 | - parent::setUp(); |
|
| 48 | - |
|
| 49 | - $db = Server::get(IDBConnection::class); |
|
| 50 | - $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); |
|
| 51 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 52 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 53 | - $this->random = Server::get(ISecureRandom::class); |
|
| 54 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 55 | - $dispatcher = $this->createMock(IEventDispatcher::class); |
|
| 56 | - $config = $this->createMock(IConfig::class); |
|
| 57 | - $sharingBackend = $this->createMock(\OCA\DAV\CalDAV\Sharing\Backend::class); |
|
| 58 | - |
|
| 59 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
| 60 | - ->withAnyParameters() |
|
| 61 | - ->willReturn([]); |
|
| 62 | - |
|
| 63 | - $this->principal->expects($this->any())->method('getCircleMembership') |
|
| 64 | - ->withAnyParameters() |
|
| 65 | - ->willReturn([]); |
|
| 66 | - |
|
| 67 | - $this->backend = new CalDavBackend( |
|
| 68 | - $db, |
|
| 69 | - $this->principal, |
|
| 70 | - $this->userManager, |
|
| 71 | - $this->random, |
|
| 72 | - $this->logger, |
|
| 73 | - $dispatcher, |
|
| 74 | - $config, |
|
| 75 | - $sharingBackend, |
|
| 76 | - false, |
|
| 77 | - ); |
|
| 78 | - $this->l10n = $this->createMock(IL10N::class); |
|
| 79 | - $this->config = $this->createMock(IConfig::class); |
|
| 80 | - |
|
| 81 | - $this->publicCalendarRoot = new PublicCalendarRoot($this->backend, |
|
| 82 | - $this->l10n, $this->config, $this->logger); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - protected function tearDown(): void { |
|
| 86 | - parent::tearDown(); |
|
| 87 | - |
|
| 88 | - if (is_null($this->backend)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
| 92 | - ->withAnyParameters() |
|
| 93 | - ->willReturn([]); |
|
| 94 | - |
|
| 95 | - $this->principal->expects($this->any())->method('getCircleMembership') |
|
| 96 | - ->withAnyParameters() |
|
| 97 | - ->willReturn([]); |
|
| 98 | - |
|
| 99 | - $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 100 | - foreach ($books as $book) { |
|
| 101 | - $this->backend->deleteCalendar($book['id'], true); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function testGetName(): void { |
|
| 106 | - $name = $this->publicCalendarRoot->getName(); |
|
| 107 | - $this->assertEquals('public-calendars', $name); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function testGetChild(): void { |
|
| 111 | - $calendar = $this->createPublicCalendar(); |
|
| 112 | - |
|
| 113 | - $publicCalendars = $this->backend->getPublicCalendars(); |
|
| 114 | - $this->assertEquals(1, count($publicCalendars)); |
|
| 115 | - $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
| 116 | - |
|
| 117 | - $publicCalendarURI = $publicCalendars[0]['uri']; |
|
| 118 | - |
|
| 119 | - $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); |
|
| 120 | - $this->assertEquals($calendar, $calendarResult); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function testGetChildren(): void { |
|
| 124 | - $this->createPublicCalendar(); |
|
| 125 | - $calendarResults = $this->publicCalendarRoot->getChildren(); |
|
| 126 | - $this->assertSame([], $calendarResults); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function createPublicCalendar(): Calendar { |
|
| 130 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 131 | - |
|
| 132 | - $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 133 | - $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 134 | - $publicUri = $calendar->setPublishStatus(true); |
|
| 135 | - |
|
| 136 | - $calendarInfo = $this->backend->getPublicCalendar($publicUri); |
|
| 137 | - $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 138 | - |
|
| 139 | - return $calendar; |
|
| 140 | - } |
|
| 35 | + public const UNIT_TEST_USER = ''; |
|
| 36 | + private CalDavBackend $backend; |
|
| 37 | + private PublicCalendarRoot $publicCalendarRoot; |
|
| 38 | + private IL10N&MockObject $l10n; |
|
| 39 | + private Principal&MockObject $principal; |
|
| 40 | + protected IUserManager&MockObject $userManager; |
|
| 41 | + protected IGroupManager&MockObject $groupManager; |
|
| 42 | + protected IConfig&MockObject $config; |
|
| 43 | + private ISecureRandom $random; |
|
| 44 | + private LoggerInterface&MockObject $logger; |
|
| 45 | + |
|
| 46 | + protected function setUp(): void { |
|
| 47 | + parent::setUp(); |
|
| 48 | + |
|
| 49 | + $db = Server::get(IDBConnection::class); |
|
| 50 | + $this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal'); |
|
| 51 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 52 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 53 | + $this->random = Server::get(ISecureRandom::class); |
|
| 54 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 55 | + $dispatcher = $this->createMock(IEventDispatcher::class); |
|
| 56 | + $config = $this->createMock(IConfig::class); |
|
| 57 | + $sharingBackend = $this->createMock(\OCA\DAV\CalDAV\Sharing\Backend::class); |
|
| 58 | + |
|
| 59 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
| 60 | + ->withAnyParameters() |
|
| 61 | + ->willReturn([]); |
|
| 62 | + |
|
| 63 | + $this->principal->expects($this->any())->method('getCircleMembership') |
|
| 64 | + ->withAnyParameters() |
|
| 65 | + ->willReturn([]); |
|
| 66 | + |
|
| 67 | + $this->backend = new CalDavBackend( |
|
| 68 | + $db, |
|
| 69 | + $this->principal, |
|
| 70 | + $this->userManager, |
|
| 71 | + $this->random, |
|
| 72 | + $this->logger, |
|
| 73 | + $dispatcher, |
|
| 74 | + $config, |
|
| 75 | + $sharingBackend, |
|
| 76 | + false, |
|
| 77 | + ); |
|
| 78 | + $this->l10n = $this->createMock(IL10N::class); |
|
| 79 | + $this->config = $this->createMock(IConfig::class); |
|
| 80 | + |
|
| 81 | + $this->publicCalendarRoot = new PublicCalendarRoot($this->backend, |
|
| 82 | + $this->l10n, $this->config, $this->logger); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + protected function tearDown(): void { |
|
| 86 | + parent::tearDown(); |
|
| 87 | + |
|
| 88 | + if (is_null($this->backend)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
| 92 | + ->withAnyParameters() |
|
| 93 | + ->willReturn([]); |
|
| 94 | + |
|
| 95 | + $this->principal->expects($this->any())->method('getCircleMembership') |
|
| 96 | + ->withAnyParameters() |
|
| 97 | + ->willReturn([]); |
|
| 98 | + |
|
| 99 | + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 100 | + foreach ($books as $book) { |
|
| 101 | + $this->backend->deleteCalendar($book['id'], true); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function testGetName(): void { |
|
| 106 | + $name = $this->publicCalendarRoot->getName(); |
|
| 107 | + $this->assertEquals('public-calendars', $name); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function testGetChild(): void { |
|
| 111 | + $calendar = $this->createPublicCalendar(); |
|
| 112 | + |
|
| 113 | + $publicCalendars = $this->backend->getPublicCalendars(); |
|
| 114 | + $this->assertEquals(1, count($publicCalendars)); |
|
| 115 | + $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
| 116 | + |
|
| 117 | + $publicCalendarURI = $publicCalendars[0]['uri']; |
|
| 118 | + |
|
| 119 | + $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); |
|
| 120 | + $this->assertEquals($calendar, $calendarResult); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function testGetChildren(): void { |
|
| 124 | + $this->createPublicCalendar(); |
|
| 125 | + $calendarResults = $this->publicCalendarRoot->getChildren(); |
|
| 126 | + $this->assertSame([], $calendarResults); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function createPublicCalendar(): Calendar { |
|
| 130 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 131 | + |
|
| 132 | + $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 133 | + $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 134 | + $publicUri = $calendar->setPublishStatus(true); |
|
| 135 | + |
|
| 136 | + $calendarInfo = $this->backend->getPublicCalendar($publicUri); |
|
| 137 | + $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 138 | + |
|
| 139 | + return $calendar; |
|
| 140 | + } |
|
| 141 | 141 | } |
@@ -17,56 +17,56 @@ |
||
| 17 | 17 | |
| 18 | 18 | class CachedSubscriptionProviderTest extends TestCase { |
| 19 | 19 | |
| 20 | - private CalDavBackend&MockObject $backend; |
|
| 21 | - private CachedSubscriptionProvider $provider; |
|
| 20 | + private CalDavBackend&MockObject $backend; |
|
| 21 | + private CachedSubscriptionProvider $provider; |
|
| 22 | 22 | |
| 23 | - protected function setUp(): void { |
|
| 24 | - parent::setUp(); |
|
| 23 | + protected function setUp(): void { |
|
| 24 | + parent::setUp(); |
|
| 25 | 25 | |
| 26 | - $this->backend = $this->createMock(CalDavBackend::class); |
|
| 27 | - $this->backend |
|
| 28 | - ->expects(self::once()) |
|
| 29 | - ->method('getSubscriptionsForUser') |
|
| 30 | - ->with('user-principal-123') |
|
| 31 | - ->willReturn([ |
|
| 32 | - [ |
|
| 33 | - 'id' => 'subscription-1', |
|
| 34 | - 'uri' => 'subscription-1', |
|
| 35 | - 'principaluris' => 'user-principal-123', |
|
| 36 | - 'source' => 'https://localhost/subscription-1', |
|
| 37 | - // A subscription array has actually more properties. |
|
| 38 | - ], |
|
| 39 | - [ |
|
| 40 | - 'id' => 'subscription-2', |
|
| 41 | - 'uri' => 'subscription-2', |
|
| 42 | - 'principaluri' => 'user-principal-123', |
|
| 43 | - 'source' => 'https://localhost/subscription-2', |
|
| 44 | - // A subscription array has actually more properties. |
|
| 45 | - ] |
|
| 46 | - ]); |
|
| 26 | + $this->backend = $this->createMock(CalDavBackend::class); |
|
| 27 | + $this->backend |
|
| 28 | + ->expects(self::once()) |
|
| 29 | + ->method('getSubscriptionsForUser') |
|
| 30 | + ->with('user-principal-123') |
|
| 31 | + ->willReturn([ |
|
| 32 | + [ |
|
| 33 | + 'id' => 'subscription-1', |
|
| 34 | + 'uri' => 'subscription-1', |
|
| 35 | + 'principaluris' => 'user-principal-123', |
|
| 36 | + 'source' => 'https://localhost/subscription-1', |
|
| 37 | + // A subscription array has actually more properties. |
|
| 38 | + ], |
|
| 39 | + [ |
|
| 40 | + 'id' => 'subscription-2', |
|
| 41 | + 'uri' => 'subscription-2', |
|
| 42 | + 'principaluri' => 'user-principal-123', |
|
| 43 | + 'source' => 'https://localhost/subscription-2', |
|
| 44 | + // A subscription array has actually more properties. |
|
| 45 | + ] |
|
| 46 | + ]); |
|
| 47 | 47 | |
| 48 | - $this->provider = new CachedSubscriptionProvider($this->backend); |
|
| 49 | - } |
|
| 48 | + $this->provider = new CachedSubscriptionProvider($this->backend); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function testGetCalendars(): void { |
|
| 52 | - $calendars = $this->provider->getCalendars( |
|
| 53 | - 'user-principal-123', |
|
| 54 | - [] |
|
| 55 | - ); |
|
| 51 | + public function testGetCalendars(): void { |
|
| 52 | + $calendars = $this->provider->getCalendars( |
|
| 53 | + 'user-principal-123', |
|
| 54 | + [] |
|
| 55 | + ); |
|
| 56 | 56 | |
| 57 | - $this->assertCount(2, $calendars); |
|
| 58 | - $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]); |
|
| 59 | - $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[1]); |
|
| 60 | - } |
|
| 57 | + $this->assertCount(2, $calendars); |
|
| 58 | + $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]); |
|
| 59 | + $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[1]); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function testGetCalendarsFilterByUri(): void { |
|
| 63 | - $calendars = $this->provider->getCalendars( |
|
| 64 | - 'user-principal-123', |
|
| 65 | - ['subscription-1'] |
|
| 66 | - ); |
|
| 62 | + public function testGetCalendarsFilterByUri(): void { |
|
| 63 | + $calendars = $this->provider->getCalendars( |
|
| 64 | + 'user-principal-123', |
|
| 65 | + ['subscription-1'] |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - $this->assertCount(1, $calendars); |
|
| 69 | - $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]); |
|
| 70 | - $this->assertEquals('subscription-1', $calendars[0]->getUri()); |
|
| 71 | - } |
|
| 68 | + $this->assertCount(1, $calendars); |
|
| 69 | + $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]); |
|
| 70 | + $this->assertEquals('subscription-1', $calendars[0]->getUri()); |
|
| 71 | + } |
|
| 72 | 72 | } |