From: provokateurin Date: Wed, 6 Nov 2024 15:20:38 +0000 (+0100) Subject: fix(theming): Return default theme if the user never selected a theme X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c786e41a428473fd19ed503114be421c8534b09d;p=nextcloud-server.git fix(theming): Return default theme if the user never selected a theme Signed-off-by: provokateurin --- diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php index d080752a032..8244e69e219 100644 --- a/apps/theming/lib/Service/ThemesService.php +++ b/apps/theming/lib/Service/ThemesService.php @@ -143,7 +143,7 @@ class ThemesService { $this->setEnabledThemes($enabledThemes); return $enabledThemes; } - + return $themesIds; } @@ -176,7 +176,7 @@ class ThemesService { } $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); } diff --git a/apps/theming/tests/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php index 4728a2cf64e..1b152b00721 100644 --- a/apps/theming/tests/Service/ThemesServiceTest.php +++ b/apps/theming/tests/Service/ThemesServiceTest.php @@ -138,8 +138,8 @@ class ThemesServiceTest extends TestCase { 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']], @@ -164,7 +164,7 @@ class ThemesServiceTest extends TestCase { $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])); @@ -173,7 +173,7 @@ class ThemesServiceTest extends TestCase { public function dataTestDisableTheme() { return [ - ['dark', [], []], + ['dark', ['default'], ['default']], ['dark', ['dark'], []], ['opendyslexic', ['dark', 'opendyslexic'], ['dark'], ], ['light-highcontrast', ['opendyslexic'], ['opendyslexic']], @@ -198,7 +198,7 @@ class ThemesServiceTest extends TestCase { $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)); @@ -232,7 +232,7 @@ class ThemesServiceTest extends TestCase { $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)); @@ -251,14 +251,14 @@ class ThemesServiceTest extends TestCase { $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() { @@ -273,7 +273,7 @@ class ThemesServiceTest extends TestCase { $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')