From c786e41a428473fd19ed503114be421c8534b09d Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 6 Nov 2024 16:20:38 +0100 Subject: [PATCH] fix(theming): Return default theme if the user never selected a theme Signed-off-by: provokateurin --- apps/theming/lib/Service/ThemesService.php | 4 ++-- .../tests/Service/ThemesServiceTest.php | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/theming/lib/Service/ThemesService.php b/apps/theming/lib/Service/ThemesService.php index d080752a032a3..8244e69e21911 100644 --- a/apps/theming/lib/Service/ThemesService.php +++ b/apps/theming/lib/Service/ThemesService.php @@ -143,7 +143,7 @@ public function disableTheme(ITheme $theme): array { $this->setEnabledThemes($enabledThemes); return $enabledThemes; } - + return $themesIds; } @@ -176,7 +176,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); } diff --git a/apps/theming/tests/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php index 4728a2cf64ed5..1b152b0072124 100644 --- a/apps/theming/tests/Service/ThemesServiceTest.php +++ b/apps/theming/tests/Service/ThemesServiceTest.php @@ -138,8 +138,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']], @@ -164,7 +164,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])); @@ -173,7 +173,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']], @@ -198,7 +198,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)); @@ -232,7 +232,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)); @@ -251,14 +251,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() { @@ -273,7 +273,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')