|
31 | 31 | use OCA\DAV\CalDAV\CalendarImpl; |
32 | 32 | use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; |
33 | 33 | use OCA\DAV\CalDAV\Schedule\Plugin; |
| 34 | +use OCA\DAV\Connector\Sabre\Server; |
| 35 | +use OCP\Calendar\Exceptions\CalendarException; |
34 | 36 | use PHPUnit\Framework\MockObject\MockObject; |
| 37 | +use Sabre\VObject\Component\VCalendar; |
| 38 | +use Sabre\VObject\Component\VEvent; |
| 39 | +use Sabre\VObject\ITip\Message; |
| 40 | +use Sabre\VObject\Reader; |
35 | 41 |
|
| 42 | +/** |
| 43 | + * @group DB |
| 44 | + */ |
36 | 45 | class CalendarImplTest extends \Test\TestCase { |
37 | | - |
38 | 46 | /** @var CalendarImpl */ |
39 | 47 | private $calendarImpl; |
40 | 48 |
|
@@ -69,7 +77,7 @@ public function testGetKey() { |
69 | 77 | } |
70 | 78 |
|
71 | 79 | public function testGetDisplayname() { |
72 | | - $this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123'); |
| 80 | + $this->assertEquals($this->calendarImpl->getDisplayName(), 'user readable name 123'); |
73 | 81 | } |
74 | 82 |
|
75 | 83 | public function testGetDisplayColor() { |
@@ -132,76 +140,140 @@ public function testGetPermissionAll() { |
132 | 140 | } |
133 | 141 |
|
134 | 142 | public function testHandleImipMessage(): void { |
135 | | - $invitationResponseServer = $this->createConfiguredMock(InvitationResponseServer::class, [ |
136 | | - 'server' => $this->createConfiguredMock(CalDavBackend::class, [ |
137 | | - 'getPlugin' => [ |
138 | | - 'auth' => $this->createMock(CustomPrincipalPlugin::class), |
139 | | - 'schedule' => $this->createMock(Plugin::class) |
140 | | - ] |
141 | | - ]) |
142 | | - ]); |
143 | | - |
144 | 143 | $message = <<<EOF |
145 | 144 | BEGIN:VCALENDAR |
146 | 145 | PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN |
147 | 146 | METHOD:REPLY |
148 | 147 | VERSION:2.0 |
149 | 148 | BEGIN:VEVENT |
150 | | -ATTENDEE;PARTSTAT=mailto:[email protected]:ACCEPTED |
| 149 | +ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected] |
151 | 150 | ORGANIZER:mailto:[email protected] |
152 | 151 | UID:aUniqueUid |
153 | 152 | SEQUENCE:2 |
154 | 153 | REQUEST-STATUS:2.0;Success |
155 | | -%sEND:VEVENT |
| 154 | +END:VEVENT |
156 | 155 | END:VCALENDAR |
157 | 156 | EOF; |
158 | 157 |
|
159 | 158 | /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
160 | | - $authPlugin = $invitationResponseServer->server->getPlugin('auth'); |
| 159 | + $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
161 | 160 | $authPlugin->expects(self::once()) |
162 | | - ->method('setPrincipalUri') |
| 161 | + ->method('setCurrentPrincipal') |
163 | 162 | ->with($this->calendar->getPrincipalURI()); |
164 | 163 |
|
| 164 | + /** @var \Sabre\DAVACL\Plugin|MockObject $aclPlugin*/ |
| 165 | + $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
| 166 | + |
165 | 167 | /** @var Plugin|MockObject $schedulingPlugin */ |
166 | | - $schedulingPlugin = $invitationResponseServer->server->getPlugin('caldav-schedule'); |
| 168 | + $schedulingPlugin = $this->createMock(Plugin::class); |
| 169 | + $iTipMessage = $this->getITipMessage($message); |
| 170 | + $iTipMessage-> recipient = "mailto:[email protected]"; |
167 | 171 | $schedulingPlugin->expects(self::once()) |
168 | | - ->method('setPathOfCalendarObjectChange') |
169 | | - ->with('fullcalendarname'); |
| 172 | + ->method('scheduleLocalDelivery') |
| 173 | + ->with($iTipMessage); |
| 174 | + |
| 175 | + $server = $this->createMock(Server::class); |
| 176 | + $server->expects($this->any()) |
| 177 | + ->method('getPlugin') |
| 178 | + ->willReturnMap([ |
| 179 | + ['auth', $authPlugin], |
| 180 | + ['acl', $aclPlugin], |
| 181 | + ['caldav-schedule', $schedulingPlugin] |
| 182 | + ]); |
| 183 | + |
| 184 | + $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer', 'isExternalAttendee']); |
| 185 | + $invitationResponseServer->server = $server; |
| 186 | + $invitationResponseServer->expects($this->any()) |
| 187 | + ->method('getServer') |
| 188 | + ->willReturn($server); |
| 189 | + $invitationResponseServer->expects(self::once()) |
| 190 | + ->method('isExternalAttendee') |
| 191 | + ->willReturn(false); |
| 192 | + |
| 193 | + $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
| 194 | + ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
| 195 | + ->onlyMethods(['getInvitationResponseServer']) |
| 196 | + ->getMock(); |
| 197 | + $calendarImpl->expects($this->once()) |
| 198 | + ->method('getInvitationResponseServer') |
| 199 | + ->willReturn($invitationResponseServer); |
| 200 | + |
| 201 | + $calendarImpl->handleIMipMessage('filename.ics', $message); |
170 | 202 | } |
171 | 203 |
|
172 | 204 | public function testHandleImipMessageNoCalendarUri(): void { |
173 | | - $invitationResponseServer = $this->createConfiguredMock(InvitationResponseServer::class, [ |
174 | | - 'server' => $this->createConfiguredMock(CalDavBackend::class, [ |
175 | | - 'getPlugin' => [ |
176 | | - 'auth' => $this->createMock(CustomPrincipalPlugin::class), |
177 | | - 'schedule' => $this->createMock(Plugin::class) |
178 | | - ] |
179 | | - ]) |
180 | | - ]); |
| 205 | + /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
| 206 | + $authPlugin = $this->createMock(CustomPrincipalPlugin::class); |
| 207 | + $authPlugin->expects(self::once()) |
| 208 | + ->method('setCurrentPrincipal') |
| 209 | + ->with($this->calendar->getPrincipalURI()); |
| 210 | + unset($this->calendarInfo['uri']); |
| 211 | + |
| 212 | + /** @var Plugin|MockObject $schedulingPlugin */ |
| 213 | + $schedulingPlugin = $this->createMock(Plugin::class); |
| 214 | + |
| 215 | + /** @var \Sabre\DAVACL\Plugin|MockObject $schedulingPlugin */ |
| 216 | + $aclPlugin = $this->createMock(\Sabre\DAVACL\Plugin::class); |
| 217 | + |
| 218 | + $server = |
| 219 | + $this->createMock(Server::class); |
| 220 | + $server->expects($this->any()) |
| 221 | + ->method('getPlugin') |
| 222 | + ->willReturnMap([ |
| 223 | + ['auth', $authPlugin], |
| 224 | + ['acl', $aclPlugin], |
| 225 | + ['caldav-schedule', $schedulingPlugin] |
| 226 | + ]); |
| 227 | + |
| 228 | + $invitationResponseServer = $this->createPartialMock(InvitationResponseServer::class, ['getServer']); |
| 229 | + $invitationResponseServer->server = $server; |
| 230 | + $invitationResponseServer->expects($this->any()) |
| 231 | + ->method('getServer') |
| 232 | + ->willReturn($server); |
| 233 | + |
| 234 | + $calendarImpl = $this->getMockBuilder(CalendarImpl::class) |
| 235 | + ->setConstructorArgs([$this->calendar, $this->calendarInfo, $this->backend]) |
| 236 | + ->onlyMethods(['getInvitationResponseServer']) |
| 237 | + ->getMock(); |
| 238 | + $calendarImpl->expects($this->once()) |
| 239 | + ->method('getInvitationResponseServer') |
| 240 | + ->willReturn($invitationResponseServer); |
181 | 241 |
|
182 | 242 | $message = <<<EOF |
183 | 243 | BEGIN:VCALENDAR |
184 | 244 | PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN |
185 | 245 | METHOD:REPLY |
186 | 246 | VERSION:2.0 |
187 | 247 | BEGIN:VEVENT |
188 | | -ATTENDEE;PARTSTAT=mailto:[email protected]:ACCEPTED |
| 248 | +ATTENDEE;PARTSTAT=ACCEPTED:mailto:[email protected] |
189 | 249 | ORGANIZER:mailto:[email protected] |
190 | 250 | UID:aUniqueUid |
191 | 251 | SEQUENCE:2 |
192 | 252 | REQUEST-STATUS:2.0;Success |
193 | | -%sEND:VEVENT |
| 253 | +END:VEVENT |
194 | 254 | END:VCALENDAR |
195 | 255 | EOF; |
196 | 256 |
|
197 | | - /** @var CustomPrincipalPlugin|MockObject $authPlugin */ |
198 | | - $authPlugin = $invitationResponseServer->server->getPlugin('auth'); |
199 | | - $authPlugin->expects(self::once()) |
200 | | - ->method('setPrincipalUri') |
201 | | - ->with($this->calendar->getPrincipalURI()); |
| 257 | + $this->expectException(CalendarException::class); |
| 258 | + $calendarImpl->handleIMipMessage('filename.ics', $message); |
| 259 | + } |
202 | 260 |
|
203 | | - unset($this->calendarInfo['uri']); |
204 | | - $this->expectException('CalendarException'); |
205 | | - $this->calendarImpl->handleIMipMessage('filename.ics', $message); |
| 261 | + private function getITipMessage($calendarData): Message { |
| 262 | + $iTipMessage = new Message(); |
| 263 | + /** @var VCalendar $vObject */ |
| 264 | + $vObject = Reader::read($calendarData); |
| 265 | + /** @var VEvent $vEvent */ |
| 266 | + $vEvent = $vObject->{'VEVENT'}; |
| 267 | + $orgaizer = $vEvent->{'ORGANIZER'}->getValue(); |
| 268 | + $attendee = $vEvent->{'ATTENDEE'}->getValue(); |
| 269 | + |
| 270 | + $iTipMessage->method = $vObject->{'METHOD'}->getValue(); |
| 271 | + $iTipMessage->recipient = $orgaizer; |
| 272 | + $iTipMessage->sender = $attendee; |
| 273 | + $iTipMessage->uid = isset($vEvent->{'UID'}) ? $vEvent->{'UID'}->getValue() : ''; |
| 274 | + $iTipMessage->component = 'VEVENT'; |
| 275 | + $iTipMessage->sequence = isset($vEvent->{'SEQUENCE'}) ? (int)$vEvent->{'SEQUENCE'}->getValue() : 0; |
| 276 | + $iTipMessage->message = $vObject; |
| 277 | + return $iTipMessage; |
206 | 278 | } |
207 | 279 | } |
0 commit comments