request = $this->createMock(IRequest::class); $this->config = $this->createMock(IConfig::class); $this->userSession = $this->createMock(IUserSession::class); $this->themesService = $this->createMock(ThemesService::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->backgroundService = $this->createMock(BackgroundService::class); $this->themes = [ 'default' => $this->createMock(DefaultTheme::class), 'light' => $this->createMock(LightTheme::class), 'dark' => $this->createMock(DarkTheme::class), 'light-highcontrast' => $this->createMock(HighContrastTheme::class), 'dark-highcontrast' => $this->createMock(DarkHighContrastTheme::class), 'opendyslexic' => $this->createMock(DyslexiaFont::class), ]; $user = $this->createMock(IUser::class); $this->userSession->expects($this->any()) ->method('getUser') ->willReturn($user); $user->expects($this->any()) ->method('getUID') ->willReturn('user'); $this->userThemeController = new UserThemeController( Application::APP_ID, $this->request, $this->config, $this->userSession, $this->themesService, $this->themingDefaults, $this->backgroundService, ); parent::setUp(); } public function dataTestThemes() { return [ ['default'], ['light'], ['dark'], ['light-highcontrast'], ['dark-highcontrast'], ['opendyslexic'], ['', OCSBadRequestException::class], ['badTheme', OCSBadRequestException::class], ]; } /** * @dataProvider dataTestThemes * * @param string $themeId * @param string $exception */ public function testEnableTheme($themeId, ?string $exception = null): void { $this->themesService ->expects($this->any()) ->method('getThemes') ->willReturn($this->themes); if ($exception) { $this->expectException($exception); } $expected = new DataResponse(); $this->assertEquals($expected, $this->userThemeController->enableTheme($themeId)); } /** * @dataProvider dataTestThemes * * @param string $themeId * @param string $exception */ public function testDisableTheme($themeId, ?string $exception = null): void { $this->themesService ->expects($this->any()) ->method('getThemes') ->willReturn($this->themes); if ($exception) { $this->expectException($exception); } $expected = new DataResponse(); $this->assertEquals($expected, $this->userThemeController->disableTheme($themeId)); } }