Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/dav/lib/CalDAV/TimezoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public function __construct(private IConfig $config,
}

public function getUserTimezone(string $userId): ?string {
$fromConfig = $this->config->getUserValue(
$userId,
'core',
'timezone',
);
if ($fromConfig !== '') {
return $fromConfig;
}

$availabilityPropPath = 'calendars/' . $userId . '/inbox';
$availabilityProp = '{' . Plugin::NS_CALDAV . '}calendar-availability';
$availabilities = $this->propertyMapper->findPropertyByPathAndName($userId, $availabilityPropPath, $availabilityProp);
Expand Down
31 changes: 25 additions & 6 deletions apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,22 @@ protected function setUp(): void {
);
}

public function testGetUserTimezoneFromSettings(): void {
$this->config->expects(self::once())
->method('getUserValue')
->with('test123', 'core', 'timezone', '')
->willReturn('Europe/Warsaw');

$timezone = $this->service->getUserTimezone('test123');

self::assertSame('Europe/Warsaw', $timezone);
}

public function testGetUserTimezoneFromAvailability(): void {
$this->config->expects(self::once())
->method('getUserValue')
->with('test123', 'core', 'timezone', '')
->willReturn('');
$property = new Property();
$property->setPropertyvalue('BEGIN:VCALENDAR
PRODID:Nextcloud DAV app
Expand All @@ -99,10 +114,12 @@ public function testGetUserTimezoneFromAvailability(): void {
}

public function testGetUserTimezoneFromPersonalCalendar(): void {
$this->config->expects(self::once())
$this->config->expects(self::exactly(2))
->method('getUserValue')
->with('test123', 'dav', 'defaultCalendar')
->willReturn('personal-1');
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
$personal = $this->createMock(CalendarImpl::class);
Expand All @@ -126,10 +143,12 @@ public function testGetUserTimezoneFromPersonalCalendar(): void {
}

public function testGetUserTimezoneFromAny(): void {
$this->config->expects(self::once())
$this->config->expects(self::exactly(2))
->method('getUserValue')
->with('test123', 'dav', 'defaultCalendar')
->willReturn('personal-1');
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
$personal = $this->createMock(CalendarImpl::class);
Expand Down