Skip to content

Commit

Permalink
test: Add unit test for anonymous initial state access
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Jul 8, 2024
1 parent 7852908 commit 04db832
Showing 1 changed file with 99 additions and 3 deletions.
102 changes: 99 additions & 3 deletions tests/php/unit/Service/CalendarInitialStateServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ protected function setUp(): void {
$this->initialStateService = $this->createMock(IInitialState::class);
$this->compareVersion = $this->createMock(CompareVersion::class);
$this->userId = 'user123';
}

public function testRun(): void {
$this->service = new CalendarInitialStateService(
$this->appName,
$this->initialStateService,
Expand All @@ -60,9 +62,6 @@ protected function setUp(): void {
$this->compareVersion,
$this->userId,
);
}

public function testIndex(): void {
$this->config->expects(self::exactly(16))
->method('getAppValue')
->willReturnMap([
Expand Down Expand Up @@ -146,13 +145,110 @@ public function testIndex(): void {
$this->service->run();
}

public function testRunAnonymously(): void {
$this->service = new CalendarInitialStateService(
$this->appName,
$this->initialStateService,
$this->appManager,
$this->config,
$this->appointmentContfigService,
$this->compareVersion,
null,
);
$this->config->expects(self::exactly(16))
->method('getAppValue')
->willReturnMap([
['calendar', 'eventLimit', 'yes', 'defaultEventLimit'],
['calendar', 'currentView', 'dayGridMonth', 'defaultCurrentView'],
['calendar', 'showWeekends', 'yes', 'defaultShowWeekends'],
['calendar', 'showWeekNr', 'no', 'defaultShowWeekNr'],
['calendar', 'skipPopover', 'no', 'defaultSkipPopover'],
['calendar', 'timezone', 'automatic', 'defaultTimezone'],
['calendar', 'slotDuration', '00:30:00', 'defaultSlotDuration'],
['calendar', 'defaultReminder', 'none', 'defaultDefaultReminder'],
['calendar', 'showTasks', 'yes', 'defaultShowTasks'],
['calendar', 'installed_version', '', '1.0.0'],
['calendar', 'hideEventExport', 'no', 'yes'],
['calendar', 'disableAppointments', 'no', 'no'],
['calendar', 'forceEventAlarmType', '', 'forceEventAlarmType'],
['dav', 'allow_calendar_link_subscriptions', 'yes', 'no'],
['calendar', 'showResources', 'yes', 'yes'],
['calendar', 'publicCalendars', ''],
]);
$this->config->expects(self::exactly(11))
->method('getUserValue')
->willReturnMap([
[null, 'calendar', 'eventLimit', 'defaultEventLimit', 'yes'],
[null, 'calendar', 'firstRun', 'yes', 'yes'],
[null, 'calendar', 'currentView', 'defaultCurrentView', 'timeGridWeek'],
[null, 'calendar', 'showWeekends', 'defaultShowWeekends', 'yes'],
[null, 'calendar', 'showWeekNr', 'defaultShowWeekNr', 'yes'],
[null, 'calendar', 'skipPopover', 'defaultSkipPopover', 'yes'],
[null, 'calendar', 'timezone', 'defaultTimezone', 'Europe/Berlin'],
[null, 'dav', 'attachmentsFolder', '/Calendar', '/Calendar'],
[null, 'calendar', 'slotDuration', 'defaultSlotDuration', '00:15:00'],
[null, 'calendar', 'defaultReminder', 'defaultDefaultReminder', '00:10:00'],
[null, 'calendar', 'showTasks', 'defaultShowTasks', '00:15:00'],
]);
$this->appManager->expects(self::exactly(3))
->method('isEnabledForUser')
->willReturnMap([
['spreed', null, true],
['tasks', null, true],
['circles', null, false],
]);
$this->appManager->expects(self::exactly(2))
->method('getAppVersion')
->willReturnMap([
['spreed', true, '12.0.0'],
['circles', true, '22.0.0'],
]);
$this->initialStateService->expects(self::exactly(22))
->method('provideInitialState')
->withConsecutive(
['app_version', '1.0.0'],
['event_limit', true],
['first_run', true],
['initial_view', 'timeGridWeek'],
['show_weekends', true],
['show_week_numbers', true],
['skip_popover', true],
['talk_enabled', true],
['talk_api_version', 'v4'],
['timezone', 'Europe/Berlin'],
['attachments_folder', '/Calendar'],
['slot_duration', '00:15:00'],
['default_reminder', '00:10:00'],
['show_tasks', false],
['tasks_enabled', true],
['hide_event_export', true],
['force_event_alarm_type', null],
['disable_appointments', false],
['can_subscribe_link', false],
['show_resources', true],
['isCirclesEnabled', false],
['publicCalendars', null],
);

$this->service->run();
}

/**
* @dataProvider viewFixDataProvider
*
* @param string $savedView
* @param string $expectedView
*/
public function testIndexViewFix(string $savedView, string $expectedView): void {
$this->service = new CalendarInitialStateService(
$this->appName,
$this->initialStateService,
$this->appManager,
$this->config,
$this->appointmentContfigService,
$this->compareVersion,
$this->userId,
);
$this->config->expects(self::exactly(16))
->method('getAppValue')
->willReturnMap([
Expand Down

0 comments on commit 04db832

Please sign in to comment.