4141use OCP \IUser ;
4242use OCP \IUserSession ;
4343use PHPUnit \Framework \MockObject \MockObject ;
44+ use Psr \Log \LoggerInterface ;
4445use Test \TestCase ;
4546
4647class ThemesServiceTest extends TestCase {
@@ -51,6 +52,9 @@ class ThemesServiceTest extends TestCase {
5152 private $ userSession ;
5253 /** @var IConfig|MockObject */
5354 private $ config ;
55+ /** @var LoggerInterface|MockObject */
56+ private $ logger ;
57+
5458 /** @var ThemingDefaults|MockObject */
5559 private $ themingDefaults ;
5660
@@ -60,6 +64,7 @@ class ThemesServiceTest extends TestCase {
6064 protected function setUp (): void {
6165 $ this ->userSession = $ this ->createMock (IUserSession::class);
6266 $ this ->config = $ this ->createMock (IConfig::class);
67+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
6368 $ this ->themingDefaults = $ this ->createMock (ThemingDefaults::class);
6469
6570 $ this ->themingDefaults ->expects ($ this ->any ())
@@ -75,6 +80,7 @@ protected function setUp(): void {
7580 $ this ->themesService = new ThemesService (
7681 $ this ->userSession ,
7782 $ this ->config ,
83+ $ this ->logger ,
7884 ...array_values ($ this ->themes )
7985 );
8086
@@ -93,6 +99,42 @@ public function testGetThemes() {
9399 $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
94100 }
95101
102+ public function testGetThemesEnforced () {
103+ $ this ->config ->expects ($ this ->once ())
104+ ->method ('getSystemValueString ' )
105+ ->with ('enforce_theme ' , '' )
106+ ->willReturn ('dark ' );
107+ $ this ->logger ->expects ($ this ->never ())
108+ ->method ('error ' );
109+
110+ $ expected = [
111+ 'default ' ,
112+ 'dark ' ,
113+ ];
114+
115+ $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
116+ }
117+
118+ public function testGetThemesEnforcedInvalid () {
119+ $ this ->config ->expects ($ this ->once ())
120+ ->method ('getSystemValueString ' )
121+ ->with ('enforce_theme ' , '' )
122+ ->willReturn ('invalid ' );
123+ $ this ->logger ->expects ($ this ->once ())
124+ ->method ('error ' )
125+ ->with ('Enforced theme not found ' , ['theme ' => 'invalid ' ]);
126+
127+ $ expected = [
128+ 'default ' ,
129+ 'light ' ,
130+ 'dark ' ,
131+ 'light-highcontrast ' ,
132+ 'dark-highcontrast ' ,
133+ 'opendyslexic ' ,
134+ ];
135+
136+ $ this ->assertEquals ($ expected , array_keys ($ this ->themesService ->getThemes ()));
137+ }
96138
97139 public function dataTestEnableTheme () {
98140 return [
0 commit comments