2424use OCP \IUser ;
2525use OCP \IUserSession ;
2626use PHPUnit \Framework \MockObject \MockObject ;
27+ use Psr \Log \LoggerInterface ;
2728use Test \TestCase ;
2829
2930class ThemesServiceTest extends TestCase {
@@ -34,6 +35,9 @@ class ThemesServiceTest extends TestCase {
3435 private $ userSession ;
3536 /** @var IConfig|MockObject */
3637 private $ config ;
38+ /** @var LoggerInterface|MockObject */
39+ private $ logger ;
40+
3741 /** @var ThemingDefaults|MockObject */
3842 private $ themingDefaults ;
3943
@@ -43,6 +47,7 @@ class ThemesServiceTest extends TestCase {
4347 protected function setUp (): void {
4448 $ this ->userSession = $ this ->createMock (IUserSession::class);
4549 $ this ->config = $ this ->createMock (IConfig::class);
50+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
4651 $ this ->themingDefaults = $ this ->createMock (ThemingDefaults::class);
4752
4853 $ this ->themingDefaults ->expects ($ this ->any ())
@@ -58,6 +63,7 @@ protected function setUp(): void {
5863 $ this ->themesService = new ThemesService (
5964 $ this ->userSession ,
6065 $ this ->config ,
66+ $ this ->logger ,
6167 ...array_values ($ this ->themes )
6268 );
6369
@@ -76,6 +82,42 @@ public function testGetThemes() {
7682 $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
7783 }
7884
85+ public function testGetThemesEnforced () {
86+ $ this ->config ->expects ($ this ->once ())
87+ ->method ('getSystemValueString ' )
88+ ->with ('enforce_theme ' , '' )
89+ ->willReturn ('dark ' );
90+ $ this ->logger ->expects ($ this ->never ())
91+ ->method ('error ' );
92+
93+ $ expected = [
94+ 'default ' ,
95+ 'dark ' ,
96+ ];
97+
98+ $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
99+ }
100+
101+ public function testGetThemesEnforcedInvalid () {
102+ $ this ->config ->expects ($ this ->once ())
103+ ->method ('getSystemValueString ' )
104+ ->with ('enforce_theme ' , '' )
105+ ->willReturn ('invalid ' );
106+ $ this ->logger ->expects ($ this ->once ())
107+ ->method ('error ' )
108+ ->with ('Enforced theme not found ' , ['theme ' => 'invalid ' ]);
109+
110+ $ expected = [
111+ 'default ' ,
112+ 'light ' ,
113+ 'dark ' ,
114+ 'light-highcontrast ' ,
115+ 'dark-highcontrast ' ,
116+ 'opendyslexic ' ,
117+ ];
118+
119+ $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
120+ }
79121
80122 public function dataTestEnableTheme () {
81123 return [
0 commit comments