aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming/tests')
-rw-r--r--apps/theming/tests/CapabilitiesTest.php46
-rw-r--r--apps/theming/tests/Controller/IconControllerTest.php42
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php114
-rw-r--r--apps/theming/tests/Controller/UserThemeControllerTest.php46
-rw-r--r--apps/theming/tests/IconBuilderTest.php64
-rw-r--r--apps/theming/tests/ImageManagerTest.php42
-rw-r--r--apps/theming/tests/Service/ThemesServiceTest.php42
-rw-r--r--apps/theming/tests/ServicesTest.php20
-rw-r--r--apps/theming/tests/Settings/AdminSectionTest.php12
-rw-r--r--apps/theming/tests/Settings/AdminTest.php17
-rw-r--r--apps/theming/tests/Settings/PersonalTest.php13
-rw-r--r--apps/theming/tests/Themes/AccessibleThemeTestCase.php14
-rw-r--r--apps/theming/tests/Themes/DarkHighContrastThemeTest.php24
-rw-r--r--apps/theming/tests/Themes/DarkThemeTest.php23
-rw-r--r--apps/theming/tests/Themes/DefaultThemeTest.php23
-rw-r--r--apps/theming/tests/Themes/DyslexiaFontTest.php33
-rw-r--r--apps/theming/tests/Themes/HighContrastThemeTest.php25
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php84
-rw-r--r--apps/theming/tests/UtilTest.php42
19 files changed, 284 insertions, 442 deletions
diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php
index 1274be929ef..aa08a45a28b 100644
--- a/apps/theming/tests/CapabilitiesTest.php
+++ b/apps/theming/tests/CapabilitiesTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -24,22 +26,12 @@ use Test\TestCase;
* @package OCA\Theming\Tests
*/
class CapabilitiesTest extends TestCase {
- /** @var ThemingDefaults|MockObject */
- protected $theming;
-
- /** @var IURLGenerator|MockObject */
- protected $url;
-
- /** @var IConfig|MockObject */
- protected $config;
-
- /** @var Util|MockObject */
- protected $util;
-
+ protected ThemingDefaults&MockObject $theming;
+ protected IURLGenerator&MockObject $url;
+ protected IConfig&MockObject $config;
+ protected Util&MockObject $util;
protected IUserSession $userSession;
-
- /** @var Capabilities */
- protected $capabilities;
+ protected Capabilities $capabilities;
protected function setUp(): void {
parent::setUp();
@@ -58,10 +50,11 @@ class CapabilitiesTest extends TestCase {
);
}
- public function dataGetCapabilities() {
+ public static function dataGetCapabilities(): array {
return [
['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
'name' => 'name',
+ 'productName' => 'name',
'url' => 'url',
'slogan' => 'slogan',
'color' => '#FFFFFF',
@@ -79,6 +72,7 @@ class CapabilitiesTest extends TestCase {
]],
['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', '#fff', '#000', 'http://localhost/', false, [
'name' => 'name1',
+ 'productName' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
'color' => '#01e4a0',
@@ -96,6 +90,7 @@ class CapabilitiesTest extends TestCase {
]],
['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', true, [
'name' => 'name1',
+ 'productName' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
'color' => '#000000',
@@ -113,6 +108,7 @@ class CapabilitiesTest extends TestCase {
]],
['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', false, [
'name' => 'name1',
+ 'productName' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
'color' => '#000000',
@@ -132,19 +128,10 @@ class CapabilitiesTest extends TestCase {
}
/**
- * @dataProvider dataGetCapabilities
- * @param string $name
- * @param string $url
- * @param string $slogan
- * @param string $color
- * @param string $textColor
- * @param string $logo
- * @param string $background
- * @param string $baseUrl
- * @param bool $backgroundThemed
- * @param string[] $expected
+ * @param non-empty-array<string, string> $expected
*/
- public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $backgroundColor, $backgroundTextColor, $baseUrl, $backgroundThemed, array $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetCapabilities')]
+ public function testGetCapabilities(string $name, string $url, string $slogan, string $color, string $textColor, string $logo, string $background, string $backgroundColor, string $backgroundTextColor, string $baseUrl, bool $backgroundThemed, array $expected): void {
$this->config->expects($this->once())
->method('getAppValue')
->willReturn($background);
@@ -152,6 +139,9 @@ class CapabilitiesTest extends TestCase {
->method('getName')
->willReturn($name);
$this->theming->expects($this->once())
+ ->method('getProductName')
+ ->willReturn($name);
+ $this->theming->expects($this->once())
->method('getBaseUrl')
->willReturn($url);
$this->theming->expects($this->once())
diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php
index 42e841e9a0f..c5034600e03 100644
--- a/apps/theming/tests/Controller/IconControllerTest.php
+++ b/apps/theming/tests/Controller/IconControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -17,29 +19,19 @@ use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException;
-use OCP\IConfig;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class IconControllerTest extends TestCase {
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
- /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
- private $themingDefaults;
- /** @var ITimeFactory */
- private $timeFactory;
- /** @var IconController|\PHPUnit\Framework\MockObject\MockObject */
- private $iconController;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- private $config;
- /** @var IconBuilder|\PHPUnit\Framework\MockObject\MockObject */
- private $iconBuilder;
- /** @var FileAccessHelper|\PHPUnit\Framework\MockObject\MockObject */
- private $fileAccessHelper;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
- private $appManager;
- /** @var ImageManager */
- private $imageManager;
+ private IRequest&MockObject $request;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private ITimeFactory&MockObject $timeFactory;
+ private IconBuilder&MockObject $iconBuilder;
+ private FileAccessHelper&MockObject $fileAccessHelper;
+ private IAppManager&MockObject $appManager;
+ private ImageManager&MockObject $imageManager;
+ private IconController $iconController;
protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
@@ -103,13 +95,13 @@ class IconControllerTest extends TestCase {
$this->imageManager->expects($this->once())
->method('getImage', false)
->with('favicon')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->imageManager->expects($this->any())
->method('shouldReplaceIcons')
->willReturn(true);
$this->imageManager->expects($this->once())
->method('getCachedImage')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->iconBuilder->expects($this->once())
->method('getFavicon')
->with('core')
@@ -127,7 +119,7 @@ class IconControllerTest extends TestCase {
$this->imageManager->expects($this->once())
->method('getImage')
->with('favicon', false)
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->imageManager->expects($this->any())
->method('shouldReplaceIcons')
->willReturn(false);
@@ -152,7 +144,7 @@ class IconControllerTest extends TestCase {
$this->imageManager->expects($this->once())
->method('getImage')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->imageManager->expects($this->any())
->method('shouldReplaceIcons')
->willReturn(true);
@@ -163,7 +155,7 @@ class IconControllerTest extends TestCase {
$file = $this->iconFileMock('filename', 'filecontent');
$this->imageManager->expects($this->once())
->method('getCachedImage')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->imageManager->expects($this->once())
->method('setCachedImage')
->willReturn($file);
@@ -177,7 +169,7 @@ class IconControllerTest extends TestCase {
$this->imageManager->expects($this->once())
->method('getImage')
->with('favicon')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$this->imageManager->expects($this->any())
->method('shouldReplaceIcons')
->willReturn(false);
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index 6dfbb72bb77..fb461f03a28 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -82,7 +84,7 @@ class ThemingControllerTest extends TestCase {
parent::setUp();
}
- public function dataUpdateStylesheetSuccess() {
+ public static function dataUpdateStylesheetSuccess(): array {
return [
['name', str_repeat('a', 250), 'Saved'],
['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
@@ -95,14 +97,8 @@ class ThemingControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataUpdateStylesheetSuccess
- *
- * @param string $setting
- * @param string $value
- * @param string $message
- */
- public function testUpdateStylesheetSuccess($setting, $value, $message): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateStylesheetSuccess')]
+ public function testUpdateStylesheetSuccess(string $setting, string $value, string $message): void {
$this->themingDefaults
->expects($this->once())
->method('set')
@@ -116,8 +112,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => $message,
],
'status' => 'success',
@@ -126,7 +122,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
}
- public function dataUpdateStylesheetError() {
+ public static function dataUpdateStylesheetError(): array {
$urls = [
'url' => 'web address',
'imprintUrl' => 'legal notice address',
@@ -157,14 +153,8 @@ class ThemingControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataUpdateStylesheetError
- *
- * @param string $setting
- * @param string $value
- * @param string $message
- */
- public function testUpdateStylesheetError($setting, $value, $message): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateStylesheetError')]
+ public function testUpdateStylesheetError(string $setting, string $value, string $message): void {
$this->themingDefaults
->expects($this->never())
->method('set')
@@ -178,8 +168,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => $message,
],
'status' => 'error',
@@ -209,8 +199,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => 'No file uploaded',
],
'status' => 'failure',
@@ -239,8 +229,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => 'Invalid key',
],
'status' => 'failure',
@@ -254,9 +244,6 @@ class ThemingControllerTest extends TestCase {
/**
* Checks that trying to upload an SVG favicon without imagemagick
* results in an unsupported media type response.
- *
- * @test
- * @return void
*/
public function testUploadSVGFaviconWithoutImagemagick(): void {
$this->imageManager
@@ -291,8 +278,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => 'Unsupported image type',
],
'status' => 'failure'
@@ -332,8 +319,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => 'Unsupported image type',
],
'status' => 'failure'
@@ -344,7 +331,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage());
}
- public function dataUpdateImages() {
+ public static function dataUpdateImages(): array {
return [
['image/jpeg', false],
['image/jpeg', true],
@@ -355,8 +342,8 @@ class ThemingControllerTest extends TestCase {
];
}
- /** @dataProvider dataUpdateImages */
- public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateImages')]
+ public function testUpdateLogoNormalLogoUpload(string $mimeType, bool $folderExists = true): void {
$tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . '/logo.svg';
$destination = Server::get(ITempManager::class)->getTemporaryFolder();
@@ -394,8 +381,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'name' => 'logo.svg',
'message' => 'Saved',
'url' => 'imageUrl',
@@ -407,8 +394,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage());
}
- /** @dataProvider dataUpdateImages */
- public function testUpdateLogoLoginScreenUpload($folderExists): void {
+ public function testUpdateLogoLoginScreenUpload(): void {
$tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . 'logo.png';
touch($tmpLogo);
@@ -444,8 +430,8 @@ class ThemingControllerTest extends TestCase {
->willReturn('imageUrl');
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'name' => 'logo.svg',
'message' => 'Saved',
'url' => 'imageUrl',
@@ -489,8 +475,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => 'Unsupported image type',
],
'status' => 'failure'
@@ -500,7 +486,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage());
}
- public function dataPhpUploadErrors() {
+ public static function dataPhpUploadErrors(): array {
return [
[UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'],
[UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'],
@@ -512,10 +498,8 @@ class ThemingControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataPhpUploadErrors
- */
- public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPhpUploadErrors')]
+ public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload(int $error, string $expectedErrorMessage): void {
$this->request
->expects($this->once())
->method('getParam')
@@ -540,8 +524,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => $expectedErrorMessage,
],
'status' => 'failure'
@@ -551,9 +535,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage());
}
- /**
- * @dataProvider dataPhpUploadErrors
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataPhpUploadErrors')]
public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage): void {
$this->request
->expects($this->once())
@@ -579,8 +561,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'message' => $expectedErrorMessage
],
'status' => 'failure'
@@ -604,8 +586,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'value' => 'MyValue',
'message' => 'Saved'
],
@@ -615,15 +597,15 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->undo('MySetting'));
}
- public function dataUndoDelete() {
+ public static function dataUndoDelete(): array {
return [
[ 'backgroundMime', 'background' ],
[ 'logoMime', 'logo' ]
];
}
- /** @dataProvider dataUndoDelete */
- public function testUndoDelete($value, $filename): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUndoDelete')]
+ public function testUndoDelete(string $value, string $filename): void {
$this->l10n
->expects($this->once())
->method('t')
@@ -637,8 +619,8 @@ class ThemingControllerTest extends TestCase {
$expected = new DataResponse(
[
- 'data' =>
- [
+ 'data'
+ => [
'value' => $value,
'message' => 'Saved',
],
@@ -722,7 +704,7 @@ class ThemingControllerTest extends TestCase {
];
}
- /** @dataProvider dataGetManifest */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetManifest')]
public function testGetManifest(bool $standalone): void {
$this->config
->expects($this->once())
@@ -752,8 +734,8 @@ class ThemingControllerTest extends TestCase {
$response = new JSONResponse([
'name' => 'Nextcloud',
'start_url' => 'localhost',
- 'icons' =>
- [
+ 'icons'
+ => [
[
'src' => 'touchicon?v=0',
'type' => 'image/png',
diff --git a/apps/theming/tests/Controller/UserThemeControllerTest.php b/apps/theming/tests/Controller/UserThemeControllerTest.php
index 7d369463c0d..9a8c1cd19aa 100644
--- a/apps/theming/tests/Controller/UserThemeControllerTest.php
+++ b/apps/theming/tests/Controller/UserThemeControllerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -27,25 +29,17 @@ 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;
- /** @var ThemingDefaults */
- private $themingDefaults;
- /** @var BackgroundService|MockObject */
- private $backgroundService;
+ 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);
@@ -85,7 +79,7 @@ class UserThemeControllerTest extends TestCase {
parent::setUp();
}
- public function dataTestThemes() {
+ public static function dataTestThemes(): array {
return [
['default'],
['light'],
@@ -98,13 +92,8 @@ class UserThemeControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataTestThemes
- *
- * @param string $themeId
- * @param string $exception
- */
- public function testEnableTheme($themeId, ?string $exception = null): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestThemes')]
+ public function testEnableTheme(string $themeId, ?string $exception = null): void {
$this->themesService
->expects($this->any())
->method('getThemes')
@@ -118,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): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestThemes')]
+ public function testDisableTheme(string $themeId, ?string $exception = null): void {
$this->themesService
->expects($this->any())
->method('getThemes')
diff --git a/apps/theming/tests/IconBuilderTest.php b/apps/theming/tests/IconBuilderTest.php
index ec7bd8bcc55..d881e4eb75c 100644
--- a/apps/theming/tests/IconBuilderTest.php
+++ b/apps/theming/tests/IconBuilderTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -14,25 +16,17 @@ use OCP\App\IAppManager;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\ServerVersion;
-use PHPUnit\Framework\Error\Warning;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class IconBuilderTest extends TestCase {
-
- /** @var IConfig */
- protected $config;
- /** @var AppData */
- protected $appData;
- /** @var ThemingDefaults */
- protected $themingDefaults;
- /** @var Util */
- protected $util;
- /** @var ImageManager */
- protected $imageManager;
- /** @var IconBuilder */
- protected $iconBuilder;
- /** @var IAppManager */
- protected $appManager;
+ protected IConfig&MockObject $config;
+ protected AppData&MockObject $appData;
+ protected ThemingDefaults&MockObject $themingDefaults;
+ protected ImageManager&MockObject $imageManager;
+ protected IAppManager&MockObject $appManager;
+ protected Util $util;
+ protected IconBuilder $iconBuilder;
protected function setUp(): void {
parent::setUp();
@@ -59,7 +53,7 @@ class IconBuilderTest extends TestCase {
}
}
- public function dataRenderAppIcon() {
+ public static function dataRenderAppIcon(): array {
return [
['core', '#0082c9', 'touch-original.png'],
['core', '#FF0000', 'touch-core-red.png'],
@@ -69,13 +63,8 @@ class IconBuilderTest extends TestCase {
];
}
- /**
- * @dataProvider dataRenderAppIcon
- * @param $app
- * @param $color
- * @param $file
- */
- public function testRenderAppIcon($app, $color, $file): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')]
+ public function testRenderAppIcon(string $app, string $color, string $file): void {
$this->checkImagick();
$this->themingDefaults->expects($this->once())
->method('getColorPrimary')
@@ -98,13 +87,8 @@ class IconBuilderTest extends TestCase {
// cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
- /**
- * @dataProvider dataRenderAppIcon
- * @param $app
- * @param $color
- * @param $file
- */
- public function testGetTouchIcon($app, $color, $file): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')]
+ public function testGetTouchIcon(string $app, string $color, string $file): void {
$this->checkImagick();
$this->themingDefaults->expects($this->once())
->method('getColorPrimary')
@@ -128,13 +112,8 @@ class IconBuilderTest extends TestCase {
// cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
- /**
- * @dataProvider dataRenderAppIcon
- * @param $app
- * @param $color
- * @param $file
- */
- public function testGetFavicon($app, $color, $file): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataRenderAppIcon')]
+ public function testGetFavicon(string $app, string $color, string $file): void {
$this->checkImagick();
$this->imageManager->expects($this->once())
->method('shouldReplaceIcons')
@@ -165,8 +144,7 @@ class IconBuilderTest extends TestCase {
public function testGetFaviconNotFound(): void {
$this->checkImagick();
- $this->expectWarning(Warning::class);
- $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $util = $this->createMock(Util::class);
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
$this->imageManager->expects($this->once())
->method('shouldReplaceIcons')
@@ -179,8 +157,7 @@ class IconBuilderTest extends TestCase {
public function testGetTouchIconNotFound(): void {
$this->checkImagick();
- $this->expectWarning(Warning::class);
- $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $util = $this->createMock(Util::class);
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
$util->expects($this->once())
->method('getAppIcon')
@@ -190,8 +167,7 @@ class IconBuilderTest extends TestCase {
public function testColorSvgNotFound(): void {
$this->checkImagick();
- $this->expectWarning(Warning::class);
- $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $util = $this->createMock(Util::class);
$iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager);
$util->expects($this->once())
->method('getAppImage')
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php
index 68c8a06ee2f..0c4d555cc00 100644
--- a/apps/theming/tests/ImageManagerTest.php
+++ b/apps/theming/tests/ImageManagerTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -20,24 +22,14 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class ImageManagerTest extends TestCase {
- /** @var IConfig|MockObject */
- protected $config;
- /** @var IAppData|MockObject */
- protected $appData;
- /** @var ImageManager */
- protected $imageManager;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ICacheFactory|MockObject */
- private $cacheFactory;
- /** @var LoggerInterface|MockObject */
- private $logger;
- /** @var ITempManager|MockObject */
- private $tempManager;
- /** @var ISimpleFolder|MockObject */
- private $rootFolder;
- /** @var BackgroundService|MockObject */
- private $backgroundService;
+ protected IConfig&MockObject $config;
+ protected IAppData&MockObject $appData;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ICacheFactory&MockObject $cacheFactory;
+ private LoggerInterface&MockObject $logger;
+ private ITempManager&MockObject $tempManager;
+ private ISimpleFolder&MockObject $rootFolder;
+ protected ImageManager $imageManager;
protected function setUp(): void {
parent::setUp();
@@ -48,7 +40,7 @@ class ImageManagerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->tempManager = $this->createMock(ITempManager::class);
$this->rootFolder = $this->createMock(ISimpleFolder::class);
- $this->backgroundService = $this->createMock(BackgroundService::class);
+ $backgroundService = $this->createMock(BackgroundService::class);
$this->imageManager = new ImageManager(
$this->config,
$this->appData,
@@ -56,7 +48,7 @@ class ImageManagerTest extends TestCase {
$this->cacheFactory,
$this->logger,
$this->tempManager,
- $this->backgroundService,
+ $backgroundService,
);
$this->appData
->expects($this->any())
@@ -229,7 +221,7 @@ class ImageManagerTest extends TestCase {
$folder->expects($this->once())
->method('getFile')
->with('filename')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$image = $this->imageManager->getCachedImage('filename');
}
@@ -309,7 +301,7 @@ class ImageManagerTest extends TestCase {
}
- public function dataUpdateImage() {
+ public static function dataUpdateImage(): array {
return [
['background', __DIR__ . '/../../../tests/data/testimage.png', true, false],
['background', __DIR__ . '/../../../tests/data/testimage.png', false, false],
@@ -321,10 +313,8 @@ class ImageManagerTest extends TestCase {
];
}
- /**
- * @dataProvider dataUpdateImage
- */
- public function testUpdateImage($key, $tmpFile, $folderExists, $shouldConvert): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataUpdateImage')]
+ public function testUpdateImage(string $key, string $tmpFile, bool $folderExists, bool $shouldConvert): void {
$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
$oldFile = $this->createMock(ISimpleFile::class);
diff --git a/apps/theming/tests/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php
index 1b242c956e4..354ed1dec85 100644
--- a/apps/theming/tests/Service/ThemesServiceTest.php
+++ b/apps/theming/tests/Service/ThemesServiceTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -28,21 +30,15 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class ThemesServiceTest extends TestCase {
- /** @var ThemesService */
- private $themesService;
-
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IConfig|MockObject */
- private $config;
- /** @var LoggerInterface|MockObject */
- private $logger;
+ private IUserSession&MockObject $userSession;
+ private IConfig&MockObject $config;
+ private LoggerInterface&MockObject $logger;
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private ThemesService $themesService;
/** @var ITheme[] */
- private $themes;
+ private array $themes;
protected function setUp(): void {
$this->userSession = $this->createMock(IUserSession::class);
@@ -119,7 +115,7 @@ class ThemesServiceTest extends TestCase {
$this->assertEquals($expected, array_keys($this->themesService->getThemes()));
}
- public function dataTestEnableTheme() {
+ public static function dataTestEnableTheme(): array {
return [
['default', ['default'], ['default']],
['dark', ['default'], ['dark']],
@@ -130,12 +126,11 @@ class ThemesServiceTest extends TestCase {
}
/**
- * @dataProvider dataTestEnableTheme
*
- * @param string $toEnable
* @param string[] $enabledThemes
* @param string[] $expectedEnabled
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestEnableTheme')]
public function testEnableTheme(string $toEnable, array $enabledThemes, array $expectedEnabled): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
@@ -154,7 +149,7 @@ class ThemesServiceTest extends TestCase {
}
- public function dataTestDisableTheme() {
+ public static function dataTestDisableTheme(): array {
return [
['dark', ['default'], ['default']],
['dark', ['dark'], []],
@@ -164,12 +159,11 @@ class ThemesServiceTest extends TestCase {
}
/**
- * @dataProvider dataTestDisableTheme
*
- * @param string $toEnable
* @param string[] $enabledThemes
* @param string[] $expectedEnabled
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestDisableTheme')]
public function testDisableTheme(string $toDisable, array $enabledThemes, array $expectedEnabled): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
@@ -189,7 +183,7 @@ class ThemesServiceTest extends TestCase {
}
- public function dataTestIsEnabled() {
+ public static function dataTestIsEnabled(): array {
return [
['dark', [], false],
['dark', ['dark'], true],
@@ -199,12 +193,10 @@ class ThemesServiceTest extends TestCase {
}
/**
- * @dataProvider dataTestIsEnabled
- *
- * @param string $toEnable
* @param string[] $enabledThemes
*/
- public function testIsEnabled(string $themeId, array $enabledThemes, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsEnabled')]
+ public function testIsEnabled(string $themeId, array $enabledThemes, bool $expected): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
->method('getUser')
@@ -267,7 +259,7 @@ class ThemesServiceTest extends TestCase {
}
- public function dataTestSetEnabledThemes() {
+ public static function dataTestSetEnabledThemes(): array {
return [
[[], []],
[['light'], ['light']],
@@ -277,11 +269,11 @@ class ThemesServiceTest extends TestCase {
}
/**
- * @dataProvider dataTestSetEnabledThemes
*
* @param string[] $enabledThemes
* @param string[] $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSetEnabledThemes')]
public function testSetEnabledThemes(array $enabledThemes, array $expected): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
diff --git a/apps/theming/tests/ServicesTest.php b/apps/theming/tests/ServicesTest.php
index 516a1fca776..3971c9b6698 100644
--- a/apps/theming/tests/ServicesTest.php
+++ b/apps/theming/tests/ServicesTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -26,11 +28,9 @@ use Test\TestCase;
* @package OCA\Theming\Tests
*/
class ServicesTest extends TestCase {
- /** @var \OCA\Activity\AppInfo\Application */
- protected $app;
+ protected App $app;
- /** @var IAppContainer */
- protected $container;
+ protected IAppContainer $container;
protected function setUp(): void {
parent::setUp();
@@ -38,7 +38,7 @@ class ServicesTest extends TestCase {
$this->container = $this->app->getContainer();
}
- public function queryData() {
+ public static function queryData(): array {
return [
[IL10N::class],
@@ -60,15 +60,11 @@ class ServicesTest extends TestCase {
];
}
- /**
- * @dataProvider queryData
- * @param string $service
- * @param string $expected
- */
- public function testContainerQuery($service, $expected = null): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('queryData')]
+ public function testContainerQuery(string $service, ?string $expected = null): void {
if ($expected === null) {
$expected = $service;
}
- $this->assertTrue($this->container->query($service) instanceof $expected);
+ $this->assertInstanceOf($expected, $this->container->query($service));
}
}
diff --git a/apps/theming/tests/Settings/AdminSectionTest.php b/apps/theming/tests/Settings/AdminSectionTest.php
index a73eca1cc5a..ecb889f264b 100644
--- a/apps/theming/tests/Settings/AdminSectionTest.php
+++ b/apps/theming/tests/Settings/AdminSectionTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -9,15 +11,13 @@ use OCA\Theming\AppInfo\Application;
use OCA\Theming\Settings\AdminSection;
use OCP\IL10N;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AdminSectionTest extends TestCase {
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $url;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l;
- /** @var AdminSection */
- private $section;
+ private IURLGenerator&MockObject $url;
+ private IL10N&MockObject $l;
+ private AdminSection $section;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/theming/tests/Settings/AdminTest.php b/apps/theming/tests/Settings/AdminTest.php
index 189a91bae3a..277b94900a8 100644
--- a/apps/theming/tests/Settings/AdminTest.php
+++ b/apps/theming/tests/Settings/AdminTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,17 +17,18 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AdminTest extends TestCase {
private Admin $admin;
- private IConfig $config;
- private ThemingDefaults $themingDefaults;
- private IInitialState $initialState;
- private IURLGenerator $urlGenerator;
- private ImageManager $imageManager;
- private IL10N $l10n;
- private INavigationManager $navigationManager;
+ private IConfig&MockObject $config;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IInitialState&MockObject $initialState;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IL10N&MockObject $l10n;
+ private INavigationManager&MockObject $navigationManager;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/theming/tests/Settings/PersonalTest.php b/apps/theming/tests/Settings/PersonalTest.php
index 4630ef48c8a..9216450ec9c 100644
--- a/apps/theming/tests/Settings/PersonalTest.php
+++ b/apps/theming/tests/Settings/PersonalTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -39,7 +41,7 @@ class PersonalTest extends TestCase {
private Personal $admin;
/** @var ITheme[] */
- private $themes;
+ private array $themes;
protected function setUp(): void {
parent::setUp();
@@ -67,8 +69,7 @@ class PersonalTest extends TestCase {
);
}
-
- public function dataTestGetForm() {
+ public function dataTestGetForm(): array {
return [
['', [
$this->formatThemeForm('default'),
@@ -86,12 +87,10 @@ class PersonalTest extends TestCase {
}
/**
- * @dataProvider dataTestGetForm
- *
- * @param string $toEnable
* @param string[] $enabledThemes
*/
- public function testGetForm(string $enforcedTheme, $themesState): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetForm')]
+ public function testGetForm(string $enforcedTheme, array $themesState): void {
$this->config->expects($this->once())
->method('getSystemValueString')
->with('enforce_theme', '')
diff --git a/apps/theming/tests/Themes/AccessibleThemeTestCase.php b/apps/theming/tests/Themes/AccessibleThemeTestCase.php
index a1327a04f0b..f516e1f5116 100644
--- a/apps/theming/tests/Themes/AccessibleThemeTestCase.php
+++ b/apps/theming/tests/Themes/AccessibleThemeTestCase.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -16,10 +18,10 @@ class AccessibleThemeTestCase extends TestCase {
/**
* Set to true to check for WCAG AAA level accessibility
*/
- protected bool $WCAGaaa = false;
+ protected static bool $WCAGaaa = false;
- public function dataAccessibilityPairs() {
- $textContrast = $this->WCAGaaa ? 7.0 : 4.5;
+ public static function dataAccessibilityPairs(): array {
+ $textContrast = self::$WCAGaaa ? 7.0 : 4.5;
$elementContrast = 3.0;
return [
@@ -145,10 +147,8 @@ class AccessibleThemeTestCase extends TestCase {
];
}
- /**
- * @dataProvider dataAccessibilityPairs
- */
- public function testAccessibilityOfVariables($mainColors, $backgroundColors, $minContrast): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAccessibilityPairs')]
+ public function testAccessibilityOfVariables(array $mainColors, array $backgroundColors, float $minContrast): void {
if (!isset($this->theme)) {
$this->markTestSkipped('You need to setup $this->theme in your setUp function');
} elseif (!isset($this->util)) {
diff --git a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
index 16f7e86d217..d03e8b13300 100644
--- a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
+++ b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -22,23 +23,16 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ImageManager|MockObject */
- private $imageManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IAppManager|MockObject */
- private $appManager;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IAppManager&MockObject $appManager;
// !! important: Enable WCAG AAA tests
- protected bool $WCAGaaa = true;
+ protected static bool $WCAGaaa = true;
protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
diff --git a/apps/theming/tests/Themes/DarkThemeTest.php b/apps/theming/tests/Themes/DarkThemeTest.php
index ea570adf21d..656779b5b24 100644
--- a/apps/theming/tests/Themes/DarkThemeTest.php
+++ b/apps/theming/tests/Themes/DarkThemeTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -22,20 +24,13 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
class DarkThemeTest extends AccessibleThemeTestCase {
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ImageManager|MockObject */
- private $imageManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IAppManager|MockObject */
- private $appManager;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IAppManager&MockObject $appManager;
protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php
index b463cf4567c..d2606ffc275 100644
--- a/apps/theming/tests/Themes/DefaultThemeTest.php
+++ b/apps/theming/tests/Themes/DefaultThemeTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -22,20 +24,13 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
class DefaultThemeTest extends AccessibleThemeTestCase {
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ImageManager|MockObject */
- private $imageManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IAppManager|MockObject */
- private $appManager;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IAppManager&MockObject $appManager;
protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
diff --git a/apps/theming/tests/Themes/DyslexiaFontTest.php b/apps/theming/tests/Themes/DyslexiaFontTest.php
index 4bd8b329f2d..7d56fb4b1be 100644
--- a/apps/theming/tests/Themes/DyslexiaFontTest.php
+++ b/apps/theming/tests/Themes/DyslexiaFontTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -25,20 +27,13 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class DyslexiaFontTest extends TestCase {
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ImageManager|MockObject */
- private $imageManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IAppManager|MockObject */
- private $appManager;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IAppManager&MockObject $appManager;
private DyslexiaFont $dyslexiaFont;
@@ -141,7 +136,7 @@ class DyslexiaFontTest extends TestCase {
$this->assertStringStartsWith('OpenDyslexic', $this->dyslexiaFont->getCSSVariables()['--font-face']);
}
- public function dataTestGetCustomCss() {
+ public static function dataTestGetCustomCss(): array {
return [
['', true],
['', false],
@@ -151,15 +146,11 @@ class DyslexiaFontTest extends TestCase {
}
/**
- * @dataProvider dataTestGetCustomCss
- *
* Ensure the fonts are always loaded from the web root
* despite having url rewriting enabled or not
- *
- * @param string $webRoot
- * @param bool $prettyUrlsEnabled
*/
- public function testGetCustomCss($webRoot, $prettyUrlsEnabled): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetCustomCss')]
+ public function testGetCustomCss(string $webRoot, bool $prettyUrlsEnabled): void {
\OC::$WEBROOT = $webRoot;
$this->config->expects($this->any())
->method('getSystemValue')
diff --git a/apps/theming/tests/Themes/HighContrastThemeTest.php b/apps/theming/tests/Themes/HighContrastThemeTest.php
index 71576caf841..94f87d7433b 100644
--- a/apps/theming/tests/Themes/HighContrastThemeTest.php
+++ b/apps/theming/tests/Themes/HighContrastThemeTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -22,23 +24,16 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
class HighContrastThemeTest extends AccessibleThemeTestCase {
- /** @var ThemingDefaults|MockObject */
- private $themingDefaults;
- /** @var IUserSession|MockObject */
- private $userSession;
- /** @var IURLGenerator|MockObject */
- private $urlGenerator;
- /** @var ImageManager|MockObject */
- private $imageManager;
- /** @var IConfig|MockObject */
- private $config;
- /** @var IL10N|MockObject */
- private $l10n;
- /** @var IAppManager|MockObject */
- private $appManager;
+ private ThemingDefaults&MockObject $themingDefaults;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ImageManager&MockObject $imageManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IAppManager&MockObject $appManager;
// !! important: Enable WCAG AAA tests
- protected bool $WCAGaaa = true;
+ protected static bool $WCAGaaa = true;
protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index b8b6c6869cd..1acd12f12fa 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -27,29 +29,17 @@ class ThemingDefaultsTest extends TestCase {
private IAppConfig&MockObject $appConfig;
private IConfig&MockObject $config;
private \OC_Defaults $defaults;
-
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l10n;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
- /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $cacheFactory;
- /** @var ThemingDefaults */
- private $template;
- /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
- private $util;
- /** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
- private $cache;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
- private $appManager;
- /** @var ImageManager|\PHPUnit\Framework\MockObject\MockObject */
- private $imageManager;
- /** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */
- private $navigationManager;
- /** @var BackgroundService|\PHPUnit\Framework\MockObject\MockObject */
- private $backgroundService;
+ private IL10N|MockObject $l10n;
+ private IUserSession&MockObject $userSession;
+ private IURLGenerator&MockObject $urlGenerator;
+ private ICacheFactory&MockObject $cacheFactory;
+ private Util&MockObject $util;
+ private ICache&MockObject $cache;
+ private IAppManager&MockObject $appManager;
+ private ImageManager&MockObject $imageManager;
+ private INavigationManager&MockObject $navigationManager;
+ private BackgroundService&MockObject $backgroundService;
+ private ThemingDefaults $template;
protected function setUp(): void {
parent::setUp();
@@ -186,18 +176,15 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('https://example.com/', $this->template->getBaseUrl());
}
- public function legalUrlProvider() {
+ public static function legalUrlProvider(): array {
return [
- [ '' ],
- [ 'https://example.com/legal.html']
+ [''],
+ ['https://example.com/legal.html'],
];
}
- /**
- * @param $imprintUrl
- * @dataProvider legalUrlProvider
- */
- public function testGetImprintURL($imprintUrl): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('legalUrlProvider')]
+ public function testGetImprintURL(string $imprintUrl): void {
$this->config
->expects($this->once())
->method('getAppValue')
@@ -207,11 +194,8 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals($imprintUrl, $this->template->getImprintUrl());
}
- /**
- * @param $privacyUrl
- * @dataProvider legalUrlProvider
- */
- public function testGetPrivacyURL($privacyUrl): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('legalUrlProvider')]
+ public function testGetPrivacyURL(string $privacyUrl): void {
$this->config
->expects($this->once())
->method('getAppValue')
@@ -351,18 +335,15 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan<br/><span class="footer__legal-links"><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a> · <a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a></span>', $this->template->getShortFooter());
}
- public function invalidLegalUrlProvider() {
+ public static function invalidLegalUrlProvider(): array {
return [
['example.com/legal'], # missing scheme
['https:///legal'], # missing host
];
}
- /**
- * @param $invalidImprintUrl
- * @dataProvider invalidLegalUrlProvider
- */
- public function testGetShortFooterInvalidImprint($invalidImprintUrl): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidLegalUrlProvider')]
+ public function testGetShortFooterInvalidImprint(string $invalidImprintUrl): void {
$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
$this->config
->expects($this->exactly(5))
@@ -378,11 +359,8 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan', $this->template->getShortFooter());
}
- /**
- * @param $invalidPrivacyUrl
- * @dataProvider invalidLegalUrlProvider
- */
- public function testGetShortFooterInvalidPrivacy($invalidPrivacyUrl): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('invalidLegalUrlProvider')]
+ public function testGetShortFooterInvalidPrivacy(string $invalidPrivacyUrl): void {
$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
$this->config
->expects($this->exactly(5))
@@ -428,7 +406,7 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('#fff', $this->template->getColorPrimary());
}
- public function dataGetColorPrimary() {
+ public static function dataGetColorPrimary(): array {
return [
'with fallback default' => [
'disableTheming' => false,
@@ -469,9 +447,7 @@ class ThemingDefaultsTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetColorPrimary
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetColorPrimary')]
public function testGetColorPrimary(bool $disableTheming, string $primaryColor, string $userPrimaryColor, string $expected): void {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
@@ -803,7 +779,7 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('1234567890', $this->template->getiTunesAppId());
}
- public function dataReplaceImagePath() {
+ public static function dataReplaceImagePath(): array {
return [
['core', 'test.png', false],
['core', 'manifest.json'],
@@ -812,8 +788,8 @@ class ThemingDefaultsTest extends TestCase {
];
}
- /** @dataProvider dataReplaceImagePath */
- public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=1234abcd'): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataReplaceImagePath')]
+ public function testReplaceImagePath(string $app, string $image, string|bool $result = 'themingRoute?v=1234abcd'): void {
$this->cache->expects($this->any())
->method('get')
->with('shouldReplaceIcons')
diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php
index f664a46733d..1e944027e32 100644
--- a/apps/theming/tests/UtilTest.php
+++ b/apps/theming/tests/UtilTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -35,7 +37,7 @@ class UtilTest extends TestCase {
$this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager);
}
- public function dataColorContrast() {
+ public static function dataColorContrast(): array {
return [
['#ffffff', '#FFFFFF', 1],
['#000000', '#000000', 1],
@@ -46,14 +48,12 @@ class UtilTest extends TestCase {
];
}
- /**
- * @dataProvider dataColorContrast
- */
- public function testColorContrast(string $color1, string $color2, $contrast): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataColorContrast')]
+ public function testColorContrast(string $color1, string $color2, int|float $contrast): void {
$this->assertEqualsWithDelta($contrast, $this->util->colorContrast($color1, $color2), .001);
}
- public function dataInvertTextColor() {
+ public static function dataInvertTextColor(): array {
return [
['#ffffff', true],
['#000000', false],
@@ -61,10 +61,8 @@ class UtilTest extends TestCase {
['#ffff00', true],
];
}
- /**
- * @dataProvider dataInvertTextColor
- */
- public function testInvertTextColor($color, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataInvertTextColor')]
+ public function testInvertTextColor(string $color, bool $expected): void {
$invert = $this->util->invertTextColor($color);
$this->assertEquals($expected, $invert);
}
@@ -141,10 +139,8 @@ class UtilTest extends TestCase {
$this->assertEquals($expected, $button);
}
- /**
- * @dataProvider dataGetAppIcon
- */
- public function testGetAppIcon($app, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppIcon')]
+ public function testGetAppIcon(string $app, string $expected): void {
$this->appData->expects($this->any())
->method('getFolder')
->with('global/images')
@@ -153,7 +149,7 @@ class UtilTest extends TestCase {
$this->assertEquals($expected, $icon);
}
- public function dataGetAppIcon() {
+ public static function dataGetAppIcon(): array {
return [
['user_ldap', Server::get(IAppManager::class)->getAppPath('user_ldap') . '/img/app.svg'],
['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
@@ -176,14 +172,12 @@ class UtilTest extends TestCase {
$this->assertEquals($file, $icon);
}
- /**
- * @dataProvider dataGetAppImage
- */
- public function testGetAppImage($app, $image, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppImage')]
+ public function testGetAppImage(string $app, string $image, string|bool $expected): void {
$this->assertEquals($expected, $this->util->getAppImage($app, $image));
}
- public function dataGetAppImage() {
+ public static function dataGetAppImage(): array {
return [
['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
['files', 'folder', \OC::$SERVERROOT . '/apps/files/img/folder.svg'],
@@ -217,17 +211,15 @@ class UtilTest extends TestCase {
$this->assertTrue($actual);
}
- public function dataIsBackgroundThemed() {
+ public static function dataIsBackgroundThemed(): array {
return [
['', false],
['png', true],
['backgroundColor', false],
];
}
- /**
- * @dataProvider dataIsBackgroundThemed
- */
- public function testIsBackgroundThemed($backgroundMime, $expected): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsBackgroundThemed')]
+ public function testIsBackgroundThemed(string $backgroundMime, bool $expected): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime', '')