@@ -24,376 +24,376 @@ |
||
| 24 | 24 | |
| 25 | 25 | class BackendTest extends TestCase { |
| 26 | 26 | |
| 27 | - private IDBConnection|MockObject $db; |
|
| 28 | - private IUserManager|MockObject $userManager; |
|
| 29 | - private IGroupManager|MockObject $groupManager; |
|
| 30 | - private MockObject|Principal $principalBackend; |
|
| 31 | - private MockObject|ICache $shareCache; |
|
| 32 | - private LoggerInterface|MockObject $logger; |
|
| 33 | - private MockObject|ICacheFactory $cacheFactory; |
|
| 34 | - private Service|MockObject $calendarService; |
|
| 35 | - private CalendarSharingBackend $backend; |
|
| 36 | - |
|
| 37 | - protected function setUp(): void { |
|
| 38 | - parent::setUp(); |
|
| 39 | - $this->db = $this->createMock(IDBConnection::class); |
|
| 40 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 41 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 42 | - $this->principalBackend = $this->createMock(Principal::class); |
|
| 43 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 44 | - $this->shareCache = $this->createMock(ICache::class); |
|
| 45 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 46 | - $this->calendarService = $this->createMock(Service::class); |
|
| 47 | - $this->cacheFactory->expects(self::any()) |
|
| 48 | - ->method('createInMemory') |
|
| 49 | - ->willReturn($this->shareCache); |
|
| 50 | - |
|
| 51 | - $this->backend = new CalendarSharingBackend( |
|
| 52 | - $this->userManager, |
|
| 53 | - $this->groupManager, |
|
| 54 | - $this->principalBackend, |
|
| 55 | - $this->cacheFactory, |
|
| 56 | - $this->calendarService, |
|
| 57 | - $this->logger, |
|
| 58 | - ); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function testUpdateShareCalendarBob(): void { |
|
| 62 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 63 | - 'getOwner' => 'principals/users/alice', |
|
| 64 | - 'getResourceId' => 42, |
|
| 65 | - ]); |
|
| 66 | - $add = [ |
|
| 67 | - [ |
|
| 68 | - 'href' => 'principal:principals/users/bob', |
|
| 69 | - 'readOnly' => true, |
|
| 70 | - ] |
|
| 71 | - ]; |
|
| 72 | - $principal = 'principals/users/bob'; |
|
| 73 | - |
|
| 74 | - $this->shareCache->expects(self::once()) |
|
| 75 | - ->method('clear'); |
|
| 76 | - $this->principalBackend->expects(self::once()) |
|
| 77 | - ->method('findByUri') |
|
| 78 | - ->willReturn($principal); |
|
| 79 | - $this->userManager->expects(self::once()) |
|
| 80 | - ->method('userExists') |
|
| 81 | - ->willReturn(true); |
|
| 82 | - $this->groupManager->expects(self::never()) |
|
| 83 | - ->method('groupExists'); |
|
| 84 | - $this->calendarService->expects(self::once()) |
|
| 85 | - ->method('shareWith') |
|
| 86 | - ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 87 | - |
|
| 88 | - $this->backend->updateShares($shareable, $add, []); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function testUpdateShareCalendarGroup(): void { |
|
| 92 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 93 | - 'getOwner' => 'principals/users/alice', |
|
| 94 | - 'getResourceId' => 42, |
|
| 95 | - ]); |
|
| 96 | - $add = [ |
|
| 97 | - [ |
|
| 98 | - 'href' => 'principal:principals/groups/bob', |
|
| 99 | - 'readOnly' => true, |
|
| 100 | - ] |
|
| 101 | - ]; |
|
| 102 | - $principal = 'principals/groups/bob'; |
|
| 103 | - |
|
| 104 | - $this->shareCache->expects(self::once()) |
|
| 105 | - ->method('clear'); |
|
| 106 | - $this->principalBackend->expects(self::once()) |
|
| 107 | - ->method('findByUri') |
|
| 108 | - ->willReturn($principal); |
|
| 109 | - $this->userManager->expects(self::never()) |
|
| 110 | - ->method('userExists'); |
|
| 111 | - $this->groupManager->expects(self::once()) |
|
| 112 | - ->method('groupExists') |
|
| 113 | - ->willReturn(true); |
|
| 114 | - $this->calendarService->expects(self::once()) |
|
| 115 | - ->method('shareWith') |
|
| 116 | - ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 117 | - |
|
| 118 | - $this->backend->updateShares($shareable, $add, []); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function testUpdateShareContactsBob(): void { |
|
| 122 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 123 | - 'getOwner' => 'principals/users/alice', |
|
| 124 | - 'getResourceId' => 42, |
|
| 125 | - ]); |
|
| 126 | - $add = [ |
|
| 127 | - [ |
|
| 128 | - 'href' => 'principal:principals/users/bob', |
|
| 129 | - 'readOnly' => true, |
|
| 130 | - ] |
|
| 131 | - ]; |
|
| 132 | - $principal = 'principals/users/bob'; |
|
| 133 | - |
|
| 134 | - $this->shareCache->expects(self::once()) |
|
| 135 | - ->method('clear'); |
|
| 136 | - $this->principalBackend->expects(self::once()) |
|
| 137 | - ->method('findByUri') |
|
| 138 | - ->willReturn($principal); |
|
| 139 | - $this->userManager->expects(self::once()) |
|
| 140 | - ->method('userExists') |
|
| 141 | - ->willReturn(true); |
|
| 142 | - $this->groupManager->expects(self::never()) |
|
| 143 | - ->method('groupExists'); |
|
| 144 | - $this->calendarService->expects(self::once()) |
|
| 145 | - ->method('shareWith') |
|
| 146 | - ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 147 | - |
|
| 148 | - $this->backend->updateShares($shareable, $add, []); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function testUpdateShareContactsGroup(): void { |
|
| 152 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 153 | - 'getOwner' => 'principals/users/alice', |
|
| 154 | - 'getResourceId' => 42, |
|
| 155 | - ]); |
|
| 156 | - $add = [ |
|
| 157 | - [ |
|
| 158 | - 'href' => 'principal:principals/groups/bob', |
|
| 159 | - 'readOnly' => true, |
|
| 160 | - ] |
|
| 161 | - ]; |
|
| 162 | - $principal = 'principals/groups/bob'; |
|
| 163 | - |
|
| 164 | - $this->shareCache->expects(self::once()) |
|
| 165 | - ->method('clear'); |
|
| 166 | - $this->principalBackend->expects(self::once()) |
|
| 167 | - ->method('findByUri') |
|
| 168 | - ->willReturn($principal); |
|
| 169 | - $this->userManager->expects(self::never()) |
|
| 170 | - ->method('userExists'); |
|
| 171 | - $this->groupManager->expects(self::once()) |
|
| 172 | - ->method('groupExists') |
|
| 173 | - ->willReturn(true); |
|
| 174 | - $this->calendarService->expects(self::once()) |
|
| 175 | - ->method('shareWith') |
|
| 176 | - ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 177 | - |
|
| 178 | - $this->backend->updateShares($shareable, $add, []); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - public function testUpdateShareCircle(): void { |
|
| 182 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 183 | - 'getOwner' => 'principals/users/alice', |
|
| 184 | - 'getResourceId' => 42, |
|
| 185 | - ]); |
|
| 186 | - $add = [ |
|
| 187 | - [ |
|
| 188 | - 'href' => 'principal:principals/circles/bob', |
|
| 189 | - 'readOnly' => true, |
|
| 190 | - ] |
|
| 191 | - ]; |
|
| 192 | - $principal = 'principals/groups/bob'; |
|
| 193 | - |
|
| 194 | - $this->shareCache->expects(self::once()) |
|
| 195 | - ->method('clear'); |
|
| 196 | - $this->principalBackend->expects(self::once()) |
|
| 197 | - ->method('findByUri') |
|
| 198 | - ->willReturn($principal); |
|
| 199 | - $this->userManager->expects(self::never()) |
|
| 200 | - ->method('userExists'); |
|
| 201 | - $this->groupManager->expects(self::once()) |
|
| 202 | - ->method('groupExists') |
|
| 203 | - ->willReturn(true); |
|
| 204 | - $this->calendarService->expects(self::once()) |
|
| 205 | - ->method('shareWith') |
|
| 206 | - ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 207 | - |
|
| 208 | - $this->backend->updateShares($shareable, $add, []); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function testUnshareBob(): void { |
|
| 212 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 213 | - 'getOwner' => 'principals/users/alice', |
|
| 214 | - 'getResourceId' => 42, |
|
| 215 | - ]); |
|
| 216 | - $remove = [ |
|
| 217 | - 'principal:principals/users/bob', |
|
| 218 | - ]; |
|
| 219 | - $principal = 'principals/users/bob'; |
|
| 220 | - |
|
| 221 | - $this->shareCache->expects(self::once()) |
|
| 222 | - ->method('clear'); |
|
| 223 | - $this->principalBackend->expects(self::once()) |
|
| 224 | - ->method('findByUri') |
|
| 225 | - ->willReturn($principal); |
|
| 226 | - $this->calendarService->expects(self::once()) |
|
| 227 | - ->method('deleteShare') |
|
| 228 | - ->with($shareable->getResourceId(), $principal); |
|
| 229 | - $this->calendarService->expects(self::never()) |
|
| 230 | - ->method('unshare'); |
|
| 231 | - |
|
| 232 | - $this->backend->updateShares($shareable, [], $remove); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - public function testUnshareWithBobGroup(): void { |
|
| 236 | - $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 237 | - 'getOwner' => 'principals/users/alice', |
|
| 238 | - 'getResourceId' => 42, |
|
| 239 | - ]); |
|
| 240 | - $remove = [ |
|
| 241 | - 'principal:principals/users/bob', |
|
| 242 | - ]; |
|
| 243 | - $oldShares = [ |
|
| 244 | - [ |
|
| 245 | - 'href' => 'principal:principals/groups/bob', |
|
| 246 | - 'commonName' => 'bob', |
|
| 247 | - 'status' => 1, |
|
| 248 | - 'readOnly' => true, |
|
| 249 | - '{http://owncloud.org/ns}principal' => 'principals/groups/bob', |
|
| 250 | - '{http://owncloud.org/ns}group-share' => true, |
|
| 251 | - ] |
|
| 252 | - ]; |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - $this->shareCache->expects(self::once()) |
|
| 256 | - ->method('clear'); |
|
| 257 | - $this->principalBackend->expects(self::once()) |
|
| 258 | - ->method('findByUri') |
|
| 259 | - ->willReturn('principals/users/bob'); |
|
| 260 | - $this->calendarService->expects(self::once()) |
|
| 261 | - ->method('deleteShare') |
|
| 262 | - ->with($shareable->getResourceId(), 'principals/users/bob'); |
|
| 263 | - $this->calendarService->expects(self::never()) |
|
| 264 | - ->method('unshare'); |
|
| 265 | - |
|
| 266 | - $this->backend->updateShares($shareable, [], $remove, $oldShares); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - public function testGetShares(): void { |
|
| 270 | - $resourceId = 42; |
|
| 271 | - $principal = 'principals/groups/bob'; |
|
| 272 | - $rows = [ |
|
| 273 | - [ |
|
| 274 | - 'principaluri' => $principal, |
|
| 275 | - 'access' => Backend::ACCESS_READ, |
|
| 276 | - ] |
|
| 277 | - ]; |
|
| 278 | - $expected = [ |
|
| 279 | - [ |
|
| 280 | - 'href' => 'principal:principals/groups/bob', |
|
| 281 | - 'commonName' => 'bob', |
|
| 282 | - 'status' => 1, |
|
| 283 | - 'readOnly' => true, |
|
| 284 | - '{http://owncloud.org/ns}principal' => $principal, |
|
| 285 | - '{http://owncloud.org/ns}group-share' => true, |
|
| 286 | - ] |
|
| 287 | - ]; |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - $this->shareCache->expects(self::once()) |
|
| 291 | - ->method('get') |
|
| 292 | - ->with((string)$resourceId) |
|
| 293 | - ->willReturn(null); |
|
| 294 | - $this->calendarService->expects(self::once()) |
|
| 295 | - ->method('getShares') |
|
| 296 | - ->with($resourceId) |
|
| 297 | - ->willReturn($rows); |
|
| 298 | - $this->principalBackend->expects(self::once()) |
|
| 299 | - ->method('getPrincipalByPath') |
|
| 300 | - ->with($principal) |
|
| 301 | - ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']); |
|
| 302 | - $this->shareCache->expects(self::once()) |
|
| 303 | - ->method('set') |
|
| 304 | - ->with((string)$resourceId, $expected); |
|
| 305 | - |
|
| 306 | - $result = $this->backend->getShares($resourceId); |
|
| 307 | - $this->assertEquals($expected, $result); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - public function testGetSharesAddressbooks(): void { |
|
| 311 | - $service = $this->createMock(\OCA\DAV\CardDAV\Sharing\Service::class); |
|
| 312 | - $backend = new ContactsSharingBackend( |
|
| 313 | - $this->userManager, |
|
| 314 | - $this->groupManager, |
|
| 315 | - $this->principalBackend, |
|
| 316 | - $this->cacheFactory, |
|
| 317 | - $service, |
|
| 318 | - $this->logger); |
|
| 319 | - $resourceId = 42; |
|
| 320 | - $principal = 'principals/groups/bob'; |
|
| 321 | - $rows = [ |
|
| 322 | - [ |
|
| 323 | - 'principaluri' => $principal, |
|
| 324 | - 'access' => Backend::ACCESS_READ, |
|
| 325 | - ] |
|
| 326 | - ]; |
|
| 327 | - $expected = [ |
|
| 328 | - [ |
|
| 329 | - 'href' => 'principal:principals/groups/bob', |
|
| 330 | - 'commonName' => 'bob', |
|
| 331 | - 'status' => 1, |
|
| 332 | - 'readOnly' => true, |
|
| 333 | - '{http://owncloud.org/ns}principal' => $principal, |
|
| 334 | - '{http://owncloud.org/ns}group-share' => true, |
|
| 335 | - ] |
|
| 336 | - ]; |
|
| 337 | - |
|
| 338 | - $this->shareCache->expects(self::once()) |
|
| 339 | - ->method('get') |
|
| 340 | - ->with((string)$resourceId) |
|
| 341 | - ->willReturn(null); |
|
| 342 | - $service->expects(self::once()) |
|
| 343 | - ->method('getShares') |
|
| 344 | - ->with($resourceId) |
|
| 345 | - ->willReturn($rows); |
|
| 346 | - $this->principalBackend->expects(self::once()) |
|
| 347 | - ->method('getPrincipalByPath') |
|
| 348 | - ->with($principal) |
|
| 349 | - ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']); |
|
| 350 | - $this->shareCache->expects(self::once()) |
|
| 351 | - ->method('set') |
|
| 352 | - ->with((string)$resourceId, $expected); |
|
| 353 | - |
|
| 354 | - $result = $backend->getShares($resourceId); |
|
| 355 | - $this->assertEquals($expected, $result); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - public function testPreloadShares(): void { |
|
| 359 | - $resourceIds = [42, 99]; |
|
| 360 | - $rows = [ |
|
| 361 | - [ |
|
| 362 | - 'resourceid' => 42, |
|
| 363 | - 'principaluri' => 'principals/groups/bob', |
|
| 364 | - 'access' => Backend::ACCESS_READ, |
|
| 365 | - ], |
|
| 366 | - [ |
|
| 367 | - 'resourceid' => 99, |
|
| 368 | - 'principaluri' => 'principals/users/carlos', |
|
| 369 | - 'access' => Backend::ACCESS_READ_WRITE, |
|
| 370 | - ] |
|
| 371 | - ]; |
|
| 372 | - $principalResults = [ |
|
| 373 | - ['uri' => 'principals/groups/bob', '{DAV:}displayname' => 'bob'], |
|
| 374 | - ['uri' => 'principals/users/carlos', '{DAV:}displayname' => 'carlos'], |
|
| 375 | - ]; |
|
| 376 | - |
|
| 377 | - $this->shareCache->expects(self::exactly(2)) |
|
| 378 | - ->method('get') |
|
| 379 | - ->willReturn(null); |
|
| 380 | - $this->calendarService->expects(self::once()) |
|
| 381 | - ->method('getSharesForIds') |
|
| 382 | - ->with($resourceIds) |
|
| 383 | - ->willReturn($rows); |
|
| 384 | - $this->principalBackend->expects(self::exactly(2)) |
|
| 385 | - ->method('getPrincipalByPath') |
|
| 386 | - ->willReturnCallback(function (string $principal) use ($principalResults) { |
|
| 387 | - switch ($principal) { |
|
| 388 | - case 'principals/groups/bob': |
|
| 389 | - return $principalResults[0]; |
|
| 390 | - default: |
|
| 391 | - return $principalResults[1]; |
|
| 392 | - } |
|
| 393 | - }); |
|
| 394 | - $this->shareCache->expects(self::exactly(2)) |
|
| 395 | - ->method('set'); |
|
| 396 | - |
|
| 397 | - $this->backend->preloadShares($resourceIds); |
|
| 398 | - } |
|
| 27 | + private IDBConnection|MockObject $db; |
|
| 28 | + private IUserManager|MockObject $userManager; |
|
| 29 | + private IGroupManager|MockObject $groupManager; |
|
| 30 | + private MockObject|Principal $principalBackend; |
|
| 31 | + private MockObject|ICache $shareCache; |
|
| 32 | + private LoggerInterface|MockObject $logger; |
|
| 33 | + private MockObject|ICacheFactory $cacheFactory; |
|
| 34 | + private Service|MockObject $calendarService; |
|
| 35 | + private CalendarSharingBackend $backend; |
|
| 36 | + |
|
| 37 | + protected function setUp(): void { |
|
| 38 | + parent::setUp(); |
|
| 39 | + $this->db = $this->createMock(IDBConnection::class); |
|
| 40 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 41 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 42 | + $this->principalBackend = $this->createMock(Principal::class); |
|
| 43 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 44 | + $this->shareCache = $this->createMock(ICache::class); |
|
| 45 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 46 | + $this->calendarService = $this->createMock(Service::class); |
|
| 47 | + $this->cacheFactory->expects(self::any()) |
|
| 48 | + ->method('createInMemory') |
|
| 49 | + ->willReturn($this->shareCache); |
|
| 50 | + |
|
| 51 | + $this->backend = new CalendarSharingBackend( |
|
| 52 | + $this->userManager, |
|
| 53 | + $this->groupManager, |
|
| 54 | + $this->principalBackend, |
|
| 55 | + $this->cacheFactory, |
|
| 56 | + $this->calendarService, |
|
| 57 | + $this->logger, |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function testUpdateShareCalendarBob(): void { |
|
| 62 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 63 | + 'getOwner' => 'principals/users/alice', |
|
| 64 | + 'getResourceId' => 42, |
|
| 65 | + ]); |
|
| 66 | + $add = [ |
|
| 67 | + [ |
|
| 68 | + 'href' => 'principal:principals/users/bob', |
|
| 69 | + 'readOnly' => true, |
|
| 70 | + ] |
|
| 71 | + ]; |
|
| 72 | + $principal = 'principals/users/bob'; |
|
| 73 | + |
|
| 74 | + $this->shareCache->expects(self::once()) |
|
| 75 | + ->method('clear'); |
|
| 76 | + $this->principalBackend->expects(self::once()) |
|
| 77 | + ->method('findByUri') |
|
| 78 | + ->willReturn($principal); |
|
| 79 | + $this->userManager->expects(self::once()) |
|
| 80 | + ->method('userExists') |
|
| 81 | + ->willReturn(true); |
|
| 82 | + $this->groupManager->expects(self::never()) |
|
| 83 | + ->method('groupExists'); |
|
| 84 | + $this->calendarService->expects(self::once()) |
|
| 85 | + ->method('shareWith') |
|
| 86 | + ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 87 | + |
|
| 88 | + $this->backend->updateShares($shareable, $add, []); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function testUpdateShareCalendarGroup(): void { |
|
| 92 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 93 | + 'getOwner' => 'principals/users/alice', |
|
| 94 | + 'getResourceId' => 42, |
|
| 95 | + ]); |
|
| 96 | + $add = [ |
|
| 97 | + [ |
|
| 98 | + 'href' => 'principal:principals/groups/bob', |
|
| 99 | + 'readOnly' => true, |
|
| 100 | + ] |
|
| 101 | + ]; |
|
| 102 | + $principal = 'principals/groups/bob'; |
|
| 103 | + |
|
| 104 | + $this->shareCache->expects(self::once()) |
|
| 105 | + ->method('clear'); |
|
| 106 | + $this->principalBackend->expects(self::once()) |
|
| 107 | + ->method('findByUri') |
|
| 108 | + ->willReturn($principal); |
|
| 109 | + $this->userManager->expects(self::never()) |
|
| 110 | + ->method('userExists'); |
|
| 111 | + $this->groupManager->expects(self::once()) |
|
| 112 | + ->method('groupExists') |
|
| 113 | + ->willReturn(true); |
|
| 114 | + $this->calendarService->expects(self::once()) |
|
| 115 | + ->method('shareWith') |
|
| 116 | + ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 117 | + |
|
| 118 | + $this->backend->updateShares($shareable, $add, []); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function testUpdateShareContactsBob(): void { |
|
| 122 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 123 | + 'getOwner' => 'principals/users/alice', |
|
| 124 | + 'getResourceId' => 42, |
|
| 125 | + ]); |
|
| 126 | + $add = [ |
|
| 127 | + [ |
|
| 128 | + 'href' => 'principal:principals/users/bob', |
|
| 129 | + 'readOnly' => true, |
|
| 130 | + ] |
|
| 131 | + ]; |
|
| 132 | + $principal = 'principals/users/bob'; |
|
| 133 | + |
|
| 134 | + $this->shareCache->expects(self::once()) |
|
| 135 | + ->method('clear'); |
|
| 136 | + $this->principalBackend->expects(self::once()) |
|
| 137 | + ->method('findByUri') |
|
| 138 | + ->willReturn($principal); |
|
| 139 | + $this->userManager->expects(self::once()) |
|
| 140 | + ->method('userExists') |
|
| 141 | + ->willReturn(true); |
|
| 142 | + $this->groupManager->expects(self::never()) |
|
| 143 | + ->method('groupExists'); |
|
| 144 | + $this->calendarService->expects(self::once()) |
|
| 145 | + ->method('shareWith') |
|
| 146 | + ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 147 | + |
|
| 148 | + $this->backend->updateShares($shareable, $add, []); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function testUpdateShareContactsGroup(): void { |
|
| 152 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 153 | + 'getOwner' => 'principals/users/alice', |
|
| 154 | + 'getResourceId' => 42, |
|
| 155 | + ]); |
|
| 156 | + $add = [ |
|
| 157 | + [ |
|
| 158 | + 'href' => 'principal:principals/groups/bob', |
|
| 159 | + 'readOnly' => true, |
|
| 160 | + ] |
|
| 161 | + ]; |
|
| 162 | + $principal = 'principals/groups/bob'; |
|
| 163 | + |
|
| 164 | + $this->shareCache->expects(self::once()) |
|
| 165 | + ->method('clear'); |
|
| 166 | + $this->principalBackend->expects(self::once()) |
|
| 167 | + ->method('findByUri') |
|
| 168 | + ->willReturn($principal); |
|
| 169 | + $this->userManager->expects(self::never()) |
|
| 170 | + ->method('userExists'); |
|
| 171 | + $this->groupManager->expects(self::once()) |
|
| 172 | + ->method('groupExists') |
|
| 173 | + ->willReturn(true); |
|
| 174 | + $this->calendarService->expects(self::once()) |
|
| 175 | + ->method('shareWith') |
|
| 176 | + ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 177 | + |
|
| 178 | + $this->backend->updateShares($shareable, $add, []); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + public function testUpdateShareCircle(): void { |
|
| 182 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 183 | + 'getOwner' => 'principals/users/alice', |
|
| 184 | + 'getResourceId' => 42, |
|
| 185 | + ]); |
|
| 186 | + $add = [ |
|
| 187 | + [ |
|
| 188 | + 'href' => 'principal:principals/circles/bob', |
|
| 189 | + 'readOnly' => true, |
|
| 190 | + ] |
|
| 191 | + ]; |
|
| 192 | + $principal = 'principals/groups/bob'; |
|
| 193 | + |
|
| 194 | + $this->shareCache->expects(self::once()) |
|
| 195 | + ->method('clear'); |
|
| 196 | + $this->principalBackend->expects(self::once()) |
|
| 197 | + ->method('findByUri') |
|
| 198 | + ->willReturn($principal); |
|
| 199 | + $this->userManager->expects(self::never()) |
|
| 200 | + ->method('userExists'); |
|
| 201 | + $this->groupManager->expects(self::once()) |
|
| 202 | + ->method('groupExists') |
|
| 203 | + ->willReturn(true); |
|
| 204 | + $this->calendarService->expects(self::once()) |
|
| 205 | + ->method('shareWith') |
|
| 206 | + ->with($shareable->getResourceId(), $principal, Backend::ACCESS_READ); |
|
| 207 | + |
|
| 208 | + $this->backend->updateShares($shareable, $add, []); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function testUnshareBob(): void { |
|
| 212 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 213 | + 'getOwner' => 'principals/users/alice', |
|
| 214 | + 'getResourceId' => 42, |
|
| 215 | + ]); |
|
| 216 | + $remove = [ |
|
| 217 | + 'principal:principals/users/bob', |
|
| 218 | + ]; |
|
| 219 | + $principal = 'principals/users/bob'; |
|
| 220 | + |
|
| 221 | + $this->shareCache->expects(self::once()) |
|
| 222 | + ->method('clear'); |
|
| 223 | + $this->principalBackend->expects(self::once()) |
|
| 224 | + ->method('findByUri') |
|
| 225 | + ->willReturn($principal); |
|
| 226 | + $this->calendarService->expects(self::once()) |
|
| 227 | + ->method('deleteShare') |
|
| 228 | + ->with($shareable->getResourceId(), $principal); |
|
| 229 | + $this->calendarService->expects(self::never()) |
|
| 230 | + ->method('unshare'); |
|
| 231 | + |
|
| 232 | + $this->backend->updateShares($shareable, [], $remove); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + public function testUnshareWithBobGroup(): void { |
|
| 236 | + $shareable = $this->createConfiguredMock(IShareable::class, [ |
|
| 237 | + 'getOwner' => 'principals/users/alice', |
|
| 238 | + 'getResourceId' => 42, |
|
| 239 | + ]); |
|
| 240 | + $remove = [ |
|
| 241 | + 'principal:principals/users/bob', |
|
| 242 | + ]; |
|
| 243 | + $oldShares = [ |
|
| 244 | + [ |
|
| 245 | + 'href' => 'principal:principals/groups/bob', |
|
| 246 | + 'commonName' => 'bob', |
|
| 247 | + 'status' => 1, |
|
| 248 | + 'readOnly' => true, |
|
| 249 | + '{http://owncloud.org/ns}principal' => 'principals/groups/bob', |
|
| 250 | + '{http://owncloud.org/ns}group-share' => true, |
|
| 251 | + ] |
|
| 252 | + ]; |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + $this->shareCache->expects(self::once()) |
|
| 256 | + ->method('clear'); |
|
| 257 | + $this->principalBackend->expects(self::once()) |
|
| 258 | + ->method('findByUri') |
|
| 259 | + ->willReturn('principals/users/bob'); |
|
| 260 | + $this->calendarService->expects(self::once()) |
|
| 261 | + ->method('deleteShare') |
|
| 262 | + ->with($shareable->getResourceId(), 'principals/users/bob'); |
|
| 263 | + $this->calendarService->expects(self::never()) |
|
| 264 | + ->method('unshare'); |
|
| 265 | + |
|
| 266 | + $this->backend->updateShares($shareable, [], $remove, $oldShares); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + public function testGetShares(): void { |
|
| 270 | + $resourceId = 42; |
|
| 271 | + $principal = 'principals/groups/bob'; |
|
| 272 | + $rows = [ |
|
| 273 | + [ |
|
| 274 | + 'principaluri' => $principal, |
|
| 275 | + 'access' => Backend::ACCESS_READ, |
|
| 276 | + ] |
|
| 277 | + ]; |
|
| 278 | + $expected = [ |
|
| 279 | + [ |
|
| 280 | + 'href' => 'principal:principals/groups/bob', |
|
| 281 | + 'commonName' => 'bob', |
|
| 282 | + 'status' => 1, |
|
| 283 | + 'readOnly' => true, |
|
| 284 | + '{http://owncloud.org/ns}principal' => $principal, |
|
| 285 | + '{http://owncloud.org/ns}group-share' => true, |
|
| 286 | + ] |
|
| 287 | + ]; |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + $this->shareCache->expects(self::once()) |
|
| 291 | + ->method('get') |
|
| 292 | + ->with((string)$resourceId) |
|
| 293 | + ->willReturn(null); |
|
| 294 | + $this->calendarService->expects(self::once()) |
|
| 295 | + ->method('getShares') |
|
| 296 | + ->with($resourceId) |
|
| 297 | + ->willReturn($rows); |
|
| 298 | + $this->principalBackend->expects(self::once()) |
|
| 299 | + ->method('getPrincipalByPath') |
|
| 300 | + ->with($principal) |
|
| 301 | + ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']); |
|
| 302 | + $this->shareCache->expects(self::once()) |
|
| 303 | + ->method('set') |
|
| 304 | + ->with((string)$resourceId, $expected); |
|
| 305 | + |
|
| 306 | + $result = $this->backend->getShares($resourceId); |
|
| 307 | + $this->assertEquals($expected, $result); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + public function testGetSharesAddressbooks(): void { |
|
| 311 | + $service = $this->createMock(\OCA\DAV\CardDAV\Sharing\Service::class); |
|
| 312 | + $backend = new ContactsSharingBackend( |
|
| 313 | + $this->userManager, |
|
| 314 | + $this->groupManager, |
|
| 315 | + $this->principalBackend, |
|
| 316 | + $this->cacheFactory, |
|
| 317 | + $service, |
|
| 318 | + $this->logger); |
|
| 319 | + $resourceId = 42; |
|
| 320 | + $principal = 'principals/groups/bob'; |
|
| 321 | + $rows = [ |
|
| 322 | + [ |
|
| 323 | + 'principaluri' => $principal, |
|
| 324 | + 'access' => Backend::ACCESS_READ, |
|
| 325 | + ] |
|
| 326 | + ]; |
|
| 327 | + $expected = [ |
|
| 328 | + [ |
|
| 329 | + 'href' => 'principal:principals/groups/bob', |
|
| 330 | + 'commonName' => 'bob', |
|
| 331 | + 'status' => 1, |
|
| 332 | + 'readOnly' => true, |
|
| 333 | + '{http://owncloud.org/ns}principal' => $principal, |
|
| 334 | + '{http://owncloud.org/ns}group-share' => true, |
|
| 335 | + ] |
|
| 336 | + ]; |
|
| 337 | + |
|
| 338 | + $this->shareCache->expects(self::once()) |
|
| 339 | + ->method('get') |
|
| 340 | + ->with((string)$resourceId) |
|
| 341 | + ->willReturn(null); |
|
| 342 | + $service->expects(self::once()) |
|
| 343 | + ->method('getShares') |
|
| 344 | + ->with($resourceId) |
|
| 345 | + ->willReturn($rows); |
|
| 346 | + $this->principalBackend->expects(self::once()) |
|
| 347 | + ->method('getPrincipalByPath') |
|
| 348 | + ->with($principal) |
|
| 349 | + ->willReturn(['uri' => $principal, '{DAV:}displayname' => 'bob']); |
|
| 350 | + $this->shareCache->expects(self::once()) |
|
| 351 | + ->method('set') |
|
| 352 | + ->with((string)$resourceId, $expected); |
|
| 353 | + |
|
| 354 | + $result = $backend->getShares($resourceId); |
|
| 355 | + $this->assertEquals($expected, $result); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + public function testPreloadShares(): void { |
|
| 359 | + $resourceIds = [42, 99]; |
|
| 360 | + $rows = [ |
|
| 361 | + [ |
|
| 362 | + 'resourceid' => 42, |
|
| 363 | + 'principaluri' => 'principals/groups/bob', |
|
| 364 | + 'access' => Backend::ACCESS_READ, |
|
| 365 | + ], |
|
| 366 | + [ |
|
| 367 | + 'resourceid' => 99, |
|
| 368 | + 'principaluri' => 'principals/users/carlos', |
|
| 369 | + 'access' => Backend::ACCESS_READ_WRITE, |
|
| 370 | + ] |
|
| 371 | + ]; |
|
| 372 | + $principalResults = [ |
|
| 373 | + ['uri' => 'principals/groups/bob', '{DAV:}displayname' => 'bob'], |
|
| 374 | + ['uri' => 'principals/users/carlos', '{DAV:}displayname' => 'carlos'], |
|
| 375 | + ]; |
|
| 376 | + |
|
| 377 | + $this->shareCache->expects(self::exactly(2)) |
|
| 378 | + ->method('get') |
|
| 379 | + ->willReturn(null); |
|
| 380 | + $this->calendarService->expects(self::once()) |
|
| 381 | + ->method('getSharesForIds') |
|
| 382 | + ->with($resourceIds) |
|
| 383 | + ->willReturn($rows); |
|
| 384 | + $this->principalBackend->expects(self::exactly(2)) |
|
| 385 | + ->method('getPrincipalByPath') |
|
| 386 | + ->willReturnCallback(function (string $principal) use ($principalResults) { |
|
| 387 | + switch ($principal) { |
|
| 388 | + case 'principals/groups/bob': |
|
| 389 | + return $principalResults[0]; |
|
| 390 | + default: |
|
| 391 | + return $principalResults[1]; |
|
| 392 | + } |
|
| 393 | + }); |
|
| 394 | + $this->shareCache->expects(self::exactly(2)) |
|
| 395 | + ->method('set'); |
|
| 396 | + |
|
| 397 | + $this->backend->preloadShares($resourceIds); |
|
| 398 | + } |
|
| 399 | 399 | } |
@@ -19,314 +19,314 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | class CalendarTest extends TestCase { |
| 21 | 21 | |
| 22 | - /** @var IL10N */ |
|
| 23 | - protected $l10n; |
|
| 24 | - |
|
| 25 | - /** @var IConfig */ |
|
| 26 | - protected $config; |
|
| 27 | - |
|
| 28 | - /** @var MockObject|LoggerInterface */ |
|
| 29 | - protected $logger; |
|
| 30 | - |
|
| 31 | - protected function setUp(): void { |
|
| 32 | - parent::setUp(); |
|
| 33 | - $this->l10n = $this->getMockBuilder(IL10N::class) |
|
| 34 | - ->disableOriginalConstructor()->getMock(); |
|
| 35 | - $this->config = $this->createMock(IConfig::class); |
|
| 36 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 37 | - $this->l10n |
|
| 38 | - ->expects($this->any()) |
|
| 39 | - ->method('t') |
|
| 40 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
| 41 | - return vsprintf($text, $parameters); |
|
| 42 | - }); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function testDelete(): void { |
|
| 46 | - /** @var CalDavBackend&MockObject $backend */ |
|
| 47 | - $backend = $this->createMock(CalDavBackend::class); |
|
| 48 | - $backend->expects($this->never()) |
|
| 49 | - ->method('updateShares'); |
|
| 50 | - $backend->expects($this->once()) |
|
| 51 | - ->method('unshare'); |
|
| 52 | - |
|
| 53 | - $calendarInfo = [ |
|
| 54 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 55 | - 'principaluri' => 'user2', |
|
| 56 | - 'id' => 666, |
|
| 57 | - 'uri' => 'cal', |
|
| 58 | - ]; |
|
| 59 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 60 | - $c->delete(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - public function testDeleteFromGroup(): void { |
|
| 65 | - /** @var CalDavBackend&MockObject $backend */ |
|
| 66 | - $backend = $this->createMock(CalDavBackend::class); |
|
| 67 | - $backend->expects($this->never()) |
|
| 68 | - ->method('updateShares'); |
|
| 69 | - $backend->expects($this->once()) |
|
| 70 | - ->method('unshare'); |
|
| 71 | - |
|
| 72 | - $calendarInfo = [ |
|
| 73 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 74 | - 'principaluri' => 'user2', |
|
| 75 | - 'id' => 666, |
|
| 76 | - 'uri' => 'cal', |
|
| 77 | - ]; |
|
| 78 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 79 | - $c->delete(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function testDeleteOwn(): void { |
|
| 83 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 84 | - $backend = $this->createMock(CalDavBackend::class); |
|
| 85 | - $backend->expects($this->never())->method('updateShares'); |
|
| 86 | - $backend->expects($this->never())->method('getShares'); |
|
| 87 | - |
|
| 88 | - $this->config->expects($this->never())->method('setUserValue'); |
|
| 89 | - |
|
| 90 | - $backend->expects($this->once())->method('deleteCalendar') |
|
| 91 | - ->with(666); |
|
| 92 | - |
|
| 93 | - $calendarInfo = [ |
|
| 94 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 95 | - 'principaluri' => 'user1', |
|
| 96 | - 'id' => 666, |
|
| 97 | - 'uri' => 'cal', |
|
| 98 | - ]; |
|
| 99 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 100 | - $c->delete(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function testDeleteBirthdayCalendar(): void { |
|
| 104 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 105 | - $backend = $this->createMock(CalDavBackend::class); |
|
| 106 | - $backend->expects($this->once())->method('deleteCalendar') |
|
| 107 | - ->with(666); |
|
| 108 | - |
|
| 109 | - $this->config->expects($this->once()) |
|
| 110 | - ->method('setUserValue') |
|
| 111 | - ->with('user1', 'dav', 'generateBirthdayCalendar', 'no'); |
|
| 112 | - |
|
| 113 | - $calendarInfo = [ |
|
| 114 | - '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1', |
|
| 115 | - 'principaluri' => 'principals/users/user1', |
|
| 116 | - 'id' => 666, |
|
| 117 | - 'uri' => 'contact_birthdays', |
|
| 118 | - '{DAV:}displayname' => 'Test', |
|
| 119 | - ]; |
|
| 120 | - |
|
| 121 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 122 | - $c->delete(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function dataPropPatch() { |
|
| 126 | - return [ |
|
| 127 | - ['user1', 'user2', [], true], |
|
| 128 | - ['user1', 'user2', [ |
|
| 129 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 130 | - ], true], |
|
| 131 | - ['user1', 'user2', [ |
|
| 132 | - '{DAV:}displayname' => true, |
|
| 133 | - ], true], |
|
| 134 | - ['user1', 'user2', [ |
|
| 135 | - '{DAV:}displayname' => true, |
|
| 136 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 137 | - ], true], |
|
| 138 | - ['user1', 'user1', [], false], |
|
| 139 | - ['user1', 'user1', [ |
|
| 140 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 141 | - ], false], |
|
| 142 | - ['user1', 'user1', [ |
|
| 143 | - '{DAV:}displayname' => true, |
|
| 144 | - ], false], |
|
| 145 | - ['user1', 'user1', [ |
|
| 146 | - '{DAV:}displayname' => true, |
|
| 147 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 148 | - ], false], |
|
| 149 | - ]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @dataProvider dataPropPatch |
|
| 154 | - */ |
|
| 155 | - public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared): void { |
|
| 156 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 157 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 158 | - $calendarInfo = [ |
|
| 159 | - '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, |
|
| 160 | - 'principaluri' => $principalUri, |
|
| 161 | - 'id' => 666, |
|
| 162 | - 'uri' => 'default' |
|
| 163 | - ]; |
|
| 164 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 165 | - $propPatch = new PropPatch($mutations); |
|
| 166 | - |
|
| 167 | - if (!$shared) { |
|
| 168 | - $backend->expects($this->once()) |
|
| 169 | - ->method('updateCalendar') |
|
| 170 | - ->with(666, $propPatch); |
|
| 171 | - } |
|
| 172 | - $c->propPatch($propPatch); |
|
| 173 | - $this->addToAssertionCount(1); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @dataProvider providesReadOnlyInfo |
|
| 178 | - */ |
|
| 179 | - public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void { |
|
| 180 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 181 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 182 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 183 | - $calendarInfo = [ |
|
| 184 | - 'principaluri' => 'user2', |
|
| 185 | - 'id' => 666, |
|
| 186 | - 'uri' => $uri |
|
| 187 | - ]; |
|
| 188 | - $calendarInfo['{DAV:}displayname'] = 'Test'; |
|
| 189 | - if (!is_null($readOnlyValue)) { |
|
| 190 | - $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue; |
|
| 191 | - } |
|
| 192 | - if ($hasOwnerSet) { |
|
| 193 | - $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
| 194 | - } |
|
| 195 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 196 | - $acl = $c->getACL(); |
|
| 197 | - $childAcl = $c->getChildACL(); |
|
| 198 | - |
|
| 199 | - $expectedAcl = [[ |
|
| 200 | - 'privilege' => '{DAV:}read', |
|
| 201 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 202 | - 'protected' => true |
|
| 203 | - ], [ |
|
| 204 | - 'privilege' => '{DAV:}read', |
|
| 205 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 206 | - 'protected' => true, |
|
| 207 | - ], [ |
|
| 208 | - 'privilege' => '{DAV:}read', |
|
| 209 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
| 210 | - 'protected' => true, |
|
| 211 | - ]]; |
|
| 212 | - if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 213 | - $expectedAcl[] = [ |
|
| 214 | - 'privilege' => '{DAV:}write-properties', |
|
| 215 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 216 | - 'protected' => true |
|
| 217 | - ]; |
|
| 218 | - $expectedAcl[] = [ |
|
| 219 | - 'privilege' => '{DAV:}write-properties', |
|
| 220 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 221 | - 'protected' => true |
|
| 222 | - ]; |
|
| 223 | - } else { |
|
| 224 | - $expectedAcl[] = [ |
|
| 225 | - 'privilege' => '{DAV:}write', |
|
| 226 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 227 | - 'protected' => true |
|
| 228 | - ]; |
|
| 229 | - $expectedAcl[] = [ |
|
| 230 | - 'privilege' => '{DAV:}write', |
|
| 231 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 232 | - 'protected' => true |
|
| 233 | - ]; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $expectedAcl[] = [ |
|
| 237 | - 'privilege' => '{DAV:}write-properties', |
|
| 238 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
| 239 | - 'protected' => true |
|
| 240 | - ]; |
|
| 241 | - |
|
| 242 | - if ($hasOwnerSet) { |
|
| 243 | - $expectedAcl[] = [ |
|
| 244 | - 'privilege' => '{DAV:}read', |
|
| 245 | - 'principal' => 'user2', |
|
| 246 | - 'protected' => true |
|
| 247 | - ]; |
|
| 248 | - if ($expectsWrite) { |
|
| 249 | - $expectedAcl[] = [ |
|
| 250 | - 'privilege' => '{DAV:}write', |
|
| 251 | - 'principal' => 'user2', |
|
| 252 | - 'protected' => true |
|
| 253 | - ]; |
|
| 254 | - } else { |
|
| 255 | - $expectedAcl[] = [ |
|
| 256 | - 'privilege' => '{DAV:}write-properties', |
|
| 257 | - 'principal' => 'user2', |
|
| 258 | - 'protected' => true |
|
| 259 | - ]; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - $this->assertEquals($expectedAcl, $acl); |
|
| 263 | - $this->assertEquals($expectedAcl, $childAcl); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - public function providesReadOnlyInfo() { |
|
| 267 | - return [ |
|
| 268 | - 'read-only property not set' => [true, null, true], |
|
| 269 | - 'read-only property is false' => [true, false, true], |
|
| 270 | - 'read-only property is true' => [false, true, true], |
|
| 271 | - 'read-only property not set and no owner' => [true, null, false], |
|
| 272 | - 'read-only property is false and no owner' => [true, false, false], |
|
| 273 | - 'read-only property is true and no owner' => [false, true, false], |
|
| 274 | - 'birthday calendar' => [false, false, false, BirthdayService::BIRTHDAY_CALENDAR_URI] |
|
| 275 | - ]; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @dataProvider providesConfidentialClassificationData |
|
| 280 | - * @param int $expectedChildren |
|
| 281 | - * @param bool $isShared |
|
| 282 | - */ |
|
| 283 | - public function testPrivateClassification($expectedChildren, $isShared): void { |
|
| 284 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 285 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
| 286 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 287 | - |
|
| 288 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 289 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 290 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 291 | - $calObject0, $calObject1, $calObject2 |
|
| 292 | - ]); |
|
| 293 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 294 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 295 | - ->willReturn([ |
|
| 296 | - $calObject0, $calObject1, $calObject2 |
|
| 297 | - ]); |
|
| 298 | - $backend->expects($this->any())->method('getCalendarObject') |
|
| 299 | - ->willReturn($calObject2)->with(666, 'event-2'); |
|
| 300 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 301 | - |
|
| 302 | - $calendarInfo = [ |
|
| 303 | - 'principaluri' => 'user2', |
|
| 304 | - 'id' => 666, |
|
| 305 | - 'uri' => 'cal', |
|
| 306 | - ]; |
|
| 307 | - |
|
| 308 | - if ($isShared) { |
|
| 309 | - $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
| 310 | - } |
|
| 311 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 312 | - $children = $c->getChildren(); |
|
| 313 | - $this->assertEquals($expectedChildren, count($children)); |
|
| 314 | - $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
| 315 | - $this->assertEquals($expectedChildren, count($children)); |
|
| 316 | - |
|
| 317 | - $this->assertEquals(!$isShared, $c->childExists('event-2')); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * @dataProvider providesConfidentialClassificationData |
|
| 322 | - * @param int $expectedChildren |
|
| 323 | - * @param bool $isShared |
|
| 324 | - */ |
|
| 325 | - public function testConfidentialClassification($expectedChildren, $isShared): void { |
|
| 326 | - $start = '20160609'; |
|
| 327 | - $end = '20160610'; |
|
| 328 | - |
|
| 329 | - $calData = <<<EOD |
|
| 22 | + /** @var IL10N */ |
|
| 23 | + protected $l10n; |
|
| 24 | + |
|
| 25 | + /** @var IConfig */ |
|
| 26 | + protected $config; |
|
| 27 | + |
|
| 28 | + /** @var MockObject|LoggerInterface */ |
|
| 29 | + protected $logger; |
|
| 30 | + |
|
| 31 | + protected function setUp(): void { |
|
| 32 | + parent::setUp(); |
|
| 33 | + $this->l10n = $this->getMockBuilder(IL10N::class) |
|
| 34 | + ->disableOriginalConstructor()->getMock(); |
|
| 35 | + $this->config = $this->createMock(IConfig::class); |
|
| 36 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 37 | + $this->l10n |
|
| 38 | + ->expects($this->any()) |
|
| 39 | + ->method('t') |
|
| 40 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
| 41 | + return vsprintf($text, $parameters); |
|
| 42 | + }); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function testDelete(): void { |
|
| 46 | + /** @var CalDavBackend&MockObject $backend */ |
|
| 47 | + $backend = $this->createMock(CalDavBackend::class); |
|
| 48 | + $backend->expects($this->never()) |
|
| 49 | + ->method('updateShares'); |
|
| 50 | + $backend->expects($this->once()) |
|
| 51 | + ->method('unshare'); |
|
| 52 | + |
|
| 53 | + $calendarInfo = [ |
|
| 54 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 55 | + 'principaluri' => 'user2', |
|
| 56 | + 'id' => 666, |
|
| 57 | + 'uri' => 'cal', |
|
| 58 | + ]; |
|
| 59 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 60 | + $c->delete(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + public function testDeleteFromGroup(): void { |
|
| 65 | + /** @var CalDavBackend&MockObject $backend */ |
|
| 66 | + $backend = $this->createMock(CalDavBackend::class); |
|
| 67 | + $backend->expects($this->never()) |
|
| 68 | + ->method('updateShares'); |
|
| 69 | + $backend->expects($this->once()) |
|
| 70 | + ->method('unshare'); |
|
| 71 | + |
|
| 72 | + $calendarInfo = [ |
|
| 73 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 74 | + 'principaluri' => 'user2', |
|
| 75 | + 'id' => 666, |
|
| 76 | + 'uri' => 'cal', |
|
| 77 | + ]; |
|
| 78 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 79 | + $c->delete(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testDeleteOwn(): void { |
|
| 83 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 84 | + $backend = $this->createMock(CalDavBackend::class); |
|
| 85 | + $backend->expects($this->never())->method('updateShares'); |
|
| 86 | + $backend->expects($this->never())->method('getShares'); |
|
| 87 | + |
|
| 88 | + $this->config->expects($this->never())->method('setUserValue'); |
|
| 89 | + |
|
| 90 | + $backend->expects($this->once())->method('deleteCalendar') |
|
| 91 | + ->with(666); |
|
| 92 | + |
|
| 93 | + $calendarInfo = [ |
|
| 94 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 95 | + 'principaluri' => 'user1', |
|
| 96 | + 'id' => 666, |
|
| 97 | + 'uri' => 'cal', |
|
| 98 | + ]; |
|
| 99 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 100 | + $c->delete(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function testDeleteBirthdayCalendar(): void { |
|
| 104 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 105 | + $backend = $this->createMock(CalDavBackend::class); |
|
| 106 | + $backend->expects($this->once())->method('deleteCalendar') |
|
| 107 | + ->with(666); |
|
| 108 | + |
|
| 109 | + $this->config->expects($this->once()) |
|
| 110 | + ->method('setUserValue') |
|
| 111 | + ->with('user1', 'dav', 'generateBirthdayCalendar', 'no'); |
|
| 112 | + |
|
| 113 | + $calendarInfo = [ |
|
| 114 | + '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1', |
|
| 115 | + 'principaluri' => 'principals/users/user1', |
|
| 116 | + 'id' => 666, |
|
| 117 | + 'uri' => 'contact_birthdays', |
|
| 118 | + '{DAV:}displayname' => 'Test', |
|
| 119 | + ]; |
|
| 120 | + |
|
| 121 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 122 | + $c->delete(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function dataPropPatch() { |
|
| 126 | + return [ |
|
| 127 | + ['user1', 'user2', [], true], |
|
| 128 | + ['user1', 'user2', [ |
|
| 129 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 130 | + ], true], |
|
| 131 | + ['user1', 'user2', [ |
|
| 132 | + '{DAV:}displayname' => true, |
|
| 133 | + ], true], |
|
| 134 | + ['user1', 'user2', [ |
|
| 135 | + '{DAV:}displayname' => true, |
|
| 136 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 137 | + ], true], |
|
| 138 | + ['user1', 'user1', [], false], |
|
| 139 | + ['user1', 'user1', [ |
|
| 140 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 141 | + ], false], |
|
| 142 | + ['user1', 'user1', [ |
|
| 143 | + '{DAV:}displayname' => true, |
|
| 144 | + ], false], |
|
| 145 | + ['user1', 'user1', [ |
|
| 146 | + '{DAV:}displayname' => true, |
|
| 147 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
| 148 | + ], false], |
|
| 149 | + ]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @dataProvider dataPropPatch |
|
| 154 | + */ |
|
| 155 | + public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared): void { |
|
| 156 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 157 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 158 | + $calendarInfo = [ |
|
| 159 | + '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, |
|
| 160 | + 'principaluri' => $principalUri, |
|
| 161 | + 'id' => 666, |
|
| 162 | + 'uri' => 'default' |
|
| 163 | + ]; |
|
| 164 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 165 | + $propPatch = new PropPatch($mutations); |
|
| 166 | + |
|
| 167 | + if (!$shared) { |
|
| 168 | + $backend->expects($this->once()) |
|
| 169 | + ->method('updateCalendar') |
|
| 170 | + ->with(666, $propPatch); |
|
| 171 | + } |
|
| 172 | + $c->propPatch($propPatch); |
|
| 173 | + $this->addToAssertionCount(1); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @dataProvider providesReadOnlyInfo |
|
| 178 | + */ |
|
| 179 | + public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void { |
|
| 180 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 181 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 182 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 183 | + $calendarInfo = [ |
|
| 184 | + 'principaluri' => 'user2', |
|
| 185 | + 'id' => 666, |
|
| 186 | + 'uri' => $uri |
|
| 187 | + ]; |
|
| 188 | + $calendarInfo['{DAV:}displayname'] = 'Test'; |
|
| 189 | + if (!is_null($readOnlyValue)) { |
|
| 190 | + $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue; |
|
| 191 | + } |
|
| 192 | + if ($hasOwnerSet) { |
|
| 193 | + $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
| 194 | + } |
|
| 195 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 196 | + $acl = $c->getACL(); |
|
| 197 | + $childAcl = $c->getChildACL(); |
|
| 198 | + |
|
| 199 | + $expectedAcl = [[ |
|
| 200 | + 'privilege' => '{DAV:}read', |
|
| 201 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 202 | + 'protected' => true |
|
| 203 | + ], [ |
|
| 204 | + 'privilege' => '{DAV:}read', |
|
| 205 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 206 | + 'protected' => true, |
|
| 207 | + ], [ |
|
| 208 | + 'privilege' => '{DAV:}read', |
|
| 209 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
| 210 | + 'protected' => true, |
|
| 211 | + ]]; |
|
| 212 | + if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 213 | + $expectedAcl[] = [ |
|
| 214 | + 'privilege' => '{DAV:}write-properties', |
|
| 215 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 216 | + 'protected' => true |
|
| 217 | + ]; |
|
| 218 | + $expectedAcl[] = [ |
|
| 219 | + 'privilege' => '{DAV:}write-properties', |
|
| 220 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 221 | + 'protected' => true |
|
| 222 | + ]; |
|
| 223 | + } else { |
|
| 224 | + $expectedAcl[] = [ |
|
| 225 | + 'privilege' => '{DAV:}write', |
|
| 226 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
| 227 | + 'protected' => true |
|
| 228 | + ]; |
|
| 229 | + $expectedAcl[] = [ |
|
| 230 | + 'privilege' => '{DAV:}write', |
|
| 231 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
| 232 | + 'protected' => true |
|
| 233 | + ]; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $expectedAcl[] = [ |
|
| 237 | + 'privilege' => '{DAV:}write-properties', |
|
| 238 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
| 239 | + 'protected' => true |
|
| 240 | + ]; |
|
| 241 | + |
|
| 242 | + if ($hasOwnerSet) { |
|
| 243 | + $expectedAcl[] = [ |
|
| 244 | + 'privilege' => '{DAV:}read', |
|
| 245 | + 'principal' => 'user2', |
|
| 246 | + 'protected' => true |
|
| 247 | + ]; |
|
| 248 | + if ($expectsWrite) { |
|
| 249 | + $expectedAcl[] = [ |
|
| 250 | + 'privilege' => '{DAV:}write', |
|
| 251 | + 'principal' => 'user2', |
|
| 252 | + 'protected' => true |
|
| 253 | + ]; |
|
| 254 | + } else { |
|
| 255 | + $expectedAcl[] = [ |
|
| 256 | + 'privilege' => '{DAV:}write-properties', |
|
| 257 | + 'principal' => 'user2', |
|
| 258 | + 'protected' => true |
|
| 259 | + ]; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + $this->assertEquals($expectedAcl, $acl); |
|
| 263 | + $this->assertEquals($expectedAcl, $childAcl); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + public function providesReadOnlyInfo() { |
|
| 267 | + return [ |
|
| 268 | + 'read-only property not set' => [true, null, true], |
|
| 269 | + 'read-only property is false' => [true, false, true], |
|
| 270 | + 'read-only property is true' => [false, true, true], |
|
| 271 | + 'read-only property not set and no owner' => [true, null, false], |
|
| 272 | + 'read-only property is false and no owner' => [true, false, false], |
|
| 273 | + 'read-only property is true and no owner' => [false, true, false], |
|
| 274 | + 'birthday calendar' => [false, false, false, BirthdayService::BIRTHDAY_CALENDAR_URI] |
|
| 275 | + ]; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @dataProvider providesConfidentialClassificationData |
|
| 280 | + * @param int $expectedChildren |
|
| 281 | + * @param bool $isShared |
|
| 282 | + */ |
|
| 283 | + public function testPrivateClassification($expectedChildren, $isShared): void { |
|
| 284 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 285 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
| 286 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 287 | + |
|
| 288 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 289 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 290 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 291 | + $calObject0, $calObject1, $calObject2 |
|
| 292 | + ]); |
|
| 293 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 294 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 295 | + ->willReturn([ |
|
| 296 | + $calObject0, $calObject1, $calObject2 |
|
| 297 | + ]); |
|
| 298 | + $backend->expects($this->any())->method('getCalendarObject') |
|
| 299 | + ->willReturn($calObject2)->with(666, 'event-2'); |
|
| 300 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 301 | + |
|
| 302 | + $calendarInfo = [ |
|
| 303 | + 'principaluri' => 'user2', |
|
| 304 | + 'id' => 666, |
|
| 305 | + 'uri' => 'cal', |
|
| 306 | + ]; |
|
| 307 | + |
|
| 308 | + if ($isShared) { |
|
| 309 | + $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
| 310 | + } |
|
| 311 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 312 | + $children = $c->getChildren(); |
|
| 313 | + $this->assertEquals($expectedChildren, count($children)); |
|
| 314 | + $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
| 315 | + $this->assertEquals($expectedChildren, count($children)); |
|
| 316 | + |
|
| 317 | + $this->assertEquals(!$isShared, $c->childExists('event-2')); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * @dataProvider providesConfidentialClassificationData |
|
| 322 | + * @param int $expectedChildren |
|
| 323 | + * @param bool $isShared |
|
| 324 | + */ |
|
| 325 | + public function testConfidentialClassification($expectedChildren, $isShared): void { |
|
| 326 | + $start = '20160609'; |
|
| 327 | + $end = '20160610'; |
|
| 328 | + |
|
| 329 | + $calData = <<<EOD |
|
| 330 | 330 | BEGIN:VCALENDAR |
| 331 | 331 | PRODID:-//ownCloud calendar v1.2.2 |
| 332 | 332 | BEGIN:VEVENT |
@@ -368,84 +368,84 @@ discard block |
||
| 368 | 368 | END:VCALENDAR |
| 369 | 369 | EOD; |
| 370 | 370 | |
| 371 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 372 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
| 373 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 374 | - |
|
| 375 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 376 | - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 377 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 378 | - $calObject0, $calObject1, $calObject2 |
|
| 379 | - ]); |
|
| 380 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 381 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 382 | - ->willReturn([ |
|
| 383 | - $calObject0, $calObject1, $calObject2 |
|
| 384 | - ]); |
|
| 385 | - $backend->expects($this->any())->method('getCalendarObject') |
|
| 386 | - ->willReturn($calObject1)->with(666, 'event-1'); |
|
| 387 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 388 | - |
|
| 389 | - $calendarInfo = [ |
|
| 390 | - '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user1' : 'user2', |
|
| 391 | - 'principaluri' => 'user2', |
|
| 392 | - 'id' => 666, |
|
| 393 | - 'uri' => 'cal', |
|
| 394 | - ]; |
|
| 395 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 396 | - |
|
| 397 | - $this->assertEquals(count($c->getChildren()), $expectedChildren); |
|
| 398 | - |
|
| 399 | - // test private event |
|
| 400 | - $privateEvent = $c->getChild('event-1'); |
|
| 401 | - $calData = $privateEvent->get(); |
|
| 402 | - $event = Reader::read($calData); |
|
| 403 | - |
|
| 404 | - $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
| 405 | - $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
| 406 | - |
|
| 407 | - if ($isShared) { |
|
| 408 | - $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 409 | - $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
| 410 | - $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
| 411 | - $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
| 412 | - $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
| 413 | - } else { |
|
| 414 | - $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // Test l10n |
|
| 418 | - $l10n = $this->createMock(IL10N::class); |
|
| 419 | - if ($isShared) { |
|
| 420 | - $l10n->expects($this->once()) |
|
| 421 | - ->method('t') |
|
| 422 | - ->with('Busy') |
|
| 423 | - ->willReturn('Translated busy'); |
|
| 424 | - } else { |
|
| 425 | - $l10n->expects($this->never()) |
|
| 426 | - ->method('t'); |
|
| 427 | - } |
|
| 428 | - $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger); |
|
| 429 | - |
|
| 430 | - $calData = $c->getChild('event-1')->get(); |
|
| 431 | - $event = Reader::read($calData); |
|
| 432 | - |
|
| 433 | - if ($isShared) { |
|
| 434 | - $this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 435 | - } else { |
|
| 436 | - $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - public function providesConfidentialClassificationData() { |
|
| 441 | - return [ |
|
| 442 | - [3, false], |
|
| 443 | - [2, true] |
|
| 444 | - ]; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - public function testRemoveVAlarms(): void { |
|
| 448 | - $publicObjectData = <<<EOD |
|
| 371 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
| 372 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
| 373 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
| 374 | + |
|
| 375 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 376 | + $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); |
|
| 377 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
| 378 | + $calObject0, $calObject1, $calObject2 |
|
| 379 | + ]); |
|
| 380 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
| 381 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
| 382 | + ->willReturn([ |
|
| 383 | + $calObject0, $calObject1, $calObject2 |
|
| 384 | + ]); |
|
| 385 | + $backend->expects($this->any())->method('getCalendarObject') |
|
| 386 | + ->willReturn($calObject1)->with(666, 'event-1'); |
|
| 387 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
| 388 | + |
|
| 389 | + $calendarInfo = [ |
|
| 390 | + '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user1' : 'user2', |
|
| 391 | + 'principaluri' => 'user2', |
|
| 392 | + 'id' => 666, |
|
| 393 | + 'uri' => 'cal', |
|
| 394 | + ]; |
|
| 395 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
| 396 | + |
|
| 397 | + $this->assertEquals(count($c->getChildren()), $expectedChildren); |
|
| 398 | + |
|
| 399 | + // test private event |
|
| 400 | + $privateEvent = $c->getChild('event-1'); |
|
| 401 | + $calData = $privateEvent->get(); |
|
| 402 | + $event = Reader::read($calData); |
|
| 403 | + |
|
| 404 | + $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
| 405 | + $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
| 406 | + |
|
| 407 | + if ($isShared) { |
|
| 408 | + $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 409 | + $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
| 410 | + $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
| 411 | + $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
| 412 | + $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
| 413 | + } else { |
|
| 414 | + $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // Test l10n |
|
| 418 | + $l10n = $this->createMock(IL10N::class); |
|
| 419 | + if ($isShared) { |
|
| 420 | + $l10n->expects($this->once()) |
|
| 421 | + ->method('t') |
|
| 422 | + ->with('Busy') |
|
| 423 | + ->willReturn('Translated busy'); |
|
| 424 | + } else { |
|
| 425 | + $l10n->expects($this->never()) |
|
| 426 | + ->method('t'); |
|
| 427 | + } |
|
| 428 | + $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger); |
|
| 429 | + |
|
| 430 | + $calData = $c->getChild('event-1')->get(); |
|
| 431 | + $event = Reader::read($calData); |
|
| 432 | + |
|
| 433 | + if ($isShared) { |
|
| 434 | + $this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue()); |
|
| 435 | + } else { |
|
| 436 | + $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + public function providesConfidentialClassificationData() { |
|
| 441 | + return [ |
|
| 442 | + [3, false], |
|
| 443 | + [2, true] |
|
| 444 | + ]; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + public function testRemoveVAlarms(): void { |
|
| 448 | + $publicObjectData = <<<EOD |
|
| 449 | 449 | BEGIN:VCALENDAR |
| 450 | 450 | VERSION:2.0 |
| 451 | 451 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | |
| 470 | 470 | EOD; |
| 471 | 471 | |
| 472 | - $confidentialObjectData = <<<EOD |
|
| 472 | + $confidentialObjectData = <<<EOD |
|
| 473 | 473 | BEGIN:VCALENDAR |
| 474 | 474 | VERSION:2.0 |
| 475 | 475 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | |
| 494 | 494 | EOD; |
| 495 | 495 | |
| 496 | - $publicObjectDataWithoutVAlarm = <<<EOD |
|
| 496 | + $publicObjectDataWithoutVAlarm = <<<EOD |
|
| 497 | 497 | BEGIN:VCALENDAR |
| 498 | 498 | VERSION:2.0 |
| 499 | 499 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | |
| 514 | 514 | EOD; |
| 515 | 515 | |
| 516 | - $confidentialObjectCleaned = <<<EOD |
|
| 516 | + $confidentialObjectCleaned = <<<EOD |
|
| 517 | 517 | BEGIN:VCALENDAR |
| 518 | 518 | VERSION:2.0 |
| 519 | 519 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -532,94 +532,94 @@ discard block |
||
| 532 | 532 | |
| 533 | 533 | |
| 534 | 534 | |
| 535 | - $publicObject = ['uri' => 'event-0', |
|
| 536 | - 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC, |
|
| 537 | - 'calendardata' => $publicObjectData]; |
|
| 538 | - |
|
| 539 | - $confidentialObject = ['uri' => 'event-1', |
|
| 540 | - 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, |
|
| 541 | - 'calendardata' => $confidentialObjectData]; |
|
| 542 | - |
|
| 543 | - /** @var MockObject | CalDavBackend $backend */ |
|
| 544 | - $backend = $this->createMock(CalDavBackend::class); |
|
| 545 | - $backend->expects($this->any()) |
|
| 546 | - ->method('getCalendarObjects') |
|
| 547 | - ->willReturn([$publicObject, $confidentialObject]); |
|
| 548 | - |
|
| 549 | - $backend->expects($this->any()) |
|
| 550 | - ->method('getMultipleCalendarObjects') |
|
| 551 | - ->with(666, ['event-0', 'event-1']) |
|
| 552 | - ->willReturn([$publicObject, $confidentialObject]); |
|
| 553 | - |
|
| 554 | - $backend->expects($this->any()) |
|
| 555 | - ->method('getCalendarObject') |
|
| 556 | - ->willReturnCallback(function ($cId, $uri) use ($publicObject, $confidentialObject) { |
|
| 557 | - switch ($uri) { |
|
| 558 | - case 'event-0': |
|
| 559 | - return $publicObject; |
|
| 560 | - |
|
| 561 | - case 'event-1': |
|
| 562 | - return $confidentialObject; |
|
| 563 | - |
|
| 564 | - default: |
|
| 565 | - throw new \Exception('unexpected uri'); |
|
| 566 | - } |
|
| 567 | - }); |
|
| 568 | - |
|
| 569 | - $backend->expects($this->any()) |
|
| 570 | - ->method('applyShareAcl') |
|
| 571 | - ->willReturnArgument(1); |
|
| 572 | - |
|
| 573 | - $calendarInfoOwner = [ |
|
| 574 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 575 | - 'principaluri' => 'user1', |
|
| 576 | - 'id' => 666, |
|
| 577 | - 'uri' => 'cal', |
|
| 578 | - ]; |
|
| 579 | - $calendarInfoSharedRW = [ |
|
| 580 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 581 | - 'principaluri' => 'user2', |
|
| 582 | - 'id' => 666, |
|
| 583 | - 'uri' => 'cal', |
|
| 584 | - ]; |
|
| 585 | - $calendarInfoSharedRO = [ |
|
| 586 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 587 | - '{http://owncloud.org/ns}read-only' => true, |
|
| 588 | - 'principaluri' => 'user2', |
|
| 589 | - 'id' => 666, |
|
| 590 | - 'uri' => 'cal', |
|
| 591 | - ]; |
|
| 592 | - |
|
| 593 | - $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger); |
|
| 594 | - $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger); |
|
| 595 | - $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger); |
|
| 596 | - |
|
| 597 | - $this->assertCount(2, $ownerCalendar->getChildren()); |
|
| 598 | - $this->assertCount(2, $rwCalendar->getChildren()); |
|
| 599 | - $this->assertCount(2, $roCalendar->getChildren()); |
|
| 600 | - |
|
| 601 | - // calendar data shall not be altered for the owner |
|
| 602 | - $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); |
|
| 603 | - $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData); |
|
| 604 | - |
|
| 605 | - // valarms shall not be removed for read-write shares |
|
| 606 | - $this->assertEquals( |
|
| 607 | - $this->fixLinebreak($rwCalendar->getChild('event-0')->get()), |
|
| 608 | - $this->fixLinebreak($publicObjectData)); |
|
| 609 | - $this->assertEquals( |
|
| 610 | - $this->fixLinebreak($rwCalendar->getChild('event-1')->get()), |
|
| 611 | - $this->fixLinebreak($confidentialObjectCleaned)); |
|
| 612 | - |
|
| 613 | - // valarms shall be removed for read-only shares |
|
| 614 | - $this->assertEquals( |
|
| 615 | - $this->fixLinebreak($roCalendar->getChild('event-0')->get()), |
|
| 616 | - $this->fixLinebreak($publicObjectDataWithoutVAlarm)); |
|
| 617 | - $this->assertEquals( |
|
| 618 | - $this->fixLinebreak($roCalendar->getChild('event-1')->get()), |
|
| 619 | - $this->fixLinebreak($confidentialObjectCleaned)); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - private function fixLinebreak($str) { |
|
| 623 | - return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); |
|
| 624 | - } |
|
| 535 | + $publicObject = ['uri' => 'event-0', |
|
| 536 | + 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC, |
|
| 537 | + 'calendardata' => $publicObjectData]; |
|
| 538 | + |
|
| 539 | + $confidentialObject = ['uri' => 'event-1', |
|
| 540 | + 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, |
|
| 541 | + 'calendardata' => $confidentialObjectData]; |
|
| 542 | + |
|
| 543 | + /** @var MockObject | CalDavBackend $backend */ |
|
| 544 | + $backend = $this->createMock(CalDavBackend::class); |
|
| 545 | + $backend->expects($this->any()) |
|
| 546 | + ->method('getCalendarObjects') |
|
| 547 | + ->willReturn([$publicObject, $confidentialObject]); |
|
| 548 | + |
|
| 549 | + $backend->expects($this->any()) |
|
| 550 | + ->method('getMultipleCalendarObjects') |
|
| 551 | + ->with(666, ['event-0', 'event-1']) |
|
| 552 | + ->willReturn([$publicObject, $confidentialObject]); |
|
| 553 | + |
|
| 554 | + $backend->expects($this->any()) |
|
| 555 | + ->method('getCalendarObject') |
|
| 556 | + ->willReturnCallback(function ($cId, $uri) use ($publicObject, $confidentialObject) { |
|
| 557 | + switch ($uri) { |
|
| 558 | + case 'event-0': |
|
| 559 | + return $publicObject; |
|
| 560 | + |
|
| 561 | + case 'event-1': |
|
| 562 | + return $confidentialObject; |
|
| 563 | + |
|
| 564 | + default: |
|
| 565 | + throw new \Exception('unexpected uri'); |
|
| 566 | + } |
|
| 567 | + }); |
|
| 568 | + |
|
| 569 | + $backend->expects($this->any()) |
|
| 570 | + ->method('applyShareAcl') |
|
| 571 | + ->willReturnArgument(1); |
|
| 572 | + |
|
| 573 | + $calendarInfoOwner = [ |
|
| 574 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 575 | + 'principaluri' => 'user1', |
|
| 576 | + 'id' => 666, |
|
| 577 | + 'uri' => 'cal', |
|
| 578 | + ]; |
|
| 579 | + $calendarInfoSharedRW = [ |
|
| 580 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 581 | + 'principaluri' => 'user2', |
|
| 582 | + 'id' => 666, |
|
| 583 | + 'uri' => 'cal', |
|
| 584 | + ]; |
|
| 585 | + $calendarInfoSharedRO = [ |
|
| 586 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 587 | + '{http://owncloud.org/ns}read-only' => true, |
|
| 588 | + 'principaluri' => 'user2', |
|
| 589 | + 'id' => 666, |
|
| 590 | + 'uri' => 'cal', |
|
| 591 | + ]; |
|
| 592 | + |
|
| 593 | + $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger); |
|
| 594 | + $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger); |
|
| 595 | + $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger); |
|
| 596 | + |
|
| 597 | + $this->assertCount(2, $ownerCalendar->getChildren()); |
|
| 598 | + $this->assertCount(2, $rwCalendar->getChildren()); |
|
| 599 | + $this->assertCount(2, $roCalendar->getChildren()); |
|
| 600 | + |
|
| 601 | + // calendar data shall not be altered for the owner |
|
| 602 | + $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); |
|
| 603 | + $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData); |
|
| 604 | + |
|
| 605 | + // valarms shall not be removed for read-write shares |
|
| 606 | + $this->assertEquals( |
|
| 607 | + $this->fixLinebreak($rwCalendar->getChild('event-0')->get()), |
|
| 608 | + $this->fixLinebreak($publicObjectData)); |
|
| 609 | + $this->assertEquals( |
|
| 610 | + $this->fixLinebreak($rwCalendar->getChild('event-1')->get()), |
|
| 611 | + $this->fixLinebreak($confidentialObjectCleaned)); |
|
| 612 | + |
|
| 613 | + // valarms shall be removed for read-only shares |
|
| 614 | + $this->assertEquals( |
|
| 615 | + $this->fixLinebreak($roCalendar->getChild('event-0')->get()), |
|
| 616 | + $this->fixLinebreak($publicObjectDataWithoutVAlarm)); |
|
| 617 | + $this->assertEquals( |
|
| 618 | + $this->fixLinebreak($roCalendar->getChild('event-1')->get()), |
|
| 619 | + $this->fixLinebreak($confidentialObjectCleaned)); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + private function fixLinebreak($str) { |
|
| 623 | + return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); |
|
| 624 | + } |
|
| 625 | 625 | } |
@@ -32,128 +32,128 @@ discard block |
||
| 32 | 32 | * @package OCA\DAV\Tests\unit\CalDAV |
| 33 | 33 | */ |
| 34 | 34 | class CalDavBackendTest extends AbstractCalDavBackend { |
| 35 | - public function testCalendarOperations(): void { |
|
| 36 | - $calendarId = $this->createTestCalendar(); |
|
| 37 | - |
|
| 38 | - // update its display name |
|
| 39 | - $patch = new PropPatch([ |
|
| 40 | - '{DAV:}displayname' => 'Unit test', |
|
| 41 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing' |
|
| 42 | - ]); |
|
| 43 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 44 | - ->method('dispatchTyped'); |
|
| 45 | - $this->backend->updateCalendar($calendarId, $patch); |
|
| 46 | - $patch->commit(); |
|
| 47 | - $this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER)); |
|
| 48 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 49 | - $this->assertCount(1, $calendars); |
|
| 50 | - $this->assertEquals('Unit test', $calendars[0]['{DAV:}displayname']); |
|
| 51 | - $this->assertEquals('Calendar used for unit testing', $calendars[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']); |
|
| 52 | - $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']); |
|
| 53 | - |
|
| 54 | - // delete the address book |
|
| 55 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 56 | - ->method('dispatchTyped'); |
|
| 57 | - $this->backend->deleteCalendar($calendars[0]['id'], true); |
|
| 58 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 59 | - self::assertEmpty($calendars); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function providesSharingData() { |
|
| 63 | - return [ |
|
| 64 | - [true, true, true, false, [ |
|
| 65 | - [ |
|
| 66 | - 'href' => 'principal:' . self::UNIT_TEST_USER1, |
|
| 67 | - 'readOnly' => false |
|
| 68 | - ], |
|
| 69 | - [ |
|
| 70 | - 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 71 | - 'readOnly' => true |
|
| 72 | - ] |
|
| 73 | - ], [ |
|
| 74 | - self::UNIT_TEST_USER1, |
|
| 75 | - self::UNIT_TEST_GROUP, |
|
| 76 | - ]], |
|
| 77 | - [true, true, true, false, [ |
|
| 78 | - [ |
|
| 79 | - 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 80 | - 'readOnly' => true, |
|
| 81 | - ], |
|
| 82 | - [ |
|
| 83 | - 'href' => 'principal:' . self::UNIT_TEST_GROUP2, |
|
| 84 | - 'readOnly' => false, |
|
| 85 | - ], |
|
| 86 | - ], [ |
|
| 87 | - self::UNIT_TEST_GROUP, |
|
| 88 | - self::UNIT_TEST_GROUP2, |
|
| 89 | - ]], |
|
| 90 | - [true, true, true, true, [ |
|
| 91 | - [ |
|
| 92 | - 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 93 | - 'readOnly' => false, |
|
| 94 | - ], |
|
| 95 | - [ |
|
| 96 | - 'href' => 'principal:' . self::UNIT_TEST_GROUP2, |
|
| 97 | - 'readOnly' => true, |
|
| 98 | - ], |
|
| 99 | - ], [ |
|
| 100 | - self::UNIT_TEST_GROUP, |
|
| 101 | - self::UNIT_TEST_GROUP2, |
|
| 102 | - ]], |
|
| 103 | - [true, false, false, false, [ |
|
| 104 | - [ |
|
| 105 | - 'href' => 'principal:' . self::UNIT_TEST_USER1, |
|
| 106 | - 'readOnly' => true |
|
| 107 | - ], |
|
| 108 | - ], [ |
|
| 109 | - self::UNIT_TEST_USER1, |
|
| 110 | - ]], |
|
| 111 | - |
|
| 112 | - ]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @dataProvider providesSharingData |
|
| 117 | - */ |
|
| 118 | - public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add, $principals): void { |
|
| 119 | - $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 120 | - $config = $this->createMock(IConfig::class); |
|
| 121 | - |
|
| 122 | - $l10n = $this->createMock(IL10N::class); |
|
| 123 | - $l10n->expects($this->any()) |
|
| 124 | - ->method('t') |
|
| 125 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
| 126 | - return vsprintf($text, $parameters); |
|
| 127 | - }); |
|
| 128 | - |
|
| 129 | - $this->userManager->expects($this->any()) |
|
| 130 | - ->method('userExists') |
|
| 131 | - ->willReturn(true); |
|
| 132 | - $this->groupManager->expects($this->any()) |
|
| 133 | - ->method('groupExists') |
|
| 134 | - ->willReturn(true); |
|
| 135 | - $this->principal->expects(self::atLeastOnce()) |
|
| 136 | - ->method('findByUri') |
|
| 137 | - ->willReturnOnConsecutiveCalls(...$principals); |
|
| 138 | - |
|
| 139 | - $calendarId = $this->createTestCalendar(); |
|
| 140 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 141 | - $this->assertCount(1, $calendars); |
|
| 142 | - $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger); |
|
| 143 | - $this->backend->updateShares($calendar, $add, []); |
|
| 144 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); |
|
| 145 | - $this->assertCount(1, $calendars); |
|
| 146 | - $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger); |
|
| 147 | - $acl = $calendar->getACL(); |
|
| 148 | - $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); |
|
| 149 | - $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); |
|
| 150 | - $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); |
|
| 151 | - $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); |
|
| 152 | - $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner()); |
|
| 153 | - |
|
| 154 | - // test acls on the child |
|
| 155 | - $uri = static::getUniqueID('calobj'); |
|
| 156 | - $calData = <<<'EOD' |
|
| 35 | + public function testCalendarOperations(): void { |
|
| 36 | + $calendarId = $this->createTestCalendar(); |
|
| 37 | + |
|
| 38 | + // update its display name |
|
| 39 | + $patch = new PropPatch([ |
|
| 40 | + '{DAV:}displayname' => 'Unit test', |
|
| 41 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing' |
|
| 42 | + ]); |
|
| 43 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 44 | + ->method('dispatchTyped'); |
|
| 45 | + $this->backend->updateCalendar($calendarId, $patch); |
|
| 46 | + $patch->commit(); |
|
| 47 | + $this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER)); |
|
| 48 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 49 | + $this->assertCount(1, $calendars); |
|
| 50 | + $this->assertEquals('Unit test', $calendars[0]['{DAV:}displayname']); |
|
| 51 | + $this->assertEquals('Calendar used for unit testing', $calendars[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']); |
|
| 52 | + $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']); |
|
| 53 | + |
|
| 54 | + // delete the address book |
|
| 55 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 56 | + ->method('dispatchTyped'); |
|
| 57 | + $this->backend->deleteCalendar($calendars[0]['id'], true); |
|
| 58 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 59 | + self::assertEmpty($calendars); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function providesSharingData() { |
|
| 63 | + return [ |
|
| 64 | + [true, true, true, false, [ |
|
| 65 | + [ |
|
| 66 | + 'href' => 'principal:' . self::UNIT_TEST_USER1, |
|
| 67 | + 'readOnly' => false |
|
| 68 | + ], |
|
| 69 | + [ |
|
| 70 | + 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 71 | + 'readOnly' => true |
|
| 72 | + ] |
|
| 73 | + ], [ |
|
| 74 | + self::UNIT_TEST_USER1, |
|
| 75 | + self::UNIT_TEST_GROUP, |
|
| 76 | + ]], |
|
| 77 | + [true, true, true, false, [ |
|
| 78 | + [ |
|
| 79 | + 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 80 | + 'readOnly' => true, |
|
| 81 | + ], |
|
| 82 | + [ |
|
| 83 | + 'href' => 'principal:' . self::UNIT_TEST_GROUP2, |
|
| 84 | + 'readOnly' => false, |
|
| 85 | + ], |
|
| 86 | + ], [ |
|
| 87 | + self::UNIT_TEST_GROUP, |
|
| 88 | + self::UNIT_TEST_GROUP2, |
|
| 89 | + ]], |
|
| 90 | + [true, true, true, true, [ |
|
| 91 | + [ |
|
| 92 | + 'href' => 'principal:' . self::UNIT_TEST_GROUP, |
|
| 93 | + 'readOnly' => false, |
|
| 94 | + ], |
|
| 95 | + [ |
|
| 96 | + 'href' => 'principal:' . self::UNIT_TEST_GROUP2, |
|
| 97 | + 'readOnly' => true, |
|
| 98 | + ], |
|
| 99 | + ], [ |
|
| 100 | + self::UNIT_TEST_GROUP, |
|
| 101 | + self::UNIT_TEST_GROUP2, |
|
| 102 | + ]], |
|
| 103 | + [true, false, false, false, [ |
|
| 104 | + [ |
|
| 105 | + 'href' => 'principal:' . self::UNIT_TEST_USER1, |
|
| 106 | + 'readOnly' => true |
|
| 107 | + ], |
|
| 108 | + ], [ |
|
| 109 | + self::UNIT_TEST_USER1, |
|
| 110 | + ]], |
|
| 111 | + |
|
| 112 | + ]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @dataProvider providesSharingData |
|
| 117 | + */ |
|
| 118 | + public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add, $principals): void { |
|
| 119 | + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 120 | + $config = $this->createMock(IConfig::class); |
|
| 121 | + |
|
| 122 | + $l10n = $this->createMock(IL10N::class); |
|
| 123 | + $l10n->expects($this->any()) |
|
| 124 | + ->method('t') |
|
| 125 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
| 126 | + return vsprintf($text, $parameters); |
|
| 127 | + }); |
|
| 128 | + |
|
| 129 | + $this->userManager->expects($this->any()) |
|
| 130 | + ->method('userExists') |
|
| 131 | + ->willReturn(true); |
|
| 132 | + $this->groupManager->expects($this->any()) |
|
| 133 | + ->method('groupExists') |
|
| 134 | + ->willReturn(true); |
|
| 135 | + $this->principal->expects(self::atLeastOnce()) |
|
| 136 | + ->method('findByUri') |
|
| 137 | + ->willReturnOnConsecutiveCalls(...$principals); |
|
| 138 | + |
|
| 139 | + $calendarId = $this->createTestCalendar(); |
|
| 140 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 141 | + $this->assertCount(1, $calendars); |
|
| 142 | + $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger); |
|
| 143 | + $this->backend->updateShares($calendar, $add, []); |
|
| 144 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); |
|
| 145 | + $this->assertCount(1, $calendars); |
|
| 146 | + $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger); |
|
| 147 | + $acl = $calendar->getACL(); |
|
| 148 | + $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); |
|
| 149 | + $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); |
|
| 150 | + $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); |
|
| 151 | + $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); |
|
| 152 | + $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner()); |
|
| 153 | + |
|
| 154 | + // test acls on the child |
|
| 155 | + $uri = static::getUniqueID('calobj'); |
|
| 156 | + $calData = <<<'EOD' |
|
| 157 | 157 | BEGIN:VCALENDAR |
| 158 | 158 | VERSION:2.0 |
| 159 | 159 | PRODID:ownCloud Calendar |
@@ -170,35 +170,35 @@ discard block |
||
| 170 | 170 | END:VCALENDAR |
| 171 | 171 | EOD; |
| 172 | 172 | |
| 173 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 174 | - ->method('dispatchTyped'); |
|
| 175 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 176 | - |
|
| 177 | - /** @var IACL $child */ |
|
| 178 | - $child = $calendar->getChild($uri); |
|
| 179 | - $acl = $child->getACL(); |
|
| 180 | - $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); |
|
| 181 | - $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); |
|
| 182 | - $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); |
|
| 183 | - $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); |
|
| 184 | - |
|
| 185 | - // delete the calendar |
|
| 186 | - $this->dispatcher->expects(self::once()) |
|
| 187 | - ->method('dispatchTyped') |
|
| 188 | - ->with(self::callback(function ($event) { |
|
| 189 | - return $event instanceof CalendarDeletedEvent; |
|
| 190 | - })); |
|
| 191 | - $this->backend->deleteCalendar($calendars[0]['id'], true); |
|
| 192 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 193 | - self::assertEmpty($calendars); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - public function testCalendarObjectsOperations(): void { |
|
| 197 | - $calendarId = $this->createTestCalendar(); |
|
| 198 | - |
|
| 199 | - // create a card |
|
| 200 | - $uri = static::getUniqueID('calobj'); |
|
| 201 | - $calData = <<<'EOD' |
|
| 173 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 174 | + ->method('dispatchTyped'); |
|
| 175 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 176 | + |
|
| 177 | + /** @var IACL $child */ |
|
| 178 | + $child = $calendar->getChild($uri); |
|
| 179 | + $acl = $child->getACL(); |
|
| 180 | + $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl); |
|
| 181 | + $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl); |
|
| 182 | + $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl); |
|
| 183 | + $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl); |
|
| 184 | + |
|
| 185 | + // delete the calendar |
|
| 186 | + $this->dispatcher->expects(self::once()) |
|
| 187 | + ->method('dispatchTyped') |
|
| 188 | + ->with(self::callback(function ($event) { |
|
| 189 | + return $event instanceof CalendarDeletedEvent; |
|
| 190 | + })); |
|
| 191 | + $this->backend->deleteCalendar($calendars[0]['id'], true); |
|
| 192 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
| 193 | + self::assertEmpty($calendars); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + public function testCalendarObjectsOperations(): void { |
|
| 197 | + $calendarId = $this->createTestCalendar(); |
|
| 198 | + |
|
| 199 | + // create a card |
|
| 200 | + $uri = static::getUniqueID('calobj'); |
|
| 201 | + $calData = <<<'EOD' |
|
| 202 | 202 | BEGIN:VCALENDAR |
| 203 | 203 | VERSION:2.0 |
| 204 | 204 | PRODID:ownCloud Calendar |
@@ -215,30 +215,30 @@ discard block |
||
| 215 | 215 | END:VCALENDAR |
| 216 | 216 | EOD; |
| 217 | 217 | |
| 218 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 219 | - ->method('dispatchTyped'); |
|
| 220 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 221 | - |
|
| 222 | - // get all the calendar objects |
|
| 223 | - $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 224 | - $this->assertCount(1, $calendarObjects); |
|
| 225 | - $this->assertEquals($calendarId, $calendarObjects[0]['calendarid']); |
|
| 226 | - $this->assertArrayHasKey('classification', $calendarObjects[0]); |
|
| 227 | - |
|
| 228 | - // get the calendar objects |
|
| 229 | - $calendarObject = $this->backend->getCalendarObject($calendarId, $uri); |
|
| 230 | - $this->assertNotNull($calendarObject); |
|
| 231 | - $this->assertArrayHasKey('id', $calendarObject); |
|
| 232 | - $this->assertArrayHasKey('uri', $calendarObject); |
|
| 233 | - $this->assertArrayHasKey('lastmodified', $calendarObject); |
|
| 234 | - $this->assertArrayHasKey('etag', $calendarObject); |
|
| 235 | - $this->assertArrayHasKey('size', $calendarObject); |
|
| 236 | - $this->assertArrayHasKey('classification', $calendarObject); |
|
| 237 | - $this->assertArrayHasKey('{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at', $calendarObject); |
|
| 238 | - $this->assertEquals($calData, $calendarObject['calendardata']); |
|
| 239 | - |
|
| 240 | - // update the card |
|
| 241 | - $calData = <<<'EOD' |
|
| 218 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 219 | + ->method('dispatchTyped'); |
|
| 220 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 221 | + |
|
| 222 | + // get all the calendar objects |
|
| 223 | + $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 224 | + $this->assertCount(1, $calendarObjects); |
|
| 225 | + $this->assertEquals($calendarId, $calendarObjects[0]['calendarid']); |
|
| 226 | + $this->assertArrayHasKey('classification', $calendarObjects[0]); |
|
| 227 | + |
|
| 228 | + // get the calendar objects |
|
| 229 | + $calendarObject = $this->backend->getCalendarObject($calendarId, $uri); |
|
| 230 | + $this->assertNotNull($calendarObject); |
|
| 231 | + $this->assertArrayHasKey('id', $calendarObject); |
|
| 232 | + $this->assertArrayHasKey('uri', $calendarObject); |
|
| 233 | + $this->assertArrayHasKey('lastmodified', $calendarObject); |
|
| 234 | + $this->assertArrayHasKey('etag', $calendarObject); |
|
| 235 | + $this->assertArrayHasKey('size', $calendarObject); |
|
| 236 | + $this->assertArrayHasKey('classification', $calendarObject); |
|
| 237 | + $this->assertArrayHasKey('{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at', $calendarObject); |
|
| 238 | + $this->assertEquals($calData, $calendarObject['calendardata']); |
|
| 239 | + |
|
| 240 | + // update the card |
|
| 241 | + $calData = <<<'EOD' |
|
| 242 | 242 | BEGIN:VCALENDAR |
| 243 | 243 | VERSION:2.0 |
| 244 | 244 | PRODID:ownCloud Calendar |
@@ -253,28 +253,28 @@ discard block |
||
| 253 | 253 | END:VEVENT |
| 254 | 254 | END:VCALENDAR |
| 255 | 255 | EOD; |
| 256 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 257 | - ->method('dispatchTyped'); |
|
| 258 | - $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 259 | - $calendarObject = $this->backend->getCalendarObject($calendarId, $uri); |
|
| 260 | - $this->assertEquals($calData, $calendarObject['calendardata']); |
|
| 256 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 257 | + ->method('dispatchTyped'); |
|
| 258 | + $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 259 | + $calendarObject = $this->backend->getCalendarObject($calendarId, $uri); |
|
| 260 | + $this->assertEquals($calData, $calendarObject['calendardata']); |
|
| 261 | 261 | |
| 262 | - // delete the card |
|
| 263 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 264 | - ->method('dispatchTyped'); |
|
| 265 | - $this->backend->deleteCalendarObject($calendarId, $uri); |
|
| 266 | - $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 267 | - $this->assertCount(0, $calendarObjects); |
|
| 268 | - } |
|
| 262 | + // delete the card |
|
| 263 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 264 | + ->method('dispatchTyped'); |
|
| 265 | + $this->backend->deleteCalendarObject($calendarId, $uri); |
|
| 266 | + $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 267 | + $this->assertCount(0, $calendarObjects); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | |
| 271 | - public function testMultipleCalendarObjectsWithSameUID(): void { |
|
| 272 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
| 273 | - $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.'); |
|
| 271 | + public function testMultipleCalendarObjectsWithSameUID(): void { |
|
| 272 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
| 273 | + $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.'); |
|
| 274 | 274 | |
| 275 | - $calendarId = $this->createTestCalendar(); |
|
| 275 | + $calendarId = $this->createTestCalendar(); |
|
| 276 | 276 | |
| 277 | - $calData = <<<'EOD' |
|
| 277 | + $calData = <<<'EOD' |
|
| 278 | 278 | BEGIN:VCALENDAR |
| 279 | 279 | VERSION:2.0 |
| 280 | 280 | PRODID:ownCloud Calendar |
@@ -291,18 +291,18 @@ discard block |
||
| 291 | 291 | END:VCALENDAR |
| 292 | 292 | EOD; |
| 293 | 293 | |
| 294 | - $uri0 = static::getUniqueID('event'); |
|
| 295 | - $uri1 = static::getUniqueID('event'); |
|
| 296 | - $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
| 297 | - $this->backend->createCalendarObject($calendarId, $uri1, $calData); |
|
| 298 | - } |
|
| 294 | + $uri0 = static::getUniqueID('event'); |
|
| 295 | + $uri1 = static::getUniqueID('event'); |
|
| 296 | + $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
| 297 | + $this->backend->createCalendarObject($calendarId, $uri1, $calData); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - public function testMultiCalendarObjects(): void { |
|
| 301 | - $calendarId = $this->createTestCalendar(); |
|
| 300 | + public function testMultiCalendarObjects(): void { |
|
| 301 | + $calendarId = $this->createTestCalendar(); |
|
| 302 | 302 | |
| 303 | - // create an event |
|
| 304 | - $calData = []; |
|
| 305 | - $calData[] = <<<'EOD' |
|
| 303 | + // create an event |
|
| 304 | + $calData = []; |
|
| 305 | + $calData[] = <<<'EOD' |
|
| 306 | 306 | BEGIN:VCALENDAR |
| 307 | 307 | VERSION:2.0 |
| 308 | 308 | PRODID:ownCloud Calendar |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | END:VCALENDAR |
| 320 | 320 | EOD; |
| 321 | 321 | |
| 322 | - $calData[] = <<<'EOD' |
|
| 322 | + $calData[] = <<<'EOD' |
|
| 323 | 323 | BEGIN:VCALENDAR |
| 324 | 324 | VERSION:2.0 |
| 325 | 325 | PRODID:ownCloud Calendar |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | END:VCALENDAR |
| 337 | 337 | EOD; |
| 338 | 338 | |
| 339 | - $calData[] = <<<'EOD' |
|
| 339 | + $calData[] = <<<'EOD' |
|
| 340 | 340 | BEGIN:VCALENDAR |
| 341 | 341 | VERSION:2.0 |
| 342 | 342 | PRODID:ownCloud Calendar |
@@ -353,88 +353,88 @@ discard block |
||
| 353 | 353 | END:VCALENDAR |
| 354 | 354 | EOD; |
| 355 | 355 | |
| 356 | - $uri0 = static::getUniqueID('card'); |
|
| 357 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 358 | - ->method('dispatchTyped'); |
|
| 359 | - $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]); |
|
| 360 | - $uri1 = static::getUniqueID('card'); |
|
| 361 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 362 | - ->method('dispatchTyped'); |
|
| 363 | - $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]); |
|
| 364 | - $uri2 = static::getUniqueID('card'); |
|
| 365 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 366 | - ->method('dispatchTyped'); |
|
| 367 | - $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]); |
|
| 368 | - |
|
| 369 | - // get all the cards |
|
| 370 | - $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 371 | - $this->assertCount(3, $calendarObjects); |
|
| 372 | - |
|
| 373 | - // get the cards |
|
| 374 | - $calendarObjects = $this->backend->getMultipleCalendarObjects($calendarId, [$uri1, $uri2]); |
|
| 375 | - $this->assertCount(2, $calendarObjects); |
|
| 376 | - foreach ($calendarObjects as $card) { |
|
| 377 | - $this->assertArrayHasKey('id', $card); |
|
| 378 | - $this->assertArrayHasKey('uri', $card); |
|
| 379 | - $this->assertArrayHasKey('lastmodified', $card); |
|
| 380 | - $this->assertArrayHasKey('etag', $card); |
|
| 381 | - $this->assertArrayHasKey('size', $card); |
|
| 382 | - $this->assertArrayHasKey('classification', $card); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - usort($calendarObjects, function ($a, $b) { |
|
| 386 | - return $a['id'] - $b['id']; |
|
| 387 | - }); |
|
| 388 | - |
|
| 389 | - $this->assertEquals($calData[1], $calendarObjects[0]['calendardata']); |
|
| 390 | - $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']); |
|
| 391 | - |
|
| 392 | - // delete the card |
|
| 393 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 394 | - ->method('dispatchTyped'); |
|
| 395 | - $this->backend->deleteCalendarObject($calendarId, $uri0); |
|
| 396 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 397 | - ->method('dispatchTyped'); |
|
| 398 | - $this->backend->deleteCalendarObject($calendarId, $uri1); |
|
| 399 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 400 | - ->method('dispatchTyped'); |
|
| 401 | - $this->backend->deleteCalendarObject($calendarId, $uri2); |
|
| 402 | - $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 403 | - $this->assertCount(0, $calendarObjects); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * @dataProvider providesCalendarQueryParameters |
|
| 408 | - */ |
|
| 409 | - public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFilter): void { |
|
| 410 | - $calendarId = $this->createTestCalendar(); |
|
| 411 | - $events = []; |
|
| 412 | - $events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z'); |
|
| 413 | - $events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z'); |
|
| 414 | - $events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z'); |
|
| 415 | - if (PHP_INT_SIZE > 8) { |
|
| 416 | - $events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z'); |
|
| 417 | - } else { |
|
| 418 | - /* On 32bit we do not support events after 2038 */ |
|
| 419 | - $events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z'); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - $result = $this->backend->calendarQuery($calendarId, [ |
|
| 423 | - 'name' => '', |
|
| 424 | - 'prop-filters' => $propFilters, |
|
| 425 | - 'comp-filters' => $compFilter |
|
| 426 | - ]); |
|
| 427 | - |
|
| 428 | - $expectedEventsInResult = array_map(function ($index) use ($events) { |
|
| 429 | - return $events[$index]; |
|
| 430 | - }, $expectedEventsInResult); |
|
| 431 | - $this->assertEqualsCanonicalizing($expectedEventsInResult, $result); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - public function testGetCalendarObjectByUID(): void { |
|
| 435 | - $calendarId = $this->createTestCalendar(); |
|
| 436 | - $uri = static::getUniqueID('calobj'); |
|
| 437 | - $calData = <<<'EOD' |
|
| 356 | + $uri0 = static::getUniqueID('card'); |
|
| 357 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 358 | + ->method('dispatchTyped'); |
|
| 359 | + $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]); |
|
| 360 | + $uri1 = static::getUniqueID('card'); |
|
| 361 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 362 | + ->method('dispatchTyped'); |
|
| 363 | + $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]); |
|
| 364 | + $uri2 = static::getUniqueID('card'); |
|
| 365 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 366 | + ->method('dispatchTyped'); |
|
| 367 | + $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]); |
|
| 368 | + |
|
| 369 | + // get all the cards |
|
| 370 | + $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 371 | + $this->assertCount(3, $calendarObjects); |
|
| 372 | + |
|
| 373 | + // get the cards |
|
| 374 | + $calendarObjects = $this->backend->getMultipleCalendarObjects($calendarId, [$uri1, $uri2]); |
|
| 375 | + $this->assertCount(2, $calendarObjects); |
|
| 376 | + foreach ($calendarObjects as $card) { |
|
| 377 | + $this->assertArrayHasKey('id', $card); |
|
| 378 | + $this->assertArrayHasKey('uri', $card); |
|
| 379 | + $this->assertArrayHasKey('lastmodified', $card); |
|
| 380 | + $this->assertArrayHasKey('etag', $card); |
|
| 381 | + $this->assertArrayHasKey('size', $card); |
|
| 382 | + $this->assertArrayHasKey('classification', $card); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + usort($calendarObjects, function ($a, $b) { |
|
| 386 | + return $a['id'] - $b['id']; |
|
| 387 | + }); |
|
| 388 | + |
|
| 389 | + $this->assertEquals($calData[1], $calendarObjects[0]['calendardata']); |
|
| 390 | + $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']); |
|
| 391 | + |
|
| 392 | + // delete the card |
|
| 393 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 394 | + ->method('dispatchTyped'); |
|
| 395 | + $this->backend->deleteCalendarObject($calendarId, $uri0); |
|
| 396 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 397 | + ->method('dispatchTyped'); |
|
| 398 | + $this->backend->deleteCalendarObject($calendarId, $uri1); |
|
| 399 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 400 | + ->method('dispatchTyped'); |
|
| 401 | + $this->backend->deleteCalendarObject($calendarId, $uri2); |
|
| 402 | + $calendarObjects = $this->backend->getCalendarObjects($calendarId); |
|
| 403 | + $this->assertCount(0, $calendarObjects); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * @dataProvider providesCalendarQueryParameters |
|
| 408 | + */ |
|
| 409 | + public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFilter): void { |
|
| 410 | + $calendarId = $this->createTestCalendar(); |
|
| 411 | + $events = []; |
|
| 412 | + $events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z'); |
|
| 413 | + $events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z'); |
|
| 414 | + $events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z'); |
|
| 415 | + if (PHP_INT_SIZE > 8) { |
|
| 416 | + $events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z'); |
|
| 417 | + } else { |
|
| 418 | + /* On 32bit we do not support events after 2038 */ |
|
| 419 | + $events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z'); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + $result = $this->backend->calendarQuery($calendarId, [ |
|
| 423 | + 'name' => '', |
|
| 424 | + 'prop-filters' => $propFilters, |
|
| 425 | + 'comp-filters' => $compFilter |
|
| 426 | + ]); |
|
| 427 | + |
|
| 428 | + $expectedEventsInResult = array_map(function ($index) use ($events) { |
|
| 429 | + return $events[$index]; |
|
| 430 | + }, $expectedEventsInResult); |
|
| 431 | + $this->assertEqualsCanonicalizing($expectedEventsInResult, $result); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + public function testGetCalendarObjectByUID(): void { |
|
| 435 | + $calendarId = $this->createTestCalendar(); |
|
| 436 | + $uri = static::getUniqueID('calobj'); |
|
| 437 | + $calData = <<<'EOD' |
|
| 438 | 438 | BEGIN:VCALENDAR |
| 439 | 439 | VERSION:2.0 |
| 440 | 440 | PRODID:ownCloud Calendar |
@@ -452,175 +452,175 @@ discard block |
||
| 452 | 452 | EOD; |
| 453 | 453 | |
| 454 | 454 | |
| 455 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 456 | - |
|
| 457 | - $co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8'); |
|
| 458 | - $this->assertNotNull($co); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - public function providesCalendarQueryParameters() { |
|
| 462 | - return [ |
|
| 463 | - 'all' => [[0, 1, 2, 3], [], []], |
|
| 464 | - 'only-todos' => [[], ['name' => 'VTODO'], []], |
|
| 465 | - 'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],], |
|
| 466 | - 'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], |
|
| 467 | - 'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],], |
|
| 468 | - 'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2036-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], |
|
| 469 | - ]; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - public function testCalendarSynchronization(): void { |
|
| 473 | - |
|
| 474 | - // construct calendar for testing |
|
| 475 | - $calendarId = $this->createTestCalendar(); |
|
| 476 | - |
|
| 477 | - /** test fresh sync state with NO events in calendar */ |
|
| 478 | - // construct test state |
|
| 479 | - $stateTest = ['syncToken' => 1, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 480 | - // retrieve live state |
|
| 481 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 482 | - // test live state |
|
| 483 | - $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with NO events in calendar'); |
|
| 484 | - |
|
| 485 | - /** test delta sync state with NO events in calendar */ |
|
| 486 | - // construct test state |
|
| 487 | - $stateTest = ['syncToken' => 1, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 488 | - // retrieve live state |
|
| 489 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '2', 1); |
|
| 490 | - // test live state |
|
| 491 | - $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with NO events in calendar'); |
|
| 492 | - |
|
| 493 | - /** add events to calendar */ |
|
| 494 | - $event1 = $this->createEvent($calendarId, '20240701T130000Z', '20240701T140000Z'); |
|
| 495 | - $event2 = $this->createEvent($calendarId, '20240701T140000Z', '20240701T150000Z'); |
|
| 496 | - $event3 = $this->createEvent($calendarId, '20240701T150000Z', '20240701T160000Z'); |
|
| 497 | - |
|
| 498 | - /** test fresh sync state with events in calendar */ |
|
| 499 | - // construct expected state |
|
| 500 | - $stateTest = ['syncToken' => 4, 'added' => [$event1, $event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 501 | - sort($stateTest['added']); |
|
| 502 | - // retrieve live state |
|
| 503 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 504 | - // sort live state results |
|
| 505 | - sort($stateLive['added']); |
|
| 506 | - sort($stateLive['modified']); |
|
| 507 | - sort($stateLive['deleted']); |
|
| 508 | - // test live state |
|
| 509 | - $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with events in calendar'); |
|
| 510 | - |
|
| 511 | - /** test delta sync state with events in calendar */ |
|
| 512 | - // construct expected state |
|
| 513 | - $stateTest = ['syncToken' => 4, 'added' => [$event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 514 | - sort($stateTest['added']); |
|
| 515 | - // retrieve live state |
|
| 516 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '2', 1); |
|
| 517 | - // sort live state results |
|
| 518 | - sort($stateLive['added']); |
|
| 519 | - sort($stateLive['modified']); |
|
| 520 | - sort($stateLive['deleted']); |
|
| 521 | - // test live state |
|
| 522 | - $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with events in calendar'); |
|
| 523 | - |
|
| 524 | - /** modify/delete events in calendar */ |
|
| 525 | - $this->deleteEvent($calendarId, $event1); |
|
| 526 | - $this->modifyEvent($calendarId, $event2, '20250701T140000Z', '20250701T150000Z'); |
|
| 527 | - |
|
| 528 | - /** test fresh sync state with modified/deleted events in calendar */ |
|
| 529 | - // construct expected state |
|
| 530 | - $stateTest = ['syncToken' => 6, 'added' => [$event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 531 | - sort($stateTest['added']); |
|
| 532 | - // retrieve live state |
|
| 533 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 534 | - // sort live state results |
|
| 535 | - sort($stateLive['added']); |
|
| 536 | - sort($stateLive['modified']); |
|
| 537 | - sort($stateLive['deleted']); |
|
| 538 | - // test live state |
|
| 539 | - $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with modified/deleted events in calendar'); |
|
| 540 | - |
|
| 541 | - /** test delta sync state with modified/deleted events in calendar */ |
|
| 542 | - // construct expected state |
|
| 543 | - $stateTest = ['syncToken' => 6, 'added' => [$event3], 'modified' => [$event2], 'deleted' => [$event1]]; |
|
| 544 | - // retrieve live state |
|
| 545 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '3', 1); |
|
| 546 | - // test live state |
|
| 547 | - $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with modified/deleted events in calendar'); |
|
| 548 | - |
|
| 549 | - /** test delta sync state with modified/deleted events in calendar and invalid token */ |
|
| 550 | - // construct expected state |
|
| 551 | - $stateTest = ['syncToken' => 6, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 552 | - // retrieve live state |
|
| 553 | - $stateLive = $this->backend->getChangesForCalendar($calendarId, '6', 1); |
|
| 554 | - // test live state |
|
| 555 | - $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with modified/deleted events in calendar and invalid token'); |
|
| 556 | - |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - public function testPublications(): void { |
|
| 560 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
| 561 | - ->method('dispatchTyped'); |
|
| 562 | - |
|
| 563 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 564 | - |
|
| 565 | - $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 566 | - |
|
| 567 | - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 568 | - $l10n = $this->createMock(IL10N::class); |
|
| 569 | - $config = $this->createMock(IConfig::class); |
|
| 570 | - $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 571 | - $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger); |
|
| 572 | - $calendar->setPublishStatus(true); |
|
| 573 | - $this->assertNotEquals(false, $calendar->getPublishStatus()); |
|
| 574 | - |
|
| 575 | - $publicCalendars = $this->backend->getPublicCalendars(); |
|
| 576 | - $this->assertCount(1, $publicCalendars); |
|
| 577 | - $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
| 578 | - $this->assertEquals('User\'s displayname', $publicCalendars[0]['{http://nextcloud.com/ns}owner-displayname']); |
|
| 579 | - |
|
| 580 | - $publicCalendarURI = $publicCalendars[0]['uri']; |
|
| 581 | - $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI); |
|
| 582 | - $this->assertEquals(true, $publicCalendar['{http://owncloud.org/ns}public']); |
|
| 583 | - |
|
| 584 | - $calendar->setPublishStatus(false); |
|
| 585 | - $this->assertEquals(false, $calendar->getPublishStatus()); |
|
| 586 | - |
|
| 587 | - $this->expectException(NotFound::class); |
|
| 588 | - $this->backend->getPublicCalendar($publicCalendarURI); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - public function testSubscriptions(): void { |
|
| 592 | - $id = $this->backend->createSubscription(self::UNIT_TEST_USER, 'Subscription', [ |
|
| 593 | - '{http://calendarserver.org/ns/}source' => new Href('test-source'), |
|
| 594 | - '{http://apple.com/ns/ical/}calendar-color' => '#1C4587', |
|
| 595 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => '' |
|
| 596 | - ]); |
|
| 597 | - |
|
| 598 | - $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 599 | - $this->assertCount(1, $subscriptions); |
|
| 600 | - $this->assertEquals('#1C4587', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']); |
|
| 601 | - $this->assertEquals(true, $subscriptions[0]['{http://calendarserver.org/ns/}subscribed-strip-todos']); |
|
| 602 | - $this->assertEquals($id, $subscriptions[0]['id']); |
|
| 603 | - |
|
| 604 | - $patch = new PropPatch([ |
|
| 605 | - '{DAV:}displayname' => 'Unit test', |
|
| 606 | - '{http://apple.com/ns/ical/}calendar-color' => '#ac0606', |
|
| 607 | - ]); |
|
| 608 | - $this->backend->updateSubscription($id, $patch); |
|
| 609 | - $patch->commit(); |
|
| 610 | - |
|
| 611 | - $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 612 | - $this->assertCount(1, $subscriptions); |
|
| 613 | - $this->assertEquals($id, $subscriptions[0]['id']); |
|
| 614 | - $this->assertEquals('Unit test', $subscriptions[0]['{DAV:}displayname']); |
|
| 615 | - $this->assertEquals('#ac0606', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']); |
|
| 616 | - |
|
| 617 | - $this->backend->deleteSubscription($id); |
|
| 618 | - $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 619 | - $this->assertCount(0, $subscriptions); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - public function providesSchedulingData() { |
|
| 623 | - $data = <<<EOS |
|
| 455 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 456 | + |
|
| 457 | + $co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8'); |
|
| 458 | + $this->assertNotNull($co); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + public function providesCalendarQueryParameters() { |
|
| 462 | + return [ |
|
| 463 | + 'all' => [[0, 1, 2, 3], [], []], |
|
| 464 | + 'only-todos' => [[], ['name' => 'VTODO'], []], |
|
| 465 | + 'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],], |
|
| 466 | + 'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], |
|
| 467 | + 'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],], |
|
| 468 | + 'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2036-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],], |
|
| 469 | + ]; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + public function testCalendarSynchronization(): void { |
|
| 473 | + |
|
| 474 | + // construct calendar for testing |
|
| 475 | + $calendarId = $this->createTestCalendar(); |
|
| 476 | + |
|
| 477 | + /** test fresh sync state with NO events in calendar */ |
|
| 478 | + // construct test state |
|
| 479 | + $stateTest = ['syncToken' => 1, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 480 | + // retrieve live state |
|
| 481 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 482 | + // test live state |
|
| 483 | + $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with NO events in calendar'); |
|
| 484 | + |
|
| 485 | + /** test delta sync state with NO events in calendar */ |
|
| 486 | + // construct test state |
|
| 487 | + $stateTest = ['syncToken' => 1, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 488 | + // retrieve live state |
|
| 489 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '2', 1); |
|
| 490 | + // test live state |
|
| 491 | + $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with NO events in calendar'); |
|
| 492 | + |
|
| 493 | + /** add events to calendar */ |
|
| 494 | + $event1 = $this->createEvent($calendarId, '20240701T130000Z', '20240701T140000Z'); |
|
| 495 | + $event2 = $this->createEvent($calendarId, '20240701T140000Z', '20240701T150000Z'); |
|
| 496 | + $event3 = $this->createEvent($calendarId, '20240701T150000Z', '20240701T160000Z'); |
|
| 497 | + |
|
| 498 | + /** test fresh sync state with events in calendar */ |
|
| 499 | + // construct expected state |
|
| 500 | + $stateTest = ['syncToken' => 4, 'added' => [$event1, $event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 501 | + sort($stateTest['added']); |
|
| 502 | + // retrieve live state |
|
| 503 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 504 | + // sort live state results |
|
| 505 | + sort($stateLive['added']); |
|
| 506 | + sort($stateLive['modified']); |
|
| 507 | + sort($stateLive['deleted']); |
|
| 508 | + // test live state |
|
| 509 | + $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with events in calendar'); |
|
| 510 | + |
|
| 511 | + /** test delta sync state with events in calendar */ |
|
| 512 | + // construct expected state |
|
| 513 | + $stateTest = ['syncToken' => 4, 'added' => [$event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 514 | + sort($stateTest['added']); |
|
| 515 | + // retrieve live state |
|
| 516 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '2', 1); |
|
| 517 | + // sort live state results |
|
| 518 | + sort($stateLive['added']); |
|
| 519 | + sort($stateLive['modified']); |
|
| 520 | + sort($stateLive['deleted']); |
|
| 521 | + // test live state |
|
| 522 | + $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with events in calendar'); |
|
| 523 | + |
|
| 524 | + /** modify/delete events in calendar */ |
|
| 525 | + $this->deleteEvent($calendarId, $event1); |
|
| 526 | + $this->modifyEvent($calendarId, $event2, '20250701T140000Z', '20250701T150000Z'); |
|
| 527 | + |
|
| 528 | + /** test fresh sync state with modified/deleted events in calendar */ |
|
| 529 | + // construct expected state |
|
| 530 | + $stateTest = ['syncToken' => 6, 'added' => [$event2, $event3], 'modified' => [], 'deleted' => []]; |
|
| 531 | + sort($stateTest['added']); |
|
| 532 | + // retrieve live state |
|
| 533 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 534 | + // sort live state results |
|
| 535 | + sort($stateLive['added']); |
|
| 536 | + sort($stateLive['modified']); |
|
| 537 | + sort($stateLive['deleted']); |
|
| 538 | + // test live state |
|
| 539 | + $this->assertEquals($stateTest, $stateLive, 'Failed test fresh sync state with modified/deleted events in calendar'); |
|
| 540 | + |
|
| 541 | + /** test delta sync state with modified/deleted events in calendar */ |
|
| 542 | + // construct expected state |
|
| 543 | + $stateTest = ['syncToken' => 6, 'added' => [$event3], 'modified' => [$event2], 'deleted' => [$event1]]; |
|
| 544 | + // retrieve live state |
|
| 545 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '3', 1); |
|
| 546 | + // test live state |
|
| 547 | + $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with modified/deleted events in calendar'); |
|
| 548 | + |
|
| 549 | + /** test delta sync state with modified/deleted events in calendar and invalid token */ |
|
| 550 | + // construct expected state |
|
| 551 | + $stateTest = ['syncToken' => 6, 'added' => [], 'modified' => [], 'deleted' => []]; |
|
| 552 | + // retrieve live state |
|
| 553 | + $stateLive = $this->backend->getChangesForCalendar($calendarId, '6', 1); |
|
| 554 | + // test live state |
|
| 555 | + $this->assertEquals($stateTest, $stateLive, 'Failed test delta sync state with modified/deleted events in calendar and invalid token'); |
|
| 556 | + |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + public function testPublications(): void { |
|
| 560 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
| 561 | + ->method('dispatchTyped'); |
|
| 562 | + |
|
| 563 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 564 | + |
|
| 565 | + $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 566 | + |
|
| 567 | + /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */ |
|
| 568 | + $l10n = $this->createMock(IL10N::class); |
|
| 569 | + $config = $this->createMock(IConfig::class); |
|
| 570 | + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 571 | + $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger); |
|
| 572 | + $calendar->setPublishStatus(true); |
|
| 573 | + $this->assertNotEquals(false, $calendar->getPublishStatus()); |
|
| 574 | + |
|
| 575 | + $publicCalendars = $this->backend->getPublicCalendars(); |
|
| 576 | + $this->assertCount(1, $publicCalendars); |
|
| 577 | + $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); |
|
| 578 | + $this->assertEquals('User\'s displayname', $publicCalendars[0]['{http://nextcloud.com/ns}owner-displayname']); |
|
| 579 | + |
|
| 580 | + $publicCalendarURI = $publicCalendars[0]['uri']; |
|
| 581 | + $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI); |
|
| 582 | + $this->assertEquals(true, $publicCalendar['{http://owncloud.org/ns}public']); |
|
| 583 | + |
|
| 584 | + $calendar->setPublishStatus(false); |
|
| 585 | + $this->assertEquals(false, $calendar->getPublishStatus()); |
|
| 586 | + |
|
| 587 | + $this->expectException(NotFound::class); |
|
| 588 | + $this->backend->getPublicCalendar($publicCalendarURI); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + public function testSubscriptions(): void { |
|
| 592 | + $id = $this->backend->createSubscription(self::UNIT_TEST_USER, 'Subscription', [ |
|
| 593 | + '{http://calendarserver.org/ns/}source' => new Href('test-source'), |
|
| 594 | + '{http://apple.com/ns/ical/}calendar-color' => '#1C4587', |
|
| 595 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => '' |
|
| 596 | + ]); |
|
| 597 | + |
|
| 598 | + $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 599 | + $this->assertCount(1, $subscriptions); |
|
| 600 | + $this->assertEquals('#1C4587', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']); |
|
| 601 | + $this->assertEquals(true, $subscriptions[0]['{http://calendarserver.org/ns/}subscribed-strip-todos']); |
|
| 602 | + $this->assertEquals($id, $subscriptions[0]['id']); |
|
| 603 | + |
|
| 604 | + $patch = new PropPatch([ |
|
| 605 | + '{DAV:}displayname' => 'Unit test', |
|
| 606 | + '{http://apple.com/ns/ical/}calendar-color' => '#ac0606', |
|
| 607 | + ]); |
|
| 608 | + $this->backend->updateSubscription($id, $patch); |
|
| 609 | + $patch->commit(); |
|
| 610 | + |
|
| 611 | + $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 612 | + $this->assertCount(1, $subscriptions); |
|
| 613 | + $this->assertEquals($id, $subscriptions[0]['id']); |
|
| 614 | + $this->assertEquals('Unit test', $subscriptions[0]['{DAV:}displayname']); |
|
| 615 | + $this->assertEquals('#ac0606', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']); |
|
| 616 | + |
|
| 617 | + $this->backend->deleteSubscription($id); |
|
| 618 | + $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
| 619 | + $this->assertCount(0, $subscriptions); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + public function providesSchedulingData() { |
|
| 623 | + $data = <<<EOS |
|
| 624 | 624 | BEGIN:VCALENDAR |
| 625 | 625 | VERSION:2.0 |
| 626 | 626 | PRODID:-//Sabre//Sabre VObject 3.5.0//EN |
@@ -685,74 +685,74 @@ discard block |
||
| 685 | 685 | END:VCALENDAR |
| 686 | 686 | EOS; |
| 687 | 687 | |
| 688 | - return [ |
|
| 689 | - 'no data' => [''], |
|
| 690 | - 'failing on postgres' => [$data] |
|
| 691 | - ]; |
|
| 692 | - } |
|
| 688 | + return [ |
|
| 689 | + 'no data' => [''], |
|
| 690 | + 'failing on postgres' => [$data] |
|
| 691 | + ]; |
|
| 692 | + } |
|
| 693 | 693 | |
| 694 | - /** |
|
| 695 | - * @dataProvider providesSchedulingData |
|
| 696 | - * @param $objectData |
|
| 697 | - */ |
|
| 698 | - public function testScheduling($objectData): void { |
|
| 699 | - $this->backend->createSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule', $objectData); |
|
| 694 | + /** |
|
| 695 | + * @dataProvider providesSchedulingData |
|
| 696 | + * @param $objectData |
|
| 697 | + */ |
|
| 698 | + public function testScheduling($objectData): void { |
|
| 699 | + $this->backend->createSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule', $objectData); |
|
| 700 | 700 | |
| 701 | - $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER); |
|
| 702 | - $this->assertCount(1, $sos); |
|
| 701 | + $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER); |
|
| 702 | + $this->assertCount(1, $sos); |
|
| 703 | 703 | |
| 704 | - $so = $this->backend->getSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule'); |
|
| 705 | - $this->assertNotNull($so); |
|
| 704 | + $so = $this->backend->getSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule'); |
|
| 705 | + $this->assertNotNull($so); |
|
| 706 | 706 | |
| 707 | - $this->backend->deleteSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule'); |
|
| 707 | + $this->backend->deleteSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule'); |
|
| 708 | 708 | |
| 709 | - $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER); |
|
| 710 | - $this->assertCount(0, $sos); |
|
| 711 | - } |
|
| 709 | + $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER); |
|
| 710 | + $this->assertCount(0, $sos); |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * @dataProvider providesCalDataForGetDenormalizedData |
|
| 715 | - */ |
|
| 716 | - public function testGetDenormalizedData($expected, $key, $calData): void { |
|
| 717 | - try { |
|
| 718 | - $actual = $this->backend->getDenormalizedData($calData); |
|
| 719 | - $this->assertEquals($expected, $actual[$key]); |
|
| 720 | - } catch (\Throwable $e) { |
|
| 721 | - if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) { |
|
| 722 | - $this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime'); |
|
| 723 | - } |
|
| 724 | - throw $e; |
|
| 725 | - } |
|
| 726 | - } |
|
| 713 | + /** |
|
| 714 | + * @dataProvider providesCalDataForGetDenormalizedData |
|
| 715 | + */ |
|
| 716 | + public function testGetDenormalizedData($expected, $key, $calData): void { |
|
| 717 | + try { |
|
| 718 | + $actual = $this->backend->getDenormalizedData($calData); |
|
| 719 | + $this->assertEquals($expected, $actual[$key]); |
|
| 720 | + } catch (\Throwable $e) { |
|
| 721 | + if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) { |
|
| 722 | + $this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime'); |
|
| 723 | + } |
|
| 724 | + throw $e; |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | 727 | |
| 728 | - public function providesCalDataForGetDenormalizedData(): array { |
|
| 729 | - return [ |
|
| 730 | - 'first occurrence before unix epoch starts' => [0, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nDTSTART;VALUE=DATE:16040222\r\nDTEND;VALUE=DATE:16040223\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 731 | - 'no first occurrence because yearly' => [null, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 728 | + public function providesCalDataForGetDenormalizedData(): array { |
|
| 729 | + return [ |
|
| 730 | + 'first occurrence before unix epoch starts' => [0, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nDTSTART;VALUE=DATE:16040222\r\nDTEND;VALUE=DATE:16040223\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 731 | + 'no first occurrence because yearly' => [null, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 732 | 732 | |
| 733 | - 'last occurrence is max when only last VEVENT in group is weekly' => [(new DateTime(CalDavBackend::MAX_DATE))->getTimestamp(), 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200812T103000\r\nDTEND;TZID=America/Los_Angeles:20200812T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20200811T123000\r\nCREATED:20200626T181848Z\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200728T123000\r\nDTEND;TZID=America/Los_Angeles:20200728T130000\r\nEXDATE;TZID=America/Los_Angeles:20200818T123000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Setting up recurring time on our calendars\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 733 | + 'last occurrence is max when only last VEVENT in group is weekly' => [(new DateTime(CalDavBackend::MAX_DATE))->getTimestamp(), 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200812T103000\r\nDTEND;TZID=America/Los_Angeles:20200812T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20200811T123000\r\nCREATED:20200626T181848Z\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200728T123000\r\nDTEND;TZID=America/Los_Angeles:20200728T130000\r\nEXDATE;TZID=America/Los_Angeles:20200818T123000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Setting up recurring time on our calendars\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 734 | 734 | |
| 735 | - 'last occurrence before unix epoch starts' => [0, 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:19110324\r\nDTEND;VALUE=DATE:19110325\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Very old event\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Some old event\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 735 | + 'last occurrence before unix epoch starts' => [0, 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:19110324\r\nDTEND;VALUE=DATE:19110325\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Very old event\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Some old event\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 736 | 736 | |
| 737 | - 'first occurrence is found when not first VEVENT in group' => [(new DateTime('2020-09-01T110000', new DateTimeZone('America/Los_Angeles')))->getTimestamp(), 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20201013T110000\r\nDTEND;TZID=America/Los_Angeles:20201013T120000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20201013T110000\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200925T042014Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200901T110000\r\nDTEND;TZID=America/Los_Angeles:20200901T120000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nEXDATE;TZID=America/Los_Angeles:20200922T110000\r\nEXDATE;TZID=America/Los_Angeles:20200915T110000\r\nEXDATE;TZID=America/Los_Angeles:20200908T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200915T162810Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 737 | + 'first occurrence is found when not first VEVENT in group' => [(new DateTime('2020-09-01T110000', new DateTimeZone('America/Los_Angeles')))->getTimestamp(), 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20201013T110000\r\nDTEND;TZID=America/Los_Angeles:20201013T120000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20201013T110000\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200925T042014Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200901T110000\r\nDTEND;TZID=America/Los_Angeles:20200901T120000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nEXDATE;TZID=America/Los_Angeles:20200922T110000\r\nEXDATE;TZID=America/Los_Angeles:20200915T110000\r\nEXDATE;TZID=America/Los_Angeles:20200908T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:[email protected]\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200915T162810Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], |
|
| 738 | 738 | |
| 739 | - 'CLASS:PRIVATE' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PRIVATE\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 739 | + 'CLASS:PRIVATE' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PRIVATE\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 740 | 740 | |
| 741 | - 'CLASS:PUBLIC' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PUBLIC\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 741 | + 'CLASS:PUBLIC' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PUBLIC\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 742 | 742 | |
| 743 | - 'CLASS:CONFIDENTIAL' => [CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:CONFIDENTIAL\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 743 | + 'CLASS:CONFIDENTIAL' => [CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:CONFIDENTIAL\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 744 | 744 | |
| 745 | - 'no class set -> public' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nTRANSP:OPAQUE\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 745 | + 'no class set -> public' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nTRANSP:OPAQUE\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 746 | 746 | |
| 747 | - 'unknown class -> private' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:VERTRAULICH\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 748 | - ]; |
|
| 749 | - } |
|
| 747 | + 'unknown class -> private' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:VERTRAULICH\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"], |
|
| 748 | + ]; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - public function testCalendarSearch(): void { |
|
| 752 | - $calendarId = $this->createTestCalendar(); |
|
| 751 | + public function testCalendarSearch(): void { |
|
| 752 | + $calendarId = $this->createTestCalendar(); |
|
| 753 | 753 | |
| 754 | - $uri = static::getUniqueID('calobj'); |
|
| 755 | - $calData = <<<EOD |
|
| 754 | + $uri = static::getUniqueID('calobj'); |
|
| 755 | + $calData = <<<EOD |
|
| 756 | 756 | BEGIN:VCALENDAR |
| 757 | 757 | VERSION:2.0 |
| 758 | 758 | PRODID:ownCloud Calendar |
@@ -769,24 +769,24 @@ discard block |
||
| 769 | 769 | END:VCALENDAR |
| 770 | 770 | EOD; |
| 771 | 771 | |
| 772 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 772 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 773 | 773 | |
| 774 | - $search1 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 775 | - 'comps' => [ |
|
| 776 | - 'VEVENT', |
|
| 777 | - 'VTODO' |
|
| 778 | - ], |
|
| 779 | - 'props' => [ |
|
| 780 | - 'SUMMARY', |
|
| 781 | - 'LOCATION' |
|
| 782 | - ], |
|
| 783 | - 'search-term' => 'Test', |
|
| 784 | - ]); |
|
| 785 | - $this->assertEquals(count($search1), 1); |
|
| 774 | + $search1 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 775 | + 'comps' => [ |
|
| 776 | + 'VEVENT', |
|
| 777 | + 'VTODO' |
|
| 778 | + ], |
|
| 779 | + 'props' => [ |
|
| 780 | + 'SUMMARY', |
|
| 781 | + 'LOCATION' |
|
| 782 | + ], |
|
| 783 | + 'search-term' => 'Test', |
|
| 784 | + ]); |
|
| 785 | + $this->assertEquals(count($search1), 1); |
|
| 786 | 786 | |
| 787 | 787 | |
| 788 | - // update the card |
|
| 789 | - $calData = <<<'EOD' |
|
| 788 | + // update the card |
|
| 789 | + $calData = <<<'EOD' |
|
| 790 | 790 | BEGIN:VCALENDAR |
| 791 | 791 | VERSION:2.0 |
| 792 | 792 | PRODID:ownCloud Calendar |
@@ -802,93 +802,93 @@ discard block |
||
| 802 | 802 | END:VEVENT |
| 803 | 803 | END:VCALENDAR |
| 804 | 804 | EOD; |
| 805 | - $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 806 | - |
|
| 807 | - $search2 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 808 | - 'comps' => [ |
|
| 809 | - 'VEVENT', |
|
| 810 | - 'VTODO' |
|
| 811 | - ], |
|
| 812 | - 'props' => [ |
|
| 813 | - 'SUMMARY', |
|
| 814 | - 'LOCATION' |
|
| 815 | - ], |
|
| 816 | - 'search-term' => 'Test', |
|
| 817 | - ]); |
|
| 818 | - $this->assertEquals(count($search2), 0); |
|
| 819 | - |
|
| 820 | - $search3 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 821 | - 'comps' => [ |
|
| 822 | - 'VEVENT', |
|
| 823 | - 'VTODO' |
|
| 824 | - ], |
|
| 825 | - 'props' => [ |
|
| 826 | - 'SUMMARY', |
|
| 827 | - 'LOCATION' |
|
| 828 | - ], |
|
| 829 | - 'params' => [ |
|
| 830 | - [ |
|
| 831 | - 'property' => 'ATTENDEE', |
|
| 832 | - 'parameter' => 'CN' |
|
| 833 | - ] |
|
| 834 | - ], |
|
| 835 | - 'search-term' => 'Test', |
|
| 836 | - ]); |
|
| 837 | - $this->assertEquals(count($search3), 1); |
|
| 838 | - |
|
| 839 | - // t matches both summary and attendee's CN, but we want unique results |
|
| 840 | - $search4 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 841 | - 'comps' => [ |
|
| 842 | - 'VEVENT', |
|
| 843 | - 'VTODO' |
|
| 844 | - ], |
|
| 845 | - 'props' => [ |
|
| 846 | - 'SUMMARY', |
|
| 847 | - 'LOCATION' |
|
| 848 | - ], |
|
| 849 | - 'params' => [ |
|
| 850 | - [ |
|
| 851 | - 'property' => 'ATTENDEE', |
|
| 852 | - 'parameter' => 'CN' |
|
| 853 | - ] |
|
| 854 | - ], |
|
| 855 | - 'search-term' => 't', |
|
| 856 | - ]); |
|
| 857 | - $this->assertEquals(count($search4), 1); |
|
| 858 | - |
|
| 859 | - $this->backend->deleteCalendarObject($calendarId, $uri); |
|
| 860 | - |
|
| 861 | - $search5 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 862 | - 'comps' => [ |
|
| 863 | - 'VEVENT', |
|
| 864 | - 'VTODO' |
|
| 865 | - ], |
|
| 866 | - 'props' => [ |
|
| 867 | - 'SUMMARY', |
|
| 868 | - 'LOCATION' |
|
| 869 | - ], |
|
| 870 | - 'params' => [ |
|
| 871 | - [ |
|
| 872 | - 'property' => 'ATTENDEE', |
|
| 873 | - 'parameter' => 'CN' |
|
| 874 | - ] |
|
| 875 | - ], |
|
| 876 | - 'search-term' => 't', |
|
| 877 | - ]); |
|
| 878 | - $this->assertEquals(count($search5), 0); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - /** |
|
| 882 | - * @dataProvider searchDataProvider |
|
| 883 | - */ |
|
| 884 | - public function testSearch(bool $isShared, array $searchOptions, int $count): void { |
|
| 885 | - $calendarId = $this->createTestCalendar(); |
|
| 886 | - |
|
| 887 | - $uris = []; |
|
| 888 | - $calData = []; |
|
| 889 | - |
|
| 890 | - $uris[] = static::getUniqueID('calobj'); |
|
| 891 | - $calData[] = <<<EOD |
|
| 805 | + $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 806 | + |
|
| 807 | + $search2 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 808 | + 'comps' => [ |
|
| 809 | + 'VEVENT', |
|
| 810 | + 'VTODO' |
|
| 811 | + ], |
|
| 812 | + 'props' => [ |
|
| 813 | + 'SUMMARY', |
|
| 814 | + 'LOCATION' |
|
| 815 | + ], |
|
| 816 | + 'search-term' => 'Test', |
|
| 817 | + ]); |
|
| 818 | + $this->assertEquals(count($search2), 0); |
|
| 819 | + |
|
| 820 | + $search3 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 821 | + 'comps' => [ |
|
| 822 | + 'VEVENT', |
|
| 823 | + 'VTODO' |
|
| 824 | + ], |
|
| 825 | + 'props' => [ |
|
| 826 | + 'SUMMARY', |
|
| 827 | + 'LOCATION' |
|
| 828 | + ], |
|
| 829 | + 'params' => [ |
|
| 830 | + [ |
|
| 831 | + 'property' => 'ATTENDEE', |
|
| 832 | + 'parameter' => 'CN' |
|
| 833 | + ] |
|
| 834 | + ], |
|
| 835 | + 'search-term' => 'Test', |
|
| 836 | + ]); |
|
| 837 | + $this->assertEquals(count($search3), 1); |
|
| 838 | + |
|
| 839 | + // t matches both summary and attendee's CN, but we want unique results |
|
| 840 | + $search4 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 841 | + 'comps' => [ |
|
| 842 | + 'VEVENT', |
|
| 843 | + 'VTODO' |
|
| 844 | + ], |
|
| 845 | + 'props' => [ |
|
| 846 | + 'SUMMARY', |
|
| 847 | + 'LOCATION' |
|
| 848 | + ], |
|
| 849 | + 'params' => [ |
|
| 850 | + [ |
|
| 851 | + 'property' => 'ATTENDEE', |
|
| 852 | + 'parameter' => 'CN' |
|
| 853 | + ] |
|
| 854 | + ], |
|
| 855 | + 'search-term' => 't', |
|
| 856 | + ]); |
|
| 857 | + $this->assertEquals(count($search4), 1); |
|
| 858 | + |
|
| 859 | + $this->backend->deleteCalendarObject($calendarId, $uri); |
|
| 860 | + |
|
| 861 | + $search5 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [ |
|
| 862 | + 'comps' => [ |
|
| 863 | + 'VEVENT', |
|
| 864 | + 'VTODO' |
|
| 865 | + ], |
|
| 866 | + 'props' => [ |
|
| 867 | + 'SUMMARY', |
|
| 868 | + 'LOCATION' |
|
| 869 | + ], |
|
| 870 | + 'params' => [ |
|
| 871 | + [ |
|
| 872 | + 'property' => 'ATTENDEE', |
|
| 873 | + 'parameter' => 'CN' |
|
| 874 | + ] |
|
| 875 | + ], |
|
| 876 | + 'search-term' => 't', |
|
| 877 | + ]); |
|
| 878 | + $this->assertEquals(count($search5), 0); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + /** |
|
| 882 | + * @dataProvider searchDataProvider |
|
| 883 | + */ |
|
| 884 | + public function testSearch(bool $isShared, array $searchOptions, int $count): void { |
|
| 885 | + $calendarId = $this->createTestCalendar(); |
|
| 886 | + |
|
| 887 | + $uris = []; |
|
| 888 | + $calData = []; |
|
| 889 | + |
|
| 890 | + $uris[] = static::getUniqueID('calobj'); |
|
| 891 | + $calData[] = <<<EOD |
|
| 892 | 892 | BEGIN:VCALENDAR |
| 893 | 893 | VERSION:2.0 |
| 894 | 894 | PRODID:Nextcloud Calendar |
@@ -905,8 +905,8 @@ discard block |
||
| 905 | 905 | END:VCALENDAR |
| 906 | 906 | EOD; |
| 907 | 907 | |
| 908 | - $uris[] = static::getUniqueID('calobj'); |
|
| 909 | - $calData[] = <<<EOD |
|
| 908 | + $uris[] = static::getUniqueID('calobj'); |
|
| 909 | + $calData[] = <<<EOD |
|
| 910 | 910 | BEGIN:VCALENDAR |
| 911 | 911 | VERSION:2.0 |
| 912 | 912 | PRODID:Nextcloud Calendar |
@@ -924,8 +924,8 @@ discard block |
||
| 924 | 924 | END:VCALENDAR |
| 925 | 925 | EOD; |
| 926 | 926 | |
| 927 | - $uris[] = static::getUniqueID('calobj'); |
|
| 928 | - $calData[] = <<<EOD |
|
| 927 | + $uris[] = static::getUniqueID('calobj'); |
|
| 928 | + $calData[] = <<<EOD |
|
| 929 | 929 | BEGIN:VCALENDAR |
| 930 | 930 | VERSION:2.0 |
| 931 | 931 | PRODID:Nextcloud Calendar |
@@ -943,8 +943,8 @@ discard block |
||
| 943 | 943 | END:VCALENDAR |
| 944 | 944 | EOD; |
| 945 | 945 | |
| 946 | - $uris[] = static::getUniqueID('calobj'); |
|
| 947 | - $calData[] = <<<EOD |
|
| 946 | + $uris[] = static::getUniqueID('calobj'); |
|
| 947 | + $calData[] = <<<EOD |
|
| 948 | 948 | BEGIN:VCALENDAR |
| 949 | 949 | VERSION:2.0 |
| 950 | 950 | PRODID:Nextcloud Calendar |
@@ -962,38 +962,38 @@ discard block |
||
| 962 | 962 | END:VCALENDAR |
| 963 | 963 | EOD; |
| 964 | 964 | |
| 965 | - $uriCount = count($uris); |
|
| 966 | - for ($i = 0; $i < $uriCount; $i++) { |
|
| 967 | - $this->backend->createCalendarObject($calendarId, |
|
| 968 | - $uris[$i], $calData[$i]); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - $calendarInfo = [ |
|
| 972 | - 'id' => $calendarId, |
|
| 973 | - 'principaluri' => 'user1', |
|
| 974 | - '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1', |
|
| 975 | - ]; |
|
| 976 | - |
|
| 977 | - $result = $this->backend->search($calendarInfo, 'Test', |
|
| 978 | - ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null); |
|
| 979 | - |
|
| 980 | - $this->assertCount($count, $result); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - public function searchDataProvider() { |
|
| 984 | - return [ |
|
| 985 | - [false, [], 4], |
|
| 986 | - [true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2], |
|
| 987 | - [true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0], |
|
| 988 | - ]; |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - public function testSameUriSameIdForDifferentCalendarTypes(): void { |
|
| 992 | - $calendarId = $this->createTestCalendar(); |
|
| 993 | - $subscriptionId = $this->createTestSubscription(); |
|
| 994 | - |
|
| 995 | - $uri = static::getUniqueID('calobj'); |
|
| 996 | - $calData = <<<EOD |
|
| 965 | + $uriCount = count($uris); |
|
| 966 | + for ($i = 0; $i < $uriCount; $i++) { |
|
| 967 | + $this->backend->createCalendarObject($calendarId, |
|
| 968 | + $uris[$i], $calData[$i]); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + $calendarInfo = [ |
|
| 972 | + 'id' => $calendarId, |
|
| 973 | + 'principaluri' => 'user1', |
|
| 974 | + '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1', |
|
| 975 | + ]; |
|
| 976 | + |
|
| 977 | + $result = $this->backend->search($calendarInfo, 'Test', |
|
| 978 | + ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null); |
|
| 979 | + |
|
| 980 | + $this->assertCount($count, $result); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + public function searchDataProvider() { |
|
| 984 | + return [ |
|
| 985 | + [false, [], 4], |
|
| 986 | + [true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2], |
|
| 987 | + [true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0], |
|
| 988 | + ]; |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + public function testSameUriSameIdForDifferentCalendarTypes(): void { |
|
| 992 | + $calendarId = $this->createTestCalendar(); |
|
| 993 | + $subscriptionId = $this->createTestSubscription(); |
|
| 994 | + |
|
| 995 | + $uri = static::getUniqueID('calobj'); |
|
| 996 | + $calData = <<<EOD |
|
| 997 | 997 | BEGIN:VCALENDAR |
| 998 | 998 | VERSION:2.0 |
| 999 | 999 | PRODID:ownCloud Calendar |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | END:VCALENDAR |
| 1011 | 1011 | EOD; |
| 1012 | 1012 | |
| 1013 | - $calData2 = <<<EOD |
|
| 1013 | + $calData2 = <<<EOD |
|
| 1014 | 1014 | BEGIN:VCALENDAR |
| 1015 | 1015 | VERSION:2.0 |
| 1016 | 1016 | PRODID:ownCloud Calendar |
@@ -1027,17 +1027,17 @@ discard block |
||
| 1027 | 1027 | END:VCALENDAR |
| 1028 | 1028 | EOD; |
| 1029 | 1029 | |
| 1030 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1031 | - $this->backend->createCalendarObject($subscriptionId, $uri, $calData2, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
| 1030 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1031 | + $this->backend->createCalendarObject($subscriptionId, $uri, $calData2, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
| 1032 | 1032 | |
| 1033 | - $this->assertEquals($calData, $this->backend->getCalendarObject($calendarId, $uri, CalDavBackend::CALENDAR_TYPE_CALENDAR)['calendardata']); |
|
| 1034 | - $this->assertEquals($calData2, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)['calendardata']); |
|
| 1035 | - } |
|
| 1033 | + $this->assertEquals($calData, $this->backend->getCalendarObject($calendarId, $uri, CalDavBackend::CALENDAR_TYPE_CALENDAR)['calendardata']); |
|
| 1034 | + $this->assertEquals($calData2, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)['calendardata']); |
|
| 1035 | + } |
|
| 1036 | 1036 | |
| 1037 | - public function testPurgeAllCachedEventsForSubscription(): void { |
|
| 1038 | - $subscriptionId = $this->createTestSubscription(); |
|
| 1039 | - $uri = static::getUniqueID('calobj'); |
|
| 1040 | - $calData = <<<EOD |
|
| 1037 | + public function testPurgeAllCachedEventsForSubscription(): void { |
|
| 1038 | + $subscriptionId = $this->createTestSubscription(); |
|
| 1039 | + $uri = static::getUniqueID('calobj'); |
|
| 1040 | + $calData = <<<EOD |
|
| 1041 | 1041 | BEGIN:VCALENDAR |
| 1042 | 1042 | VERSION:2.0 |
| 1043 | 1043 | PRODID:ownCloud Calendar |
@@ -1054,30 +1054,30 @@ discard block |
||
| 1054 | 1054 | END:VCALENDAR |
| 1055 | 1055 | EOD; |
| 1056 | 1056 | |
| 1057 | - $this->backend->createCalendarObject($subscriptionId, $uri, $calData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
| 1058 | - $this->backend->purgeAllCachedEventsForSubscription($subscriptionId); |
|
| 1057 | + $this->backend->createCalendarObject($subscriptionId, $uri, $calData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
| 1058 | + $this->backend->purgeAllCachedEventsForSubscription($subscriptionId); |
|
| 1059 | 1059 | |
| 1060 | - $this->assertEquals(null, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)); |
|
| 1061 | - } |
|
| 1060 | + $this->assertEquals(null, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)); |
|
| 1061 | + } |
|
| 1062 | 1062 | |
| 1063 | - public function testCalendarMovement(): void { |
|
| 1064 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 1063 | + public function testCalendarMovement(): void { |
|
| 1064 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); |
|
| 1065 | 1065 | |
| 1066 | - $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); |
|
| 1066 | + $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); |
|
| 1067 | 1067 | |
| 1068 | - $calendarInfoUser = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 1068 | + $calendarInfoUser = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; |
|
| 1069 | 1069 | |
| 1070 | - $this->backend->moveCalendar('Example', self::UNIT_TEST_USER, self::UNIT_TEST_USER1); |
|
| 1071 | - $this->assertCount(0, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); |
|
| 1072 | - $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)); |
|
| 1070 | + $this->backend->moveCalendar('Example', self::UNIT_TEST_USER, self::UNIT_TEST_USER1); |
|
| 1071 | + $this->assertCount(0, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); |
|
| 1072 | + $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)); |
|
| 1073 | 1073 | |
| 1074 | - $calendarInfoUser1 = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)[0]; |
|
| 1075 | - $this->assertEquals($calendarInfoUser['id'], $calendarInfoUser1['id']); |
|
| 1076 | - $this->assertEquals($calendarInfoUser['uri'], $calendarInfoUser1['uri']); |
|
| 1077 | - } |
|
| 1074 | + $calendarInfoUser1 = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)[0]; |
|
| 1075 | + $this->assertEquals($calendarInfoUser['id'], $calendarInfoUser1['id']); |
|
| 1076 | + $this->assertEquals($calendarInfoUser['uri'], $calendarInfoUser1['uri']); |
|
| 1077 | + } |
|
| 1078 | 1078 | |
| 1079 | - public function testSearchPrincipal(): void { |
|
| 1080 | - $myPublic = <<<EOD |
|
| 1079 | + public function testSearchPrincipal(): void { |
|
| 1080 | + $myPublic = <<<EOD |
|
| 1081 | 1081 | BEGIN:VCALENDAR |
| 1082 | 1082 | VERSION:2.0 |
| 1083 | 1083 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | END:VEVENT |
| 1114 | 1114 | END:VCALENDAR |
| 1115 | 1115 | EOD; |
| 1116 | - $myPrivate = <<<EOD |
|
| 1116 | + $myPrivate = <<<EOD |
|
| 1117 | 1117 | BEGIN:VCALENDAR |
| 1118 | 1118 | VERSION:2.0 |
| 1119 | 1119 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | END:VEVENT |
| 1150 | 1150 | END:VCALENDAR |
| 1151 | 1151 | EOD; |
| 1152 | - $myConfidential = <<<EOD |
|
| 1152 | + $myConfidential = <<<EOD |
|
| 1153 | 1153 | BEGIN:VCALENDAR |
| 1154 | 1154 | VERSION:2.0 |
| 1155 | 1155 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | END:VCALENDAR |
| 1187 | 1187 | EOD; |
| 1188 | 1188 | |
| 1189 | - $sharerPublic = <<<EOD |
|
| 1189 | + $sharerPublic = <<<EOD |
|
| 1190 | 1190 | BEGIN:VCALENDAR |
| 1191 | 1191 | VERSION:2.0 |
| 1192 | 1192 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1222,7 +1222,7 @@ discard block |
||
| 1222 | 1222 | END:VEVENT |
| 1223 | 1223 | END:VCALENDAR |
| 1224 | 1224 | EOD; |
| 1225 | - $sharerPrivate = <<<EOD |
|
| 1225 | + $sharerPrivate = <<<EOD |
|
| 1226 | 1226 | BEGIN:VCALENDAR |
| 1227 | 1227 | VERSION:2.0 |
| 1228 | 1228 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1258,7 +1258,7 @@ discard block |
||
| 1258 | 1258 | END:VEVENT |
| 1259 | 1259 | END:VCALENDAR |
| 1260 | 1260 | EOD; |
| 1261 | - $sharerConfidential = <<<EOD |
|
| 1261 | + $sharerConfidential = <<<EOD |
|
| 1262 | 1262 | BEGIN:VCALENDAR |
| 1263 | 1263 | VERSION:2.0 |
| 1264 | 1264 | PRODID:-//dmfs.org//mimedir.icalendar//EN |
@@ -1295,81 +1295,81 @@ discard block |
||
| 1295 | 1295 | END:VCALENDAR |
| 1296 | 1296 | EOD; |
| 1297 | 1297 | |
| 1298 | - $l10n = $this->createMock(IL10N::class); |
|
| 1299 | - $l10n |
|
| 1300 | - ->expects($this->any()) |
|
| 1301 | - ->method('t') |
|
| 1302 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
| 1303 | - return vsprintf($text, $parameters); |
|
| 1304 | - }); |
|
| 1305 | - $config = $this->createMock(IConfig::class); |
|
| 1306 | - $this->userManager->expects($this->any()) |
|
| 1307 | - ->method('userExists') |
|
| 1308 | - ->willReturn(true); |
|
| 1309 | - $this->groupManager->expects($this->any()) |
|
| 1310 | - ->method('groupExists') |
|
| 1311 | - ->willReturn(true); |
|
| 1312 | - $this->principal->expects(self::atLeastOnce()) |
|
| 1313 | - ->method('findByUri') |
|
| 1314 | - ->willReturn(self::UNIT_TEST_USER); |
|
| 1315 | - |
|
| 1316 | - $me = self::UNIT_TEST_USER; |
|
| 1317 | - $sharer = self::UNIT_TEST_USER1; |
|
| 1318 | - $this->backend->createCalendar($me, 'calendar-uri-me', []); |
|
| 1319 | - $this->backend->createCalendar($sharer, 'calendar-uri-sharer', []); |
|
| 1320 | - |
|
| 1321 | - $myCalendars = $this->backend->getCalendarsForUser($me); |
|
| 1322 | - $this->assertCount(1, $myCalendars); |
|
| 1323 | - |
|
| 1324 | - $sharerCalendars = $this->backend->getCalendarsForUser($sharer); |
|
| 1325 | - $this->assertCount(1, $sharerCalendars); |
|
| 1326 | - |
|
| 1327 | - $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 1328 | - $sharerCalendar = new Calendar($this->backend, $sharerCalendars[0], $l10n, $config, $logger); |
|
| 1329 | - $this->backend->updateShares($sharerCalendar, [ |
|
| 1330 | - [ |
|
| 1331 | - 'href' => 'principal:' . $me, |
|
| 1332 | - 'readOnly' => false, |
|
| 1333 | - ], |
|
| 1334 | - ], []); |
|
| 1335 | - |
|
| 1336 | - $this->assertCount(2, $this->backend->getCalendarsForUser($me)); |
|
| 1337 | - |
|
| 1338 | - $this->backend->createCalendarObject($myCalendars[0]['id'], 'event0.ics', $myPublic); |
|
| 1339 | - $this->backend->createCalendarObject($myCalendars[0]['id'], 'event1.ics', $myPrivate); |
|
| 1340 | - $this->backend->createCalendarObject($myCalendars[0]['id'], 'event2.ics', $myConfidential); |
|
| 1341 | - |
|
| 1342 | - $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event3.ics', $sharerPublic); |
|
| 1343 | - $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event4.ics', $sharerPrivate); |
|
| 1344 | - $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event5.ics', $sharerConfidential); |
|
| 1345 | - |
|
| 1346 | - $mySearchResults = $this->backend->searchPrincipalUri($me, 'Test', ['VEVENT'], ['SUMMARY'], []); |
|
| 1347 | - $sharerSearchResults = $this->backend->searchPrincipalUri($sharer, 'Test', ['VEVENT'], ['SUMMARY'], []); |
|
| 1348 | - |
|
| 1349 | - $this->assertCount(4, $mySearchResults); |
|
| 1350 | - $this->assertCount(3, $sharerSearchResults); |
|
| 1351 | - |
|
| 1352 | - $this->assertEquals($myPublic, $mySearchResults[0]['calendardata']); |
|
| 1353 | - $this->assertEquals($myPrivate, $mySearchResults[1]['calendardata']); |
|
| 1354 | - $this->assertEquals($myConfidential, $mySearchResults[2]['calendardata']); |
|
| 1355 | - $this->assertEquals($sharerPublic, $mySearchResults[3]['calendardata']); |
|
| 1356 | - |
|
| 1357 | - $this->assertEquals($sharerPublic, $sharerSearchResults[0]['calendardata']); |
|
| 1358 | - $this->assertEquals($sharerPrivate, $sharerSearchResults[1]['calendardata']); |
|
| 1359 | - $this->assertEquals($sharerConfidential, $sharerSearchResults[2]['calendardata']); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * @throws \OCP\DB\Exception |
|
| 1364 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 1365 | - */ |
|
| 1366 | - public function testPruneOutdatedSyncTokens(): void { |
|
| 1367 | - $calendarId = $this->createTestCalendar(); |
|
| 1368 | - $changes = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 1369 | - $syncToken = $changes['syncToken']; |
|
| 1370 | - |
|
| 1371 | - $uri = static::getUniqueID('calobj'); |
|
| 1372 | - $calData = <<<EOD |
|
| 1298 | + $l10n = $this->createMock(IL10N::class); |
|
| 1299 | + $l10n |
|
| 1300 | + ->expects($this->any()) |
|
| 1301 | + ->method('t') |
|
| 1302 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
| 1303 | + return vsprintf($text, $parameters); |
|
| 1304 | + }); |
|
| 1305 | + $config = $this->createMock(IConfig::class); |
|
| 1306 | + $this->userManager->expects($this->any()) |
|
| 1307 | + ->method('userExists') |
|
| 1308 | + ->willReturn(true); |
|
| 1309 | + $this->groupManager->expects($this->any()) |
|
| 1310 | + ->method('groupExists') |
|
| 1311 | + ->willReturn(true); |
|
| 1312 | + $this->principal->expects(self::atLeastOnce()) |
|
| 1313 | + ->method('findByUri') |
|
| 1314 | + ->willReturn(self::UNIT_TEST_USER); |
|
| 1315 | + |
|
| 1316 | + $me = self::UNIT_TEST_USER; |
|
| 1317 | + $sharer = self::UNIT_TEST_USER1; |
|
| 1318 | + $this->backend->createCalendar($me, 'calendar-uri-me', []); |
|
| 1319 | + $this->backend->createCalendar($sharer, 'calendar-uri-sharer', []); |
|
| 1320 | + |
|
| 1321 | + $myCalendars = $this->backend->getCalendarsForUser($me); |
|
| 1322 | + $this->assertCount(1, $myCalendars); |
|
| 1323 | + |
|
| 1324 | + $sharerCalendars = $this->backend->getCalendarsForUser($sharer); |
|
| 1325 | + $this->assertCount(1, $sharerCalendars); |
|
| 1326 | + |
|
| 1327 | + $logger = $this->createMock(\Psr\Log\LoggerInterface::class); |
|
| 1328 | + $sharerCalendar = new Calendar($this->backend, $sharerCalendars[0], $l10n, $config, $logger); |
|
| 1329 | + $this->backend->updateShares($sharerCalendar, [ |
|
| 1330 | + [ |
|
| 1331 | + 'href' => 'principal:' . $me, |
|
| 1332 | + 'readOnly' => false, |
|
| 1333 | + ], |
|
| 1334 | + ], []); |
|
| 1335 | + |
|
| 1336 | + $this->assertCount(2, $this->backend->getCalendarsForUser($me)); |
|
| 1337 | + |
|
| 1338 | + $this->backend->createCalendarObject($myCalendars[0]['id'], 'event0.ics', $myPublic); |
|
| 1339 | + $this->backend->createCalendarObject($myCalendars[0]['id'], 'event1.ics', $myPrivate); |
|
| 1340 | + $this->backend->createCalendarObject($myCalendars[0]['id'], 'event2.ics', $myConfidential); |
|
| 1341 | + |
|
| 1342 | + $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event3.ics', $sharerPublic); |
|
| 1343 | + $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event4.ics', $sharerPrivate); |
|
| 1344 | + $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event5.ics', $sharerConfidential); |
|
| 1345 | + |
|
| 1346 | + $mySearchResults = $this->backend->searchPrincipalUri($me, 'Test', ['VEVENT'], ['SUMMARY'], []); |
|
| 1347 | + $sharerSearchResults = $this->backend->searchPrincipalUri($sharer, 'Test', ['VEVENT'], ['SUMMARY'], []); |
|
| 1348 | + |
|
| 1349 | + $this->assertCount(4, $mySearchResults); |
|
| 1350 | + $this->assertCount(3, $sharerSearchResults); |
|
| 1351 | + |
|
| 1352 | + $this->assertEquals($myPublic, $mySearchResults[0]['calendardata']); |
|
| 1353 | + $this->assertEquals($myPrivate, $mySearchResults[1]['calendardata']); |
|
| 1354 | + $this->assertEquals($myConfidential, $mySearchResults[2]['calendardata']); |
|
| 1355 | + $this->assertEquals($sharerPublic, $mySearchResults[3]['calendardata']); |
|
| 1356 | + |
|
| 1357 | + $this->assertEquals($sharerPublic, $sharerSearchResults[0]['calendardata']); |
|
| 1358 | + $this->assertEquals($sharerPrivate, $sharerSearchResults[1]['calendardata']); |
|
| 1359 | + $this->assertEquals($sharerConfidential, $sharerSearchResults[2]['calendardata']); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * @throws \OCP\DB\Exception |
|
| 1364 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 1365 | + */ |
|
| 1366 | + public function testPruneOutdatedSyncTokens(): void { |
|
| 1367 | + $calendarId = $this->createTestCalendar(); |
|
| 1368 | + $changes = $this->backend->getChangesForCalendar($calendarId, '', 1); |
|
| 1369 | + $syncToken = $changes['syncToken']; |
|
| 1370 | + |
|
| 1371 | + $uri = static::getUniqueID('calobj'); |
|
| 1372 | + $calData = <<<EOD |
|
| 1373 | 1373 | BEGIN:VCALENDAR |
| 1374 | 1374 | VERSION:2.0 |
| 1375 | 1375 | PRODID:Nextcloud Calendar |
@@ -1386,10 +1386,10 @@ discard block |
||
| 1386 | 1386 | END:VCALENDAR |
| 1387 | 1387 | EOD; |
| 1388 | 1388 | |
| 1389 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1389 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1390 | 1390 | |
| 1391 | - // update the card |
|
| 1392 | - $calData = <<<'EOD' |
|
| 1391 | + // update the card |
|
| 1392 | + $calData = <<<'EOD' |
|
| 1393 | 1393 | BEGIN:VCALENDAR |
| 1394 | 1394 | VERSION:2.0 |
| 1395 | 1395 | PRODID:Nextcloud Calendar |
@@ -1405,29 +1405,29 @@ discard block |
||
| 1405 | 1405 | END:VEVENT |
| 1406 | 1406 | END:VCALENDAR |
| 1407 | 1407 | EOD; |
| 1408 | - $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 1408 | + $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 1409 | 1409 | |
| 1410 | - // Keep everything |
|
| 1411 | - $deleted = $this->backend->pruneOutdatedSyncTokens(0, 0); |
|
| 1412 | - self::assertSame(0, $deleted); |
|
| 1410 | + // Keep everything |
|
| 1411 | + $deleted = $this->backend->pruneOutdatedSyncTokens(0, 0); |
|
| 1412 | + self::assertSame(0, $deleted); |
|
| 1413 | 1413 | |
| 1414 | - $deleted = $this->backend->pruneOutdatedSyncTokens(0, time()); |
|
| 1415 | - // At least one from the object creation and one from the object update |
|
| 1416 | - $this->assertGreaterThanOrEqual(2, $deleted); |
|
| 1417 | - $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1); |
|
| 1418 | - $this->assertEmpty($changes['added']); |
|
| 1419 | - $this->assertEmpty($changes['modified']); |
|
| 1420 | - $this->assertEmpty($changes['deleted']); |
|
| 1414 | + $deleted = $this->backend->pruneOutdatedSyncTokens(0, time()); |
|
| 1415 | + // At least one from the object creation and one from the object update |
|
| 1416 | + $this->assertGreaterThanOrEqual(2, $deleted); |
|
| 1417 | + $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1); |
|
| 1418 | + $this->assertEmpty($changes['added']); |
|
| 1419 | + $this->assertEmpty($changes['modified']); |
|
| 1420 | + $this->assertEmpty($changes['deleted']); |
|
| 1421 | 1421 | |
| 1422 | - // Test that objects remain |
|
| 1422 | + // Test that objects remain |
|
| 1423 | 1423 | |
| 1424 | - // Currently changes are empty |
|
| 1425 | - $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1426 | - $this->assertEquals(0, count($changes['added'] + $changes['modified'] + $changes['deleted'])); |
|
| 1424 | + // Currently changes are empty |
|
| 1425 | + $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1426 | + $this->assertEquals(0, count($changes['added'] + $changes['modified'] + $changes['deleted'])); |
|
| 1427 | 1427 | |
| 1428 | - // Create card |
|
| 1429 | - $uri = static::getUniqueID('calobj'); |
|
| 1430 | - $calData = <<<EOD |
|
| 1428 | + // Create card |
|
| 1429 | + $uri = static::getUniqueID('calobj'); |
|
| 1430 | + $calData = <<<EOD |
|
| 1431 | 1431 | BEGIN:VCALENDAR |
| 1432 | 1432 | VERSION:2.0 |
| 1433 | 1433 | PRODID:Nextcloud Calendar |
@@ -1443,16 +1443,16 @@ discard block |
||
| 1443 | 1443 | END:VEVENT |
| 1444 | 1444 | END:VCALENDAR |
| 1445 | 1445 | EOD; |
| 1446 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1446 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1447 | 1447 | |
| 1448 | - // We now have one add |
|
| 1449 | - $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1450 | - $this->assertEquals(1, count($changes['added'])); |
|
| 1451 | - $this->assertEmpty($changes['modified']); |
|
| 1452 | - $this->assertEmpty($changes['deleted']); |
|
| 1448 | + // We now have one add |
|
| 1449 | + $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1450 | + $this->assertEquals(1, count($changes['added'])); |
|
| 1451 | + $this->assertEmpty($changes['modified']); |
|
| 1452 | + $this->assertEmpty($changes['deleted']); |
|
| 1453 | 1453 | |
| 1454 | - // update the card |
|
| 1455 | - $calData = <<<'EOD' |
|
| 1454 | + // update the card |
|
| 1455 | + $calData = <<<'EOD' |
|
| 1456 | 1456 | BEGIN:VCALENDAR |
| 1457 | 1457 | VERSION:2.0 |
| 1458 | 1458 | PRODID:Nextcloud Calendar |
@@ -1468,38 +1468,38 @@ discard block |
||
| 1468 | 1468 | END:VEVENT |
| 1469 | 1469 | END:VCALENDAR |
| 1470 | 1470 | EOD; |
| 1471 | - $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 1472 | - |
|
| 1473 | - // One add, one modify, but shortened to modify |
|
| 1474 | - $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1475 | - $this->assertEmpty($changes['added']); |
|
| 1476 | - $this->assertEquals(1, count($changes['modified'])); |
|
| 1477 | - $this->assertEmpty($changes['deleted']); |
|
| 1478 | - |
|
| 1479 | - // Delete all but last change |
|
| 1480 | - $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); |
|
| 1481 | - $this->assertEquals(1, $deleted); // We had two changes before, now one |
|
| 1482 | - |
|
| 1483 | - // Only update should remain |
|
| 1484 | - $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1485 | - $this->assertEmpty($changes['added']); |
|
| 1486 | - $this->assertEquals(1, count($changes['modified'])); |
|
| 1487 | - $this->assertEmpty($changes['deleted']); |
|
| 1488 | - |
|
| 1489 | - // Check that no crash occurs when prune is called without current changes |
|
| 1490 | - $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); |
|
| 1491 | - self::assertSame(0, $deleted); |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - public function testSearchAndExpandRecurrences(): void { |
|
| 1495 | - $calendarId = $this->createTestCalendar(); |
|
| 1496 | - $calendarInfo = [ |
|
| 1497 | - 'id' => $calendarId, |
|
| 1498 | - 'principaluri' => 'user1', |
|
| 1499 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1500 | - ]; |
|
| 1501 | - |
|
| 1502 | - $calData = <<<'EOD' |
|
| 1471 | + $this->backend->updateCalendarObject($calendarId, $uri, $calData); |
|
| 1472 | + |
|
| 1473 | + // One add, one modify, but shortened to modify |
|
| 1474 | + $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1475 | + $this->assertEmpty($changes['added']); |
|
| 1476 | + $this->assertEquals(1, count($changes['modified'])); |
|
| 1477 | + $this->assertEmpty($changes['deleted']); |
|
| 1478 | + |
|
| 1479 | + // Delete all but last change |
|
| 1480 | + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); |
|
| 1481 | + $this->assertEquals(1, $deleted); // We had two changes before, now one |
|
| 1482 | + |
|
| 1483 | + // Only update should remain |
|
| 1484 | + $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100); |
|
| 1485 | + $this->assertEmpty($changes['added']); |
|
| 1486 | + $this->assertEquals(1, count($changes['modified'])); |
|
| 1487 | + $this->assertEmpty($changes['deleted']); |
|
| 1488 | + |
|
| 1489 | + // Check that no crash occurs when prune is called without current changes |
|
| 1490 | + $deleted = $this->backend->pruneOutdatedSyncTokens(1, time()); |
|
| 1491 | + self::assertSame(0, $deleted); |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + public function testSearchAndExpandRecurrences(): void { |
|
| 1495 | + $calendarId = $this->createTestCalendar(); |
|
| 1496 | + $calendarInfo = [ |
|
| 1497 | + 'id' => $calendarId, |
|
| 1498 | + 'principaluri' => 'user1', |
|
| 1499 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1500 | + ]; |
|
| 1501 | + |
|
| 1502 | + $calData = <<<'EOD' |
|
| 1503 | 1503 | BEGIN:VCALENDAR |
| 1504 | 1504 | PRODID:-//IDN nextcloud.com//Calendar app 4.5.0-alpha.2//EN |
| 1505 | 1505 | CALSCALE:GREGORIAN |
@@ -1518,50 +1518,50 @@ discard block |
||
| 1518 | 1518 | END:VEVENT |
| 1519 | 1519 | END:VCALENDAR |
| 1520 | 1520 | EOD; |
| 1521 | - $uri = static::getUniqueID('calobj'); |
|
| 1522 | - $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1523 | - |
|
| 1524 | - $start = new DateTimeImmutable('2023-09-20T00:00:00Z'); |
|
| 1525 | - $end = $start->add(new DateInterval('P14D')); |
|
| 1526 | - |
|
| 1527 | - $results = $this->backend->search( |
|
| 1528 | - $calendarInfo, |
|
| 1529 | - '', |
|
| 1530 | - [], |
|
| 1531 | - [ |
|
| 1532 | - 'timerange' => [ |
|
| 1533 | - 'start' => $start, |
|
| 1534 | - 'end' => $end, |
|
| 1535 | - ] |
|
| 1536 | - ], |
|
| 1537 | - null, |
|
| 1538 | - null, |
|
| 1539 | - ); |
|
| 1540 | - |
|
| 1541 | - $this->assertCount(1, $results); |
|
| 1542 | - $this->assertCount(14, $results[0]['objects']); |
|
| 1543 | - foreach ($results as $result) { |
|
| 1544 | - foreach ($result['objects'] as $object) { |
|
| 1545 | - $this->assertEquals($object['UID'][0], '7b7d5d12-683c-48ce-973a-b3e1cb0bae2a'); |
|
| 1546 | - $this->assertEquals($object['SUMMARY'][0], 'Daily Event'); |
|
| 1547 | - $this->assertGreaterThanOrEqual( |
|
| 1548 | - $start->getTimestamp(), |
|
| 1549 | - $object['DTSTART'][0]->getTimestamp(), |
|
| 1550 | - 'Recurrence starting before requested start', |
|
| 1551 | - ); |
|
| 1552 | - $this->assertLessThanOrEqual( |
|
| 1553 | - $end->getTimestamp(), |
|
| 1554 | - $object['DTSTART'][0]->getTimestamp(), |
|
| 1555 | - 'Recurrence starting after requested end', |
|
| 1556 | - ); |
|
| 1557 | - } |
|
| 1558 | - } |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - public function testRestoreChanges(): void { |
|
| 1562 | - $calendarId = $this->createTestCalendar(); |
|
| 1563 | - $uri1 = static::getUniqueID('calobj1') . '.ics'; |
|
| 1564 | - $calData = <<<EOD |
|
| 1521 | + $uri = static::getUniqueID('calobj'); |
|
| 1522 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
|
| 1523 | + |
|
| 1524 | + $start = new DateTimeImmutable('2023-09-20T00:00:00Z'); |
|
| 1525 | + $end = $start->add(new DateInterval('P14D')); |
|
| 1526 | + |
|
| 1527 | + $results = $this->backend->search( |
|
| 1528 | + $calendarInfo, |
|
| 1529 | + '', |
|
| 1530 | + [], |
|
| 1531 | + [ |
|
| 1532 | + 'timerange' => [ |
|
| 1533 | + 'start' => $start, |
|
| 1534 | + 'end' => $end, |
|
| 1535 | + ] |
|
| 1536 | + ], |
|
| 1537 | + null, |
|
| 1538 | + null, |
|
| 1539 | + ); |
|
| 1540 | + |
|
| 1541 | + $this->assertCount(1, $results); |
|
| 1542 | + $this->assertCount(14, $results[0]['objects']); |
|
| 1543 | + foreach ($results as $result) { |
|
| 1544 | + foreach ($result['objects'] as $object) { |
|
| 1545 | + $this->assertEquals($object['UID'][0], '7b7d5d12-683c-48ce-973a-b3e1cb0bae2a'); |
|
| 1546 | + $this->assertEquals($object['SUMMARY'][0], 'Daily Event'); |
|
| 1547 | + $this->assertGreaterThanOrEqual( |
|
| 1548 | + $start->getTimestamp(), |
|
| 1549 | + $object['DTSTART'][0]->getTimestamp(), |
|
| 1550 | + 'Recurrence starting before requested start', |
|
| 1551 | + ); |
|
| 1552 | + $this->assertLessThanOrEqual( |
|
| 1553 | + $end->getTimestamp(), |
|
| 1554 | + $object['DTSTART'][0]->getTimestamp(), |
|
| 1555 | + 'Recurrence starting after requested end', |
|
| 1556 | + ); |
|
| 1557 | + } |
|
| 1558 | + } |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + public function testRestoreChanges(): void { |
|
| 1562 | + $calendarId = $this->createTestCalendar(); |
|
| 1563 | + $uri1 = static::getUniqueID('calobj1') . '.ics'; |
|
| 1564 | + $calData = <<<EOD |
|
| 1565 | 1565 | BEGIN:VCALENDAR |
| 1566 | 1566 | VERSION:2.0 |
| 1567 | 1567 | PRODID:Nextcloud Calendar |
@@ -1577,8 +1577,8 @@ discard block |
||
| 1577 | 1577 | END:VEVENT |
| 1578 | 1578 | END:VCALENDAR |
| 1579 | 1579 | EOD; |
| 1580 | - $this->backend->createCalendarObject($calendarId, $uri1, $calData); |
|
| 1581 | - $calData = <<<EOD |
|
| 1580 | + $this->backend->createCalendarObject($calendarId, $uri1, $calData); |
|
| 1581 | + $calData = <<<EOD |
|
| 1582 | 1582 | BEGIN:VCALENDAR |
| 1583 | 1583 | VERSION:2.0 |
| 1584 | 1584 | PRODID:Nextcloud Calendar |
@@ -1595,9 +1595,9 @@ discard block |
||
| 1595 | 1595 | END:VEVENT |
| 1596 | 1596 | END:VCALENDAR |
| 1597 | 1597 | EOD; |
| 1598 | - $this->backend->updateCalendarObject($calendarId, $uri1, $calData); |
|
| 1599 | - $uri2 = static::getUniqueID('calobj2') . '.ics'; |
|
| 1600 | - $calData = <<<EOD |
|
| 1598 | + $this->backend->updateCalendarObject($calendarId, $uri1, $calData); |
|
| 1599 | + $uri2 = static::getUniqueID('calobj2') . '.ics'; |
|
| 1600 | + $calData = <<<EOD |
|
| 1601 | 1601 | BEGIN:VCALENDAR |
| 1602 | 1602 | VERSION:2.0 |
| 1603 | 1603 | PRODID:Nextcloud Calendar |
@@ -1613,11 +1613,11 @@ discard block |
||
| 1613 | 1613 | END:VEVENT |
| 1614 | 1614 | END:VCALENDAR |
| 1615 | 1615 | EOD; |
| 1616 | - $this->backend->createCalendarObject($calendarId, $uri2, $calData); |
|
| 1617 | - $changesBefore = $this->backend->getChangesForCalendar($calendarId, null, 1); |
|
| 1618 | - $this->backend->deleteCalendarObject($calendarId, $uri2); |
|
| 1619 | - $uri3 = static::getUniqueID('calobj3') . '.ics'; |
|
| 1620 | - $calData = <<<EOD |
|
| 1616 | + $this->backend->createCalendarObject($calendarId, $uri2, $calData); |
|
| 1617 | + $changesBefore = $this->backend->getChangesForCalendar($calendarId, null, 1); |
|
| 1618 | + $this->backend->deleteCalendarObject($calendarId, $uri2); |
|
| 1619 | + $uri3 = static::getUniqueID('calobj3') . '.ics'; |
|
| 1620 | + $calData = <<<EOD |
|
| 1621 | 1621 | BEGIN:VCALENDAR |
| 1622 | 1622 | VERSION:2.0 |
| 1623 | 1623 | PRODID:Nextcloud Calendar |
@@ -1633,261 +1633,261 @@ discard block |
||
| 1633 | 1633 | END:VEVENT |
| 1634 | 1634 | END:VCALENDAR |
| 1635 | 1635 | EOD; |
| 1636 | - $this->backend->createCalendarObject($calendarId, $uri3, $calData); |
|
| 1637 | - $deleteChanges = $this->db->getQueryBuilder(); |
|
| 1638 | - $deleteChanges->delete('calendarchanges') |
|
| 1639 | - ->where($deleteChanges->expr()->eq('calendarid', $deleteChanges->createNamedParameter($calendarId))); |
|
| 1640 | - $deleteChanges->executeStatement(); |
|
| 1641 | - |
|
| 1642 | - $this->backend->restoreChanges($calendarId); |
|
| 1643 | - |
|
| 1644 | - $changesAfter = $this->backend->getChangesForCalendar($calendarId, $changesBefore['syncToken'], 1); |
|
| 1645 | - self::assertEquals([], $changesAfter['added']); |
|
| 1646 | - self::assertEqualsCanonicalizing([$uri1, $uri3], $changesAfter['modified']); |
|
| 1647 | - self::assertEquals([$uri2], $changesAfter['deleted']); |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - public function testSearchWithLimitAndTimeRange(): void { |
|
| 1651 | - $calendarId = $this->createTestCalendar(); |
|
| 1652 | - $calendarInfo = [ |
|
| 1653 | - 'id' => $calendarId, |
|
| 1654 | - 'principaluri' => 'user1', |
|
| 1655 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1656 | - ]; |
|
| 1657 | - |
|
| 1658 | - $testFiles = [ |
|
| 1659 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1660 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1661 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1662 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1663 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1664 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', |
|
| 1665 | - ]; |
|
| 1666 | - |
|
| 1667 | - foreach ($testFiles as $testFile) { |
|
| 1668 | - $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1669 | - $calendarData = \file_get_contents($testFile); |
|
| 1670 | - $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1674 | - $end = $start->add(new DateInterval('P14D')); |
|
| 1675 | - |
|
| 1676 | - $results = $this->backend->search( |
|
| 1677 | - $calendarInfo, |
|
| 1678 | - '', |
|
| 1679 | - [], |
|
| 1680 | - [ |
|
| 1681 | - 'timerange' => [ |
|
| 1682 | - 'start' => $start, |
|
| 1683 | - 'end' => $end, |
|
| 1684 | - ] |
|
| 1685 | - ], |
|
| 1686 | - 4, |
|
| 1687 | - null, |
|
| 1688 | - ); |
|
| 1689 | - |
|
| 1690 | - $this->assertCount(2, $results); |
|
| 1691 | - |
|
| 1692 | - $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1693 | - $this->assertGreaterThanOrEqual( |
|
| 1694 | - $start->getTimestamp(), |
|
| 1695 | - $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1696 | - 'Recurrence starting before requested start', |
|
| 1697 | - ); |
|
| 1698 | - |
|
| 1699 | - $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1700 | - $this->assertGreaterThanOrEqual( |
|
| 1701 | - $start->getTimestamp(), |
|
| 1702 | - $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1703 | - 'Recurrence starting before requested start', |
|
| 1704 | - ); |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - public function testSearchWithLimitAndTimeRangeShouldNotReturnMoreObjectsThenLimit(): void { |
|
| 1708 | - $calendarId = $this->createTestCalendar(); |
|
| 1709 | - $calendarInfo = [ |
|
| 1710 | - 'id' => $calendarId, |
|
| 1711 | - 'principaluri' => 'user1', |
|
| 1712 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1713 | - ]; |
|
| 1714 | - |
|
| 1715 | - $testFiles = [ |
|
| 1716 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1717 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1718 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1719 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1720 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1721 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', |
|
| 1722 | - ]; |
|
| 1723 | - |
|
| 1724 | - foreach ($testFiles as $testFile) { |
|
| 1725 | - $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1726 | - $calendarData = \file_get_contents($testFile); |
|
| 1727 | - $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1731 | - $end = $start->add(new DateInterval('P14D')); |
|
| 1732 | - |
|
| 1733 | - $results = $this->backend->search( |
|
| 1734 | - $calendarInfo, |
|
| 1735 | - '', |
|
| 1736 | - [], |
|
| 1737 | - [ |
|
| 1738 | - 'timerange' => [ |
|
| 1739 | - 'start' => $start, |
|
| 1740 | - 'end' => $end, |
|
| 1741 | - ] |
|
| 1742 | - ], |
|
| 1743 | - 1, |
|
| 1744 | - null, |
|
| 1745 | - ); |
|
| 1746 | - |
|
| 1747 | - $this->assertCount(1, $results); |
|
| 1748 | - |
|
| 1749 | - $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1750 | - $this->assertGreaterThanOrEqual( |
|
| 1751 | - $start->getTimestamp(), |
|
| 1752 | - $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1753 | - 'Recurrence starting before requested start', |
|
| 1754 | - ); |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - public function testSearchWithLimitAndTimeRangeShouldReturnObjectsInTheSameOrder(): void { |
|
| 1758 | - $calendarId = $this->createTestCalendar(); |
|
| 1759 | - $calendarInfo = [ |
|
| 1760 | - 'id' => $calendarId, |
|
| 1761 | - 'principaluri' => 'user1', |
|
| 1762 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1763 | - ]; |
|
| 1764 | - |
|
| 1765 | - $testFiles = [ |
|
| 1766 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1767 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1768 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1769 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1770 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', // <-- intentional! |
|
| 1771 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1772 | - ]; |
|
| 1773 | - |
|
| 1774 | - foreach ($testFiles as $testFile) { |
|
| 1775 | - $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1776 | - $calendarData = \file_get_contents($testFile); |
|
| 1777 | - $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1778 | - } |
|
| 1779 | - |
|
| 1780 | - $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1781 | - $end = $start->add(new DateInterval('P14D')); |
|
| 1782 | - |
|
| 1783 | - $results = $this->backend->search( |
|
| 1784 | - $calendarInfo, |
|
| 1785 | - '', |
|
| 1786 | - [], |
|
| 1787 | - [ |
|
| 1788 | - 'timerange' => [ |
|
| 1789 | - 'start' => $start, |
|
| 1790 | - 'end' => $end, |
|
| 1791 | - ] |
|
| 1792 | - ], |
|
| 1793 | - 2, |
|
| 1794 | - null, |
|
| 1795 | - ); |
|
| 1796 | - |
|
| 1797 | - $this->assertCount(2, $results); |
|
| 1798 | - |
|
| 1799 | - $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1800 | - $this->assertGreaterThanOrEqual( |
|
| 1801 | - $start->getTimestamp(), |
|
| 1802 | - $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1803 | - 'Recurrence starting before requested start', |
|
| 1804 | - ); |
|
| 1805 | - |
|
| 1806 | - $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1807 | - $this->assertGreaterThanOrEqual( |
|
| 1808 | - $start->getTimestamp(), |
|
| 1809 | - $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1810 | - 'Recurrence starting before requested start', |
|
| 1811 | - ); |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - public function testSearchShouldReturnObjectsInTheSameOrderMissingDate(): void { |
|
| 1815 | - $calendarId = $this->createTestCalendar(); |
|
| 1816 | - $calendarInfo = [ |
|
| 1817 | - 'id' => $calendarId, |
|
| 1818 | - 'principaluri' => 'user1', |
|
| 1819 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1820 | - ]; |
|
| 1821 | - |
|
| 1822 | - $testFiles = [ |
|
| 1823 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', // <-- intentional! |
|
| 1824 | - __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1825 | - __DIR__ . '/../test_fixtures/caldav-search-missing-start-1.ics', |
|
| 1826 | - __DIR__ . '/../test_fixtures/caldav-search-missing-start-2.ics', |
|
| 1827 | - ]; |
|
| 1828 | - |
|
| 1829 | - foreach ($testFiles as $testFile) { |
|
| 1830 | - $objectUri = static::getUniqueID('search-return-objects-in-same-order-'); |
|
| 1831 | - $calendarData = \file_get_contents($testFile); |
|
| 1832 | - $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - $results = $this->backend->search( |
|
| 1836 | - $calendarInfo, |
|
| 1837 | - '', |
|
| 1838 | - [], |
|
| 1839 | - [], |
|
| 1840 | - 4, |
|
| 1841 | - null, |
|
| 1842 | - ); |
|
| 1843 | - |
|
| 1844 | - $this->assertCount(4, $results); |
|
| 1845 | - |
|
| 1846 | - $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1847 | - $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1848 | - $this->assertEquals('Missing DTSTART 1', $results[2]['objects'][0]['SUMMARY'][0]); |
|
| 1849 | - $this->assertEquals('Missing DTSTART 2', $results[3]['objects'][0]['SUMMARY'][0]); |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - public function testUnshare(): void { |
|
| 1853 | - $principalGroup = 'principal:' . self::UNIT_TEST_GROUP; |
|
| 1854 | - $principalUser = 'principal:' . self::UNIT_TEST_USER; |
|
| 1855 | - |
|
| 1856 | - $l10n = $this->createMock(IL10N::class); |
|
| 1857 | - $l10n->method('t') |
|
| 1858 | - ->willReturnCallback(fn ($text, $parameters = []) => vsprintf($text, $parameters)); |
|
| 1859 | - $config = $this->createMock(IConfig::class); |
|
| 1860 | - $logger = new NullLogger(); |
|
| 1861 | - |
|
| 1862 | - $this->principal->expects($this->exactly(2)) |
|
| 1863 | - ->method('findByUri') |
|
| 1864 | - ->willReturnMap([ |
|
| 1865 | - [$principalGroup, '', self::UNIT_TEST_GROUP], |
|
| 1866 | - [$principalUser, '', self::UNIT_TEST_USER], |
|
| 1867 | - ]); |
|
| 1868 | - $this->groupManager->expects($this->once()) |
|
| 1869 | - ->method('groupExists') |
|
| 1870 | - ->willReturn(true); |
|
| 1871 | - $this->dispatcher->expects($this->exactly(2)) |
|
| 1872 | - ->method('dispatchTyped'); |
|
| 1873 | - |
|
| 1874 | - $calendarId = $this->createTestCalendar(); |
|
| 1875 | - $calendarInfo = $this->backend->getCalendarById($calendarId); |
|
| 1876 | - |
|
| 1877 | - $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger); |
|
| 1878 | - |
|
| 1879 | - $this->backend->updateShares( |
|
| 1880 | - shareable: $calendar, |
|
| 1881 | - add: [ |
|
| 1882 | - ['href' => $principalGroup, 'readOnly' => false] |
|
| 1883 | - ], |
|
| 1884 | - remove: [] |
|
| 1885 | - ); |
|
| 1886 | - |
|
| 1887 | - $this->backend->unshare( |
|
| 1888 | - shareable: $calendar, |
|
| 1889 | - principal: $principalUser |
|
| 1890 | - ); |
|
| 1891 | - |
|
| 1892 | - } |
|
| 1636 | + $this->backend->createCalendarObject($calendarId, $uri3, $calData); |
|
| 1637 | + $deleteChanges = $this->db->getQueryBuilder(); |
|
| 1638 | + $deleteChanges->delete('calendarchanges') |
|
| 1639 | + ->where($deleteChanges->expr()->eq('calendarid', $deleteChanges->createNamedParameter($calendarId))); |
|
| 1640 | + $deleteChanges->executeStatement(); |
|
| 1641 | + |
|
| 1642 | + $this->backend->restoreChanges($calendarId); |
|
| 1643 | + |
|
| 1644 | + $changesAfter = $this->backend->getChangesForCalendar($calendarId, $changesBefore['syncToken'], 1); |
|
| 1645 | + self::assertEquals([], $changesAfter['added']); |
|
| 1646 | + self::assertEqualsCanonicalizing([$uri1, $uri3], $changesAfter['modified']); |
|
| 1647 | + self::assertEquals([$uri2], $changesAfter['deleted']); |
|
| 1648 | + } |
|
| 1649 | + |
|
| 1650 | + public function testSearchWithLimitAndTimeRange(): void { |
|
| 1651 | + $calendarId = $this->createTestCalendar(); |
|
| 1652 | + $calendarInfo = [ |
|
| 1653 | + 'id' => $calendarId, |
|
| 1654 | + 'principaluri' => 'user1', |
|
| 1655 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1656 | + ]; |
|
| 1657 | + |
|
| 1658 | + $testFiles = [ |
|
| 1659 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1660 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1661 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1662 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1663 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1664 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', |
|
| 1665 | + ]; |
|
| 1666 | + |
|
| 1667 | + foreach ($testFiles as $testFile) { |
|
| 1668 | + $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1669 | + $calendarData = \file_get_contents($testFile); |
|
| 1670 | + $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1674 | + $end = $start->add(new DateInterval('P14D')); |
|
| 1675 | + |
|
| 1676 | + $results = $this->backend->search( |
|
| 1677 | + $calendarInfo, |
|
| 1678 | + '', |
|
| 1679 | + [], |
|
| 1680 | + [ |
|
| 1681 | + 'timerange' => [ |
|
| 1682 | + 'start' => $start, |
|
| 1683 | + 'end' => $end, |
|
| 1684 | + ] |
|
| 1685 | + ], |
|
| 1686 | + 4, |
|
| 1687 | + null, |
|
| 1688 | + ); |
|
| 1689 | + |
|
| 1690 | + $this->assertCount(2, $results); |
|
| 1691 | + |
|
| 1692 | + $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1693 | + $this->assertGreaterThanOrEqual( |
|
| 1694 | + $start->getTimestamp(), |
|
| 1695 | + $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1696 | + 'Recurrence starting before requested start', |
|
| 1697 | + ); |
|
| 1698 | + |
|
| 1699 | + $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1700 | + $this->assertGreaterThanOrEqual( |
|
| 1701 | + $start->getTimestamp(), |
|
| 1702 | + $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1703 | + 'Recurrence starting before requested start', |
|
| 1704 | + ); |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + public function testSearchWithLimitAndTimeRangeShouldNotReturnMoreObjectsThenLimit(): void { |
|
| 1708 | + $calendarId = $this->createTestCalendar(); |
|
| 1709 | + $calendarInfo = [ |
|
| 1710 | + 'id' => $calendarId, |
|
| 1711 | + 'principaluri' => 'user1', |
|
| 1712 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1713 | + ]; |
|
| 1714 | + |
|
| 1715 | + $testFiles = [ |
|
| 1716 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1717 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1718 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1719 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1720 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1721 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', |
|
| 1722 | + ]; |
|
| 1723 | + |
|
| 1724 | + foreach ($testFiles as $testFile) { |
|
| 1725 | + $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1726 | + $calendarData = \file_get_contents($testFile); |
|
| 1727 | + $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1731 | + $end = $start->add(new DateInterval('P14D')); |
|
| 1732 | + |
|
| 1733 | + $results = $this->backend->search( |
|
| 1734 | + $calendarInfo, |
|
| 1735 | + '', |
|
| 1736 | + [], |
|
| 1737 | + [ |
|
| 1738 | + 'timerange' => [ |
|
| 1739 | + 'start' => $start, |
|
| 1740 | + 'end' => $end, |
|
| 1741 | + ] |
|
| 1742 | + ], |
|
| 1743 | + 1, |
|
| 1744 | + null, |
|
| 1745 | + ); |
|
| 1746 | + |
|
| 1747 | + $this->assertCount(1, $results); |
|
| 1748 | + |
|
| 1749 | + $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1750 | + $this->assertGreaterThanOrEqual( |
|
| 1751 | + $start->getTimestamp(), |
|
| 1752 | + $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1753 | + 'Recurrence starting before requested start', |
|
| 1754 | + ); |
|
| 1755 | + } |
|
| 1756 | + |
|
| 1757 | + public function testSearchWithLimitAndTimeRangeShouldReturnObjectsInTheSameOrder(): void { |
|
| 1758 | + $calendarId = $this->createTestCalendar(); |
|
| 1759 | + $calendarInfo = [ |
|
| 1760 | + 'id' => $calendarId, |
|
| 1761 | + 'principaluri' => 'user1', |
|
| 1762 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1763 | + ]; |
|
| 1764 | + |
|
| 1765 | + $testFiles = [ |
|
| 1766 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-1.ics', |
|
| 1767 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-2.ics', |
|
| 1768 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-3.ics', |
|
| 1769 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-4.ics', |
|
| 1770 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', // <-- intentional! |
|
| 1771 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1772 | + ]; |
|
| 1773 | + |
|
| 1774 | + foreach ($testFiles as $testFile) { |
|
| 1775 | + $objectUri = static::getUniqueID('search-limit-timerange-'); |
|
| 1776 | + $calendarData = \file_get_contents($testFile); |
|
| 1777 | + $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1778 | + } |
|
| 1779 | + |
|
| 1780 | + $start = new DateTimeImmutable('2024-05-06T00:00:00Z'); |
|
| 1781 | + $end = $start->add(new DateInterval('P14D')); |
|
| 1782 | + |
|
| 1783 | + $results = $this->backend->search( |
|
| 1784 | + $calendarInfo, |
|
| 1785 | + '', |
|
| 1786 | + [], |
|
| 1787 | + [ |
|
| 1788 | + 'timerange' => [ |
|
| 1789 | + 'start' => $start, |
|
| 1790 | + 'end' => $end, |
|
| 1791 | + ] |
|
| 1792 | + ], |
|
| 1793 | + 2, |
|
| 1794 | + null, |
|
| 1795 | + ); |
|
| 1796 | + |
|
| 1797 | + $this->assertCount(2, $results); |
|
| 1798 | + |
|
| 1799 | + $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1800 | + $this->assertGreaterThanOrEqual( |
|
| 1801 | + $start->getTimestamp(), |
|
| 1802 | + $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1803 | + 'Recurrence starting before requested start', |
|
| 1804 | + ); |
|
| 1805 | + |
|
| 1806 | + $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1807 | + $this->assertGreaterThanOrEqual( |
|
| 1808 | + $start->getTimestamp(), |
|
| 1809 | + $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(), |
|
| 1810 | + 'Recurrence starting before requested start', |
|
| 1811 | + ); |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + public function testSearchShouldReturnObjectsInTheSameOrderMissingDate(): void { |
|
| 1815 | + $calendarId = $this->createTestCalendar(); |
|
| 1816 | + $calendarInfo = [ |
|
| 1817 | + 'id' => $calendarId, |
|
| 1818 | + 'principaluri' => 'user1', |
|
| 1819 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
| 1820 | + ]; |
|
| 1821 | + |
|
| 1822 | + $testFiles = [ |
|
| 1823 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-6.ics', // <-- intentional! |
|
| 1824 | + __DIR__ . '/../test_fixtures/caldav-search-limit-timerange-5.ics', |
|
| 1825 | + __DIR__ . '/../test_fixtures/caldav-search-missing-start-1.ics', |
|
| 1826 | + __DIR__ . '/../test_fixtures/caldav-search-missing-start-2.ics', |
|
| 1827 | + ]; |
|
| 1828 | + |
|
| 1829 | + foreach ($testFiles as $testFile) { |
|
| 1830 | + $objectUri = static::getUniqueID('search-return-objects-in-same-order-'); |
|
| 1831 | + $calendarData = \file_get_contents($testFile); |
|
| 1832 | + $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData); |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + $results = $this->backend->search( |
|
| 1836 | + $calendarInfo, |
|
| 1837 | + '', |
|
| 1838 | + [], |
|
| 1839 | + [], |
|
| 1840 | + 4, |
|
| 1841 | + null, |
|
| 1842 | + ); |
|
| 1843 | + |
|
| 1844 | + $this->assertCount(4, $results); |
|
| 1845 | + |
|
| 1846 | + $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]); |
|
| 1847 | + $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]); |
|
| 1848 | + $this->assertEquals('Missing DTSTART 1', $results[2]['objects'][0]['SUMMARY'][0]); |
|
| 1849 | + $this->assertEquals('Missing DTSTART 2', $results[3]['objects'][0]['SUMMARY'][0]); |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + public function testUnshare(): void { |
|
| 1853 | + $principalGroup = 'principal:' . self::UNIT_TEST_GROUP; |
|
| 1854 | + $principalUser = 'principal:' . self::UNIT_TEST_USER; |
|
| 1855 | + |
|
| 1856 | + $l10n = $this->createMock(IL10N::class); |
|
| 1857 | + $l10n->method('t') |
|
| 1858 | + ->willReturnCallback(fn ($text, $parameters = []) => vsprintf($text, $parameters)); |
|
| 1859 | + $config = $this->createMock(IConfig::class); |
|
| 1860 | + $logger = new NullLogger(); |
|
| 1861 | + |
|
| 1862 | + $this->principal->expects($this->exactly(2)) |
|
| 1863 | + ->method('findByUri') |
|
| 1864 | + ->willReturnMap([ |
|
| 1865 | + [$principalGroup, '', self::UNIT_TEST_GROUP], |
|
| 1866 | + [$principalUser, '', self::UNIT_TEST_USER], |
|
| 1867 | + ]); |
|
| 1868 | + $this->groupManager->expects($this->once()) |
|
| 1869 | + ->method('groupExists') |
|
| 1870 | + ->willReturn(true); |
|
| 1871 | + $this->dispatcher->expects($this->exactly(2)) |
|
| 1872 | + ->method('dispatchTyped'); |
|
| 1873 | + |
|
| 1874 | + $calendarId = $this->createTestCalendar(); |
|
| 1875 | + $calendarInfo = $this->backend->getCalendarById($calendarId); |
|
| 1876 | + |
|
| 1877 | + $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger); |
|
| 1878 | + |
|
| 1879 | + $this->backend->updateShares( |
|
| 1880 | + shareable: $calendar, |
|
| 1881 | + add: [ |
|
| 1882 | + ['href' => $principalGroup, 'readOnly' => false] |
|
| 1883 | + ], |
|
| 1884 | + remove: [] |
|
| 1885 | + ); |
|
| 1886 | + |
|
| 1887 | + $this->backend->unshare( |
|
| 1888 | + shareable: $calendar, |
|
| 1889 | + principal: $principalUser |
|
| 1890 | + ); |
|
| 1891 | + |
|
| 1892 | + } |
|
| 1893 | 1893 | } |
@@ -28,222 +28,222 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class CalDavSharingBackendTest extends TestCase { |
| 30 | 30 | |
| 31 | - private IDBConnection $db; |
|
| 32 | - private IUserManager $userManager; |
|
| 33 | - private IGroupManager $groupManager; |
|
| 34 | - private Principal $principalBackend; |
|
| 35 | - private ICacheFactory $cacheFactory; |
|
| 36 | - private LoggerInterface $logger; |
|
| 37 | - private SharingMapper $sharingMapper; |
|
| 38 | - private SharingService $sharingService; |
|
| 39 | - private Backend $sharingBackend; |
|
| 40 | - |
|
| 41 | - private $resourceIds = [10001]; |
|
| 42 | - |
|
| 43 | - protected function setUp(): void { |
|
| 44 | - parent::setUp(); |
|
| 45 | - |
|
| 46 | - $this->db = Server::get(IDBConnection::class); |
|
| 47 | - |
|
| 48 | - $this->userManager = $this->createMock(IUserManager::class); |
|
| 49 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 50 | - $this->principalBackend = $this->createMock(Principal::class); |
|
| 51 | - $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 52 | - $this->cacheFactory->method('createInMemory') |
|
| 53 | - ->willReturn(new \OC\Memcache\NullCache()); |
|
| 54 | - $this->logger = new \Psr\Log\NullLogger(); |
|
| 55 | - |
|
| 56 | - $this->sharingMapper = new SharingMapper($this->db); |
|
| 57 | - $this->sharingService = new \OCA\DAV\CalDAV\Sharing\Service($this->sharingMapper); |
|
| 58 | - |
|
| 59 | - $this->sharingBackend = new \OCA\DAV\CalDAV\Sharing\Backend( |
|
| 60 | - $this->userManager, |
|
| 61 | - $this->groupManager, |
|
| 62 | - $this->principalBackend, |
|
| 63 | - $this->cacheFactory, |
|
| 64 | - $this->sharingService, |
|
| 65 | - $this->logger |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - $this->removeFixtures(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - protected function tearDown(): void { |
|
| 72 | - $this->removeFixtures(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - protected function removeFixtures(): void { |
|
| 76 | - $qb = $this->db->getQueryBuilder(); |
|
| 77 | - $qb->delete('dav_shares') |
|
| 78 | - ->where($qb->expr()->in('resourceid', $qb->createNamedParameter($this->resourceIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 79 | - $qb->executeStatement(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function testShareCalendarWithGroup(): void { |
|
| 83 | - $calendar = $this->createMock(Calendar::class); |
|
| 84 | - $calendar->method('getResourceId') |
|
| 85 | - ->willReturn(10001); |
|
| 86 | - $calendar->method('getOwner') |
|
| 87 | - ->willReturn('principals/users/admin'); |
|
| 88 | - |
|
| 89 | - $this->principalBackend->method('findByUri') |
|
| 90 | - ->willReturn('principals/groups/alice_bob'); |
|
| 91 | - |
|
| 92 | - $this->groupManager->method('groupExists') |
|
| 93 | - ->willReturn(true); |
|
| 94 | - |
|
| 95 | - $this->sharingBackend->updateShares( |
|
| 96 | - $calendar, |
|
| 97 | - [['href' => 'principals/groups/alice_bob']], |
|
| 98 | - [], |
|
| 99 | - [] |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function testUnshareCalendarFromGroup(): void { |
|
| 106 | - $calendar = $this->createMock(Calendar::class); |
|
| 107 | - $calendar->method('getResourceId') |
|
| 108 | - ->willReturn(10001); |
|
| 109 | - $calendar->method('getOwner') |
|
| 110 | - ->willReturn('principals/users/admin'); |
|
| 111 | - |
|
| 112 | - $this->principalBackend->method('findByUri') |
|
| 113 | - ->willReturn('principals/groups/alice_bob'); |
|
| 114 | - |
|
| 115 | - $this->groupManager->method('groupExists') |
|
| 116 | - ->willReturn(true); |
|
| 117 | - |
|
| 118 | - $this->sharingBackend->updateShares( |
|
| 119 | - shareable: $calendar, |
|
| 120 | - add: [['href' => 'principals/groups/alice_bob']], |
|
| 121 | - remove: [], |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 125 | - |
|
| 126 | - $this->sharingBackend->updateShares( |
|
| 127 | - shareable: $calendar, |
|
| 128 | - add: [], |
|
| 129 | - remove: ['principals/groups/alice_bob'], |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - $this->assertCount(0, $this->sharingService->getShares(10001)); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - public function testShareCalendarWithGroupAndUnshareAsUser(): void { |
|
| 136 | - $calendar = $this->createMock(Calendar::class); |
|
| 137 | - $calendar->method('getResourceId') |
|
| 138 | - ->willReturn(10001); |
|
| 139 | - $calendar->method('getOwner') |
|
| 140 | - ->willReturn('principals/users/admin'); |
|
| 141 | - |
|
| 142 | - $this->principalBackend->method('findByUri') |
|
| 143 | - ->willReturnMap([ |
|
| 144 | - ['principals/groups/alice_bob', '', 'principals/groups/alice_bob'], |
|
| 145 | - ['principals/users/bob', '', 'principals/users/bob'], |
|
| 146 | - ]); |
|
| 147 | - $this->principalBackend->method('getGroupMembership') |
|
| 148 | - ->willReturn([ |
|
| 149 | - 'principals/groups/alice_bob', |
|
| 150 | - ]); |
|
| 151 | - $this->principalBackend->method('getCircleMembership') |
|
| 152 | - ->willReturn([]); |
|
| 153 | - |
|
| 154 | - $this->groupManager->method('groupExists') |
|
| 155 | - ->willReturn(true); |
|
| 156 | - |
|
| 157 | - /* |
|
| 31 | + private IDBConnection $db; |
|
| 32 | + private IUserManager $userManager; |
|
| 33 | + private IGroupManager $groupManager; |
|
| 34 | + private Principal $principalBackend; |
|
| 35 | + private ICacheFactory $cacheFactory; |
|
| 36 | + private LoggerInterface $logger; |
|
| 37 | + private SharingMapper $sharingMapper; |
|
| 38 | + private SharingService $sharingService; |
|
| 39 | + private Backend $sharingBackend; |
|
| 40 | + |
|
| 41 | + private $resourceIds = [10001]; |
|
| 42 | + |
|
| 43 | + protected function setUp(): void { |
|
| 44 | + parent::setUp(); |
|
| 45 | + |
|
| 46 | + $this->db = Server::get(IDBConnection::class); |
|
| 47 | + |
|
| 48 | + $this->userManager = $this->createMock(IUserManager::class); |
|
| 49 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
| 50 | + $this->principalBackend = $this->createMock(Principal::class); |
|
| 51 | + $this->cacheFactory = $this->createMock(ICacheFactory::class); |
|
| 52 | + $this->cacheFactory->method('createInMemory') |
|
| 53 | + ->willReturn(new \OC\Memcache\NullCache()); |
|
| 54 | + $this->logger = new \Psr\Log\NullLogger(); |
|
| 55 | + |
|
| 56 | + $this->sharingMapper = new SharingMapper($this->db); |
|
| 57 | + $this->sharingService = new \OCA\DAV\CalDAV\Sharing\Service($this->sharingMapper); |
|
| 58 | + |
|
| 59 | + $this->sharingBackend = new \OCA\DAV\CalDAV\Sharing\Backend( |
|
| 60 | + $this->userManager, |
|
| 61 | + $this->groupManager, |
|
| 62 | + $this->principalBackend, |
|
| 63 | + $this->cacheFactory, |
|
| 64 | + $this->sharingService, |
|
| 65 | + $this->logger |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + $this->removeFixtures(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + protected function tearDown(): void { |
|
| 72 | + $this->removeFixtures(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + protected function removeFixtures(): void { |
|
| 76 | + $qb = $this->db->getQueryBuilder(); |
|
| 77 | + $qb->delete('dav_shares') |
|
| 78 | + ->where($qb->expr()->in('resourceid', $qb->createNamedParameter($this->resourceIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 79 | + $qb->executeStatement(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function testShareCalendarWithGroup(): void { |
|
| 83 | + $calendar = $this->createMock(Calendar::class); |
|
| 84 | + $calendar->method('getResourceId') |
|
| 85 | + ->willReturn(10001); |
|
| 86 | + $calendar->method('getOwner') |
|
| 87 | + ->willReturn('principals/users/admin'); |
|
| 88 | + |
|
| 89 | + $this->principalBackend->method('findByUri') |
|
| 90 | + ->willReturn('principals/groups/alice_bob'); |
|
| 91 | + |
|
| 92 | + $this->groupManager->method('groupExists') |
|
| 93 | + ->willReturn(true); |
|
| 94 | + |
|
| 95 | + $this->sharingBackend->updateShares( |
|
| 96 | + $calendar, |
|
| 97 | + [['href' => 'principals/groups/alice_bob']], |
|
| 98 | + [], |
|
| 99 | + [] |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function testUnshareCalendarFromGroup(): void { |
|
| 106 | + $calendar = $this->createMock(Calendar::class); |
|
| 107 | + $calendar->method('getResourceId') |
|
| 108 | + ->willReturn(10001); |
|
| 109 | + $calendar->method('getOwner') |
|
| 110 | + ->willReturn('principals/users/admin'); |
|
| 111 | + |
|
| 112 | + $this->principalBackend->method('findByUri') |
|
| 113 | + ->willReturn('principals/groups/alice_bob'); |
|
| 114 | + |
|
| 115 | + $this->groupManager->method('groupExists') |
|
| 116 | + ->willReturn(true); |
|
| 117 | + |
|
| 118 | + $this->sharingBackend->updateShares( |
|
| 119 | + shareable: $calendar, |
|
| 120 | + add: [['href' => 'principals/groups/alice_bob']], |
|
| 121 | + remove: [], |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 125 | + |
|
| 126 | + $this->sharingBackend->updateShares( |
|
| 127 | + shareable: $calendar, |
|
| 128 | + add: [], |
|
| 129 | + remove: ['principals/groups/alice_bob'], |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + $this->assertCount(0, $this->sharingService->getShares(10001)); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + public function testShareCalendarWithGroupAndUnshareAsUser(): void { |
|
| 136 | + $calendar = $this->createMock(Calendar::class); |
|
| 137 | + $calendar->method('getResourceId') |
|
| 138 | + ->willReturn(10001); |
|
| 139 | + $calendar->method('getOwner') |
|
| 140 | + ->willReturn('principals/users/admin'); |
|
| 141 | + |
|
| 142 | + $this->principalBackend->method('findByUri') |
|
| 143 | + ->willReturnMap([ |
|
| 144 | + ['principals/groups/alice_bob', '', 'principals/groups/alice_bob'], |
|
| 145 | + ['principals/users/bob', '', 'principals/users/bob'], |
|
| 146 | + ]); |
|
| 147 | + $this->principalBackend->method('getGroupMembership') |
|
| 148 | + ->willReturn([ |
|
| 149 | + 'principals/groups/alice_bob', |
|
| 150 | + ]); |
|
| 151 | + $this->principalBackend->method('getCircleMembership') |
|
| 152 | + ->willReturn([]); |
|
| 153 | + |
|
| 154 | + $this->groupManager->method('groupExists') |
|
| 155 | + ->willReturn(true); |
|
| 156 | + |
|
| 157 | + /* |
|
| 158 | 158 | * Owner is sharing the calendar with a group. |
| 159 | 159 | */ |
| 160 | - $this->sharingBackend->updateShares( |
|
| 161 | - shareable: $calendar, |
|
| 162 | - add: [['href' => 'principals/groups/alice_bob']], |
|
| 163 | - remove: [], |
|
| 164 | - ); |
|
| 160 | + $this->sharingBackend->updateShares( |
|
| 161 | + shareable: $calendar, |
|
| 162 | + add: [['href' => 'principals/groups/alice_bob']], |
|
| 163 | + remove: [], |
|
| 164 | + ); |
|
| 165 | 165 | |
| 166 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 166 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 167 | 167 | |
| 168 | - /* |
|
| 168 | + /* |
|
| 169 | 169 | * Member of the group unshares the calendar. |
| 170 | 170 | */ |
| 171 | - $this->sharingBackend->unshare( |
|
| 172 | - shareable: $calendar, |
|
| 173 | - principalUri: 'principals/users/bob' |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 177 | - $this->assertCount(1, $this->sharingService->getUnshares(10001)); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Tests the functionality of sharing a calendar with a user, then with a group (that includes the shared user), |
|
| 182 | - * and subsequently unsharing it from the individual user. Verifies that the unshare operation correctly removes the specific user share |
|
| 183 | - * without creating an additional unshare entry. |
|
| 184 | - */ |
|
| 185 | - public function testShareCalendarWithUserThenGroupThenUnshareUser(): void { |
|
| 186 | - $calendar = $this->createMock(Calendar::class); |
|
| 187 | - $calendar->method('getResourceId') |
|
| 188 | - ->willReturn(10001); |
|
| 189 | - $calendar->method('getOwner') |
|
| 190 | - ->willReturn('principals/users/admin'); |
|
| 191 | - |
|
| 192 | - $this->principalBackend->method('findByUri') |
|
| 193 | - ->willReturnMap([ |
|
| 194 | - ['principals/groups/alice_bob', '', 'principals/groups/alice_bob'], |
|
| 195 | - ['principals/users/bob', '', 'principals/users/bob'], |
|
| 196 | - ]); |
|
| 197 | - $this->principalBackend->method('getGroupMembership') |
|
| 198 | - ->willReturn([ |
|
| 199 | - 'principals/groups/alice_bob', |
|
| 200 | - ]); |
|
| 201 | - $this->principalBackend->method('getCircleMembership') |
|
| 202 | - ->willReturn([]); |
|
| 203 | - |
|
| 204 | - $this->userManager->method('userExists') |
|
| 205 | - ->willReturn(true); |
|
| 206 | - $this->groupManager->method('groupExists') |
|
| 207 | - ->willReturn(true); |
|
| 208 | - |
|
| 209 | - /* |
|
| 171 | + $this->sharingBackend->unshare( |
|
| 172 | + shareable: $calendar, |
|
| 173 | + principalUri: 'principals/users/bob' |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 177 | + $this->assertCount(1, $this->sharingService->getUnshares(10001)); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Tests the functionality of sharing a calendar with a user, then with a group (that includes the shared user), |
|
| 182 | + * and subsequently unsharing it from the individual user. Verifies that the unshare operation correctly removes the specific user share |
|
| 183 | + * without creating an additional unshare entry. |
|
| 184 | + */ |
|
| 185 | + public function testShareCalendarWithUserThenGroupThenUnshareUser(): void { |
|
| 186 | + $calendar = $this->createMock(Calendar::class); |
|
| 187 | + $calendar->method('getResourceId') |
|
| 188 | + ->willReturn(10001); |
|
| 189 | + $calendar->method('getOwner') |
|
| 190 | + ->willReturn('principals/users/admin'); |
|
| 191 | + |
|
| 192 | + $this->principalBackend->method('findByUri') |
|
| 193 | + ->willReturnMap([ |
|
| 194 | + ['principals/groups/alice_bob', '', 'principals/groups/alice_bob'], |
|
| 195 | + ['principals/users/bob', '', 'principals/users/bob'], |
|
| 196 | + ]); |
|
| 197 | + $this->principalBackend->method('getGroupMembership') |
|
| 198 | + ->willReturn([ |
|
| 199 | + 'principals/groups/alice_bob', |
|
| 200 | + ]); |
|
| 201 | + $this->principalBackend->method('getCircleMembership') |
|
| 202 | + ->willReturn([]); |
|
| 203 | + |
|
| 204 | + $this->userManager->method('userExists') |
|
| 205 | + ->willReturn(true); |
|
| 206 | + $this->groupManager->method('groupExists') |
|
| 207 | + ->willReturn(true); |
|
| 208 | + |
|
| 209 | + /* |
|
| 210 | 210 | * Step 1) The owner shares the calendar with a user. |
| 211 | 211 | */ |
| 212 | - $this->sharingBackend->updateShares( |
|
| 213 | - shareable: $calendar, |
|
| 214 | - add: [['href' => 'principals/users/bob']], |
|
| 215 | - remove: [], |
|
| 216 | - ); |
|
| 212 | + $this->sharingBackend->updateShares( |
|
| 213 | + shareable: $calendar, |
|
| 214 | + add: [['href' => 'principals/users/bob']], |
|
| 215 | + remove: [], |
|
| 216 | + ); |
|
| 217 | 217 | |
| 218 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 218 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 219 | 219 | |
| 220 | - /* |
|
| 220 | + /* |
|
| 221 | 221 | * Step 2) The owner shares the calendar with a group that includes the |
| 222 | 222 | * user from step 1 as a member. |
| 223 | 223 | */ |
| 224 | - $this->sharingBackend->updateShares( |
|
| 225 | - shareable: $calendar, |
|
| 226 | - add: [['href' => 'principals/groups/alice_bob']], |
|
| 227 | - remove: [], |
|
| 228 | - ); |
|
| 224 | + $this->sharingBackend->updateShares( |
|
| 225 | + shareable: $calendar, |
|
| 226 | + add: [['href' => 'principals/groups/alice_bob']], |
|
| 227 | + remove: [], |
|
| 228 | + ); |
|
| 229 | 229 | |
| 230 | - $this->assertCount(2, $this->sharingService->getShares(10001)); |
|
| 230 | + $this->assertCount(2, $this->sharingService->getShares(10001)); |
|
| 231 | 231 | |
| 232 | - /* |
|
| 232 | + /* |
|
| 233 | 233 | * Step 3) Unshare the calendar from user as owner. |
| 234 | 234 | */ |
| 235 | - $this->sharingBackend->updateShares( |
|
| 236 | - shareable: $calendar, |
|
| 237 | - add: [], |
|
| 238 | - remove: ['principals/users/bob'], |
|
| 239 | - ); |
|
| 235 | + $this->sharingBackend->updateShares( |
|
| 236 | + shareable: $calendar, |
|
| 237 | + add: [], |
|
| 238 | + remove: ['principals/users/bob'], |
|
| 239 | + ); |
|
| 240 | 240 | |
| 241 | - /* |
|
| 241 | + /* |
|
| 242 | 242 | * The purpose of this test is to ensure that removing a user from a share, as the owner, does not result in an "unshare" row being added. |
| 243 | 243 | * Instead, the actual user share should be removed. |
| 244 | 244 | */ |
| 245 | - $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 246 | - $this->assertCount(0, $this->sharingService->getUnshares(10001)); |
|
| 247 | - } |
|
| 245 | + $this->assertCount(1, $this->sharingService->getShares(10001)); |
|
| 246 | + $this->assertCount(0, $this->sharingService->getUnshares(10001)); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | } |