aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/autoload.php16
-rw-r--r--tests/bootstrap.php2
-rw-r--r--tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js24
-rw-r--r--tests/data/integritycheck/mimetypeListModified/core/signature.json4
-rw-r--r--tests/lib/App/AppManagerTest.php6
-rw-r--r--tests/lib/AppFramework/Routing/RouteParserTest.php347
-rw-r--r--tests/lib/AppFramework/Routing/RoutingTest.php477
-rw-r--r--tests/lib/AutoLoaderTest.php57
-rw-r--r--tests/lib/Comments/ManagerTest.php2
-rw-r--r--tests/lib/Files/Cache/CacheTest.php2
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php85
-rw-r--r--tests/lib/Files/FilenameValidatorTest.php2
-rw-r--r--tests/lib/Files/FilesystemTest.php5
-rw-r--r--tests/lib/Files/Mount/ObjectHomeMountProviderTest.php242
-rw-r--r--tests/lib/Files/Mount/RootMountProviderTest.php7
-rw-r--r--tests/lib/Files/Node/HookConnectorTest.php2
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php13
-rw-r--r--tests/lib/Files/Storage/CommonTest.php3
-rw-r--r--tests/lib/Files/Storage/HomeTest.php3
-rw-r--r--tests/lib/Files/Storage/LocalTest.php3
-rw-r--r--tests/lib/Files/Storage/Wrapper/QuotaTest.php5
-rw-r--r--tests/lib/Files/Storage/Wrapper/WrapperTest.php4
-rw-r--r--tests/lib/Files/Utils/ScannerTest.php2
-rw-r--r--tests/lib/Files/ViewTest.php4
-rw-r--r--tests/lib/FilesTest.php42
-rw-r--r--tests/lib/HelperStorageTest.php1
-rw-r--r--tests/lib/LegacyHelperTest.php104
-rw-r--r--tests/lib/Preview/OfficeTest.php10
-rw-r--r--tests/lib/Settings/DeclarativeManagerTest.php38
-rw-r--r--tests/lib/TempManagerTest.php3
-rw-r--r--tests/lib/TestCase.php5
-rw-r--r--tests/lib/TextProcessing/TextProcessingTest.php14
-rw-r--r--tests/lib/Traits/MountProviderTrait.php2
-rw-r--r--tests/lib/User/UserTest.php9
-rw-r--r--tests/lib/UtilTest.php80
35 files changed, 818 insertions, 807 deletions
diff --git a/tests/autoload.php b/tests/autoload.php
new file mode 100644
index 00000000000..05fc3852924
--- /dev/null
+++ b/tests/autoload.php
@@ -0,0 +1,16 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+require_once __DIR__ . '/../lib/base.php';
+
+/**
+ * This is a file that applications can require to be able to autoload the class Test\TestCase from Nextcloud tests
+ */
+
+\OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib/', true);
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 3fdc6b51fba..655b60f114b 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -12,8 +12,8 @@ if ($configDir) {
}
require_once __DIR__ . '/../lib/base.php';
+require_once __DIR__ . '/autoload.php';
-\OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib/', true);
\OC::$composerAutoloader->addPsr4('Tests\\', OC::$SERVERROOT . '/tests/', true);
// load all enabled apps
diff --git a/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js b/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js
index 8d5c7702caa..2ac7338d04b 100644
--- a/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js
+++ b/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js
@@ -153,12 +153,19 @@ OC.MimeTypeList={
"x-office-spreadsheet"
],
themes: [],
- names: {'application/epub+zip': t('core', "Electronic book document"),
+ names: {'application/cmd': t('core', "Windows Command Script"),
+'application/epub+zip': t('core', "Electronic book document"),
+'application/font-sfnt': t('core', "TrueType Font Collection"),
+'application/font-woff': t('core', "Web Open Font Format"),
'application/gpx+xml': t('core', "GPX geographic data"),
'application/gzip': t('core', "Gzip archive"),
'application/illustrator': t('core', "Adobe Illustrator document"),
+'application/java': t('core', "Java source code"),
+'application/javascript': t('core', "JavaScript source code"),
'application/json': t('core', "JSON document"),
-'application/msword': t('core', "Word document"),
+'application/msaccess': t('core', "Microsoft Access database"),
+'application/msonenote': t('core', "Microsoft OneNote document"),
+'application/msword': t('core', "Microsoft Word document"),
'application/octet-stream': t('core', "Unknown"),
'application/pdf': t('core', "PDF document"),
'application/postscript': t('core', "PostScript document"),
@@ -172,6 +179,7 @@ OC.MimeTypeList={
'application/vnd.ms-excel.sheet.binary.macroEnabled.12': t('core', "Excel 2007 binary spreadsheet"),
'application/vnd.ms-excel.sheet.macroEnabled.12': t('core', "Excel spreadsheet"),
'application/vnd.ms-excel.template.macroEnabled.12': t('core', "Excel spreadsheet template"),
+'application/vnd.ms-outlook': t('core', "Outlook Message"),
'application/vnd.ms-powerpoint': t('core', "PowerPoint presentation"),
'application/vnd.ms-powerpoint.addin.macroEnabled.12': t('core', "PowerPoint add-in"),
'application/vnd.ms-powerpoint.presentation.macroEnabled.12': t('core', "PowerPoint presentation"),
@@ -203,7 +211,9 @@ OC.MimeTypeList={
'application/x-7z-compressed': t('core', "7-zip archive"),
'application/x-blender': t('core', "Blender scene"),
'application/x-bzip2': t('core', "Bzip2 archive"),
+'application/x-deb': t('core', "Debian package"),
'application/x-fictionbook+xml': t('core', "FictionBook document"),
+'application/x-font': t('core', "Unknown font"),
'application/x-krita': t('core', "Krita document"),
'application/x-mobipocket-ebook': t('core', "Mobipocket e-book"),
'application/x-msi': t('core', "Windows Installer package"),
@@ -219,19 +229,24 @@ OC.MimeTypeList={
'audio/mp4': t('core', "MPEG-4 audio"),
'audio/mpeg': t('core', "MP3 audio"),
'audio/ogg': t('core', "Ogg audio"),
+'audio/wav': t('core', "RIFF\/WAVe standard Audio"),
'audio/webm': t('core', "WebM audio"),
'audio/x-scpls': t('core', "MP3 ShoutCast playlist"),
'image/bmp': t('core', "Windows BMP image"),
+'image/bpg': t('core', "Better Portable Graphics image"),
'image/emf': t('core', "EMF image"),
'image/gif': t('core', "GIF image"),
+'image/heic': t('core', "HEIC image"),
'image/heif': t('core', "HEIF image"),
'image/jp2': t('core', "JPEG-2000 JP2 image"),
'image/jpeg': t('core', "JPEG image"),
'image/png': t('core', "PNG image"),
'image/svg+xml': t('core', "SVG image"),
+'image/tga': t('core', "Truevision Targa image"),
'image/tiff': t('core', "TIFF image"),
'image/webp': t('core', "WebP image"),
'image/x-dcraw': t('core', "Digital raw image"),
+'image/x-icon': t('core', "Windows Icon"),
'message/rfc822': t('core', "Email message"),
'text/calendar': t('core', "VCS\/ICS calendar"),
'text/css': t('core', "CSS stylesheet"),
@@ -240,13 +255,17 @@ OC.MimeTypeList={
'text/markdown': t('core', "Markdown document"),
'text/org': t('core', "Org-mode file"),
'text/plain': t('core', "Plain text document"),
+'text/rtf': t('core', "Rich Text document"),
'text/vcard': t('core', "Electronic business card"),
'text/x-c++src': t('core', "C++ source code"),
+'text/x-java-source': t('core', "Java source code"),
'text/x-ldif': t('core', "LDIF address book"),
'text/x-nfo': t('core', "NFO document"),
+'text/x-php': t('core', "PHP source"),
'text/x-python': t('core', "Python script"),
'text/x-rst': t('core', "ReStructuredText document"),
'video/3gpp': t('core', "3GPP multimedia file"),
+'video/MP2T': t('core', "MPEG video"),
'video/dv': t('core', "DV video"),
'video/mp2t': t('core', "MPEG-2 transport stream"),
'video/mp4': t('core', "MPEG-4 video"),
@@ -257,6 +276,7 @@ OC.MimeTypeList={
'video/x-flv': t('core', "Flash video"),
'video/x-matroska': t('core', "Matroska video"),
'video/x-ms-wmv': t('core', "Windows Media video"),
+'video/x-msvideo': t('core', "AVI video"),
'my-custom/mimetype': t('core', "Custom Document"),
},
};
diff --git a/tests/data/integritycheck/mimetypeListModified/core/signature.json b/tests/data/integritycheck/mimetypeListModified/core/signature.json
index cac26e900c5..04f4c1b923c 100644
--- a/tests/data/integritycheck/mimetypeListModified/core/signature.json
+++ b/tests/data/integritycheck/mimetypeListModified/core/signature.json
@@ -1,7 +1,7 @@
{
"hashes": {
- "core\/js\/mimetypelist.js": "1f672ccc11dd5f0cf8753461476b05fbf6fec018db00fc59b074947953ba99481103f84ace140255995278da7ef4e3b49d263cc29a4b29786fb19413083fe928"
+ "core\/js\/mimetypelist.js": "1bb7ea82996776ad23da2841beefe7b80b3d25d410c6aaf53f73d094705ad95694520427888c16922286645208d7619de3c71c9c8e22c13dabc7c8bf26c92b57"
},
- "signature": "V7eDZqrauafx5b\/taQ0Z2GYyuX6gjLU2\/igpQxs4o3YGG+ruBNk5PFoJxBbLogt5QrUIPilVJy3+2f4BkzWl7E2El51d2O+Ctg+cWATCvF6SJyhCdzZQLknyLXr4n+r7FlvHpiSQ8c88Aq2gNrBpK34Lq7YKjfln7q19vWIGUIYcE5gJJzhloSTF76\/yq3gIw48EXVrYMdT0nhE5zzk+pKJSvJCmtZGeyocXfHdRKGViH1egKvB8AJkTMByDbLKd9ZXhGrrQ1QWtJHLCDLrv6oBykz7N9J8yRbrKXjeuBtDAUfYHZeUbx7DYStNEWa3npXtst1HSJ7mMV5QYT9S9HbQp7qMQQBoze81QH3DS7jpksSkRr5w\/kE6FiNe8B8s56DMrNUo6NOFhsNRZF\/SNkVMgbRuckpCDHAE6hkz3+DwTQB7uYGu3qc965Yxn9YiGD83ep++c9CkEMOQL2q+CftbVMXVjF++Ml9P\/9N+ARF1t9mffEC8vOGaU1OR6DmPsbl1mlvkdP1RMKwa3Kp0nWEsWhDjjcB9b1hf4KCsPb6iiiyAV21qgigK73Aq\/8NRy0RlNB4rWsbb1NAV2tnnrJRbwdJrtS5dvTBADmsazt73jzkpc36vJNhBRaMUKTW05x7wnrw9K6MQDkjLuzfXJQWEJQtr+4dP9oyasamBufKc=",
+ "signature": "g+orHgCwPo9+RODiV5AgTdXTeQrN0avYsww7M1jHefef12kPX38MDUVWaMYYjEMw3r7G9pgHqfBPzQcZ4WmTaPnUm7E3Anb8P71jTpFwOzKdR4o\/uu1QfEeMcIMNfoD7ikkg4IKsroD+XreRPJOxVL81Ouse+QnTOGcicUS2V2uFFxc9Is7I9TeGCVawWzDYOLXkbTGRekSS863vz3tdmgCEmFCcCd498GHPTnkCvm5D52zqbeJCnVitjNzvtPY+zUmEpei\/CMOQoAQul9\/bP\/89bSgOgJYaWIgmN7X3FGuPOAiS62XZ6eBlBDdjT67m8VbVw75zFY3HV6YwrcOri6zvTv4Uc6Xy2fm+mxNuIkn+0vnOnhik0bW46gFFpBlBrFbMS7fZgPhvjLwkew1GjL+sAnejnuLEUYVHbisJr4CtmkJFzeG\/WK85PQOTPfHiZd550vu7RH8sYrRpXHrAFu\/w4Ziw93CJO0CU0xXHATmtb9mn47dtsXLEYw0NbZWMxWAV7JPGHbW6qxn1nYm+1aKpm+UEhZ2ZbBW5LnGEGU+hTg7LpR9OHyvo2ASORvrgWF5c4S3US8MRLXmDrv76Oux0WaktRNZUm7W0r9HyUCkCdzOJi4ZWB1w951wJgvplTDWQtYkZ3T7ujsRPT6YGH\/WvvBSKcLKi5PcZUmCiH\/Q=",
"certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6AbrD8WiOzBuT\/ODy6k5T1arEdHO+Pux0W1\r\nMxYJJI4kH74KKgMpC0SB0Rt+8WrMqV1r3hhJ46df6Xr\/xolP3oD+eLbShPcblhdS\r\nVtkZEkoev8Sh6L2wDCeHDyPxzvj1w2dTdGVO9Kztn0xIlyfEBakqvBWtcxyi3Ln0\r\nklnxlMx3tPDUE4kqvpia9qNiB1AN2PV93eNr5\/2riAzIssMFSCarWCx0AKYb54+d\r\nxLpcYFyqPJ0ydBCkF78DD45RCZet6PNYkdzgbqlUWEGGomkuDoJbBg4wzgzO0D77\r\nH87KFhYW8tKFFvF1V3AHl\/sFQ9tDHaxM9Y0pZ2jPp\/ccdiqnmdkBxBDqsiRvHvVB\r\nCn6qpb4vWGFC7vHOBfYspmEL1zLlKXZv3ezMZEZw7O9ZvUP3VO\/wAtd2vUW8UFiq\r\ns2v1QnNLN6jNh51obcwmrBvWhJy9vQIdtIjQbDxqWTHh1zUSrw9wrlklCBZ\/zrM0\r\ni8nfCFwTxWRxp3H9KoECzO\/zS5R5KIS7s3\/wq\/w9T2Ie4rcecgXwDizwnn0C\/aKc\r\nbDIjujpL1s9HO05pcD\/V3wKcPZ1izymBkmMyIbL52iRVN5FTVHeZdXPpFuq+CTQJ\r\nQ238lC+A\/KOVAgMBAAEwDQYJKoZIhvcNAQEFBQADggIBAGoKTnh8RfJV4sQItVC2\r\nAvfJagkrIqZ3iiQTUBQGTKBsTnAqE1H7QgUSV9vSd+8rgvHkyZsRjmtyR1e3A6Ji\r\noNCXUbExC\/0iCPUqdHZIVb+Lc\/vWuv4ByFMybGPydgtLoEUX2ZrKFWmcgZFDUSRd\r\n9Uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----"
} \ No newline at end of file
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php
index 2e1163cf9db..c8f7f2cb172 100644
--- a/tests/lib/App/AppManagerTest.php
+++ b/tests/lib/App/AppManagerTest.php
@@ -159,15 +159,15 @@ class AppManagerTest extends TestCase {
}
}
- public function dataGetAppIcon(): array {
+ public static function dataGetAppIcon(): array {
$nothing = function ($appId) {
- $this->assertEquals('test', $appId);
+ self::assertEquals('test', $appId);
throw new \RuntimeException();
};
$createCallback = function ($workingIcons) {
return function ($appId, $icon) use ($workingIcons) {
- $this->assertEquals('test', $appId);
+ self::assertEquals('test', $appId);
if (in_array($icon, $workingIcons)) {
return '/path/' . $icon;
}
diff --git a/tests/lib/AppFramework/Routing/RouteParserTest.php b/tests/lib/AppFramework/Routing/RouteParserTest.php
new file mode 100644
index 00000000000..406c5f1f3a5
--- /dev/null
+++ b/tests/lib/AppFramework/Routing/RouteParserTest.php
@@ -0,0 +1,347 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace Test\AppFramework\Routing;
+
+use OC\AppFramework\Routing\RouteParser;
+use Symfony\Component\Routing\Route as RoutingRoute;
+use Symfony\Component\Routing\RouteCollection;
+
+class RouteParserTest extends \Test\TestCase {
+
+ protected RouteParser $parser;
+
+ protected function setUp(): void {
+ $this->parser = new RouteParser();
+ }
+
+ public function testParseRoutes(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('app1.folders.open'));
+ $this->assertArrayHasKey('app1.folders.create', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/create', 'POST', 'FoldersController', 'create', route: $collection->get('app1.folders.create'));
+ }
+
+ public function testParseRoutesRootApps(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'core');
+ $this->assertArrayHasKey('core.folders.open', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/open', 'GET', 'FoldersController', 'open', app: 'core', route: $collection->get('core.folders.open'));
+ $this->assertArrayHasKey('core.folders.create', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/create', 'POST', 'FoldersController', 'create', app: 'core', route: $collection->get('core.folders.create'));
+ }
+
+ public function testParseRoutesWithResources(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ], 'resources' => [
+ 'names' => ['url' => '/names'],
+ 'folder_names' => ['url' => '/folder/names'],
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleResource('/apps/app1/folder/names', 'folder_names', 'FolderNamesController', 'app1', $collection);
+ $this->assertSimpleResource('/apps/app1/names', 'names', 'NamesController', 'app1', $collection);
+ }
+
+ public function testParseRoutesWithPostfix(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'POST'],
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'PUT', 'postfix' => '-edit']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.update', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'POST', 'FoldersController', 'update', route: $collection->get('app1.folders.update'));
+ $this->assertArrayHasKey('app1.folders.update-edit', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'PUT', 'FoldersController', 'update', route: $collection->get('app1.folders.update-edit'));
+ }
+
+ public function testParseRoutesKebabCaseAction(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open_folder', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open_folder', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'openFolder', route: $collection->get('app1.folders.open_folder'));
+ }
+
+ public function testParseRoutesKebabCaseController(): void {
+ $routes = ['routes' => [
+ ['name' => 'my_folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.my_folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'MyFoldersController', 'open', route: $collection->get('app1.my_folders.open'));
+ }
+
+ public function testParseRoutesLowercaseVerb(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#delete', 'url' => '/{folderId}/delete', 'verb' => 'delete']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.delete', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/delete', 'DELETE', 'FoldersController', 'delete', route: $collection->get('app1.folders.delete'));
+ }
+
+ public function testParseRoutesMissingVerb(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open']
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesWithRequirements(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'requirements' => ['folderId' => '\d+']]
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', requirements: ['folderId' => '\d+'], route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesWithDefaults(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'defaults' => ['hello' => 'world']]
+ ]];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertArrayHasKey('app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', defaults: ['hello' => 'world'], route: $collection->get('app1.folders.open'));
+ }
+
+ public function testParseRoutesInvalidName(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseDefaultRoutes($routes, 'app1');
+ }
+
+ public function testParseRoutesInvalidName2(): void {
+ $routes = ['routes' => [
+ ['name' => 'folders#open#action', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseDefaultRoutes($routes, 'app1');
+ }
+
+ public function testParseRoutesEmpty(): void {
+ $routes = ['routes' => []];
+
+ $collection = $this->parser->parseDefaultRoutes($routes, 'app1');
+ $this->assertEquals(0, $collection->count());
+ }
+
+ // OCS routes
+
+ public function testParseOcsRoutes(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('ocs.app1.folders.open'));
+ $this->assertArrayHasKey('ocs.app1.folders.create', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/create', 'POST', 'FoldersController', 'create', route: $collection->get('ocs.app1.folders.create'));
+ }
+
+ public function testParseOcsRoutesRootApps(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ['name' => 'folders#create', 'url' => '/{folderId}/create', 'verb' => 'POST']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'core');
+ $this->assertArrayHasKey('ocs.core.folders.open', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/open', 'GET', 'FoldersController', 'open', app: 'core', route: $collection->get('ocs.core.folders.open'));
+ $this->assertArrayHasKey('ocs.core.folders.create', $collection->all());
+ $this->assertSimpleRoute('/{folderId}/create', 'POST', 'FoldersController', 'create', app: 'core', route: $collection->get('ocs.core.folders.create'));
+ }
+
+ public function testParseOcsRoutesWithPostfix(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'POST'],
+ ['name' => 'folders#update', 'url' => '/{folderId}/update', 'verb' => 'PUT', 'postfix' => '-edit']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.update', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'POST', 'FoldersController', 'update', route: $collection->get('ocs.app1.folders.update'));
+ $this->assertArrayHasKey('ocs.app1.folders.update-edit', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/update', 'PUT', 'FoldersController', 'update', route: $collection->get('ocs.app1.folders.update-edit'));
+ }
+
+ public function testParseOcsRoutesKebabCaseAction(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open_folder', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open_folder', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'openFolder', route: $collection->get('ocs.app1.folders.open_folder'));
+ }
+
+ public function testParseOcsRoutesKebabCaseController(): void {
+ $routes = ['ocs' => [
+ ['name' => 'my_folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.my_folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'MyFoldersController', 'open', route: $collection->get('ocs.app1.my_folders.open'));
+ }
+
+ public function testParseOcsRoutesLowercaseVerb(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#delete', 'url' => '/{folderId}/delete', 'verb' => 'delete']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.delete', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/delete', 'DELETE', 'FoldersController', 'delete', route: $collection->get('ocs.app1.folders.delete'));
+ }
+
+ public function testParseOcsRoutesMissingVerb(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open']
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesWithRequirements(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'requirements' => ['folderId' => '\d+']]
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', requirements: ['folderId' => '\d+'], route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesWithDefaults(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET', 'defaults' => ['hello' => 'world']]
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertSimpleRoute('/apps/app1/{folderId}/open', 'GET', 'FoldersController', 'open', defaults: ['hello' => 'world'], route: $collection->get('ocs.app1.folders.open'));
+ }
+
+ public function testParseOcsRoutesInvalidName(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders', 'url' => '/{folderId}/open', 'verb' => 'GET']
+ ]];
+
+ $this->expectException(\UnexpectedValueException::class);
+ $this->parser->parseOCSRoutes($routes, 'app1');
+ }
+
+ public function testParseOcsRoutesEmpty(): void {
+ $routes = ['ocs' => []];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertEquals(0, $collection->count());
+ }
+
+ public function testParseOcsRoutesWithResources(): void {
+ $routes = ['ocs' => [
+ ['name' => 'folders#open', 'url' => '/{folderId}/open', 'verb' => 'GET'],
+ ], 'ocs-resources' => [
+ 'names' => ['url' => '/names', 'root' => '/core/something'],
+ 'folder_names' => ['url' => '/folder/names'],
+ ]];
+
+ $collection = $this->parser->parseOCSRoutes($routes, 'app1');
+ $this->assertArrayHasKey('ocs.app1.folders.open', $collection->all());
+ $this->assertOcsResource('/apps/app1/folder/names', 'folder_names', 'FolderNamesController', 'app1', $collection);
+ $this->assertOcsResource('/core/something/names', 'names', 'NamesController', 'app1', $collection);
+ }
+
+ protected function assertSimpleRoute(
+ string $path,
+ string $method,
+ string $controller,
+ string $action,
+ string $app = 'app1',
+ array $requirements = [],
+ array $defaults = [],
+ ?RoutingRoute $route = null,
+ ): void {
+ self::assertEquals($path, $route->getPath());
+ self::assertEqualsCanonicalizing([$method], $route->getMethods());
+ self::assertEqualsCanonicalizing($requirements, $route->getRequirements());
+ self::assertEquals([...$defaults, 'action' => null, 'caller' => [$app, $controller, $action]], $route->getDefaults());
+ }
+
+ protected function assertSimpleResource(
+ string $path,
+ string $resourceName,
+ string $controller,
+ string $app,
+ RouteCollection $collection,
+ ): void {
+ self::assertArrayHasKey("$app.$resourceName.index", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.show", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.create", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.update", $collection->all());
+ self::assertArrayHasKey("$app.$resourceName.destroy", $collection->all());
+
+ $this->assertSimpleRoute($path, 'GET', $controller, 'index', $app, route: $collection->get("$app.$resourceName.index"));
+ $this->assertSimpleRoute($path, 'POST', $controller, 'create', $app, route: $collection->get("$app.$resourceName.create"));
+ $this->assertSimpleRoute("$path/{id}", 'GET', $controller, 'show', $app, route: $collection->get("$app.$resourceName.show"));
+ $this->assertSimpleRoute("$path/{id}", 'PUT', $controller, 'update', $app, route: $collection->get("$app.$resourceName.update"));
+ $this->assertSimpleRoute("$path/{id}", 'DELETE', $controller, 'destroy', $app, route: $collection->get("$app.$resourceName.destroy"));
+ }
+
+ protected function assertOcsResource(
+ string $path,
+ string $resourceName,
+ string $controller,
+ string $app,
+ RouteCollection $collection,
+ ): void {
+ self::assertArrayHasKey("ocs.$app.$resourceName.index", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.show", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.create", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.update", $collection->all());
+ self::assertArrayHasKey("ocs.$app.$resourceName.destroy", $collection->all());
+
+ $this->assertSimpleRoute($path, 'GET', $controller, 'index', $app, route: $collection->get("ocs.$app.$resourceName.index"));
+ $this->assertSimpleRoute($path, 'POST', $controller, 'create', $app, route: $collection->get("ocs.$app.$resourceName.create"));
+ $this->assertSimpleRoute("$path/{id}", 'GET', $controller, 'show', $app, route: $collection->get("ocs.$app.$resourceName.show"));
+ $this->assertSimpleRoute("$path/{id}", 'PUT', $controller, 'update', $app, route: $collection->get("ocs.$app.$resourceName.update"));
+ $this->assertSimpleRoute("$path/{id}", 'DELETE', $controller, 'destroy', $app, route: $collection->get("ocs.$app.$resourceName.destroy"));
+ }
+}
diff --git a/tests/lib/AppFramework/Routing/RoutingTest.php b/tests/lib/AppFramework/Routing/RoutingTest.php
deleted file mode 100644
index 703e613f790..00000000000
--- a/tests/lib/AppFramework/Routing/RoutingTest.php
+++ /dev/null
@@ -1,477 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace Test\AppFramework\Routing;
-
-use OC\AppFramework\DependencyInjection\DIContainer;
-use OC\AppFramework\Routing\RouteConfig;
-use OC\Route\Route;
-use OC\Route\Router;
-use OCP\App\IAppManager;
-use OCP\Diagnostics\IEventLogger;
-use OCP\IConfig;
-use OCP\IRequest;
-use OCP\Route\IRouter;
-use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Container\ContainerInterface;
-use Psr\Log\LoggerInterface;
-
-class RoutingTest extends \Test\TestCase {
- public function testSimpleRoute(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithUnderScoreNames(): void {
- $routes = ['routes' => [
- ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'root' => '']
- ]];
-
- $this->assertSimpleRoute($routes, 'admin_folders.open_current', 'DELETE', '/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent', [], [], '', true);
- }
-
- public function testSimpleOCSRoute(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'GET']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithMissingVerb(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleOCSRouteWithMissingVerb(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'GET', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithLowercaseVerb(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleOCSRouteWithLowercaseVerb(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open');
- }
-
- public function testSimpleRouteWithRequirements(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']]
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
- }
-
- public function testSimpleOCSRouteWithRequirements(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'requirements' => ['something']]
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', ['something']);
- }
-
- public function testSimpleRouteWithDefaults(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', [], 'defaults' => ['param' => 'foobar']]
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
- }
-
-
- public function testSimpleOCSRouteWithDefaults(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'defaults' => ['param' => 'foobar']]
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], ['param' => 'foobar']);
- }
-
- public function testSimpleRouteWithPostfix(): void {
- $routes = ['routes' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something']
- ]];
-
- $this->assertSimpleRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
- }
-
- public function testSimpleOCSRouteWithPostfix(): void {
- $routes = ['ocs' => [
- ['name' => 'folders#open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete', 'postfix' => '_something']
- ]
- ];
-
- $this->assertSimpleOCSRoute($routes, 'folders.open', 'DELETE', '/apps/app1/folders/{folderId}/open', 'FoldersController', 'open', [], [], '_something');
- }
-
-
- public function testSimpleRouteWithBrokenName(): void {
- $this->expectException(\UnexpectedValueException::class);
-
- $routes = ['routes' => [
- ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // load route configuration
- $container = new DIContainer('app1');
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
-
- public function testSimpleOCSRouteWithBrokenName(): void {
- $this->expectException(\UnexpectedValueException::class);
-
- $routes = ['ocs' => [
- ['name' => 'folders_open', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // load route configuration
- $container = new DIContainer('app1');
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
- public function testSimpleOCSRouteWithUnderScoreNames(): void {
- $routes = ['ocs' => [
- ['name' => 'admin_folders#open_current', 'url' => '/folders/{folderId}/open', 'verb' => 'delete']
- ]];
-
- $this->assertSimpleOCSRoute($routes, 'admin_folders.open_current', 'DELETE', '/apps/app1/folders/{folderId}/open', 'AdminFoldersController', 'openCurrent');
- }
-
- public function testOCSResource(): void {
- $routes = ['ocs-resources' => ['account' => ['url' => '/accounts']]];
-
- $this->assertOCSResource($routes, 'account', '/apps/app1/accounts', 'AccountController', 'id');
- }
-
- public function testOCSResourceWithUnderScoreName(): void {
- $routes = ['ocs-resources' => ['admin_accounts' => ['url' => '/admin/accounts']]];
-
- $this->assertOCSResource($routes, 'admin_accounts', '/apps/app1/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- public function testOCSResourceWithRoot(): void {
- $routes = ['ocs-resources' => ['admin_accounts' => ['url' => '/admin/accounts', 'root' => '/core/endpoint']]];
-
- $this->assertOCSResource($routes, 'admin_accounts', '/core/endpoint/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- public function testResource(): void {
- $routes = ['resources' => ['account' => ['url' => '/accounts']]];
-
- $this->assertResource($routes, 'account', '/apps/app1/accounts', 'AccountController', 'id');
- }
-
- public function testResourceWithUnderScoreName(): void {
- $routes = ['resources' => ['admin_accounts' => ['url' => '/admin/accounts']]];
-
- $this->assertResource($routes, 'admin_accounts', '/apps/app1/admin/accounts', 'AdminAccountsController', 'id');
- }
-
- private function assertSimpleRoute($routes, $name, $verb, $url, $controllerName, $actionName, array $requirements = [], array $defaults = [], $postfix = '', $allowRootUrl = false): void {
- if ($postfix) {
- $name .= $postfix;
- }
-
- // route mocks
- $container = new DIContainer('app1');
- $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // we expect create to be called once:
- $router
- ->expects($this->once())
- ->method('create')
- ->with($this->equalTo('app1.' . $name), $this->equalTo($url))
- ->willReturn($route);
-
- // load route configuration
- $config = new RouteConfig($container, $router, $routes);
- if ($allowRootUrl) {
- self::invokePrivate($config, 'rootUrlApps', [['app1']]);
- }
-
- $config->register();
- }
-
- /**
- * @param $routes
- * @param string $name
- * @param string $verb
- * @param string $url
- * @param string $controllerName
- * @param string $actionName
- * @param array $requirements
- * @param array $defaults
- * @param string $postfix
- */
- private function assertSimpleOCSRoute($routes,
- $name,
- $verb,
- $url,
- $controllerName,
- $actionName,
- array $requirements = [],
- array $defaults = [],
- $postfix = '') {
- if ($postfix) {
- $name .= $postfix;
- }
-
- // route mocks
- $container = new DIContainer('app1');
- $route = $this->mockRoute($container, $verb, $controllerName, $actionName, $requirements, $defaults);
-
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // we expect create to be called once:
- $router
- ->expects($this->once())
- ->method('create')
- ->with($this->equalTo('ocs.app1.' . $name), $this->equalTo($url))
- ->willReturn($route);
-
- // load route configuration
- $config = new RouteConfig($container, $router, $routes);
-
- $config->register();
- }
-
- /**
- * @param array $yaml
- * @param string $resourceName
- * @param string $url
- * @param string $controllerName
- * @param string $paramName
- */
- private function assertOCSResource($yaml, $resourceName, $url, $controllerName, $paramName): void {
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // route mocks
- $container = new DIContainer('app1');
- $indexRoute = $this->mockRoute($container, 'GET', $controllerName, 'index');
- $showRoute = $this->mockRoute($container, 'GET', $controllerName, 'show');
- $createRoute = $this->mockRoute($container, 'POST', $controllerName, 'create');
- $updateRoute = $this->mockRoute($container, 'PUT', $controllerName, 'update');
- $destroyRoute = $this->mockRoute($container, 'DELETE', $controllerName, 'destroy');
-
- $urlWithParam = $url . '/{' . $paramName . '}';
-
- $calls = [
- ['name' => 'ocs.app1.' . $resourceName . '.index', 'pattern' => $url, 'route' => $indexRoute],
- ['name' => 'ocs.app1.' . $resourceName . '.show', 'pattern' => $urlWithParam, 'route' => $showRoute],
- ['name' => 'ocs.app1.' . $resourceName . '.create', 'pattern' => $url, 'route' => $createRoute],
- ['name' => 'ocs.app1.' . $resourceName . '.update', 'pattern' => $urlWithParam, 'route' => $updateRoute],
- ['name' => 'ocs.app1.' . $resourceName . '.destroy', 'pattern' => $urlWithParam, 'route' => $destroyRoute],
- ];
-
- // we expect create to be called five times:
- $router
- ->expects($this->exactly(5))
- ->method('create')
- ->willReturnCallback(function (string $name, string $pattern) use (&$calls) {
- $expected = array_shift($calls);
- $this->assertEquals($expected['name'], $name);
- $this->assertEquals($expected['pattern'], $pattern);
- return $expected['route'];
- });
-
- // load route configuration
- $config = new RouteConfig($container, $router, $yaml);
-
- $config->register();
- }
-
- /**
- * @param string $resourceName
- * @param string $url
- * @param string $controllerName
- * @param string $paramName
- */
- private function assertResource($yaml, $resourceName, $url, $controllerName, $paramName) {
- /** @var IRouter|MockObject $router */
- $router = $this->getMockBuilder(Router::class)
- ->onlyMethods(['create'])
- ->setConstructorArgs([
- $this->createMock(LoggerInterface::class),
- $this->createMock(IRequest::class),
- $this->createMock(IConfig::class),
- $this->createMock(IEventLogger::class),
- $this->createMock(ContainerInterface::class),
- $this->createMock(IAppManager::class),
- ])
- ->getMock();
-
- // route mocks
- $container = new DIContainer('app1');
- $indexRoute = $this->mockRoute($container, 'GET', $controllerName, 'index');
- $showRoute = $this->mockRoute($container, 'GET', $controllerName, 'show');
- $createRoute = $this->mockRoute($container, 'POST', $controllerName, 'create');
- $updateRoute = $this->mockRoute($container, 'PUT', $controllerName, 'update');
- $destroyRoute = $this->mockRoute($container, 'DELETE', $controllerName, 'destroy');
-
- $urlWithParam = $url . '/{' . $paramName . '}';
-
- $calls = [
- ['name' => 'app1.' . $resourceName . '.index', 'pattern' => $url, 'route' => $indexRoute],
- ['name' => 'app1.' . $resourceName . '.show', 'pattern' => $urlWithParam, 'route' => $showRoute],
- ['name' => 'app1.' . $resourceName . '.create', 'pattern' => $url, 'route' => $createRoute],
- ['name' => 'app1.' . $resourceName . '.update', 'pattern' => $urlWithParam, 'route' => $updateRoute],
- ['name' => 'app1.' . $resourceName . '.destroy', 'pattern' => $urlWithParam, 'route' => $destroyRoute],
- ];
- // we expect create to be called five times:
- $router
- ->expects($this->exactly(5))
- ->method('create')
- ->willReturnCallback(function (string $name, string $pattern) use (&$calls) {
- $expected = array_shift($calls);
- $this->assertEquals($expected['name'], $name);
- $this->assertEquals($expected['pattern'], $pattern);
- return $expected['route'];
- });
-
- // load route configuration
- $config = new RouteConfig($container, $router, $yaml);
-
- $config->register();
- }
-
- /**
- * @param DIContainer $container
- * @param string $verb
- * @param string $controllerName
- * @param string $actionName
- * @param array $requirements
- * @param array $defaults
- * @return MockObject
- */
- private function mockRoute(
- DIContainer $container,
- $verb,
- $controllerName,
- $actionName,
- array $requirements = [],
- array $defaults = [],
- ) {
- $route = $this->getMockBuilder(Route::class)
- ->onlyMethods(['method', 'requirements', 'defaults'])
- ->disableOriginalConstructor()
- ->getMock();
- $route
- ->expects($this->once())
- ->method('method')
- ->with($this->equalTo($verb))
- ->willReturn($route);
-
- if (count($requirements) > 0) {
- $route
- ->expects($this->once())
- ->method('requirements')
- ->with($this->equalTo($requirements))
- ->willReturn($route);
- }
-
- $route->expects($this->once())
- ->method('defaults')
- ->with($this->callback(function (array $def) use ($defaults, $controllerName, $actionName) {
- $defaults['caller'] = ['app1', $controllerName, $actionName];
-
- $this->assertEquals($defaults, $def);
- return true;
- }))
- ->willReturn($route);
-
- return $route;
- }
-}
diff --git a/tests/lib/AutoLoaderTest.php b/tests/lib/AutoLoaderTest.php
deleted file mode 100644
index 72d4a2e94cf..00000000000
--- a/tests/lib/AutoLoaderTest.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-namespace Test;
-
-class AutoLoaderTest extends TestCase {
- /**
- * @var \OC\Autoloader $loader
- */
- private $loader;
-
- protected function setUp(): void {
- parent::setUp();
- $this->loader = new \OC\AutoLoader([]);
- }
-
- public function testLegacyPath(): void {
- $this->assertEquals([
- \OC::$SERVERROOT . '/lib/private/legacy/json.php',
- ], $this->loader->findClass('OC_JSON'));
- }
-
- public function testLoadTestTestCase(): void {
- $this->assertEquals([
- \OC::$SERVERROOT . '/tests/lib/TestCase.php'
- ], $this->loader->findClass('Test\TestCase'));
- }
-
- public function testLoadCore(): void {
- $this->assertEquals([
- \OC::$SERVERROOT . '/lib/private/legacy/foo/bar.php',
- ], $this->loader->findClass('OC_Foo_Bar'));
- }
-
- public function testLoadPublicNamespace(): void {
- $this->assertEquals([], $this->loader->findClass('OCP\Foo\Bar'));
- }
-
- public function testLoadAppNamespace(): void {
- $result = $this->loader->findClass('OCA\Files\Foobar');
- $this->assertEquals(2, count($result));
- $this->assertStringEndsWith('apps/files/foobar.php', $result[0]);
- $this->assertStringEndsWith('apps/files/lib/foobar.php', $result[1]);
- }
-
- public function testLoadCoreNamespaceCore(): void {
- $this->assertEquals([], $this->loader->findClass('OC\Core\Foo\Bar'));
- }
-
- public function testLoadCoreNamespaceSettings(): void {
- $this->assertEquals([], $this->loader->findClass('OC\Settings\Foo\Bar'));
- }
-}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index fb2f913f291..86e70c56026 100644
--- a/tests/lib/Comments/ManagerTest.php
+++ b/tests/lib/Comments/ManagerTest.php
@@ -1073,6 +1073,7 @@ class ManagerTest extends TestCase {
* @return array<string, IComment>
*/
private function proccessComments(array $data): array {
+ $this->connection->beginTransaction();
/** @var array<string, IComment> $comments */
$comments = [];
foreach ($data as $comment) {
@@ -1088,6 +1089,7 @@ class ManagerTest extends TestCase {
$comment = $this->testSave($message, $actorId, $verb, $parentId, $id);
$comments[$comment->getMessage() . '#' . $comment->getActorId()] = $comment;
}
+ $this->connection->commit();
return $comments;
}
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index 55b210a1e2d..2815003a996 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -393,7 +393,7 @@ class CacheTest extends \Test\TestCase {
$id4 = $this->cache->put($file4, $fileData['foo2']);
$id5 = $this->cache->put($file5, $fileData['foo3']);
- $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId);
+ $tagManager = \OCP\Server::get(\OCP\ITagManager::class)->load('files', [], false, $userId);
$this->assertTrue($tagManager->tagAs($id1, 'tag1'));
$this->assertTrue($tagManager->tagAs($id1, 'tag2'));
$this->assertTrue($tagManager->tagAs($id2, 'tag2'));
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index 88b8b7767dd..88c0ceaef08 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -10,6 +10,7 @@ namespace Test\Files\Config;
use OC\DB\Exceptions\DbalException;
use OC\DB\QueryBuilder\Literal;
use OC\Files\Cache\Cache;
+use OC\Files\Config\UserMountCache;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OC\User\Manager;
@@ -17,6 +18,9 @@ use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\Event\UserMountAddedEvent;
+use OCP\Files\Config\Event\UserMountRemovedEvent;
+use OCP\Files\Config\Event\UserMountUpdatedEvent;
use OCP\Files\Config\ICachedMountInfo;
use OCP\ICacheFactory;
use OCP\IConfig;
@@ -30,28 +34,19 @@ use Test\Util\User\Dummy;
* @group DB
*/
class UserMountCacheTest extends TestCase {
- /**
- * @var IDBConnection
- */
- private $connection;
-
- /**
- * @var IUserManager
- */
- private $userManager;
-
- /**
- * @var \OC\Files\Config\UserMountCache
- */
- private $cache;
-
- private $fileIds = [];
+ private IDBConnection $connection;
+ private IUserManager $userManager;
+ private IEventDispatcher $eventDispatcher;
+ private UserMountCache $cache;
+ private array $fileIds = [];
protected function setUp(): void {
parent::setUp();
$this->fileIds = [];
+
$this->connection = \OC::$server->getDatabaseConnection();
+
$config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
@@ -63,13 +58,22 @@ class UserMountCacheTest extends TestCase {
->expects($this->any())
->method('getAppValue')
->willReturnArgument(2);
+
$this->userManager = new Manager($config, $this->createMock(ICacheFactory::class), $this->createMock(IEventDispatcher::class), $this->createMock(LoggerInterface::class));
$userBackend = new Dummy();
$userBackend->createUser('u1', '');
$userBackend->createUser('u2', '');
$userBackend->createUser('u3', '');
$this->userManager->registerBackend($userBackend);
- $this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(LoggerInterface::class), $this->createMock(IEventLogger::class));
+
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
+
+ $this->cache = new UserMountCache($this->connection,
+ $this->userManager,
+ $this->createMock(LoggerInterface::class),
+ $this->createMock(IEventLogger::class),
+ $this->eventDispatcher,
+ );
}
protected function tearDown(): void {
@@ -121,6 +125,11 @@ class UserMountCacheTest extends TestCase {
}
public function testNewMounts(): void {
+ $this->eventDispatcher
+ ->expects($this->once())
+ ->method('dispatchTyped')
+ ->with($this->callback(fn (UserMountAddedEvent $event) => $event->mountPoint->getMountPoint() === '/asd/'));
+
$user = $this->userManager->get('u1');
[$storage] = $this->getStorage(10);
@@ -141,6 +150,11 @@ class UserMountCacheTest extends TestCase {
}
public function testSameMounts(): void {
+ $this->eventDispatcher
+ ->expects($this->once())
+ ->method('dispatchTyped')
+ ->with($this->callback(fn (UserMountAddedEvent $event) => $event->mountPoint->getMountPoint() === '/asd/'));
+
$user = $this->userManager->get('u1');
[$storage] = $this->getStorage(10);
@@ -165,6 +179,18 @@ class UserMountCacheTest extends TestCase {
}
public function testRemoveMounts(): void {
+ $operation = 0;
+ $this->eventDispatcher
+ ->expects($this->exactly(2))
+ ->method('dispatchTyped')
+ ->with($this->callback(function (UserMountAddedEvent|UserMountRemovedEvent $event) use (&$operation) {
+ return match(++$operation) {
+ 1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/asd/',
+ 2 => $event instanceof UserMountRemovedEvent && $event->mountPoint->getMountPoint() === '/asd/',
+ default => false,
+ };
+ }));
+
$user = $this->userManager->get('u1');
[$storage] = $this->getStorage(10);
@@ -184,6 +210,19 @@ class UserMountCacheTest extends TestCase {
}
public function testChangeMounts(): void {
+ $operation = 0;
+ $this->eventDispatcher
+ ->expects($this->exactly(3))
+ ->method('dispatchTyped')
+ ->with($this->callback(function (UserMountAddedEvent|UserMountRemovedEvent $event) use (&$operation) {
+ return match(++$operation) {
+ 1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/bar/',
+ 2 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/foo/',
+ 3 => $event instanceof UserMountRemovedEvent && $event->mountPoint->getMountPoint() === '/bar/',
+ default => false,
+ };
+ }));
+
$user = $this->userManager->get('u1');
[$storage] = $this->getStorage(10);
@@ -207,6 +246,18 @@ class UserMountCacheTest extends TestCase {
}
public function testChangeMountId(): void {
+ $operation = 0;
+ $this->eventDispatcher
+ ->expects($this->exactly(2))
+ ->method('dispatchTyped')
+ ->with($this->callback(function (UserMountAddedEvent|UserMountUpdatedEvent $event) use (&$operation) {
+ return match(++$operation) {
+ 1 => $event instanceof UserMountAddedEvent && $event->mountPoint->getMountPoint() === '/foo/',
+ 2 => $event instanceof UserMountUpdatedEvent && $event->oldMountPoint->getMountId() === null && $event->newMountPoint->getMountId() === 1,
+ default => false,
+ };
+ }));
+
$user = $this->userManager->get('u1');
[$storage] = $this->getStorage(10);
diff --git a/tests/lib/Files/FilenameValidatorTest.php b/tests/lib/Files/FilenameValidatorTest.php
index db7874b0bd5..a52971d109e 100644
--- a/tests/lib/Files/FilenameValidatorTest.php
+++ b/tests/lib/Files/FilenameValidatorTest.php
@@ -409,7 +409,7 @@ class FilenameValidatorTest extends TestCase {
$this->assertEquals($expected, $validator->sanitizeFilename($filename));
}
- public function dataSanitizeFilename(): array {
+ public static function dataSanitizeFilename(): array {
return [
'valid name' => [
'a * b.txt', ['.htaccess'], [], [], [], 'a * b.txt'
diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php
index 4a3543474a1..529b4f58428 100644
--- a/tests/lib/Files/FilesystemTest.php
+++ b/tests/lib/Files/FilesystemTest.php
@@ -10,6 +10,7 @@ namespace Test\Files;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
use OC\User\NoUserException;
+use OCP\Files;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
@@ -74,7 +75,7 @@ class FilesystemTest extends \Test\TestCase {
protected function tearDown(): void {
foreach ($this->tmpDirs as $dir) {
- \OC_Helper::rmdirr($dir);
+ Files::rmdirr($dir);
}
$this->logout();
@@ -472,7 +473,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
$mount = new MountPoint(new Temporary([]), '/foo/bar');
$mountProvider = new DummyMountProvider([self::TEST_FILESYSTEM_USER2 => [$mount]]);
- \OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
+ \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class)->registerProvider($mountProvider);
$this->assertEquals('/foo/bar/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
}
}
diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
index 3daf82461cb..2b809835953 100644
--- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
@@ -7,6 +7,9 @@
namespace Test\Files\Mount;
use OC\Files\Mount\ObjectHomeMountProvider;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
+use OCP\App\IAppManager;
+use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IUser;
@@ -31,51 +34,54 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->user = $this->createMock(IUser::class);
$this->loader = $this->createMock(IStorageFactory::class);
- $this->provider = new ObjectHomeMountProvider($this->config);
+ $objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->createMock(IAppManager::class));
+ $this->provider = new ObjectHomeMountProvider($objectStoreConfig);
}
public function testSingleBucket(): void {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with($this->equalTo('objectstore'), '')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
-
- $this->user->expects($this->never())->method($this->anything());
- $this->loader->expects($this->never())->method($this->anything());
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar'
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
- $config = $this->invokePrivate($this->provider, 'getSingleBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'multibucket' => false], $objectStore->getArguments());
}
public function testMultiBucket(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with($this->equalTo('objectstore_multibucket'), '')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar'
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
- ->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn(null);
+ $this->config->method('getUserValue')
+ ->willReturn(null);
$this->config->expects($this->once())
->method('setUserValue')
@@ -87,42 +93,37 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->equalTo(null)
);
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('49', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketWithPrefix(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
+ $this->config
->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn(null);
+ ->willReturn(null);
$this->config->expects($this->once())
->method('setUserValue')
@@ -134,66 +135,70 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
$this->equalTo(null)
);
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('myBucketPrefix49', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 'myBucketPrefix49', 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketBucketAlreadySet(): void {
- $this->config->expects($this->once())
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- 'arguments' => [
- 'bucket' => 'myBucketPrefix',
- ],
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());
- $this->config->expects($this->once())
+ $this->config
->method('getUserValue')
- ->with(
- $this->equalTo('uid'),
- $this->equalTo('homeobjectstore'),
- $this->equalTo('bucket'),
- $this->equalTo(null)
- )->willReturn('awesomeBucket1');
+ ->willReturnCallback(function ($uid, $app, $key, $default) {
+ if ($uid === 'uid' && $app === 'homeobjectstore' && $key === 'bucket') {
+ return 'awesomeBucket1';
+ } else {
+ return $default;
+ }
+ });
$this->config->expects($this->never())
->method('setUserValue');
- $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);
+ $mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
+ $arguments = $this->invokePrivate($mount, 'arguments');
- $this->assertArrayHasKey('class', $config);
- $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
- $this->assertArrayHasKey('arguments', $config);
- $this->assertArrayHasKey('user', $config['arguments']);
- $this->assertSame($this->user, $config['arguments']['user']);
- $this->assertArrayHasKey('objectstore', $config['arguments']);
- $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
- $this->assertArrayHasKey('bucket', $config['arguments']);
- $this->assertEquals('awesomeBucket1', $config['arguments']['bucket']);
+ $objectStore = $arguments['objectstore'];
+ $this->assertInstanceOf(FakeObjectStore::class, $objectStore);
+ $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments());
}
public function testMultiBucketConfigFirst(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->with('objectstore_multibucket')
- ->willReturn([
- 'class' => 'Test\Files\Mount\FakeObjectStore',
- ]);
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ if ($key === 'objectstore_multibucket') {
+ return [
+ 'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
+ ];
+ } else {
+ return $default;
+ }
+ });
$this->user->method('getUID')
->willReturn('uid');
@@ -204,11 +209,15 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
}
public function testMultiBucketConfigFirstFallBackSingle(): void {
- $this->config->expects($this->exactly(2))
+ $this->config
->method('getSystemValue')->willReturnMap([
- ['objectstore_multibucket', '', ''],
- ['objectstore', '', [
+ ['objectstore_multibucket', null, null],
+ ['objectstore', null, [
'class' => 'Test\Files\Mount\FakeObjectStore',
+ 'arguments' => [
+ 'foo' => 'bar',
+ 'bucket' => 'myBucketPrefix',
+ ],
]],
]);
@@ -221,16 +230,17 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
}
public function testNoObjectStore(): void {
- $this->config->expects($this->exactly(2))
- ->method('getSystemValue')
- ->willReturn('');
+ $this->config->method('getSystemValue')
+ ->willReturnCallback(function ($key, $default) {
+ return $default;
+ });
$mount = $this->provider->getHomeMountForUser($this->user, $this->loader);
$this->assertNull($mount);
}
}
-class FakeObjectStore {
+class FakeObjectStore implements IObjectStore {
private $arguments;
public function __construct(array $arguments) {
@@ -240,4 +250,22 @@ class FakeObjectStore {
public function getArguments() {
return $this->arguments;
}
+
+ public function getStorageId() {
+ }
+
+ public function readObject($urn) {
+ }
+
+ public function writeObject($urn, $stream, ?string $mimetype = null) {
+ }
+
+ public function deleteObject($urn) {
+ }
+
+ public function objectExists($urn) {
+ }
+
+ public function copyObject($from, $to) {
+ }
}
diff --git a/tests/lib/Files/Mount/RootMountProviderTest.php b/tests/lib/Files/Mount/RootMountProviderTest.php
index 2613cfd4b7b..bf29bfa070a 100644
--- a/tests/lib/Files/Mount/RootMountProviderTest.php
+++ b/tests/lib/Files/Mount/RootMountProviderTest.php
@@ -10,11 +10,12 @@ namespace Test\Files\Mount;
use OC\Files\Mount\RootMountProvider;
use OC\Files\ObjectStore\ObjectStoreStorage;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Files\ObjectStore\S3;
use OC\Files\Storage\LocalRootStorage;
use OC\Files\Storage\StorageFactory;
+use OCP\App\IAppManager;
use OCP\IConfig;
-use Psr\Log\LoggerInterface;
use Test\TestCase;
/**
@@ -40,8 +41,8 @@ class RootMountProviderTest extends TestCase {
private function getProvider(array $systemConfig): RootMountProvider {
$config = $this->getConfig($systemConfig);
- $provider = new RootMountProvider($config, $this->createMock(LoggerInterface::class));
- return $provider;
+ $objectStoreConfig = new PrimaryObjectStoreConfig($config, $this->createMock(IAppManager::class));
+ return new RootMountProvider($objectStoreConfig, $config);
}
public function testLocal(): void {
diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php
index b9e16299dd0..87e83fd0a3b 100644
--- a/tests/lib/Files/Node/HookConnectorTest.php
+++ b/tests/lib/Files/Node/HookConnectorTest.php
@@ -80,7 +80,7 @@ class HookConnectorTest extends TestCase {
Filesystem::getMountManager(),
$this->view,
\OC::$server->getUserManager()->get($this->userId),
- \OC::$server->getUserMountCache(),
+ \OCP\Server::get(\OCP\Files\Config\IUserMountCache::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index 3dbdc3afc27..508f328fae2 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -262,4 +262,17 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($cache->inCache('new.txt'));
$this->assertEquals(\OCP\Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
}
+
+ public function testCopyFolderSize(): void {
+ $cache = $this->instance->getCache();
+
+ $this->instance->mkdir('source');
+ $this->instance->file_put_contents('source/test.txt', 'foo');
+ $this->instance->getUpdater()->update('source/test.txt');
+ $this->assertEquals(3, $cache->get('source')->getSize());
+
+ $this->assertTrue($this->instance->copy('source', 'target'));
+
+ $this->assertEquals(3, $cache->get('target')->getSize());
+ }
}
diff --git a/tests/lib/Files/Storage/CommonTest.php b/tests/lib/Files/Storage/CommonTest.php
index b51b35be8f9..529615f3733 100644
--- a/tests/lib/Files/Storage/CommonTest.php
+++ b/tests/lib/Files/Storage/CommonTest.php
@@ -9,6 +9,7 @@ namespace Test\Files\Storage;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Wrapper;
+use OCP\Files;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
@@ -37,7 +38,7 @@ class CommonTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
$this->restoreService(IFilenameValidator::class);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/HomeTest.php b/tests/lib/Files/Storage/HomeTest.php
index b6d0f1aa85a..26b81c6f1a0 100644
--- a/tests/lib/Files/Storage/HomeTest.php
+++ b/tests/lib/Files/Storage/HomeTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\User\User;
+use OCP\Files;
class DummyUser extends User {
private $home;
@@ -62,7 +63,7 @@ class HomeTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/LocalTest.php b/tests/lib/Files/Storage/LocalTest.php
index 65bc538ef17..13317fad7bb 100644
--- a/tests/lib/Files/Storage/LocalTest.php
+++ b/tests/lib/Files/Storage/LocalTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Files;
/**
* Class LocalTest
@@ -30,7 +31,7 @@ class LocalTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
index aebae9b3c62..3115f1288a0 100644
--- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php
+++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
@@ -10,8 +10,7 @@ namespace Test\Files\Storage\Wrapper;
//ensure the constants are loaded
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\Local;
-
-\OC::$loader->load('\OC\Files\Filesystem');
+use OCP\Files;
/**
* Class QuotaTest
@@ -35,7 +34,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/Wrapper/WrapperTest.php b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
index 1d0f41bf3ed..4cbae1762fc 100644
--- a/tests/lib/Files/Storage/Wrapper/WrapperTest.php
+++ b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
@@ -7,6 +7,8 @@
namespace Test\Files\Storage\Wrapper;
+use OCP\Files;
+
class WrapperTest extends \Test\Files\Storage\Storage {
/**
* @var string tmpDir
@@ -22,7 +24,7 @@ class WrapperTest extends \Test\Files\Storage\Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php
index 51089e5560c..047da5851b7 100644
--- a/tests/lib/Files/Utils/ScannerTest.php
+++ b/tests/lib/Files/Utils/ScannerTest.php
@@ -124,7 +124,7 @@ class ScannerTest extends \Test\TestCase {
}
});
- \OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
+ \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class)->registerProvider($mountProvider);
$cache = $storage->getCache();
$storage->mkdir('folder');
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index b790c9ed6e8..d611df372e6 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -155,7 +155,7 @@ class ViewTest extends \Test\TestCase {
$this->userObject->delete();
$this->groupObject->delete();
- $mountProviderCollection = \OC::$server->getMountProviderCollection();
+ $mountProviderCollection = \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class);
self::invokePrivate($mountProviderCollection, 'providers', [[]]);
parent::tearDown();
@@ -1626,7 +1626,7 @@ class ViewTest extends \Test\TestCase {
->method('getMountsForUser')
->willReturn($mounts);
- $mountProviderCollection = \OC::$server->getMountProviderCollection();
+ $mountProviderCollection = \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class);
$mountProviderCollection->registerProvider($mountProvider);
return $mounts;
diff --git a/tests/lib/FilesTest.php b/tests/lib/FilesTest.php
new file mode 100644
index 00000000000..2ba6ce2666b
--- /dev/null
+++ b/tests/lib/FilesTest.php
@@ -0,0 +1,42 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test;
+
+use OCP\Files;
+use OCP\ITempManager;
+use OCP\Server;
+
+class FilesTest extends TestCase {
+
+ /**
+ * Tests recursive folder deletion with rmdirr()
+ */
+ public function testRecursiveFolderDeletion(): void {
+ $baseDir = Server::get(ITempManager::class)->getTemporaryFolder() . '/';
+ mkdir($baseDir . 'a/b/c/d/e', 0777, true);
+ mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
+ mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
+ mkdir($baseDir . 'a1/b', 0777, true);
+ mkdir($baseDir . 'a1/c', 0777, true);
+ file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
+ file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
+ file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
+ Files::rmdirr($baseDir . 'a');
+
+ $this->assertFalse(file_exists($baseDir . 'a'));
+ $this->assertTrue(file_exists($baseDir . 'a1'));
+
+ Files::rmdirr($baseDir);
+ $this->assertFalse(file_exists($baseDir));
+ }
+}
diff --git a/tests/lib/HelperStorageTest.php b/tests/lib/HelperStorageTest.php
index e4e877ab2a8..628e77e935a 100644
--- a/tests/lib/HelperStorageTest.php
+++ b/tests/lib/HelperStorageTest.php
@@ -94,6 +94,7 @@ class HelperStorageTest extends \Test\TestCase {
$this->assertEquals(5, $storageInfo['used']);
$this->assertEquals(17, $storageInfo['total']);
}
+
private function getIncludeExternalStorage(): bool {
$class = new \ReflectionClass(\OC_Helper::class);
$prop = $class->getProperty('quotaIncludeExternalStorage');
diff --git a/tests/lib/LegacyHelperTest.php b/tests/lib/LegacyHelperTest.php
index 15af5ca06e8..0938640b892 100644
--- a/tests/lib/LegacyHelperTest.php
+++ b/tests/lib/LegacyHelperTest.php
@@ -23,85 +23,6 @@ class LegacyHelperTest extends \Test\TestCase {
\OC::$WEBROOT = $this->originalWebRoot;
}
- /**
- * @dataProvider humanFileSizeProvider
- */
- public function testHumanFileSize($expected, $input): void {
- $result = OC_Helper::humanFileSize($input);
- $this->assertEquals($expected, $result);
- }
-
- public static function humanFileSizeProvider(): array {
- return [
- ['0 B', 0],
- ['1 KB', 1024],
- ['9.5 MB', 10000000],
- ['1.3 GB', 1395864371],
- ['465.7 GB', 500000000000],
- ['454.7 TB', 500000000000000],
- ['444.1 PB', 500000000000000000],
- ];
- }
-
- /**
- * @dataProvider providesComputerFileSize
- */
- public function testComputerFileSize($expected, $input): void {
- $result = OC_Helper::computerFileSize($input);
- $this->assertEquals($expected, $result);
- }
-
- public static function providesComputerFileSize(): array {
- return [
- [0.0, '0 B'],
- [1024.0, '1 KB'],
- [1395864371.0, '1.3 GB'],
- [9961472.0, '9.5 MB'],
- [500041567437.0, '465.7 GB'],
- [false, '12 GB etfrhzui']
- ];
- }
-
- public function testMb_array_change_key_case(): void {
- $arrayStart = [
- 'Foo' => 'bar',
- 'Bar' => 'foo',
- ];
- $arrayResult = [
- 'foo' => 'bar',
- 'bar' => 'foo',
- ];
- $result = OC_Helper::mb_array_change_key_case($arrayStart);
- $expected = $arrayResult;
- $this->assertEquals($result, $expected);
-
- $arrayStart = [
- 'foo' => 'bar',
- 'bar' => 'foo',
- ];
- $arrayResult = [
- 'FOO' => 'bar',
- 'BAR' => 'foo',
- ];
- $result = OC_Helper::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
- $expected = $arrayResult;
- $this->assertEquals($result, $expected);
- }
-
- public function testRecursiveArraySearch(): void {
- $haystack = [
- 'Foo' => 'own',
- 'Bar' => 'Cloud',
- ];
-
- $result = OC_Helper::recursiveArraySearch($haystack, 'own');
- $expected = 'Foo';
- $this->assertEquals($result, $expected);
-
- $result = OC_Helper::recursiveArraySearch($haystack, 'NotFound');
- $this->assertFalse($result);
- }
-
public function testBuildNotExistingFileNameForView(): void {
$viewMock = $this->createMock(View::class);
$this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
@@ -227,29 +148,4 @@ class LegacyHelperTest extends \Test\TestCase {
[3670, true, \OC::$SERVERROOT . '/tests/data/testimage.png', \OC::$SERVERROOT . '/tests/data/testimage-copy.png'],
];
}
-
- /**
- * Tests recursive folder deletion with rmdirr()
- */
- public function testRecursiveFolderDeletion(): void {
- $baseDir = \OC::$server->getTempManager()->getTemporaryFolder() . '/';
- mkdir($baseDir . 'a/b/c/d/e', 0777, true);
- mkdir($baseDir . 'a/b/c1/d/e', 0777, true);
- mkdir($baseDir . 'a/b/c2/d/e', 0777, true);
- mkdir($baseDir . 'a/b1/c1/d/e', 0777, true);
- mkdir($baseDir . 'a/b2/c1/d/e', 0777, true);
- mkdir($baseDir . 'a/b3/c1/d/e', 0777, true);
- mkdir($baseDir . 'a1/b', 0777, true);
- mkdir($baseDir . 'a1/c', 0777, true);
- file_put_contents($baseDir . 'a/test.txt', 'Hello file!');
- file_put_contents($baseDir . 'a/b1/c1/test one.txt', 'Hello file one!');
- file_put_contents($baseDir . 'a1/b/test two.txt', 'Hello file two!');
- \OC_Helper::rmdirr($baseDir . 'a');
-
- $this->assertFalse(file_exists($baseDir . 'a'));
- $this->assertTrue(file_exists($baseDir . 'a1'));
-
- \OC_Helper::rmdirr($baseDir);
- $this->assertFalse(file_exists($baseDir));
- }
}
diff --git a/tests/lib/Preview/OfficeTest.php b/tests/lib/Preview/OfficeTest.php
index c9019d017a3..167c442dd34 100644
--- a/tests/lib/Preview/OfficeTest.php
+++ b/tests/lib/Preview/OfficeTest.php
@@ -7,6 +7,9 @@
namespace Test\Preview;
+use OCP\IBinaryFinder;
+use OCP\Server;
+
/**
* Class OfficeTest
*
@@ -16,10 +19,11 @@ namespace Test\Preview;
*/
class OfficeTest extends Provider {
protected function setUp(): void {
- $libreofficeBinary = \OC_Helper::findBinaryPath('libreoffice');
- $openofficeBinary = ($libreofficeBinary) ? null : \OC_Helper::findBinaryPath('openoffice');
+ $binaryFinder = Server::get(IBinaryFinder::class);
+ $libreofficeBinary = $binaryFinder->findBinaryPath('libreoffice');
+ $openofficeBinary = $libreofficeBinary === false ? $binaryFinder->findBinaryPath('openoffice') : false;
- if ($libreofficeBinary || $openofficeBinary) {
+ if ($libreofficeBinary !== false || $openofficeBinary !== false) {
parent::setUp();
$fileName = 'testimage.odt';
diff --git a/tests/lib/Settings/DeclarativeManagerTest.php b/tests/lib/Settings/DeclarativeManagerTest.php
index 522264acd8c..d279dfa46f0 100644
--- a/tests/lib/Settings/DeclarativeManagerTest.php
+++ b/tests/lib/Settings/DeclarativeManagerTest.php
@@ -18,6 +18,7 @@ use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
+use OCP\Security\ICrypto;
use OCP\Settings\DeclarativeSettingsTypes;
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
use OCP\Settings\IDeclarativeManager;
@@ -50,6 +51,9 @@ class DeclarativeManagerTest extends TestCase {
/** @var LoggerInterface|MockObject */
private $logger;
+ /** @var ICrypto|MockObject */
+ private $crypto;
+
/** @var IUser|MockObject */
private $user;
@@ -215,6 +219,36 @@ class DeclarativeManagerTest extends TestCase {
],
],
],
+ [
+ 'id' => 'test_sensitive_field',
+ 'title' => 'Sensitive text field',
+ 'description' => 'Set some secure value setting that is stored encrypted',
+ 'type' => DeclarativeSettingsTypes::TEXT,
+ 'label' => 'Sensitive field',
+ 'placeholder' => 'Set secure value',
+ 'default' => '',
+ 'sensitive' => true, // only for TEXT, PASSWORD types
+ ],
+ [
+ 'id' => 'test_sensitive_field_2',
+ 'title' => 'Sensitive password field',
+ 'description' => 'Set some password setting that is stored encrypted',
+ 'type' => DeclarativeSettingsTypes::PASSWORD,
+ 'label' => 'Sensitive field',
+ 'placeholder' => 'Set secure value',
+ 'default' => '',
+ 'sensitive' => true, // only for TEXT, PASSWORD types
+ ],
+ [
+ 'id' => 'test_non_sensitive_field',
+ 'title' => 'Password field',
+ 'description' => 'Set some password setting',
+ 'type' => DeclarativeSettingsTypes::PASSWORD,
+ 'label' => 'Password field',
+ 'placeholder' => 'Set secure value',
+ 'default' => '',
+ 'sensitive' => false,
+ ],
],
];
@@ -229,6 +263,7 @@ class DeclarativeManagerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->crypto = $this->createMock(ICrypto::class);
$this->declarativeManager = new DeclarativeManager(
$this->eventDispatcher,
@@ -236,7 +271,8 @@ class DeclarativeManagerTest extends TestCase {
$this->coordinator,
$this->config,
$this->appConfig,
- $this->logger
+ $this->logger,
+ $this->crypto,
);
$this->user = $this->createMock(IUser::class);
diff --git a/tests/lib/TempManagerTest.php b/tests/lib/TempManagerTest.php
index 63cffc0dcae..b607772f5c3 100644
--- a/tests/lib/TempManagerTest.php
+++ b/tests/lib/TempManagerTest.php
@@ -9,6 +9,7 @@
namespace Test;
use bantu\IniGetWrapper\IniGetWrapper;
+use OCP\Files;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
@@ -26,7 +27,7 @@ class TempManagerTest extends \Test\TestCase {
protected function tearDown(): void {
if ($this->baseDir !== null) {
- \OC_Helper::rmdirr($this->baseDir);
+ Files::rmdirr($this->baseDir);
}
$this->baseDir = null;
parent::tearDown();
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 918edf7150e..9ca2606ce72 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -15,6 +15,7 @@ use OC\Files\Filesystem;
use OC\Files\Mount\CacheMountProvider;
use OC\Files\Mount\LocalHomeMountProvider;
use OC\Files\Mount\RootMountProvider;
+use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Files\SetupManager;
use OC\Template\Base;
use OCP\Command\IBus;
@@ -25,7 +26,6 @@ use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom;
-use Psr\Log\LoggerInterface;
if (version_compare(\PHPUnit\Runner\Version::id(), 10, '>=')) {
trait OnNotSuccessfulTestTrait {
@@ -332,7 +332,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
$config = \OC::$server->get(IConfig::class);
$mountProviderCollection->registerProvider(new CacheMountProvider($config));
$mountProviderCollection->registerHomeProvider(new LocalHomeMountProvider());
- $mountProviderCollection->registerRootProvider(new RootMountProvider($config, \OC::$server->get(LoggerInterface::class)));
+ $objectStoreConfig = \OC::$server->get(PrimaryObjectStoreConfig::class);
+ $mountProviderCollection->registerRootProvider(new RootMountProvider($objectStoreConfig, $config));
$setupManager->setupRoot();
diff --git a/tests/lib/TextProcessing/TextProcessingTest.php b/tests/lib/TextProcessing/TextProcessingTest.php
index 84c5492a4a2..1bbb9cf527e 100644
--- a/tests/lib/TextProcessing/TextProcessingTest.php
+++ b/tests/lib/TextProcessing/TextProcessingTest.php
@@ -118,7 +118,7 @@ class TextProcessingTest extends \Test\TestCase {
$this->eventDispatcher = new EventDispatcher(
new \Symfony\Component\EventDispatcher\EventDispatcher(),
$this->serverContainer,
- \OC::$server->get(LoggerInterface::class),
+ \OCP\Server::get(LoggerInterface::class),
);
$this->registrationContext = $this->createMock(RegistrationContext::class);
@@ -176,11 +176,11 @@ class TextProcessingTest extends \Test\TestCase {
$this->manager = new Manager(
$this->serverContainer,
$this->coordinator,
- \OC::$server->get(LoggerInterface::class),
+ \OCP\Server::get(LoggerInterface::class),
$this->jobList,
$this->taskMapper,
$config,
- \OC::$server->get(\OCP\TaskProcessing\IManager::class),
+ $this->createMock(\OCP\TaskProcessing\IManager::class),
);
}
@@ -239,7 +239,7 @@ class TextProcessingTest extends \Test\TestCase {
// run background job
$bgJob = new TaskBackgroundJob(
- \OC::$server->get(ITimeFactory::class),
+ \OCP\Server::get(ITimeFactory::class),
$this->manager,
$this->eventDispatcher,
);
@@ -314,7 +314,7 @@ class TextProcessingTest extends \Test\TestCase {
// run background job
$bgJob = new TaskBackgroundJob(
- \OC::$server->get(ITimeFactory::class),
+ \OCP\Server::get(ITimeFactory::class),
$this->manager,
$this->eventDispatcher,
);
@@ -343,9 +343,9 @@ class TextProcessingTest extends \Test\TestCase {
$this->currentTime = $this->currentTime->add(new \DateInterval('P1Y'));
// run background job
$bgJob = new RemoveOldTasksBackgroundJob(
- \OC::$server->get(ITimeFactory::class),
+ \OCP\Server::get(ITimeFactory::class),
$this->taskMapper,
- \OC::$server->get(LoggerInterface::class),
+ \OCP\Server::get(LoggerInterface::class),
);
$bgJob->setArgument([]);
$bgJob->start($this->jobList);
diff --git a/tests/lib/Traits/MountProviderTrait.php b/tests/lib/Traits/MountProviderTrait.php
index 6d947d645dd..3bb92f48e20 100644
--- a/tests/lib/Traits/MountProviderTrait.php
+++ b/tests/lib/Traits/MountProviderTrait.php
@@ -58,6 +58,6 @@ trait MountProviderTrait {
return [];
}
}));
- \OC::$server->getMountProviderCollection()->registerProvider($this->mountProvider);
+ \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class)->registerProvider($this->mountProvider);
}
}
diff --git a/tests/lib/User/UserTest.php b/tests/lib/User/UserTest.php
index 694c1e757cb..8f9560d6486 100644
--- a/tests/lib/User/UserTest.php
+++ b/tests/lib/User/UserTest.php
@@ -14,6 +14,7 @@ use OC\Hooks\PublicEmitter;
use OC\User\User;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IURLGenerator;
@@ -834,8 +835,8 @@ class UserTest extends TestCase {
$config->method('getAppValue')
->will($this->returnValueMap($appValueMap));
- $quota = $user->getQuota();
- $this->assertEquals('none', $quota);
+ $this->assertEquals('none', $user->getQuota());
+ $this->assertEquals(FileInfo::SPACE_UNLIMITED, $user->getQuotaBytes());
}
public function testGetDefaultUnlimitedQuotaForbidden(): void {
@@ -868,8 +869,8 @@ class UserTest extends TestCase {
$config->method('getAppValue')
->will($this->returnValueMap($appValueMap));
- $quota = $user->getQuota();
- $this->assertEquals('1 GB', $quota);
+ $this->assertEquals('1 GB', $user->getQuota());
+ $this->assertEquals(1024 * 1024 * 1024, $user->getQuotaBytes());
}
public function testSetQuotaAddressNoChange(): void {
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index 0063a991e48..e124ea687d8 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -334,4 +334,84 @@ class UtilTest extends \Test\TestCase {
// each of the characters is 12 bytes
$this->assertEquals('🙈', Util::shortenMultibyteString('🙈🙊🙉', 16, 2));
}
+
+ /**
+ * @dataProvider humanFileSizeProvider
+ */
+ public function testHumanFileSize($expected, $input): void {
+ $result = Util::humanFileSize($input);
+ $this->assertEquals($expected, $result);
+ }
+
+ public static function humanFileSizeProvider(): array {
+ return [
+ ['0 B', 0],
+ ['1 KB', 1024],
+ ['9.5 MB', 10000000],
+ ['1.3 GB', 1395864371],
+ ['465.7 GB', 500000000000],
+ ['454.7 TB', 500000000000000],
+ ['444.1 PB', 500000000000000000],
+ ];
+ }
+
+ /**
+ * @dataProvider providesComputerFileSize
+ */
+ public function testComputerFileSize($expected, $input): void {
+ $result = Util::computerFileSize($input);
+ $this->assertEquals($expected, $result);
+ }
+
+ public static function providesComputerFileSize(): array {
+ return [
+ [0.0, '0 B'],
+ [1024.0, '1 KB'],
+ [1395864371.0, '1.3 GB'],
+ [9961472.0, '9.5 MB'],
+ [500041567437.0, '465.7 GB'],
+ [false, '12 GB etfrhzui']
+ ];
+ }
+
+ public function testMb_array_change_key_case(): void {
+ $arrayStart = [
+ 'Foo' => 'bar',
+ 'Bar' => 'foo',
+ ];
+ $arrayResult = [
+ 'foo' => 'bar',
+ 'bar' => 'foo',
+ ];
+ $result = Util::mb_array_change_key_case($arrayStart);
+ $expected = $arrayResult;
+ $this->assertEquals($result, $expected);
+
+ $arrayStart = [
+ 'foo' => 'bar',
+ 'bar' => 'foo',
+ ];
+ $arrayResult = [
+ 'FOO' => 'bar',
+ 'BAR' => 'foo',
+ ];
+ $result = Util::mb_array_change_key_case($arrayStart, MB_CASE_UPPER);
+ $expected = $arrayResult;
+ $this->assertEquals($result, $expected);
+ }
+
+ public function testRecursiveArraySearch(): void {
+ $haystack = [
+ 'Foo' => 'own',
+ 'Bar' => 'Cloud',
+ ];
+
+ $result = Util::recursiveArraySearch($haystack, 'own');
+ $expected = 'Foo';
+ $this->assertEquals($result, $expected);
+
+ $result = Util::recursiveArraySearch($haystack, 'NotFound');
+ $this->assertFalse($result);
+ }
+
}