diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/karma.config.js | 79 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 6 | ||||
-rw-r--r-- | tests/lib/AutoLoaderTest.php | 57 | ||||
-rw-r--r-- | tests/lib/Comments/ManagerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/FilenameValidatorTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Mount/ObjectHomeMountProviderTest.php | 242 | ||||
-rw-r--r-- | tests/lib/Files/Mount/RootMountProviderTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php | 13 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/QuotaTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Settings/DeclarativeManagerTest.php | 38 | ||||
-rw-r--r-- | tests/lib/TestCase.php | 5 | ||||
-rw-r--r-- | tests/lib/TextProcessing/TextProcessingTest.php | 14 | ||||
-rw-r--r-- | tests/lib/User/UserTest.php | 9 |
13 files changed, 212 insertions, 264 deletions
diff --git a/tests/karma.config.js b/tests/karma.config.js index 072bb9d766a..cf2a399f202 100644 --- a/tests/karma.config.js +++ b/tests/karma.config.js @@ -27,30 +27,6 @@ if (!process.env.CHROMIUM_BIN) { /* jshint node: true */ module.exports = function(config) { - function findApps() { - /* - var fs = require('fs'); - var apps = fs.readdirSync('apps'); - return apps; - */ - // other apps tests don't run yet... needs further research / clean up - return [ - 'files', - 'files_versions', - { - name: 'files_sharing', - srcFiles: [ - // only test these files, others are not ready and mess - // up with the global namespace/classes/state - 'dist/files_sharing-additionalScripts.js', - 'dist/files_sharing-files_sharing_tab.js', - 'dist/files_sharing-main.js', - ], - }, - 'files_trashbin', - ]; - } - // respect NOCOVERAGE env variable // it is useful to disable coverage for debugging // because the coverage preprocessor will wrap the JS files somehow @@ -60,34 +36,15 @@ module.exports = function(config) { enableCoverage ? 'enabled' : 'disabled' ); - // default apps to test when none is specified (TODO: read from filesystem ?) - let appsToTest = [] - if (process.env.KARMA_TESTSUITE) { - appsToTest = process.env.KARMA_TESTSUITE.split(' '); - } else { - appsToTest = ['core'].concat(findApps()); - } - - console.log('Apps to test: ', appsToTest); - // read core files from core.json, // these are required by all apps so always need to be loaded // note that the loading order is important that's why they // are specified in a separate file var corePath = 'dist/'; var coreModule = require('../core/js/core.json'); - var testCore = false; var files = []; - var index; var preprocessors = {}; - // find out what apps to test from appsToTest - index = appsToTest.indexOf('core'); - if (index > -1) { - appsToTest.splice(index, 1); - testCore = true; - } - var srcFile, i; // add core library files for (i = 0; i < coreModule.libraries.length; i++) { @@ -113,40 +70,8 @@ module.exports = function(config) { } } - // TODO: settings pages - - // need to test the core app as well ? - if (testCore) { - // core tests - files.push('core/js/tests/specs/**/*.js'); - } - - function addApp(app) { - // if only a string was specified, expand to structure - if (typeof app === 'string') { - app = { - srcFiles: ['dist/' + app + '-*.js', 'apps/' + app + '/js/**/*.js'], - testFiles: 'apps/' + app + '/tests/js/**/*.js' - }; - } - - // add source files/patterns - files = files.concat(app.srcFiles || []); - // add test files/patterns - files = files.concat(app.testFiles || []); - if (enableCoverage) { - // add coverage entry for each file/pattern - for (var i = 0; i < app.srcFiles.length; i++) { - preprocessors[app.srcFiles[i]] = 'coverage'; - } - } - } - - // add source files for apps to test - for (i = 0; i < appsToTest.length; i++) { - addApp(appsToTest[i]); - } - + // core tests + files.push('core/js/tests/specs/**/*.js'); // serve images to avoid warnings files.push({ pattern: 'core/img/**/*', 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/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/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/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/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/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php index 791e8047f7f..3115f1288a0 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -12,8 +12,6 @@ use OC\Files\Cache\CacheEntry; use OC\Files\Storage\Local; use OCP\Files; -\OC::$loader->load('\OC\Files\Filesystem'); - /** * Class QuotaTest * 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/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/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 { |