diff options
Diffstat (limited to 'apps/theming/tests/Controller/UserThemeControllerTest.php')
-rw-r--r-- | apps/theming/tests/Controller/UserThemeControllerTest.php | 82 |
1 files changed, 32 insertions, 50 deletions
diff --git a/apps/theming/tests/Controller/UserThemeControllerTest.php b/apps/theming/tests/Controller/UserThemeControllerTest.php index b925085bf41..9a8c1cd19aa 100644 --- a/apps/theming/tests/Controller/UserThemeControllerTest.php +++ b/apps/theming/tests/Controller/UserThemeControllerTest.php @@ -1,35 +1,24 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com> - * - * @author John Molakvoæ <skjnldsv@protonmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Theming\Tests\Controller; +use OCA\Theming\AppInfo\Application; use OCA\Theming\Controller\UserThemeController; use OCA\Theming\ITheme; +use OCA\Theming\Service\BackgroundService; +use OCA\Theming\Service\ThemesService; use OCA\Theming\Themes\DarkHighContrastTheme; use OCA\Theming\Themes\DarkTheme; use OCA\Theming\Themes\DefaultTheme; use OCA\Theming\Themes\DyslexiaFont; use OCA\Theming\Themes\HighContrastTheme; -use OCA\Theming\Service\ThemesService; +use OCA\Theming\Themes\LightTheme; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\IConfig; @@ -40,31 +29,31 @@ use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UserThemeControllerTest extends TestCase { - /** @var UserThemeController */ - private $userThemeController; - - /** @var IRequest|MockObject */ - private $request; - /** @var IConfig|MockObject */ - private $config; - /** @var IUserSession|MockObject */ - private $userSession; - /** @var ThemeService|MockObject */ - private $themesService; + private IRequest&MockObject $request; + private IConfig&MockObject $config; + private IUserSession&MockObject $userSession; + private ThemesService&MockObject $themesService; + private ThemingDefaults&MockObject $themingDefaults; + private BackgroundService&MockObject $backgroundService; + private UserThemeController $userThemeController; + /** @var ITheme[] */ - private $themes; + private array $themes; protected function setUp(): void { $this->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), - 'highcontrast' => $this->createMock(HighContrastTheme::class), + 'light-highcontrast' => $this->createMock(HighContrastTheme::class), 'dark-highcontrast' => $this->createMock(DarkHighContrastTheme::class), 'opendyslexic' => $this->createMock(DyslexiaFont::class), ]; @@ -78,21 +67,24 @@ class UserThemeControllerTest extends TestCase { ->willReturn('user'); $this->userThemeController = new UserThemeController( - 'theming', + Application::APP_ID, $this->request, $this->config, $this->userSession, $this->themesService, + $this->themingDefaults, + $this->backgroundService, ); parent::setUp(); } - public function dataTestThemes() { + public static function dataTestThemes(): array { return [ ['default'], + ['light'], ['dark'], - ['highcontrast'], + ['light-highcontrast'], ['dark-highcontrast'], ['opendyslexic'], ['', OCSBadRequestException::class], @@ -100,13 +92,8 @@ class UserThemeControllerTest extends TestCase { ]; } - /** - * @dataProvider dataTestThemes - * - * @param string $themeId - * @param string $exception - */ - public function testEnableTheme($themeId, string $exception = null) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestThemes')] + public function testEnableTheme(string $themeId, ?string $exception = null): void { $this->themesService ->expects($this->any()) ->method('getThemes') @@ -120,13 +107,8 @@ class UserThemeControllerTest extends TestCase { $this->assertEquals($expected, $this->userThemeController->enableTheme($themeId)); } - /** - * @dataProvider dataTestThemes - * - * @param string $themeId - * @param string $exception - */ - public function testDisableTheme($themeId, string $exception = null) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestThemes')] + public function testDisableTheme(string $themeId, ?string $exception = null): void { $this->themesService ->expects($this->any()) ->method('getThemes') |