|
32 | 32 |
|
33 | 33 | namespace OCA\DAV\Tests\unit\CalDAV; |
34 | 34 |
|
| 35 | +use DateInterval; |
35 | 36 | use DateTime; |
| 37 | +use DateTimeImmutable; |
36 | 38 | use DateTimeZone; |
37 | 39 | use OCA\DAV\CalDAV\CalDavBackend; |
38 | 40 | use OCA\DAV\CalDAV\Calendar; |
@@ -1420,4 +1422,71 @@ public function testPruneOutdatedSyncTokens(): void { |
1420 | 1422 | // Check that no crash occurs when prune is called without current changes |
1421 | 1423 | $deleted = $this->backend->pruneOutdatedSyncTokens(1); |
1422 | 1424 | } |
| 1425 | + |
| 1426 | + public function testSearchAndExpandRecurrences() { |
| 1427 | + $calendarId = $this->createTestCalendar(); |
| 1428 | + $calendarInfo = [ |
| 1429 | + 'id' => $calendarId, |
| 1430 | + 'principaluri' => 'user1', |
| 1431 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
| 1432 | + ]; |
| 1433 | + |
| 1434 | + $calData = <<<'EOD' |
| 1435 | +BEGIN:VCALENDAR |
| 1436 | +PRODID:-//IDN nextcloud.com//Calendar app 4.5.0-alpha.2//EN |
| 1437 | +CALSCALE:GREGORIAN |
| 1438 | +VERSION:2.0 |
| 1439 | +BEGIN:VEVENT |
| 1440 | +CREATED:20230921T133401Z |
| 1441 | +DTSTAMP:20230921T133448Z |
| 1442 | +LAST-MODIFIED:20230921T133448Z |
| 1443 | +SEQUENCE:2 |
| 1444 | +UID:7b7d5d12-683c-48ce-973a-b3e1cb0bae2a |
| 1445 | +DTSTART;VALUE=DATE:20230912 |
| 1446 | +DTEND;VALUE=DATE:20230913 |
| 1447 | +STATUS:CONFIRMED |
| 1448 | +SUMMARY:Daily Event |
| 1449 | +RRULE:FREQ=DAILY |
| 1450 | +END:VEVENT |
| 1451 | +END:VCALENDAR |
| 1452 | +EOD; |
| 1453 | + $uri = static::getUniqueID('calobj'); |
| 1454 | + $this->backend->createCalendarObject($calendarId, $uri, $calData); |
| 1455 | + |
| 1456 | + $start = new DateTimeImmutable('2023-09-20T00:00:00Z'); |
| 1457 | + $end = $start->add(new DateInterval('P14D')); |
| 1458 | + |
| 1459 | + $results = $this->backend->search( |
| 1460 | + $calendarInfo, |
| 1461 | + '', |
| 1462 | + [], |
| 1463 | + [ |
| 1464 | + 'timerange' => [ |
| 1465 | + 'start' => $start, |
| 1466 | + 'end' => $end, |
| 1467 | + ] |
| 1468 | + ], |
| 1469 | + null, |
| 1470 | + null, |
| 1471 | + ); |
| 1472 | + |
| 1473 | + $this->assertCount(1, $results); |
| 1474 | + $this->assertCount(14, $results[0]['objects']); |
| 1475 | + foreach ($results as $result) { |
| 1476 | + foreach ($result['objects'] as $object) { |
| 1477 | + $this->assertEquals($object['UID'][0], '7b7d5d12-683c-48ce-973a-b3e1cb0bae2a'); |
| 1478 | + $this->assertEquals($object['SUMMARY'][0], 'Daily Event'); |
| 1479 | + $this->assertGreaterThanOrEqual( |
| 1480 | + $start->getTimestamp(), |
| 1481 | + $object['DTSTART'][0]->getTimestamp(), |
| 1482 | + 'Recurrence starting before requested start', |
| 1483 | + ); |
| 1484 | + $this->assertLessThanOrEqual( |
| 1485 | + $end->getTimestamp(), |
| 1486 | + $object['DTSTART'][0]->getTimestamp(), |
| 1487 | + 'Recurrence starting after requested end', |
| 1488 | + ); |
| 1489 | + } |
| 1490 | + } |
| 1491 | + } |
1423 | 1492 | } |
0 commit comments