diff options
Diffstat (limited to 'tests/lib/Files')
-rw-r--r-- | tests/lib/Files/Cache/CacheTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 85 | ||||
-rw-r--r-- | tests/lib/Files/FilenameValidatorTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/FilesystemTest.php | 5 | ||||
-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/Node/HookConnectorTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php | 13 | ||||
-rw-r--r-- | tests/lib/Files/Storage/CommonTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/Storage/HomeTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/Storage/LocalTest.php | 3 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/QuotaTest.php | 5 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/WrapperTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Utils/ScannerTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/ViewTest.php | 4 |
15 files changed, 240 insertions, 142 deletions
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; |