Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(theming): Return default theme if the user never selected a theme #49138

Merged
merged 1 commit into from
Nov 8, 2024
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
4 changes: 2 additions & 2 deletions apps/theming/lib/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function disableTheme(ITheme $theme): array {
$this->setEnabledThemes($enabledThemes);
return $enabledThemes;
}

return $themesIds;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function getEnabledThemes(): array {
}

$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '[]'));
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]'));
if ($enforcedTheme !== '') {
return array_merge([$enforcedTheme], $enabledThemes);
}
Expand Down
20 changes: 10 additions & 10 deletions apps/theming/tests/Service/ThemesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function testGetThemesEnforcedInvalid() {

public function dataTestEnableTheme() {
return [
['default', [], ['default']],
['dark', [], ['dark']],
['default', ['default'], ['default']],
['dark', ['default'], ['dark']],
['dark', ['dark'], ['dark']],
['opendyslexic', ['dark'], ['dark', 'opendyslexic']],
['dark', ['light-highcontrast', 'opendyslexic'], ['opendyslexic', 'dark']],
Expand All @@ -147,7 +147,7 @@ public function testEnableTheme(string $toEnable, array $enabledThemes, array $e

$this->config->expects($this->once())
->method('getUserValue')
->with('user', Application::APP_ID, 'enabled-themes', '[]')
->with('user', Application::APP_ID, 'enabled-themes', '["default"]')
->willReturn(json_encode($enabledThemes));

$this->assertEquals($expectedEnabled, $this->themesService->enableTheme($this->themes[$toEnable]));
Expand All @@ -156,7 +156,7 @@ public function testEnableTheme(string $toEnable, array $enabledThemes, array $e

public function dataTestDisableTheme() {
return [
['dark', [], []],
['dark', ['default'], ['default']],
['dark', ['dark'], []],
['opendyslexic', ['dark', 'opendyslexic'], ['dark'], ],
['light-highcontrast', ['opendyslexic'], ['opendyslexic']],
Expand All @@ -181,7 +181,7 @@ public function testDisableTheme(string $toDisable, array $enabledThemes, array

$this->config->expects($this->once())
->method('getUserValue')
->with('user', Application::APP_ID, 'enabled-themes', '[]')
->with('user', Application::APP_ID, 'enabled-themes', '["default"]')
->willReturn(json_encode($enabledThemes));


Expand Down Expand Up @@ -215,7 +215,7 @@ public function testIsEnabled(string $themeId, array $enabledThemes, $expected)

$this->config->expects($this->once())
->method('getUserValue')
->with('user', Application::APP_ID, 'enabled-themes', '[]')
->with('user', Application::APP_ID, 'enabled-themes', '["default"]')
->willReturn(json_encode($enabledThemes));


Expand All @@ -234,14 +234,14 @@ public function testGetEnabledThemes() {

$this->config->expects($this->once())
->method('getUserValue')
->with('user', Application::APP_ID, 'enabled-themes', '[]')
->willReturn(json_encode([]));
->with('user', Application::APP_ID, 'enabled-themes', '["default"]')
->willReturn(json_encode(['default']));
$this->config->expects($this->once())
->method('getSystemValueString')
->with('enforce_theme', '')
->willReturn('');

$this->assertEquals([], $this->themesService->getEnabledThemes());
$this->assertEquals(['default'], $this->themesService->getEnabledThemes());
}

public function testGetEnabledThemesEnforced() {
Expand All @@ -256,7 +256,7 @@ public function testGetEnabledThemesEnforced() {

$this->config->expects($this->once())
->method('getUserValue')
->with('user', Application::APP_ID, 'enabled-themes', '[]')
->with('user', Application::APP_ID, 'enabled-themes', '["default"]')
->willReturn(json_encode([]));
$this->config->expects($this->once())
->method('getSystemValueString')
Expand Down
Loading