aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files')
-rw-r--r--tests/lib/Files/Cache/CacheTest.php41
-rw-r--r--tests/lib/Files/Cache/HomeCacheTest.php26
-rw-r--r--tests/lib/Files/Cache/LocalRootScannerTest.php4
-rw-r--r--tests/lib/Files/Cache/MoveFromCacheTraitTest.php8
-rw-r--r--tests/lib/Files/Cache/ScannerTest.php8
-rw-r--r--tests/lib/Files/Cache/SearchBuilderTest.php8
-rw-r--r--tests/lib/Files/Cache/UpdaterLegacyTest.php17
-rw-r--r--tests/lib/Files/Cache/WatcherTest.php17
-rw-r--r--tests/lib/Files/Cache/Wrapper/CacheJailTest.php8
-rw-r--r--tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php3
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php3
-rw-r--r--tests/lib/Files/EtagTest.php17
-rw-r--r--tests/lib/Files/FilesystemTest.php131
-rw-r--r--tests/lib/Files/Mount/ManagerTest.php11
-rw-r--r--tests/lib/Files/Mount/MountPointTest.php9
-rw-r--r--tests/lib/Files/Mount/MountTest.php7
-rw-r--r--tests/lib/Files/Mount/ObjectHomeMountProviderTest.php7
-rw-r--r--tests/lib/Files/Node/FileTest.php73
-rw-r--r--tests/lib/Files/Node/FolderTest.php41
-rw-r--r--tests/lib/Files/Node/HookConnectorTest.php64
-rw-r--r--tests/lib/Files/Node/IntegrationTest.php5
-rw-r--r--tests/lib/Files/Node/NodeTestCase.php95
-rw-r--r--tests/lib/Files/Node/RootTest.php24
-rw-r--r--tests/lib/Files/ObjectStore/AzureTest.php4
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php13
-rw-r--r--tests/lib/Files/ObjectStore/S3Test.php4
-rw-r--r--tests/lib/Files/ObjectStore/SwiftTest.php4
-rw-r--r--tests/lib/Files/PathVerificationTest.php10
-rw-r--r--tests/lib/Files/Storage/CommonTest.php3
-rw-r--r--tests/lib/Files/Storage/CopyDirectoryTest.php3
-rw-r--r--tests/lib/Files/Storage/HomeTest.php18
-rw-r--r--tests/lib/Files/Storage/LocalTest.php25
-rw-r--r--tests/lib/Files/Storage/Storage.php3
-rw-r--r--tests/lib/Files/Storage/StorageFactoryTest.php7
-rw-r--r--tests/lib/Files/Storage/Wrapper/AvailabilityTest.php10
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncodingTest.php7
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncryptionTest.php7
-rw-r--r--tests/lib/Files/Storage/Wrapper/JailTest.php10
-rw-r--r--tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php12
-rw-r--r--tests/lib/Files/Storage/Wrapper/QuotaTest.php19
-rw-r--r--tests/lib/Files/Storage/Wrapper/WrapperTest.php10
-rw-r--r--tests/lib/Files/Stream/DummyEncryptionWrapper.php4
-rw-r--r--tests/lib/Files/Stream/HashWrapperTest.php2
-rw-r--r--tests/lib/Files/Stream/QuotaTest.php8
-rw-r--r--tests/lib/Files/Type/DetectionTest.php5
-rw-r--r--tests/lib/Files/Type/LoaderTest.php3
-rw-r--r--tests/lib/Files/Utils/ScannerTest.php25
-rw-r--r--tests/lib/Files/ViewTest.php69
48 files changed, 506 insertions, 406 deletions
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index 2815003a996..18670300850 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -11,13 +11,18 @@ use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
+use OC\Files\Storage\Temporary;
+use OC\User\User;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Search\ISearchComparison;
use OCP\IDBConnection;
+use OCP\ITagManager;
use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Server;
-class LongId extends \OC\Files\Storage\Temporary {
+class LongId extends Temporary {
public function getId(): string {
return 'long:' . str_repeat('foo', 50) . parent::getId();
}
@@ -52,10 +57,10 @@ class CacheTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->storage = new \OC\Files\Storage\Temporary([]);
- $this->storage2 = new \OC\Files\Storage\Temporary([]);
- $this->cache = new \OC\Files\Cache\Cache($this->storage);
- $this->cache2 = new \OC\Files\Cache\Cache($this->storage2);
+ $this->storage = new Temporary([]);
+ $this->storage2 = new Temporary([]);
+ $this->cache = new Cache($this->storage);
+ $this->cache2 = new Cache($this->storage2);
$this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
@@ -162,8 +167,8 @@ class CacheTest extends \Test\TestCase {
public function testFolder($folder): void {
if (strpos($folder, 'F09F9890')) {
// 4 byte UTF doesn't work on mysql
- $params = \OC::$server->get(\OC\DB\Connection::class)->getParams();
- if (\OC::$server->getDatabaseConnection()->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL && $params['charset'] !== 'utf8mb4') {
+ $params = Server::get(\OC\DB\Connection::class)->getParams();
+ if (Server::get(IDBConnection::class)->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL && $params['charset'] !== 'utf8mb4') {
$this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8');
}
}
@@ -311,13 +316,13 @@ class CacheTest extends \Test\TestCase {
}
public function testStatus(): void {
- $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo'));
+ $this->assertEquals(Cache::NOT_FOUND, $this->cache->getStatus('foo'));
$this->cache->put('foo', ['size' => -1]);
- $this->assertEquals(\OC\Files\Cache\Cache::PARTIAL, $this->cache->getStatus('foo'));
+ $this->assertEquals(Cache::PARTIAL, $this->cache->getStatus('foo'));
$this->cache->put('foo', ['size' => -1, 'mtime' => 20, 'mimetype' => 'foo/file']);
- $this->assertEquals(\OC\Files\Cache\Cache::SHALLOW, $this->cache->getStatus('foo'));
+ $this->assertEquals(Cache::SHALLOW, $this->cache->getStatus('foo'));
$this->cache->put('foo', ['size' => 10]);
- $this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo'));
+ $this->assertEquals(Cache::COMPLETE, $this->cache->getStatus('foo'));
}
public static function putWithAllKindOfQuotesData(): array {
@@ -333,7 +338,7 @@ class CacheTest extends \Test\TestCase {
* @param $fileName
*/
public function testPutWithAllKindOfQuotes($fileName): void {
- $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->get($fileName));
+ $this->assertEquals(Cache::NOT_FOUND, $this->cache->get($fileName));
$this->cache->put($fileName, ['size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file', 'etag' => $fileName]);
$cacheEntry = $this->cache->get($fileName);
@@ -371,9 +376,9 @@ class CacheTest extends \Test\TestCase {
public function testSearchQueryByTag(): void {
$userId = static::getUniqueID('user');
- \OC::$server->getUserManager()->createUser($userId, $userId);
+ Server::get(IUserManager::class)->createUser($userId, $userId);
static::loginAsUser($userId);
- $user = new \OC\User\User($userId, null, \OC::$server->get(IEventDispatcher::class));
+ $user = new User($userId, null, Server::get(IEventDispatcher::class));
$file1 = 'folder';
$file2 = 'folder/foobar';
@@ -393,7 +398,7 @@ class CacheTest extends \Test\TestCase {
$id4 = $this->cache->put($file4, $fileData['foo2']);
$id5 = $this->cache->put($file5, $fileData['foo3']);
- $tagManager = \OCP\Server::get(\OCP\ITagManager::class)->load('files', [], false, $userId);
+ $tagManager = Server::get(ITagManager::class)->load('files', [], false, $userId);
$this->assertTrue($tagManager->tagAs($id1, 'tag1'));
$this->assertTrue($tagManager->tagAs($id1, 'tag2'));
$this->assertTrue($tagManager->tagAs($id2, 'tag2'));
@@ -418,7 +423,7 @@ class CacheTest extends \Test\TestCase {
$tagManager->delete('tag2');
static::logout();
- $user = \OC::$server->getUserManager()->get($userId);
+ $user = Server::get(IUserManager::class)->get($userId);
if ($user !== null) {
try {
$user->delete();
@@ -550,7 +555,7 @@ class CacheTest extends \Test\TestCase {
if (strlen($storageId) > 64) {
$storageId = md5($storageId);
}
- $this->assertEquals([$storageId, 'foo'], \OC\Files\Cache\Cache::getById($id));
+ $this->assertEquals([$storageId, 'foo'], Cache::getById($id));
}
public function testStorageMTime(): void {
@@ -577,7 +582,7 @@ class CacheTest extends \Test\TestCase {
$storageId = $storage->getId();
$data = ['size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'];
$id = $cache->put('foo', $data);
- $this->assertEquals([md5($storageId), 'foo'], \OC\Files\Cache\Cache::getById($id));
+ $this->assertEquals([md5($storageId), 'foo'], Cache::getById($id));
}
/**
diff --git a/tests/lib/Files/Cache/HomeCacheTest.php b/tests/lib/Files/Cache/HomeCacheTest.php
index ad069de1fef..5130ad2730a 100644
--- a/tests/lib/Files/Cache/HomeCacheTest.php
+++ b/tests/lib/Files/Cache/HomeCacheTest.php
@@ -7,24 +7,20 @@
namespace Test\Files\Cache;
-class DummyUser extends \OC\User\User {
- /**
- * @var string $home
- */
- private $home;
-
- /**
- * @var string $uid
- */
- private $uid;
+use OC\Files\Storage\Home;
+use OC\User\User;
+use OCP\ITempManager;
+use OCP\Server;
+class DummyUser extends User {
/**
* @param string $uid
* @param string $home
*/
- public function __construct($uid, $home) {
- $this->home = $home;
- $this->uid = $uid;
+ public function __construct(
+ private $uid,
+ private $home,
+ ) {
}
/**
@@ -68,8 +64,8 @@ class HomeCacheTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->user = new DummyUser('foo', \OC::$server->getTempManager()->getTemporaryFolder());
- $this->storage = new \OC\Files\Storage\Home(['user' => $this->user]);
+ $this->user = new DummyUser('foo', Server::get(ITempManager::class)->getTemporaryFolder());
+ $this->storage = new Home(['user' => $this->user]);
$this->cache = $this->storage->getCache();
}
diff --git a/tests/lib/Files/Cache/LocalRootScannerTest.php b/tests/lib/Files/Cache/LocalRootScannerTest.php
index e683283b7e1..727da2ed698 100644
--- a/tests/lib/Files/Cache/LocalRootScannerTest.php
+++ b/tests/lib/Files/Cache/LocalRootScannerTest.php
@@ -9,6 +9,8 @@ declare(strict_types=1);
namespace Test\Files\Cache;
use OC\Files\Storage\LocalRootStorage;
+use OCP\ITempManager;
+use OCP\Server;
use Test\TestCase;
/**
@@ -21,7 +23,7 @@ class LocalRootScannerTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $folder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $folder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->storage = new LocalRootStorage(['datadir' => $folder]);
}
diff --git a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
index e8a6c8acf32..fc36a10892a 100644
--- a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
+++ b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php
@@ -7,10 +7,12 @@
namespace Test\Files\Cache;
+use OC\Files\Cache\Cache;
use OC\Files\Cache\MoveFromCacheTrait;
+use OC\Files\Storage\Temporary;
use OCP\Files\Cache\ICacheEntry;
-class FallBackCrossCacheMoveCache extends \OC\Files\Cache\Cache {
+class FallBackCrossCacheMoveCache extends Cache {
use MoveFromCacheTrait;
}
@@ -23,8 +25,8 @@ class MoveFromCacheTraitTest extends CacheTest {
protected function setUp(): void {
parent::setUp();
- $this->storage = new \OC\Files\Storage\Temporary([]);
- $this->storage2 = new \OC\Files\Storage\Temporary([]);
+ $this->storage = new Temporary([]);
+ $this->storage2 = new Temporary([]);
$this->cache = new FallBackCrossCacheMoveCache($this->storage);
$this->cache2 = new FallBackCrossCacheMoveCache($this->storage2);
diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php
index dc5ba5d3cdf..0502cd3717a 100644
--- a/tests/lib/Files/Cache/ScannerTest.php
+++ b/tests/lib/Files/Cache/ScannerTest.php
@@ -14,6 +14,8 @@ use OC\Files\Cache\Scanner;
use OC\Files\Storage\Storage;
use OC\Files\Storage\Temporary;
use OCP\Files\Cache\IScanner;
+use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
/**
@@ -67,7 +69,7 @@ class ScannerTest extends TestCase {
$data = "dummy file data\n";
$this->storage->file_put_contents('foo🙈.txt', $data);
- if (OC::$server->getDatabaseConnection()->supports4ByteText()) {
+ if (Server::get(IDBConnection::class)->supports4ByteText()) {
$this->assertNotNull($this->scanner->scanFile('foo🙈.txt'));
$this->assertTrue($this->cache->inCache('foo🙈.txt'), true);
@@ -337,7 +339,7 @@ class ScannerTest extends TestCase {
$oldFolderId = $this->cache->getId('folder');
// delete the folder without removing the children
- $query = OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query = Server::get(IDBConnection::class)->getQueryBuilder();
$query->delete('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
$query->execute();
@@ -363,7 +365,7 @@ class ScannerTest extends TestCase {
$oldFolderId = $this->cache->getId('folder');
// delete the folder without removing the children
- $query = OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query = Server::get(IDBConnection::class)->getQueryBuilder();
$query->delete('filecache')
->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId)));
$query->execute();
diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php
index 28af199639a..957cf6c9f42 100644
--- a/tests/lib/Files/Cache/SearchBuilderTest.php
+++ b/tests/lib/Files/Cache/SearchBuilderTest.php
@@ -16,6 +16,8 @@ use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
use OCP\FilesMetadata\IFilesMetadataManager;
+use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
/**
@@ -39,7 +41,7 @@ class SearchBuilderTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $this->builder = Server::get(IDBConnection::class)->getQueryBuilder();
$this->mimetypeLoader = $this->createMock(IMimeTypeLoader::class);
$this->filesMetadataManager = $this->createMock(IFilesMetadataManager::class);
@@ -76,7 +78,7 @@ class SearchBuilderTest extends TestCase {
protected function tearDown(): void {
parent::tearDown();
- $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $builder = Server::get(IDBConnection::class)->getQueryBuilder();
$builder->delete('filecache')
->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->numericStorageId, IQueryBuilder::PARAM_INT)));
@@ -109,7 +111,7 @@ class SearchBuilderTest extends TestCase {
$data['mimetype'] = 1;
}
- $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $builder = Server::get(IDBConnection::class)->getQueryBuilder();
$values = [];
foreach ($data as $key => $value) {
diff --git a/tests/lib/Files/Cache/UpdaterLegacyTest.php b/tests/lib/Files/Cache/UpdaterLegacyTest.php
index 0f7e9d78d77..5d1abb46c0d 100644
--- a/tests/lib/Files/Cache/UpdaterLegacyTest.php
+++ b/tests/lib/Files/Cache/UpdaterLegacyTest.php
@@ -8,8 +8,11 @@
namespace Test\Files\Cache;
use OC\Files\Filesystem as Filesystem;
+use OC\Files\Storage\Temporary;
use OC\Files\View;
use OCP\Files\Mount\IMountManager;
+use OCP\IUserManager;
+use OCP\Server;
/**
* Class UpdaterLegacyTest
@@ -39,7 +42,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->storage = new \OC\Files\Storage\Temporary([]);
+ $this->storage = new Temporary([]);
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
$this->storage->mkdir('folder');
@@ -56,13 +59,13 @@ class UpdaterLegacyTest extends \Test\TestCase {
self::$user = $this->getUniqueID();
}
- \OC::$server->getUserManager()->createUser(self::$user, 'NotAnEasyPassword123456+');
+ Server::get(IUserManager::class)->createUser(self::$user, 'NotAnEasyPassword123456+');
$this->loginAsUser(self::$user);
Filesystem::init(self::$user, '/' . self::$user . '/files');
/** @var IMountManager $manager */
- $manager = \OC::$server->get(IMountManager::class);
+ $manager = Server::get(IMountManager::class);
$manager->removeMount('/' . self::$user);
Filesystem::mount($this->storage, [], '/' . self::$user . '/files');
@@ -76,7 +79,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
}
$result = false;
- $user = \OC::$server->getUserManager()->get(self::$user);
+ $user = Server::get(IUserManager::class)->get(self::$user);
if ($user !== null) {
$result = $user->delete();
}
@@ -122,7 +125,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
}
public function testWriteWithMountPoints(): void {
- $storage2 = new \OC\Files\Storage\Temporary([]);
+ $storage2 = new Temporary([]);
$storage2->getScanner()->scan(''); //initialize etags
$cache2 = $storage2->getCache();
Filesystem::mount($storage2, [], '/' . self::$user . '/files/folder/substorage');
@@ -183,7 +186,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
}
public function testDeleteWithMountPoints(): void {
- $storage2 = new \OC\Files\Storage\Temporary([]);
+ $storage2 = new Temporary([]);
$cache2 = $storage2->getCache();
Filesystem::mount($storage2, [], '/' . self::$user . '/files/folder/substorage');
Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
@@ -239,7 +242,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
}
public function testRenameWithMountPoints(): void {
- $storage2 = new \OC\Files\Storage\Temporary([]);
+ $storage2 = new Temporary([]);
$cache2 = $storage2->getCache();
Filesystem::mount($storage2, [], '/' . self::$user . '/files/folder/substorage');
Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd');
diff --git a/tests/lib/Files/Cache/WatcherTest.php b/tests/lib/Files/Cache/WatcherTest.php
index 7319aa9b68d..c086fb3206d 100644
--- a/tests/lib/Files/Cache/WatcherTest.php
+++ b/tests/lib/Files/Cache/WatcherTest.php
@@ -7,6 +7,9 @@
namespace Test\Files\Cache;
+use OC\Files\Cache\Watcher;
+use OC\Files\Storage\Temporary;
+
/**
* Class WatcherTest
*
@@ -44,7 +47,7 @@ class WatcherTest extends \Test\TestCase {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = $storage->getWatcher();
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ $updater->setPolicy(Watcher::CHECK_ONCE);
//set the mtime to the past so it can detect an mtime change
$cache->put('', ['storage_mtime' => 10]);
@@ -85,7 +88,7 @@ class WatcherTest extends \Test\TestCase {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = $storage->getWatcher();
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ $updater->setPolicy(Watcher::CHECK_ONCE);
//set the mtime to the past so it can detect an mtime change
$cache->put('', ['storage_mtime' => 10]);
@@ -102,7 +105,7 @@ class WatcherTest extends \Test\TestCase {
$storage = $this->getTestStorage();
$cache = $storage->getCache();
$updater = $storage->getWatcher();
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ $updater->setPolicy(Watcher::CHECK_ONCE);
//set the mtime to the past so it can detect an mtime change
$cache->put('foo.txt', ['storage_mtime' => 10]);
@@ -124,7 +127,7 @@ class WatcherTest extends \Test\TestCase {
//set the mtime to the past so it can detect an mtime change
$cache->put('foo.txt', ['storage_mtime' => 10]);
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_NEVER);
+ $updater->setPolicy(Watcher::CHECK_NEVER);
$storage->file_put_contents('foo.txt', 'q');
$this->assertFalse($updater->checkUpdate('foo.txt'));
@@ -142,7 +145,7 @@ class WatcherTest extends \Test\TestCase {
//set the mtime to the past so it can detect an mtime change
$cache->put('foo.txt', ['storage_mtime' => 10]);
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ $updater->setPolicy(Watcher::CHECK_ONCE);
$storage->file_put_contents('foo.txt', 'q');
$this->assertTrue($updater->checkUpdate('foo.txt'));
@@ -160,7 +163,7 @@ class WatcherTest extends \Test\TestCase {
//set the mtime to the past so it can detect an mtime change
$cache->put('foo.txt', ['storage_mtime' => 10]);
- $updater->setPolicy(\OC\Files\Cache\Watcher::CHECK_ALWAYS);
+ $updater->setPolicy(Watcher::CHECK_ALWAYS);
$storage->file_put_contents('foo.txt', 'q');
$this->assertTrue($updater->checkUpdate('foo.txt'));
@@ -175,7 +178,7 @@ class WatcherTest extends \Test\TestCase {
* @return \OC\Files\Storage\Storage
*/
private function getTestStorage($scan = true) {
- $storage = new \OC\Files\Storage\Temporary([]);
+ $storage = new Temporary([]);
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo/logo.png');
$storage->mkdir('folder');
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index 57024e2eb79..4073f3b9bae 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -35,7 +35,7 @@ class CacheJailTest extends CacheTest {
parent::setUp();
$this->storage->mkdir('jail');
$this->sourceCache = $this->cache;
- $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, 'jail');
+ $this->cache = new CacheJail($this->sourceCache, 'jail');
$this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
}
@@ -130,7 +130,7 @@ class CacheJailTest extends CacheTest {
$this->assertEquals('bar', $path);
// path from jailed '' of foo/bar is foo/bar
- $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
+ $this->cache = new CacheJail($this->sourceCache, '');
$path = $this->cache->getPathById($id);
$this->assertEquals('jail/bar', $path);
}
@@ -200,7 +200,7 @@ class CacheJailTest extends CacheTest {
$this->sourceCache->put($file2, $data1);
$this->sourceCache->put($file3, $data1);
- $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->cache, 'bar');
+ $nested = new CacheJail($this->cache, 'bar');
$result = $nested->search('%asd%');
$this->assertCount(1, $result);
@@ -218,7 +218,7 @@ class CacheJailTest extends CacheTest {
$this->sourceCache->put($file2, $data1);
$this->sourceCache->put($file3, $data1);
- $nested = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, '');
+ $nested = new CacheJail($this->sourceCache, '');
$result = $nested->search('%asd%');
$this->assertCount(1, $result);
diff --git a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
index 9aa1ee5b723..e4e14e7d5d0 100644
--- a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
@@ -7,6 +7,7 @@
namespace Test\Files\Cache\Wrapper;
+use OC\Files\Cache\Wrapper\CachePermissionsMask;
use OCP\Constants;
use Test\Files\Cache\CacheTest;
@@ -31,7 +32,7 @@ class CachePermissionsMaskTest extends CacheTest {
}
protected function getMaskedCached($mask) {
- return new \OC\Files\Cache\Wrapper\CachePermissionsMask($this->sourceCache, $mask);
+ return new CachePermissionsMask($this->sourceCache, $mask);
}
public static function maskProvider(): array {
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index 88c0ceaef08..55251e68110 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -26,6 +26,7 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use Test\Util\User\Dummy;
@@ -45,7 +46,7 @@ class UserMountCacheTest extends TestCase {
$this->fileIds = [];
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
diff --git a/tests/lib/Files/EtagTest.php b/tests/lib/Files/EtagTest.php
index b0cdff16f4d..82ed0ceff96 100644
--- a/tests/lib/Files/EtagTest.php
+++ b/tests/lib/Files/EtagTest.php
@@ -8,8 +8,13 @@
namespace Test\Files;
use OC\Files\Filesystem;
+use OC\Files\Utils\Scanner;
+use OC\Share\Share;
use OCA\Files_Sharing\AppInfo\Application;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\ITempManager;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;
@@ -38,12 +43,12 @@ class EtagTest extends \Test\TestCase {
// init files sharing
new Application();
- \OC\Share\Share::registerBackend('file', 'OCA\Files_Sharing\ShareBackend\File');
- \OC\Share\Share::registerBackend('folder', 'OCA\Files_Sharing\ShareBackend\Folder', 'file');
+ Share::registerBackend('file', 'OCA\Files_Sharing\ShareBackend\File');
+ Share::registerBackend('folder', 'OCA\Files_Sharing\ShareBackend\Folder', 'file');
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$this->datadir = $config->getSystemValueString('datadirectory');
- $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
$config->setSystemValue('datadirectory', $this->tmpDir);
$this->userBackend = new \Test\Util\User\Dummy();
@@ -51,7 +56,7 @@ class EtagTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OC::$server->getConfig()->setSystemValue('datadirectory', $this->datadir);
+ Server::get(IConfig::class)->setSystemValue('datadirectory', $this->datadir);
$this->logout();
parent::tearDown();
@@ -71,7 +76,7 @@ class EtagTest extends \Test\TestCase {
$files = ['/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt'];
$originalEtags = $this->getEtags($files);
- $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new Scanner($user1, Server::get(IDBConnection::class), Server::get(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->backgroundScan('/');
$newEtags = $this->getEtags($files);
diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php
index 529b4f58428..9b5e24f8b74 100644
--- a/tests/lib/Files/FilesystemTest.php
+++ b/tests/lib/Files/FilesystemTest.php
@@ -7,24 +7,29 @@
namespace Test\Files;
+use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
+use OC\Files\View;
use OC\User\NoUserException;
use OCP\Files;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Storage\IStorageFactory;
+use OCP\IConfig;
+use OCP\ITempManager;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Server;
class DummyMountProvider implements IMountProvider {
- private $mounts = [];
-
/**
* @param array $mounts
*/
- public function __construct(array $mounts) {
- $this->mounts = $mounts;
+ public function __construct(
+ private array $mounts,
+ ) {
}
/**
@@ -59,7 +64,7 @@ class FilesystemTest extends \Test\TestCase {
* @return array
*/
private function getStorageData() {
- $dir = \OC::$server->getTempManager()->getTemporaryFolder();
+ $dir = Server::get(ITempManager::class)->getTemporaryFolder();
$this->tmpDirs[] = $dir;
return ['datadir' => $dir];
}
@@ -69,7 +74,7 @@ class FilesystemTest extends \Test\TestCase {
$userBackend = new \Test\Util\User\Dummy();
$userBackend->createUser(self::TEST_FILESYSTEM_USER1, self::TEST_FILESYSTEM_USER1);
$userBackend->createUser(self::TEST_FILESYSTEM_USER2, self::TEST_FILESYSTEM_USER2);
- \OC::$server->getUserManager()->registerBackend($userBackend);
+ Server::get(IUserManager::class)->registerBackend($userBackend);
$this->loginAsUser();
}
@@ -84,20 +89,20 @@ class FilesystemTest extends \Test\TestCase {
}
public function testMount(): void {
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/');
- $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/'));
- $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/some/folder'));
- [, $internalPath] = \OC\Files\Filesystem::resolvePath('/');
+ Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/');
+ $this->assertEquals('/', Filesystem::getMountPoint('/'));
+ $this->assertEquals('/', Filesystem::getMountPoint('/some/folder'));
+ [, $internalPath] = Filesystem::resolvePath('/');
$this->assertEquals('', $internalPath);
- [, $internalPath] = \OC\Files\Filesystem::resolvePath('/some/folder');
+ [, $internalPath] = Filesystem::resolvePath('/some/folder');
$this->assertEquals('some/folder', $internalPath);
- \OC\Files\Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/some');
- $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/'));
- $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/folder'));
- $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some/'));
- $this->assertEquals('/some/', \OC\Files\Filesystem::getMountPoint('/some'));
- [, $internalPath] = \OC\Files\Filesystem::resolvePath('/some/folder');
+ Filesystem::mount('\OC\Files\Storage\Local', self::getStorageData(), '/some');
+ $this->assertEquals('/', Filesystem::getMountPoint('/'));
+ $this->assertEquals('/some/', Filesystem::getMountPoint('/some/folder'));
+ $this->assertEquals('/some/', Filesystem::getMountPoint('/some/'));
+ $this->assertEquals('/some/', Filesystem::getMountPoint('/some'));
+ [, $internalPath] = Filesystem::resolvePath('/some/folder');
$this->assertEquals('folder', $internalPath);
}
@@ -199,7 +204,7 @@ class FilesystemTest extends \Test\TestCase {
* @dataProvider normalizePathData
*/
public function testNormalizePath($expected, $path, $stripTrailingSlash = true): void {
- $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash));
+ $this->assertEquals($expected, Filesystem::normalizePath($path, $stripTrailingSlash));
}
public static function normalizePathKeepUnicodeData(): array {
@@ -217,15 +222,15 @@ class FilesystemTest extends \Test\TestCase {
* @dataProvider normalizePathKeepUnicodeData
*/
public function testNormalizePathKeepUnicode($expected, $path, $keepUnicode = false): void {
- $this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, true, false, $keepUnicode));
+ $this->assertEquals($expected, Filesystem::normalizePath($path, true, false, $keepUnicode));
}
public function testNormalizePathKeepUnicodeCache(): void {
$nfdName = 'ümlaut';
$nfcName = 'ümlaut';
// call in succession due to cache
- $this->assertEquals('/' . $nfcName, \OC\Files\Filesystem::normalizePath($nfdName, true, false, false));
- $this->assertEquals('/' . $nfdName, \OC\Files\Filesystem::normalizePath($nfdName, true, false, true));
+ $this->assertEquals('/' . $nfcName, Filesystem::normalizePath($nfdName, true, false, false));
+ $this->assertEquals('/' . $nfdName, Filesystem::normalizePath($nfdName, true, false, true));
}
public static function isValidPathData(): array {
@@ -258,7 +263,7 @@ class FilesystemTest extends \Test\TestCase {
* @dataProvider isValidPathData
*/
public function testIsValidPath($path, $expected): void {
- $this->assertSame($expected, \OC\Files\Filesystem::isValidPath($path));
+ $this->assertSame($expected, Filesystem::isValidPath($path));
}
public static function isFileBlacklistedData(): array {
@@ -280,7 +285,7 @@ class FilesystemTest extends \Test\TestCase {
* @dataProvider isFileBlacklistedData
*/
public function testIsFileBlacklisted($path, $expected): void {
- $this->assertSame($expected, \OC\Files\Filesystem::isFileBlacklisted($path));
+ $this->assertSame($expected, Filesystem::isFileBlacklisted($path));
}
public function testNormalizePathUTF8(): void {
@@ -288,36 +293,36 @@ class FilesystemTest extends \Test\TestCase {
$this->markTestSkipped('UTF8 normalizer Patchwork was not found');
}
- $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88"));
- $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("\\foo\\baru\xCC\x88"));
+ $this->assertEquals("/foo/bar\xC3\xBC", Filesystem::normalizePath("/foo/baru\xCC\x88"));
+ $this->assertEquals("/foo/bar\xC3\xBC", Filesystem::normalizePath("\\foo\\baru\xCC\x88"));
}
public function testHooks(): void {
- if (\OC\Files\Filesystem::getView()) {
+ if (Filesystem::getView()) {
$user = \OC_User::getUser();
} else {
$user = self::TEST_FILESYSTEM_USER1;
$backend = new \Test\Util\User\Dummy();
Server::get(IUserManager::class)->registerBackend($backend);
$backend->createUser($user, $user);
- $userObj = \OC::$server->getUserManager()->get($user);
- \OC::$server->getUserSession()->setUser($userObj);
- \OC\Files\Filesystem::init($user, '/' . $user . '/files');
+ $userObj = Server::get(IUserManager::class)->get($user);
+ Server::get(IUserSession::class)->setUser($userObj);
+ Filesystem::init($user, '/' . $user . '/files');
}
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
- \OC\Files\Filesystem::mount('OC\Files\Storage\Temporary', [], '/');
+ Filesystem::mount('OC\Files\Storage\Temporary', [], '/');
- $rootView = new \OC\Files\View('');
+ $rootView = new View('');
$rootView->mkdir('/' . $user);
$rootView->mkdir('/' . $user . '/files');
// \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
- \OC\Files\Filesystem::mkdir('/bar');
+ Filesystem::mkdir('/bar');
// \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
- $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
+ $tmpFile = Server::get(ITempManager::class)->getTemporaryFile();
file_put_contents($tmpFile, 'foo');
$fh = fopen($tmpFile, 'r');
// \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
@@ -328,29 +333,29 @@ class FilesystemTest extends \Test\TestCase {
*
*/
public function testLocalMountWhenUserDoesNotExist(): void {
- $this->expectException(\OC\User\NoUserException::class);
+ $this->expectException(NoUserException::class);
$userId = $this->getUniqueID('user_');
- \OC\Files\Filesystem::initMountPoints($userId);
+ Filesystem::initMountPoints($userId);
}
public function testNullUserThrows(): void {
- $this->expectException(\OC\User\NoUserException::class);
+ $this->expectException(NoUserException::class);
- \OC\Files\Filesystem::initMountPoints(null);
+ Filesystem::initMountPoints(null);
}
public function testNullUserThrowsTwice(): void {
$thrown = 0;
try {
- \OC\Files\Filesystem::initMountPoints(null);
+ Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
$thrown++;
}
try {
- \OC\Files\Filesystem::initMountPoints(null);
+ Filesystem::initMountPoints(null);
} catch (NoUserException $e) {
$thrown++;
}
@@ -365,13 +370,13 @@ class FilesystemTest extends \Test\TestCase {
$userId = $this->getUniqueID('user_');
try {
- \OC\Files\Filesystem::initMountPoints($userId);
+ Filesystem::initMountPoints($userId);
} catch (NoUserException $e) {
$thrown++;
}
try {
- \OC\Files\Filesystem::initMountPoints($userId);
+ Filesystem::initMountPoints($userId);
} catch (NoUserException $e) {
$thrown++;
}
@@ -385,11 +390,11 @@ class FilesystemTest extends \Test\TestCase {
public function testHomeMount(): void {
$userId = $this->getUniqueID('user_');
- \OC::$server->getUserManager()->createUser($userId, $userId);
+ Server::get(IUserManager::class)->createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ Filesystem::initMountPoints($userId);
- $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/');
+ $homeMount = Filesystem::getStorage('/' . $userId . '/');
$this->assertTrue($homeMount->instanceOfStorage('\OCP\Files\IHomeStorage'));
if ($homeMount->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
@@ -398,7 +403,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals('home::' . $userId, $homeMount->getId());
}
- $user = \OC::$server->getUserManager()->get($userId);
+ $user = Server::get(IUserManager::class)->get($userId);
if ($user !== null) {
$user->delete();
}
@@ -406,7 +411,7 @@ class FilesystemTest extends \Test\TestCase {
public function dummyHook($arguments) {
$path = $arguments['path'];
- $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
+ $this->assertEquals($path, Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized
}
/**
@@ -414,22 +419,22 @@ class FilesystemTest extends \Test\TestCase {
*/
public function testMountDefaultCacheDir(): void {
$userId = $this->getUniqueID('user_');
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$oldCachePath = $config->getSystemValueString('cache_path', '');
// no cache path configured
$config->setSystemValue('cache_path', '');
- \OC::$server->getUserManager()->createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ Server::get(IUserManager::class)->createUser($userId, $userId);
+ Filesystem::initMountPoints($userId);
$this->assertEquals(
'/' . $userId . '/',
- \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
+ Filesystem::getMountPoint('/' . $userId . '/cache')
);
- [$storage, $internalPath] = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
+ [$storage, $internalPath] = Filesystem::resolvePath('/' . $userId . '/cache');
$this->assertTrue($storage->instanceOfStorage('\OCP\Files\IHomeStorage'));
$this->assertEquals('cache', $internalPath);
- $user = \OC::$server->getUserManager()->get($userId);
+ $user = Server::get(IUserManager::class)->get($userId);
if ($user !== null) {
$user->delete();
}
@@ -444,23 +449,23 @@ class FilesystemTest extends \Test\TestCase {
public function testMountExternalCacheDir(): void {
$userId = $this->getUniqueID('user_');
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$oldCachePath = $config->getSystemValueString('cache_path', '');
// set cache path to temp dir
- $cachePath = \OC::$server->getTempManager()->getTemporaryFolder() . '/extcache';
+ $cachePath = Server::get(ITempManager::class)->getTemporaryFolder() . '/extcache';
$config->setSystemValue('cache_path', $cachePath);
- \OC::$server->getUserManager()->createUser($userId, $userId);
- \OC\Files\Filesystem::initMountPoints($userId);
+ Server::get(IUserManager::class)->createUser($userId, $userId);
+ Filesystem::initMountPoints($userId);
$this->assertEquals(
'/' . $userId . '/cache/',
- \OC\Files\Filesystem::getMountPoint('/' . $userId . '/cache')
+ Filesystem::getMountPoint('/' . $userId . '/cache')
);
- [$storage, $internalPath] = \OC\Files\Filesystem::resolvePath('/' . $userId . '/cache');
+ [$storage, $internalPath] = Filesystem::resolvePath('/' . $userId . '/cache');
$this->assertTrue($storage->instanceOfStorage('\OC\Files\Storage\Local'));
$this->assertEquals('', $internalPath);
- $user = \OC::$server->getUserManager()->get($userId);
+ $user = Server::get(IUserManager::class)->get($userId);
if ($user !== null) {
$user->delete();
}
@@ -469,11 +474,11 @@ class FilesystemTest extends \Test\TestCase {
}
public function testRegisterMountProviderAfterSetup(): void {
- \OC\Files\Filesystem::initMountPoints(self::TEST_FILESYSTEM_USER2);
- $this->assertEquals('/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
+ Filesystem::initMountPoints(self::TEST_FILESYSTEM_USER2);
+ $this->assertEquals('/', Filesystem::getMountPoint('/foo/bar'));
$mount = new MountPoint(new Temporary([]), '/foo/bar');
$mountProvider = new DummyMountProvider([self::TEST_FILESYSTEM_USER2 => [$mount]]);
- \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class)->registerProvider($mountProvider);
- $this->assertEquals('/foo/bar/', \OC\Files\Filesystem::getMountPoint('/foo/bar'));
+ Server::get(IMountProviderCollection::class)->registerProvider($mountProvider);
+ $this->assertEquals('/foo/bar/', Filesystem::getMountPoint('/foo/bar'));
}
}
diff --git a/tests/lib/Files/Mount/ManagerTest.php b/tests/lib/Files/Mount/ManagerTest.php
index 12338c18dbd..b2ddf2d8ef4 100644
--- a/tests/lib/Files/Mount/ManagerTest.php
+++ b/tests/lib/Files/Mount/ManagerTest.php
@@ -7,6 +7,7 @@
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\SetupManagerFactory;
use OC\Files\Storage\Temporary;
@@ -28,33 +29,33 @@ class ManagerTest extends \Test\TestCase {
}
public function testFind(): void {
- $rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
+ $rootMount = new MountPoint(new Temporary([]), '/');
$this->manager->addMount($rootMount);
$this->assertEquals($rootMount, $this->manager->find('/'));
$this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
$storage = new Temporary([]);
- $mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount1 = new MountPoint($storage, '/foo');
$this->manager->addMount($mount1);
$this->assertEquals($rootMount, $this->manager->find('/'));
$this->assertEquals($mount1, $this->manager->find('/foo/bar'));
$this->assertEquals(1, count($this->manager->findIn('/')));
- $mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
+ $mount2 = new MountPoint(new Temporary([]), '/bar');
$this->manager->addMount($mount2);
$this->assertEquals(2, count($this->manager->findIn('/')));
$id = $mount1->getStorageId();
$this->assertEquals([$mount1], $this->manager->findByStorageId($id));
- $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
+ $mount3 = new MountPoint($storage, '/foo/bar');
$this->manager->addMount($mount3);
$this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
}
public function testLong(): void {
$storage = new LongId([]);
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount = new MountPoint($storage, '/foo');
$this->manager->addMount($mount);
$id = $mount->getStorageId();
diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php
index 96987c9f5eb..af66a9028eb 100644
--- a/tests/lib/Files/Mount/MountPointTest.php
+++ b/tests/lib/Files/Mount/MountPointTest.php
@@ -7,6 +7,7 @@
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\Storage\StorageFactory;
use OC\Lockdown\Filesystem\NullStorage;
use OCP\Files\Storage\IStorage;
@@ -23,7 +24,7 @@ class MountPointTest extends \Test\TestCase {
->method('wrap')
->willReturn($storage);
- $mountPoint = new \OC\Files\Mount\MountPoint(
+ $mountPoint = new MountPoint(
// just use this because a real class is needed
NullStorage::class,
'/mountpoint',
@@ -43,14 +44,14 @@ class MountPointTest extends \Test\TestCase {
$loader = $this->createMock(StorageFactory::class);
$loader->expects($this->once())
->method('wrap')
- ->will($this->throwException(new \Exception('Test storage init exception')));
+ ->willThrowException(new \Exception('Test storage init exception'));
$called = false;
- $wrapper = function ($mountPoint, $storage) use ($called) {
+ $wrapper = function ($mountPoint, $storage) use ($called): void {
$called = true;
};
- $mountPoint = new \OC\Files\Mount\MountPoint(
+ $mountPoint = new MountPoint(
// just use this because a real class is needed
NullStorage::class,
'/mountpoint',
diff --git a/tests/lib/Files/Mount/MountTest.php b/tests/lib/Files/Mount/MountTest.php
index 76d70cdd214..7be7fc67cd6 100644
--- a/tests/lib/Files/Mount/MountTest.php
+++ b/tests/lib/Files/Mount/MountTest.php
@@ -7,6 +7,7 @@
namespace Test\Files\Mount;
+use OC\Files\Mount\MountPoint;
use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Wrapper\Wrapper;
@@ -15,12 +16,12 @@ class MountTest extends \Test\TestCase {
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->disableOriginalConstructor()
->getMock();
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
+ $mount = new MountPoint($storage, '/foo');
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
}
public function testFromStorageClassname(): void {
- $mount = new \OC\Files\Mount\MountPoint('\OC\Files\Storage\Temporary', '/foo');
+ $mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo');
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $mount->getStorage());
}
@@ -38,7 +39,7 @@ class MountTest extends \Test\TestCase {
$storage = $this->getMockBuilder('\OC\Files\Storage\Temporary')
->disableOriginalConstructor()
->getMock();
- $mount = new \OC\Files\Mount\MountPoint($storage, '/foo', [], $loader);
+ $mount = new MountPoint($storage, '/foo', [], $loader);
$this->assertInstanceOf('\OC\Files\Storage\Wrapper\Wrapper', $mount->getStorage());
}
}
diff --git a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
index 2b809835953..c0b49813c93 100644
--- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
+++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
@@ -241,10 +241,9 @@ class ObjectHomeMountProviderTest extends \Test\TestCase {
}
class FakeObjectStore implements IObjectStore {
- private $arguments;
-
- public function __construct(array $arguments) {
- $this->arguments = $arguments;
+ public function __construct(
+ private array $arguments,
+ ) {
}
public function getArguments() {
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php
index 74a23520344..f3d893d5af2 100644
--- a/tests/lib/Files/Node/FileTest.php
+++ b/tests/lib/Files/Node/FileTest.php
@@ -7,7 +7,10 @@
namespace Test\Files\Node;
+use OC\Files\Node\File;
use OC\Files\Node\Root;
+use OCP\Constants;
+use OCP\Files\NotPermittedException;
/**
* Class FileTest
@@ -19,9 +22,9 @@ use OC\Files\Node\Root;
class FileTest extends NodeTestCase {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
if ($data || $internalPath || $storage) {
- return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
+ return new File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
} else {
- return new \OC\Files\Node\File($root, $view, $path);
+ return new File($root, $view, $path);
}
}
@@ -43,7 +46,7 @@ class FileTest extends NodeTestCase {
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -58,15 +61,15 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('bar', $node->getContent());
}
public function testGetContentNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
@@ -82,7 +85,7 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->getContent();
}
@@ -99,20 +102,20 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$this->view->expects($this->once())
->method('file_put_contents')
->with('/bar/foo', 'bar')
->willReturn(true);
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
public function testPutContentNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
$root = $this->getMockBuilder(Root::class)
@@ -122,9 +125,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->putContent('bar');
}
@@ -139,7 +142,7 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['mimetype' => 'text/plain']));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$this->assertEquals('text/plain', $node->getMimeType());
}
@@ -148,7 +151,7 @@ class FileTest extends NodeTestCase {
fwrite($stream, 'bar');
rewind($stream);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -159,7 +162,7 @@ class FileTest extends NodeTestCase {
$this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -174,9 +177,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('r');
$this->assertEquals($stream, $fh);
$this->assertEquals('bar', fread($fh, 3));
@@ -185,7 +188,7 @@ class FileTest extends NodeTestCase {
public function testFOpenWrite(): void {
$stream = fopen('php://memory', 'w+');
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -196,7 +199,7 @@ class FileTest extends NodeTestCase {
$this->cacheFactory,
);
$hooksCalled = 0;
- $hook = function ($file) use (&$hooksCalled) {
+ $hook = function ($file) use (&$hooksCalled): void {
$hooksCalled++;
};
@@ -211,9 +214,9 @@ class FileTest extends NodeTestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$fh = $node->fopen('w');
$this->assertEquals($stream, $fh);
fwrite($fh, 'bar');
@@ -224,9 +227,9 @@ class FileTest extends NodeTestCase {
public function testFOpenReadNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -236,7 +239,7 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function ($file) {
+ $hook = function ($file): void {
throw new \Exception('Hooks are not supposed to be called');
};
@@ -245,15 +248,15 @@ class FileTest extends NodeTestCase {
->with('/bar/foo')
->willReturn($this->getFileInfo(['permissions' => 0]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('r');
}
public function testFOpenReadWriteNoReadPermissions(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -263,24 +266,24 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_UPDATE]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_UPDATE]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
public function testFOpenReadWriteNoWritePermissions(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -290,16 +293,16 @@ class FileTest extends NodeTestCase {
$this->eventDispatcher,
$this->cacheFactory,
);
- $hook = function () {
+ $hook = function (): void {
throw new \Exception('Hooks are not supposed to be called');
};
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
- $node = new \OC\Files\Node\File($root, $this->view, '/bar/foo');
+ $node = new File($root, $this->view, '/bar/foo');
$node->fopen('w');
}
}
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 25f555e7068..53e8f07a0d3 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -21,12 +21,15 @@ use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
+use OC\Files\Storage\Storage;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOrder;
@@ -150,7 +153,7 @@ class FolderTest extends NodeTestCase {
$root->method('get')
->with('/bar/foo/asd')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$node = new Folder($root, $view, '/bar/foo');
$this->assertFalse($node->nodeExists('asd'));
@@ -168,7 +171,7 @@ class FolderTest extends NodeTestCase {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('mkdir')
->with('/bar/foo/asd')
@@ -192,7 +195,7 @@ class FolderTest extends NodeTestCase {
$view->method('getFileInfo')
->with('/foobar')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('mkdir')
->with('/foobar/asd/sdf')
@@ -206,7 +209,7 @@ class FolderTest extends NodeTestCase {
public function testNewFolderNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
@@ -218,7 +221,7 @@ class FolderTest extends NodeTestCase {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = new Folder($root, $view, '/bar/foo');
$node->newFolder('asd');
@@ -236,21 +239,21 @@ class FolderTest extends NodeTestCase {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$view->method('touch')
->with('/bar/foo/asd')
->willReturn(true);
$node = new Folder($root, $view, '/bar/foo');
- $child = new \OC\Files\Node\File($root, $view, '/bar/foo/asd', null, $node);
+ $child = new File($root, $view, '/bar/foo/asd', null, $node);
$result = $node->newFile('asd');
$this->assertEquals($child, $result);
}
public function testNewFileNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
@@ -262,7 +265,7 @@ class FolderTest extends NodeTestCase {
$view->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = new Folder($root, $view, '/bar/foo');
$node->newFile('asd');
@@ -502,7 +505,7 @@ class FolderTest extends NodeTestCase {
->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
@@ -551,7 +554,7 @@ class FolderTest extends NodeTestCase {
->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
@@ -596,7 +599,7 @@ class FolderTest extends NodeTestCase {
->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount = new MountPoint($storage, '/bar');
$storage->method('getId')->willReturn('');
$cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
@@ -640,7 +643,7 @@ class FolderTest extends NodeTestCase {
->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
- $storage = $this->createMock(\OC\Files\Storage\Storage::class);
+ $storage = $this->createMock(Storage::class);
$mount1 = new MountPoint($storage, '/bar');
$mount2 = new MountPoint($storage, '/bar/foo/asd');
$storage->method('getId')->willReturn('');
@@ -753,14 +756,14 @@ class FolderTest extends NodeTestCase {
'mtime' => $baseTime,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$id2 = $cache->put('bar/foo/old.txt', [
'storage_mtime' => $baseTime - 100,
'mtime' => $baseTime - 100,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_READ,
+ 'permissions' => Constants::PERMISSION_READ,
]);
$cache->put('bar/asd/outside.txt', [
'storage_mtime' => $baseTime,
@@ -773,7 +776,7 @@ class FolderTest extends NodeTestCase {
'mtime' => $baseTime - 600,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$node = new Folder($root, $view, $folderPath, $folderInfo);
@@ -830,7 +833,7 @@ class FolderTest extends NodeTestCase {
'mimetype' => 'text/plain',
'size' => 3,
'parent' => $id1,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$id3 = $cache->put('bar/foo/folder/asd.txt', [
'storage_mtime' => $baseTime - 100,
@@ -838,7 +841,7 @@ class FolderTest extends NodeTestCase {
'mimetype' => 'text/plain',
'size' => 3,
'parent' => $id1,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$node = new Folder($root, $view, $folderPath, $folderInfo);
@@ -891,7 +894,7 @@ class FolderTest extends NodeTestCase {
'mtime' => $baseTime,
'mimetype' => 'text/plain',
'size' => 3,
- 'permissions' => \OCP\Constants::PERMISSION_ALL,
+ 'permissions' => Constants::PERMISSION_ALL,
]);
$cache->put('outside.txt', [
diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php
index 87e83fd0a3b..0b7d26fd24d 100644
--- a/tests/lib/Files/Node/HookConnectorTest.php
+++ b/tests/lib/Files/Node/HookConnectorTest.php
@@ -15,6 +15,7 @@ use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\GenericEvent as APIGenericEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Config\IUserMountCache;
use OCP\Files\Events\Node\AbstractNodeEvent;
use OCP\Files\Events\Node\AbstractNodesEvent;
use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
@@ -32,6 +33,7 @@ use OCP\Files\Events\Node\NodeWrittenEvent;
use OCP\Files\Node;
use OCP\ICacheFactory;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
@@ -79,15 +81,15 @@ class HookConnectorTest extends TestCase {
$this->root = new Root(
Filesystem::getMountManager(),
$this->view,
- \OC::$server->getUserManager()->get($this->userId),
- \OCP\Server::get(\OCP\Files\Config\IUserMountCache::class),
+ Server::get(IUserManager::class)->get($this->userId),
+ Server::get(IUserMountCache::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
$cacheFactory,
);
- $this->eventDispatcher = \OC::$server->query(IEventDispatcher::class);
- $this->logger = \OC::$server->query(LoggerInterface::class);
+ $this->eventDispatcher = Server::get(IEventDispatcher::class);
+ $this->logger = Server::get(LoggerInterface::class);
}
protected function tearDown(): void {
@@ -98,49 +100,49 @@ class HookConnectorTest extends TestCase {
public static function viewToNodeProvider(): array {
return [
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preWrite', '\OCP\Files::preWrite', BeforeNodeWrittenEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postWrite', '\OCP\Files::postWrite', NodeWrittenEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'preTouch', '\OCP\Files::preTouch', BeforeNodeTouchedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'postTouch', '\OCP\Files::postTouch', NodeTouchedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'preCreate', '\OCP\Files::preCreate', BeforeNodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::touch('test.txt');
}, 'postCreate', '\OCP\Files::postCreate', NodeCreatedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'preDelete', '\OCP\Files::preDelete', BeforeNodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('test.txt', 'asd');
Filesystem::unlink('test.txt');
}, 'postDelete', '\OCP\Files::postDelete', NodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'preDelete', '\OCP\Files::preDelete', BeforeNodeDeletedEvent::class],
- [function () {
+ [function (): void {
Filesystem::mkdir('test.txt');
Filesystem::rmdir('test.txt');
}, 'postDelete', '\OCP\Files::postDelete', NodeDeletedEvent::class],
@@ -159,7 +161,7 @@ class HookConnectorTest extends TestCase {
/** @var Node $hookNode */
$hookNode = null;
- $this->root->listen('\OC\Files', $expectedHook, function ($node) use (&$hookNode, &$hookCalled) {
+ $this->root->listen('\OC\Files', $expectedHook, function ($node) use (&$hookNode, &$hookCalled): void {
$hookCalled = true;
$hookNode = $node;
});
@@ -167,7 +169,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
- $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
+ $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherCalled, &$dispatcherNode): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();
@@ -175,7 +177,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherCalled = false;
$newDispatcherNode = null;
- $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherCalled, &$newDispatcherNode) {
+ $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherCalled, &$newDispatcherNode): void {
if ($event instanceof $expectedEvent) {
/** @var AbstractNodeEvent $event */
$newDispatcherCalled = true;
@@ -197,19 +199,19 @@ class HookConnectorTest extends TestCase {
public static function viewToNodeProviderCopyRename(): array {
return [
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'preRename', '\OCP\Files::preRename', BeforeNodeRenamedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::rename('source', 'target');
}, 'postRename', '\OCP\Files::postRename', NodeRenamedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'preCopy', '\OCP\Files::preCopy', BeforeNodeCopiedEvent::class],
- [function () {
+ [function (): void {
Filesystem::file_put_contents('source', 'asd');
Filesystem::copy('source', 'target');
}, 'postCopy', '\OCP\Files::postCopy', NodeCopiedEvent::class],
@@ -230,7 +232,7 @@ class HookConnectorTest extends TestCase {
/** @var Node $hookTargetNode */
$hookTargetNode = null;
- $this->root->listen('\OC\Files', $expectedHook, function ($sourceNode, $targetNode) use (&$hookCalled, &$hookSourceNode, &$hookTargetNode) {
+ $this->root->listen('\OC\Files', $expectedHook, function ($sourceNode, $targetNode) use (&$hookCalled, &$hookSourceNode, &$hookTargetNode): void {
$hookCalled = true;
$hookSourceNode = $sourceNode;
$hookTargetNode = $targetNode;
@@ -241,7 +243,7 @@ class HookConnectorTest extends TestCase {
$dispatcherSourceNode = null;
/** @var Node $dispatcherTargetNode */
$dispatcherTargetNode = null;
- $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled) {
+ $this->eventDispatcher->addListener($expectedLegacyEvent, function ($event) use (&$dispatcherSourceNode, &$dispatcherTargetNode, &$dispatcherCalled): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
[$dispatcherSourceNode, $dispatcherTargetNode] = $event->getSubject();
@@ -252,7 +254,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherSourceNode = null;
/** @var Node $dispatcherTargetNode */
$newDispatcherTargetNode = null;
- $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherSourceNode, &$newDispatcherTargetNode, &$newDispatcherCalled) {
+ $this->eventDispatcher->addListener($expectedEvent, function ($event) use ($expectedEvent, &$newDispatcherSourceNode, &$newDispatcherTargetNode, &$newDispatcherCalled): void {
if ($event instanceof $expectedEvent) {
/** @var AbstractNodesEvent$event */
$newDispatcherCalled = true;
@@ -283,7 +285,7 @@ class HookConnectorTest extends TestCase {
/** @var Node $hookNode */
$hookNode = null;
- $this->root->listen('\OC\Files', 'postDelete', function ($node) use (&$hookNode, &$hookCalled) {
+ $this->root->listen('\OC\Files', 'postDelete', function ($node) use (&$hookNode, &$hookCalled): void {
$hookCalled = true;
$hookNode = $node;
});
@@ -291,7 +293,7 @@ class HookConnectorTest extends TestCase {
$dispatcherCalled = false;
/** @var Node $dispatcherNode */
$dispatcherNode = null;
- $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode) {
+ $this->eventDispatcher->addListener('\OCP\Files::postDelete', function ($event) use (&$dispatcherCalled, &$dispatcherNode): void {
/** @var GenericEvent|APIGenericEvent $event */
$dispatcherCalled = true;
$dispatcherNode = $event->getSubject();
@@ -300,7 +302,7 @@ class HookConnectorTest extends TestCase {
$newDispatcherCalled = false;
/** @var Node $dispatcherNode */
$newDispatcherNode = null;
- $this->eventDispatcher->addListener(NodeDeletedEvent::class, function ($event) use (&$newDispatcherCalled, &$newDispatcherNode) {
+ $this->eventDispatcher->addListener(NodeDeletedEvent::class, function ($event) use (&$newDispatcherCalled, &$newDispatcherNode): void {
if ($event instanceof NodeDeletedEvent) {
/** @var AbstractNodeEvent $event */
$newDispatcherCalled = true;
diff --git a/tests/lib/Files/Node/IntegrationTest.php b/tests/lib/Files/Node/IntegrationTest.php
index c90a6115f2a..6bd956326e9 100644
--- a/tests/lib/Files/Node/IntegrationTest.php
+++ b/tests/lib/Files/Node/IntegrationTest.php
@@ -16,6 +16,7 @@ use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountManager;
use OCP\ICacheFactory;
use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\Traits\UserTrait;
@@ -47,7 +48,7 @@ class IntegrationTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $manager = \OCP\Server::get(IMountManager::class);
+ $manager = Server::get(IMountManager::class);
\OC_Hook::clear('OC_Filesystem');
@@ -64,7 +65,7 @@ class IntegrationTest extends \Test\TestCase {
$manager,
$this->view,
$user,
- \OCP\Server::get(IUserMountCache::class),
+ Server::get(IUserMountCache::class),
$this->createMock(LoggerInterface::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
diff --git a/tests/lib/Files/Node/NodeTestCase.php b/tests/lib/Files/Node/NodeTestCase.php
index a2b8a3ddffe..6da4e1e9317 100644
--- a/tests/lib/Files/Node/NodeTestCase.php
+++ b/tests/lib/Files/Node/NodeTestCase.php
@@ -9,14 +9,19 @@ namespace Test\Files\Node;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
+use OC\Files\Node\File;
+use OC\Files\Node\Folder;
use OC\Files\Node\Root;
use OC\Files\View;
use OC\Memcache\ArrayCache;
+use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\InvalidPathException;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\Files\Storage\IStorage;
use OCP\ICacheFactory;
use OCP\IUser;
@@ -139,7 +144,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$this->view->expects($this->once())
->method($this->getViewDeleteMethod())
@@ -156,7 +161,7 @@ abstract class NodeTestCase extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $preListener = function ($node) use (&$test, &$hooksRun) {
+ $preListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertInstanceOf($this->getNodeClass(), $node);
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
@@ -167,7 +172,7 @@ abstract class NodeTestCase extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $postListener = function ($node) use (&$test, &$hooksRun) {
+ $postListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertInstanceOf($this->getNonExistingNodeClass(), $node);
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
@@ -176,7 +181,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$hooksRun++;
};
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -193,7 +198,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo'));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo'));
$this->view->expects($this->once())
->method($this->getViewDeleteMethod())
@@ -207,7 +212,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testDeleteNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->root->expects($this->any())
->method('getUser')
@@ -216,7 +221,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->delete();
@@ -397,7 +402,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->touch(100);
@@ -410,7 +415,7 @@ abstract class NodeTestCase extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $preListener = function ($node) use (&$test, &$hooksRun) {
+ $preListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
$hooksRun++;
@@ -419,13 +424,13 @@ abstract class NodeTestCase extends \Test\TestCase {
/**
* @param \OC\Files\Node\File $node
*/
- $postListener = function ($node) use (&$test, &$hooksRun) {
+ $postListener = function ($node) use (&$test, &$hooksRun): void {
$test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath());
$hooksRun++;
};
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->view,
$this->user,
@@ -446,7 +451,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL], 'foo'));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL], 'foo'));
$node = $this->createTestNode($root, $this->view, '/bar/foo');
$node->touch(100);
@@ -455,7 +460,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testTouchNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->root->expects($this->any())
->method('getUser')
@@ -464,7 +469,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
$node->touch(100);
@@ -472,7 +477,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testInvalidPath(): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ $this->expectException(InvalidPathException::class);
$node = $this->createTestNode($this->root, $this->view, '/../foo');
$node->getFileInfo();
@@ -486,10 +491,10 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 3]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$newNode = $this->createTestNode($this->root, $this->view, '/bar/asd');
$this->root->method('get')
@@ -505,7 +510,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testCopyNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
/**
* @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
@@ -520,10 +525,10 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ, 'fileid' => 3]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -536,7 +541,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testCopyNoParent(): void {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$this->view->expects($this->never())
->method('copy');
@@ -546,20 +551,20 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->root->expects($this->once())
->method('get')
->with('/bar/asd')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$node->copy('/bar/asd/foo');
}
public function testCopyParentIsFile(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->never())
->method('copy');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
+ $parentNode = new File($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -578,10 +583,10 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
@@ -621,13 +626,13 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
/**
* @var \OC\Files\Node\File|\PHPUnit\Framework\MockObject\MockObject $node
*/
$node = $this->createTestNode($root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($root, $this->view, '/bar');
+ $parentNode = new Folder($root, $this->view, '/bar');
$targetTestNode = $this->createTestNode($root, $this->view, '/bar/asd');
$root->expects($this->any())
@@ -636,7 +641,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$hooksRun = 0;
- $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node) {
+ $preListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node): void {
$this->assertSame($node, $sourceNode);
$this->assertInstanceOf($this->getNodeClass(), $sourceNode);
$this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
@@ -644,7 +649,7 @@ abstract class NodeTestCase extends \Test\TestCase {
$hooksRun++;
};
- $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode) {
+ $postListener = function (Node $sourceNode, Node $targetNode) use (&$hooksRun, $node, $targetTestNode): void {
$this->assertSame($node, $sourceNode);
$this->assertNotSame($node, $targetNode);
$this->assertSame($targetTestNode, $targetNode);
@@ -653,13 +658,13 @@ abstract class NodeTestCase extends \Test\TestCase {
$hooksRun++;
};
- $preWriteListener = function (Node $targetNode) use (&$hooksRun) {
+ $preWriteListener = function (Node $targetNode) use (&$hooksRun): void {
$this->assertInstanceOf($this->getNonExistingNodeClass(), $targetNode);
$this->assertEquals('/bar/asd', $targetNode->getPath());
$hooksRun++;
};
- $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode) {
+ $postWriteListener = function (Node $targetNode) use (&$hooksRun, $targetTestNode): void {
$this->assertSame($targetTestNode, $targetNode);
$hooksRun++;
};
@@ -676,17 +681,17 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testMoveNotPermitted(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_READ]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_READ]));
$this->view->expects($this->never())
->method('rename');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -698,7 +703,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testMoveNoParent(): void {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
/**
* @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage
@@ -713,20 +718,20 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->root->expects($this->once())
->method('get')
->with('/bar')
- ->will($this->throwException(new NotFoundException()));
+ ->willThrowException(new NotFoundException());
$node->move('/bar/asd');
}
public function testMoveParentIsFile(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->never())
->method('rename');
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\File($this->root, $this->view, '/bar');
+ $parentNode = new File($this->root, $this->view, '/bar');
$this->root->expects($this->once())
->method('get')
@@ -738,7 +743,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testMoveFailed(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('rename')
@@ -747,10 +752,10 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
@@ -761,7 +766,7 @@ abstract class NodeTestCase extends \Test\TestCase {
public function testCopyFailed(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$this->view->expects($this->any())
->method('copy')
@@ -770,10 +775,10 @@ abstract class NodeTestCase extends \Test\TestCase {
$this->view->expects($this->any())
->method('getFileInfo')
- ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1]));
+ ->willReturn($this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 1]));
$node = $this->createTestNode($this->root, $this->view, '/bar/foo');
- $parentNode = new \OC\Files\Node\Folder($this->root, $this->view, '/bar');
+ $parentNode = new Folder($this->root, $this->view, '/bar');
$this->root->expects($this->any())
->method('get')
diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php
index f2ef1a0e3ee..979ed1c6dcb 100644
--- a/tests/lib/Files/Node/RootTest.php
+++ b/tests/lib/Files/Node/RootTest.php
@@ -10,10 +10,14 @@ namespace Test\Files\Node;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
use OC\Files\Node\Folder;
+use OC\Files\Node\Root;
use OC\Files\View;
use OC\Memcache\ArrayCache;
+use OC\User\NoUserException;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\ICacheFactory;
use OCP\IUser;
use OCP\IUserManager;
@@ -83,7 +87,7 @@ class RootTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
@@ -107,7 +111,7 @@ class RootTest extends \Test\TestCase {
public function testGetNotFound(): void {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
/**
* @var \OC\Files\Storage\Storage $storage
@@ -116,7 +120,7 @@ class RootTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
@@ -138,10 +142,10 @@ class RootTest extends \Test\TestCase {
public function testGetInvalidPath(): void {
- $this->expectException(\OCP\Files\NotPermittedException::class);
+ $this->expectException(NotPermittedException::class);
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
@@ -157,10 +161,10 @@ class RootTest extends \Test\TestCase {
public function testGetNoStorages(): void {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$view = $this->getRootViewMock();
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$view,
$this->user,
@@ -175,7 +179,7 @@ class RootTest extends \Test\TestCase {
}
public function testGetUserFolder(): void {
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->manager,
$this->getRootViewMock(),
$this->user,
@@ -214,10 +218,10 @@ class RootTest extends \Test\TestCase {
public function testGetUserFolderWithNoUserObj(): void {
- $this->expectException(\OC\User\NoUserException::class);
+ $this->expectException(NoUserException::class);
$this->expectExceptionMessage('Backends provided no user object');
- $root = new \OC\Files\Node\Root(
+ $root = new Root(
$this->createMock(Manager::class),
$this->getRootViewMock(),
null,
diff --git a/tests/lib/Files/ObjectStore/AzureTest.php b/tests/lib/Files/ObjectStore/AzureTest.php
index 1103b15ecd2..3c07f69f65d 100644
--- a/tests/lib/Files/ObjectStore/AzureTest.php
+++ b/tests/lib/Files/ObjectStore/AzureTest.php
@@ -7,13 +7,15 @@
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\Azure;
+use OCP\IConfig;
+use OCP\Server;
/**
* @group PRIMARY-azure
*/
class AzureTest extends ObjectStoreTestCase {
protected function getInstance() {
- $config = \OC::$server->getConfig()->getSystemValue('objectstore');
+ $config = Server::get(IConfig::class)->getSystemValue('objectstore');
if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\Azure') {
$this->markTestSkipped('objectstore not configured for azure');
}
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index 508f328fae2..cca75d4f35e 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -10,6 +10,7 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Constants;
use OCP\Files\ObjectStore\IObjectStore;
use Test\Files\Storage\Storage;
@@ -231,13 +232,13 @@ class ObjectStoreStorageTest extends Storage {
$this->instance->file_put_contents('test.txt', 'foo');
$this->assertTrue($cache->inCache('test.txt'));
- $cache->update($cache->getId('test.txt'), ['permissions' => \OCP\Constants::PERMISSION_READ]);
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
$this->assertTrue($this->instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
}
/**
@@ -254,13 +255,13 @@ class ObjectStoreStorageTest extends Storage {
$instance->file_put_contents('test.txt', 'foo');
$this->assertTrue($cache->inCache('test.txt'));
- $cache->update($cache->getId('test.txt'), ['permissions' => \OCP\Constants::PERMISSION_READ]);
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $instance->getPermissions('test.txt'));
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $instance->getPermissions('test.txt'));
$this->assertTrue($instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
- $this->assertEquals(\OCP\Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
}
public function testCopyFolderSize(): void {
diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php
index 76fc80c975f..d3c282d0427 100644
--- a/tests/lib/Files/ObjectStore/S3Test.php
+++ b/tests/lib/Files/ObjectStore/S3Test.php
@@ -8,6 +8,8 @@ namespace Test\Files\ObjectStore;
use Icewind\Streams\Wrapper;
use OC\Files\ObjectStore\S3;
+use OCP\IConfig;
+use OCP\Server;
class MultiPartUploadS3 extends S3 {
public function writeObject($urn, $stream, ?string $mimetype = null) {
@@ -52,7 +54,7 @@ class S3Test extends ObjectStoreTestCase {
}
protected function getInstance() {
- $config = \OC::$server->getConfig()->getSystemValue('objectstore');
+ $config = Server::get(IConfig::class)->getSystemValue('objectstore');
if (!is_array($config) || $config['class'] !== S3::class) {
$this->markTestSkipped('objectstore not configured for s3');
}
diff --git a/tests/lib/Files/ObjectStore/SwiftTest.php b/tests/lib/Files/ObjectStore/SwiftTest.php
index 9fb8c9bb68e..2321d8eafda 100644
--- a/tests/lib/Files/ObjectStore/SwiftTest.php
+++ b/tests/lib/Files/ObjectStore/SwiftTest.php
@@ -8,6 +8,8 @@
namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\Swift;
+use OCP\IConfig;
+use OCP\Server;
/**
* @group PRIMARY-swift
@@ -17,7 +19,7 @@ class SwiftTest extends ObjectStoreTestCase {
* @return \OCP\Files\ObjectStore\IObjectStore
*/
protected function getInstance() {
- $config = \OC::$server->getConfig()->getSystemValue('objectstore');
+ $config = Server::get(IConfig::class)->getSystemValue('objectstore');
if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\Swift') {
$this->markTestSkipped('objectstore not configured for swift');
}
diff --git a/tests/lib/Files/PathVerificationTest.php b/tests/lib/Files/PathVerificationTest.php
index d6dff445c0f..8e4dfd1bb1e 100644
--- a/tests/lib/Files/PathVerificationTest.php
+++ b/tests/lib/Files/PathVerificationTest.php
@@ -10,6 +10,8 @@ namespace Test\Files;
use OC\Files\Storage\Local;
use OC\Files\View;
use OCP\Files\InvalidPathException;
+use OCP\IDBConnection;
+use OCP\Server;
/**
* Class PathVerificationTest
@@ -31,7 +33,7 @@ class PathVerificationTest extends \Test\TestCase {
public function testPathVerificationFileNameTooLong(): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ $this->expectException(InvalidPathException::class);
$this->expectExceptionMessage('Filename is too long');
$fileName = str_repeat('a', 500);
@@ -43,7 +45,7 @@ class PathVerificationTest extends \Test\TestCase {
* @dataProvider providesEmptyFiles
*/
public function testPathVerificationEmptyFileName($fileName): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ $this->expectException(InvalidPathException::class);
$this->expectExceptionMessage('Empty filename is not allowed');
$this->view->verifyPath('', $fileName);
@@ -60,7 +62,7 @@ class PathVerificationTest extends \Test\TestCase {
* @dataProvider providesDotFiles
*/
public function testPathVerificationDotFiles($fileName): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ $this->expectException(InvalidPathException::class);
$this->expectExceptionMessage('Dot files are not allowed');
$this->view->verifyPath('', $fileName);
@@ -83,7 +85,7 @@ class PathVerificationTest extends \Test\TestCase {
* @dataProvider providesAstralPlane
*/
public function testPathVerificationAstralPlane($fileName): void {
- $connection = \OC::$server->getDatabaseConnection();
+ $connection = Server::get(IDBConnection::class);
if (!$connection->supports4ByteText()) {
$this->expectException(InvalidPathException::class);
diff --git a/tests/lib/Files/Storage/CommonTest.php b/tests/lib/Files/Storage/CommonTest.php
index 529615f3733..d6904665904 100644
--- a/tests/lib/Files/Storage/CommonTest.php
+++ b/tests/lib/Files/Storage/CommonTest.php
@@ -14,6 +14,7 @@ use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
use OCP\ITempManager;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
/**
@@ -33,7 +34,7 @@ class CommonTest extends Storage {
$this->filenameValidator = $this->createMock(IFilenameValidator::class);
$this->overwriteService(IFilenameValidator::class, $this->filenameValidator);
- $this->tmpDir = \OCP\Server::get(ITempManager::class)->getTemporaryFolder();
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
$this->instance = new \OC\Files\Storage\CommonTest(['datadir' => $this->tmpDir]);
}
diff --git a/tests/lib/Files/Storage/CopyDirectoryTest.php b/tests/lib/Files/Storage/CopyDirectoryTest.php
index e434c6b787f..054101510b7 100644
--- a/tests/lib/Files/Storage/CopyDirectoryTest.php
+++ b/tests/lib/Files/Storage/CopyDirectoryTest.php
@@ -7,6 +7,7 @@
namespace Test\Files\Storage;
+use OC\Files\Storage\PolyFill\CopyDirectory;
use OC\Files\Storage\Temporary;
class StorageNoRecursiveCopy extends Temporary {
@@ -19,7 +20,7 @@ class StorageNoRecursiveCopy extends Temporary {
}
class CopyDirectoryStorage extends StorageNoRecursiveCopy {
- use \OC\Files\Storage\PolyFill\CopyDirectory;
+ use CopyDirectory;
}
/**
diff --git a/tests/lib/Files/Storage/HomeTest.php b/tests/lib/Files/Storage/HomeTest.php
index 26b81c6f1a0..f459ff5c23b 100644
--- a/tests/lib/Files/Storage/HomeTest.php
+++ b/tests/lib/Files/Storage/HomeTest.php
@@ -7,21 +7,21 @@
namespace Test\Files\Storage;
+use OC\Files\Storage\Home;
use OC\User\User;
use OCP\Files;
+use OCP\ITempManager;
+use OCP\Server;
class DummyUser extends User {
- private $home;
-
- private $uid;
-
/**
* @param string $uid
* @param string $home
*/
- public function __construct($uid, $home) {
- $this->uid = $uid;
- $this->home = $home;
+ public function __construct(
+ private $uid,
+ private $home,
+ ) {
}
public function getHome() {
@@ -56,10 +56,10 @@ class HomeTest extends Storage {
protected function setUp(): void {
parent::setUp();
- $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
$this->userId = $this->getUniqueID('user_');
$this->user = new DummyUser($this->userId, $this->tmpDir);
- $this->instance = new \OC\Files\Storage\Home(['user' => $this->user]);
+ $this->instance = new Home(['user' => $this->user]);
}
protected function tearDown(): void {
diff --git a/tests/lib/Files/Storage/LocalTest.php b/tests/lib/Files/Storage/LocalTest.php
index 13317fad7bb..e3953b7bde5 100644
--- a/tests/lib/Files/Storage/LocalTest.php
+++ b/tests/lib/Files/Storage/LocalTest.php
@@ -7,8 +7,13 @@
namespace Test\Files\Storage;
+use OC\Files\Storage\Local;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files;
+use OCP\Files\ForbiddenException;
+use OCP\Files\StorageNotAvailableException;
+use OCP\ITempManager;
+use OCP\Server;
/**
* Class LocalTest
@@ -26,8 +31,8 @@ class LocalTest extends Storage {
protected function setUp(): void {
parent::setUp();
- $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
- $this->instance = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir]);
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
+ $this->instance = new Local(['datadir' => $this->tmpDir]);
}
protected function tearDown(): void {
@@ -55,19 +60,19 @@ class LocalTest extends Storage {
public function testInvalidArgumentsEmptyArray(): void {
$this->expectException(\InvalidArgumentException::class);
- new \OC\Files\Storage\Local([]);
+ new Local([]);
}
public function testInvalidArgumentsNoArray(): void {
$this->expectException(\InvalidArgumentException::class);
- new \OC\Files\Storage\Local([]);
+ new Local([]);
}
public function testDisallowSymlinksOutsideDatadir(): void {
- $this->expectException(\OCP\Files\ForbiddenException::class);
+ $this->expectException(ForbiddenException::class);
$subDir1 = $this->tmpDir . 'sub1';
$subDir2 = $this->tmpDir . 'sub2';
@@ -77,7 +82,7 @@ class LocalTest extends Storage {
symlink($subDir2, $sym);
- $storage = new \OC\Files\Storage\Local(['datadir' => $subDir1]);
+ $storage = new Local(['datadir' => $subDir1]);
$storage->file_put_contents('sym/foo', 'bar');
}
@@ -91,7 +96,7 @@ class LocalTest extends Storage {
symlink($subDir2, $sym);
- $storage = new \OC\Files\Storage\Local(['datadir' => $subDir1]);
+ $storage = new Local(['datadir' => $subDir1]);
$storage->file_put_contents('sym/foo', 'bar');
$this->addToAssertionCount(1);
@@ -129,12 +134,12 @@ class LocalTest extends Storage {
}
public function testUnavailableExternal(): void {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
- $this->instance = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir . '/unexist', 'isExternal' => true]);
+ $this->expectException(StorageNotAvailableException::class);
+ $this->instance = new Local(['datadir' => $this->tmpDir . '/unexist', 'isExternal' => true]);
}
public function testUnavailableNonExternal(): void {
- $this->instance = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir . '/unexist']);
+ $this->instance = new Local(['datadir' => $this->tmpDir . '/unexist']);
// no exception thrown
$this->assertNotNull($this->instance);
}
diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php
index 99162e12834..3e239d005b7 100644
--- a/tests/lib/Files/Storage/Storage.php
+++ b/tests/lib/Files/Storage/Storage.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\Files\Cache\Watcher;
+use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IWriteStreamStorage;
@@ -327,7 +328,7 @@ abstract class Storage extends \Test\TestCase {
* no change.
*/
public function testCheckUpdate(): void {
- if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) {
+ if ($this->instance instanceof Wrapper) {
$this->markTestSkipped('Cannot test update check on wrappers');
}
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
diff --git a/tests/lib/Files/Storage/StorageFactoryTest.php b/tests/lib/Files/Storage/StorageFactoryTest.php
index 83e8a7bf6eb..2bdc3592631 100644
--- a/tests/lib/Files/Storage/StorageFactoryTest.php
+++ b/tests/lib/Files/Storage/StorageFactoryTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\Files\Mount\MountPoint;
+use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorage;
@@ -26,7 +27,7 @@ class DummyWrapper extends Wrapper {
class StorageFactoryTest extends TestCase {
public function testSimpleWrapper(): void {
- $instance = new \OC\Files\Storage\StorageFactory();
+ $instance = new StorageFactory();
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
$this->assertInstanceOf('\OC\Files\Storage\Temporary', $storage);
@@ -39,7 +40,7 @@ class StorageFactoryTest extends TestCase {
}
public function testRemoveWrapper(): void {
- $instance = new \OC\Files\Storage\StorageFactory();
+ $instance = new StorageFactory();
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
$instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage) {
return new DummyWrapper(['storage' => $storage]);
@@ -50,7 +51,7 @@ class StorageFactoryTest extends TestCase {
}
public function testWrapperPriority(): void {
- $instance = new \OC\Files\Storage\StorageFactory();
+ $instance = new StorageFactory();
$mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance);
$instance->addStorageWrapper('dummy1', function ($mountPoint, IStorage $storage) {
return new DummyWrapper(['storage' => $storage, 'data' => 1]);
diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
index 29277772358..8e2ead4a423 100644
--- a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
+++ b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
@@ -53,7 +53,7 @@ class AvailabilityTest extends \Test\TestCase {
*
*/
public function testUnavailable(): void {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -82,7 +82,7 @@ class AvailabilityTest extends \Test\TestCase {
];
$this->storage->expects($this->exactly(2))
->method('setAvailability')
- ->willReturnCallback(function ($value) use (&$calls) {
+ ->willReturnCallback(function ($value) use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, $value);
});
@@ -97,7 +97,7 @@ class AvailabilityTest extends \Test\TestCase {
*
*/
public function testAvailableThrowStorageNotAvailable(): void {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -106,7 +106,7 @@ class AvailabilityTest extends \Test\TestCase {
->method('test');
$this->storage->expects($this->once())
->method('mkdir')
- ->will($this->throwException(new StorageNotAvailableException()));
+ ->willThrowException(new StorageNotAvailableException());
$this->storageCache->expects($this->once())
->method('setAvailability')
->with($this->equalTo(false));
@@ -148,7 +148,7 @@ class AvailabilityTest extends \Test\TestCase {
->method('test');
$this->storage->expects($this->once())
->method('mkdir')
- ->will($this->throwException(new \Exception()));
+ ->willThrowException(new \Exception());
$this->storage->expects($this->never())
->method('setAvailability');
diff --git a/tests/lib/Files/Storage/Wrapper/EncodingTest.php b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
index 9d8a1e16145..2d29e2d0952 100644
--- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
@@ -7,6 +7,9 @@
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Encoding;
+
class EncodingTest extends \Test\Files\Storage\Storage {
public const NFD_NAME = 'ümlaut';
public const NFC_NAME = 'ümlaut';
@@ -18,8 +21,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();
- $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
- $this->instance = new \OC\Files\Storage\Wrapper\Encoding([
+ $this->sourceStorage = new Temporary([]);
+ $this->instance = new Encoding([
'storage' => $this->sourceStorage
]);
}
diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
index 1c299fa989f..8065854ec50 100644
--- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
@@ -8,7 +8,6 @@
namespace Test\Files\Storage\Wrapper;
use Exception;
-use OC;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
use OC\Encryption\File;
use OC\Encryption\Util;
@@ -28,6 +27,8 @@ use OCP\Files\Cache\ICache;
use OCP\Files\Mount\IMountPoint;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\ITempManager;
+use OCP\Server;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\Files\Storage\Storage;
@@ -726,7 +727,7 @@ class EncryptionTest extends Storage {
$storage2->expects($this->any())
->method('fopen')
->willReturnCallback(function ($path, $mode) {
- $temp = OC::$server->getTempManager();
+ $temp = Server::get(ITempManager::class);
return fopen($temp->getTemporaryFile(), $mode);
});
$storage2->method('getId')
@@ -775,7 +776,7 @@ class EncryptionTest extends Storage {
$storage2->expects($this->any())
->method('fopen')
->willReturnCallback(function ($path, $mode) {
- $temp = OC::$server->getTempManager();
+ $temp = Server::get(ITempManager::class);
return fopen($temp->getTemporaryFile(), $mode);
});
$storage2->method('getId')
diff --git a/tests/lib/Files/Storage/Wrapper/JailTest.php b/tests/lib/Files/Storage/Wrapper/JailTest.php
index fbc4e1d09ee..f7babfb609d 100644
--- a/tests/lib/Files/Storage/Wrapper/JailTest.php
+++ b/tests/lib/Files/Storage/Wrapper/JailTest.php
@@ -7,6 +7,10 @@
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Filesystem;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Jail;
+
class JailTest extends \Test\Files\Storage\Storage {
/**
* @var \OC\Files\Storage\Temporary
@@ -15,9 +19,9 @@ class JailTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();
- $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
+ $this->sourceStorage = new Temporary([]);
$this->sourceStorage->mkdir('foo');
- $this->instance = new \OC\Files\Storage\Wrapper\Jail([
+ $this->instance = new Jail([
'storage' => $this->sourceStorage,
'root' => 'foo'
]);
@@ -28,7 +32,7 @@ class JailTest extends \Test\Files\Storage\Storage {
$contents = [];
$dh = $this->sourceStorage->opendir('');
while (($file = readdir($dh)) !== false) {
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ if (!Filesystem::isIgnoredDir($file)) {
$contents[] = $file;
}
}
diff --git a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
index 5c0a035d094..003842dbbc2 100644
--- a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
+++ b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
@@ -7,6 +7,8 @@
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Constants;
use OCP\Files\Cache\IScanner;
@@ -22,7 +24,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();
- $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
+ $this->sourceStorage = new Temporary([]);
$this->instance = $this->getMaskedStorage(Constants::PERMISSION_ALL);
}
@@ -32,7 +34,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
}
protected function getMaskedStorage($mask) {
- return new \OC\Files\Storage\Wrapper\PermissionsMask([
+ return new PermissionsMask([
'storage' => $this->sourceStorage,
'mask' => $mask
]);
@@ -127,7 +129,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
public function testScanNewFilesNested(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE);
- $nestedStorage = new \OC\Files\Storage\Wrapper\PermissionsMask([
+ $nestedStorage = new PermissionsMask([
'storage' => $storage,
'mask' => Constants::PERMISSION_READ + Constants::PERMISSION_CREATE
]);
@@ -149,7 +151,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ);
$scanner = $storage->getScanner();
$called = false;
- $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
+ $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called): void {
$called = true;
});
$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);
@@ -167,7 +169,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$wrappedStorage = new Wrapper(['storage' => $storage]);
$scanner = $wrappedStorage->getScanner();
$called = false;
- $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called) {
+ $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function () use (&$called): void {
$called = true;
});
$scanner->scan('foo', IScanner::SCAN_RECURSIVE, IScanner::REUSE_ETAG | IScanner::REUSE_SIZE);
diff --git a/tests/lib/Files/Storage/Wrapper/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
index 3115f1288a0..b2bcdfa32d8 100644
--- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php
+++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
@@ -10,7 +10,10 @@ namespace Test\Files\Storage\Wrapper;
//ensure the constants are loaded
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\Local;
+use OC\Files\Storage\Wrapper\Quota;
use OCP\Files;
+use OCP\ITempManager;
+use OCP\Server;
/**
* Class QuotaTest
@@ -28,9 +31,9 @@ class QuotaTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();
- $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
- $storage = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir]);
- $this->instance = new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => 10000000]);
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
+ $storage = new Local(['datadir' => $this->tmpDir]);
+ $this->instance = new Quota(['storage' => $storage, 'quota' => 10000000]);
}
protected function tearDown(): void {
@@ -42,10 +45,10 @@ class QuotaTest extends \Test\Files\Storage\Storage {
* @param integer $limit
*/
protected function getLimitedStorage($limit) {
- $storage = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir]);
+ $storage = new Local(['datadir' => $this->tmpDir]);
$storage->mkdir('files');
$storage->getScanner()->scan('');
- return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $limit]);
+ return new Quota(['storage' => $storage, 'quota' => $limit]);
}
public function testFilePutContentsNotEnoughSpace(): void {
@@ -83,7 +86,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
->willReturn(-2);
$storage->getScanner()->scan('');
- $instance = new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => 9]);
+ $instance = new Quota(['storage' => $storage, 'quota' => 9]);
$instance->getCache()->put(
'', ['size' => 3]
);
@@ -138,7 +141,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
->method('fopen')
->willReturn(false);
- $instance = new \OC\Files\Storage\Wrapper\Quota(['storage' => $failStorage, 'quota' => 1000]);
+ $instance = new Quota(['storage' => $failStorage, 'quota' => 1000]);
$this->assertFalse($instance->fopen('failedfopen', 'r'));
}
@@ -196,7 +199,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
->with('files')
->willReturn(new CacheEntry(['size' => 50]));
- $instance = new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => 1024, 'root' => 'files']);
+ $instance = new Quota(['storage' => $storage, 'quota' => 1024, 'root' => 'files']);
$this->assertEquals(1024 - 50, $instance->free_space(''));
}
diff --git a/tests/lib/Files/Storage/Wrapper/WrapperTest.php b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
index 4cbae1762fc..d7b7683c58a 100644
--- a/tests/lib/Files/Storage/Wrapper/WrapperTest.php
+++ b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
@@ -7,7 +7,11 @@
namespace Test\Files\Storage\Wrapper;
+use OC\Files\Storage\Local;
+use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files;
+use OCP\ITempManager;
+use OCP\Server;
class WrapperTest extends \Test\Files\Storage\Storage {
/**
@@ -18,9 +22,9 @@ class WrapperTest extends \Test\Files\Storage\Storage {
protected function setUp(): void {
parent::setUp();
- $this->tmpDir = \OC::$server->getTempManager()->getTemporaryFolder();
- $storage = new \OC\Files\Storage\Local(['datadir' => $this->tmpDir]);
- $this->instance = new \OC\Files\Storage\Wrapper\Wrapper(['storage' => $storage]);
+ $this->tmpDir = Server::get(ITempManager::class)->getTemporaryFolder();
+ $storage = new Local(['datadir' => $this->tmpDir]);
+ $this->instance = new Wrapper(['storage' => $storage]);
}
protected function tearDown(): void {
diff --git a/tests/lib/Files/Stream/DummyEncryptionWrapper.php b/tests/lib/Files/Stream/DummyEncryptionWrapper.php
index 211050905bd..6846762cb67 100644
--- a/tests/lib/Files/Stream/DummyEncryptionWrapper.php
+++ b/tests/lib/Files/Stream/DummyEncryptionWrapper.php
@@ -7,7 +7,9 @@
namespace Test\Files\Stream;
-class DummyEncryptionWrapper extends \OC\Files\Stream\Encryption {
+use OC\Files\Stream\Encryption;
+
+class DummyEncryptionWrapper extends Encryption {
/**
* simulate a non-seekable stream wrapper by always return false
*
diff --git a/tests/lib/Files/Stream/HashWrapperTest.php b/tests/lib/Files/Stream/HashWrapperTest.php
index 1e9bbd8f289..66dee77b607 100644
--- a/tests/lib/Files/Stream/HashWrapperTest.php
+++ b/tests/lib/Files/Stream/HashWrapperTest.php
@@ -25,7 +25,7 @@ class HashWrapperTest extends TestCase {
$data = $tmpData;
}
- $wrapper = HashWrapper::wrap($data, $algo, function ($result) use ($hash) {
+ $wrapper = HashWrapper::wrap($data, $algo, function ($result) use ($hash): void {
$this->assertEquals($hash, $result);
});
stream_get_contents($wrapper);
diff --git a/tests/lib/Files/Stream/QuotaTest.php b/tests/lib/Files/Stream/QuotaTest.php
index 2df767d6c60..31c0f6c1453 100644
--- a/tests/lib/Files/Stream/QuotaTest.php
+++ b/tests/lib/Files/Stream/QuotaTest.php
@@ -7,6 +7,8 @@
namespace Test\Files\Stream;
+use OC\Files\Stream\Quota;
+
class QuotaTest extends \Test\TestCase {
/**
* @param string $mode
@@ -15,7 +17,7 @@ class QuotaTest extends \Test\TestCase {
*/
protected function getStream($mode, $limit) {
$source = fopen('php://temp', $mode);
- return \OC\Files\Stream\Quota::wrap($source, $limit);
+ return Quota::wrap($source, $limit);
}
public function testWriteEnoughSpace(): void {
@@ -60,7 +62,7 @@ class QuotaTest extends \Test\TestCase {
public function testWriteNotEnoughSpaceExistingStream(): void {
$source = fopen('php://temp', 'w+');
fwrite($source, 'foobar');
- $stream = \OC\Files\Stream\Quota::wrap($source, 3);
+ $stream = Quota::wrap($source, 3);
$this->assertEquals(3, fwrite($stream, 'foobar'));
rewind($stream);
$this->assertEquals('foobarfoo', fread($stream, 100));
@@ -69,7 +71,7 @@ class QuotaTest extends \Test\TestCase {
public function testWriteNotEnoughSpaceExistingStreamRewind(): void {
$source = fopen('php://temp', 'w+');
fwrite($source, 'foobar');
- $stream = \OC\Files\Stream\Quota::wrap($source, 3);
+ $stream = Quota::wrap($source, 3);
rewind($stream);
$this->assertEquals(6, fwrite($stream, 'qwerty'));
rewind($stream);
diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php
index 1005f12786a..81fb7ad4bcb 100644
--- a/tests/lib/Files/Type/DetectionTest.php
+++ b/tests/lib/Files/Type/DetectionTest.php
@@ -9,6 +9,7 @@ namespace Test\Files\Type;
use OC\Files\Type\Detection;
use OCP\IURLGenerator;
+use OCP\Server;
use Psr\Log\LoggerInterface;
class DetectionTest extends \Test\TestCase {
@@ -18,8 +19,8 @@ class DetectionTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->detection = new Detection(
- \OC::$server->getURLGenerator(),
- \OC::$server->get(LoggerInterface::class),
+ Server::get(IURLGenerator::class),
+ Server::get(LoggerInterface::class),
\OC::$SERVERROOT . '/config/',
\OC::$SERVERROOT . '/resources/config/'
);
diff --git a/tests/lib/Files/Type/LoaderTest.php b/tests/lib/Files/Type/LoaderTest.php
index 6eaf6ac2013..f1018093c45 100644
--- a/tests/lib/Files/Type/LoaderTest.php
+++ b/tests/lib/Files/Type/LoaderTest.php
@@ -9,6 +9,7 @@ namespace Test\Files\Type;
use OC\Files\Type\Loader;
use OCP\IDBConnection;
+use OCP\Server;
use Test\TestCase;
class LoaderTest extends TestCase {
@@ -16,7 +17,7 @@ class LoaderTest extends TestCase {
protected Loader $loader;
protected function setUp(): void {
- $this->db = \OC::$server->get(IDBConnection::class);
+ $this->db = Server::get(IDBConnection::class);
$this->loader = new Loader($this->db);
}
diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php
index 047da5851b7..ebad4680ff6 100644
--- a/tests/lib/Files/Utils/ScannerTest.php
+++ b/tests/lib/Files/Utils/ScannerTest.php
@@ -10,13 +10,18 @@ namespace Test\Files\Utils;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
+use OC\Files\Utils\Scanner;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Storage\IStorageFactory;
+use OCP\IDBConnection;
use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
-class TestScanner extends \OC\Files\Utils\Scanner {
+class TestScanner extends Scanner {
/**
* @var \OC\Files\Mount\MountPoint[] $mounts
*/
@@ -51,13 +56,13 @@ class ScannerTest extends \Test\TestCase {
parent::setUp();
$this->userBackend = new \Test\Util\User\Dummy();
- \OC::$server->getUserManager()->registerBackend($this->userBackend);
+ Server::get(IUserManager::class)->registerBackend($this->userBackend);
$this->loginAsUser();
}
protected function tearDown(): void {
$this->logout();
- \OC::$server->getUserManager()->removeBackend($this->userBackend);
+ Server::get(IUserManager::class)->removeBackend($this->userBackend);
parent::tearDown();
}
@@ -71,7 +76,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -93,7 +98,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -124,14 +129,14 @@ class ScannerTest extends \Test\TestCase {
}
});
- \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class)->registerProvider($mountProvider);
+ Server::get(IMountProviderCollection::class)->registerProvider($mountProvider);
$cache = $storage->getCache();
$storage->mkdir('folder');
$storage->file_put_contents('foo.txt', 'qwerty');
$storage->file_put_contents('folder/bar.txt', 'qwerty');
- $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new Scanner($uid, Server::get(IDBConnection::class), Server::get(IEventDispatcher::class), Server::get(LoggerInterface::class));
$this->assertFalse($cache->inCache('folder/bar.txt'));
$scanner->scan('/' . $uid . '/files/foo');
@@ -160,7 +165,7 @@ class ScannerTest extends \Test\TestCase {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid path to scan');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->scan($invalidPath);
}
@@ -174,7 +179,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('folder/bar.txt', 'qwerty');
$storage->touch('folder/bar.txt', time() - 200);
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('');
@@ -200,7 +205,7 @@ class ScannerTest extends \Test\TestCase {
$storage->file_put_contents('folder/bar.txt', 'qwerty');
$storage->file_put_contents('folder/subfolder/foobar.txt', 'qwerty');
- $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class));
+ $scanner = new TestScanner('', Server::get(IDBConnection::class), $this->createMock(IEventDispatcher::class), Server::get(LoggerInterface::class));
$scanner->addMount($mount);
$scanner->scan('', $recusive = false);
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index d611df372e6..36e448ea6e2 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -7,6 +7,7 @@
namespace Test\Files;
+use OC\Files\Cache\Scanner;
use OC\Files\Cache\Watcher;
use OC\Files\Filesystem;
use OC\Files\Mount\MountPoint;
@@ -20,13 +21,19 @@ use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Cache\CappedMemoryCache;
use OCP\Constants;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
+use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountManager;
+use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;
+use OCP\IConfig;
use OCP\IDBConnection;
+use OCP\IGroupManager;
+use OCP\ITempManager;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
@@ -117,8 +124,8 @@ class ViewTest extends \Test\TestCase {
Server::get(IUserManager::class)->registerBackend(new \Test\Util\User\Dummy());
//login
- $userManager = \OC::$server->getUserManager();
- $groupManager = \OC::$server->getGroupManager();
+ $userManager = Server::get(IUserManager::class);
+ $groupManager = Server::get(IGroupManager::class);
$this->user = 'test';
$this->userObject = $userManager->createUser('test', 'test');
@@ -128,7 +135,7 @@ class ViewTest extends \Test\TestCase {
self::loginAsUser($this->user);
/** @var IMountManager $manager */
- $manager = \OC::$server->get(IMountManager::class);
+ $manager = Server::get(IMountManager::class);
$manager->removeMount('/test');
$this->tempStorage = null;
@@ -149,13 +156,13 @@ class ViewTest extends \Test\TestCase {
self::logout();
/** @var SetupManager $setupManager */
- $setupManager = \OC::$server->get(SetupManager::class);
+ $setupManager = Server::get(SetupManager::class);
$setupManager->setupRoot();
$this->userObject->delete();
$this->groupObject->delete();
- $mountProviderCollection = \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class);
+ $mountProviderCollection = Server::get(IMountProviderCollection::class);
self::invokePrivate($mountProviderCollection, 'providers', [[]]);
parent::tearDown();
@@ -275,7 +282,7 @@ class ViewTest extends \Test\TestCase {
public function testGetPathNotExisting(): void {
- $this->expectException(\OCP\Files\NotFoundException::class);
+ $this->expectException(NotFoundException::class);
$storage1 = $this->getTestStorage();
Filesystem::mount($storage1, [], '/');
@@ -315,9 +322,9 @@ class ViewTest extends \Test\TestCase {
*/
public function testRemoveSharePermissionWhenSharingDisabledForUser($excludeGroups, $excludeGroupsList, $expectedShareable): void {
// Reset sharing disabled for users cache
- self::invokePrivate(\OC::$server->get(ShareDisableChecker::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
+ self::invokePrivate(Server::get(ShareDisableChecker::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$oldExcludeGroupsFlag = $config->getAppValue('core', 'shareapi_exclude_groups', 'no');
$oldExcludeGroupsList = $config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$config->setAppValue('core', 'shareapi_exclude_groups', $excludeGroups);
@@ -340,7 +347,7 @@ class ViewTest extends \Test\TestCase {
$config->setAppValue('core', 'shareapi_exclude_groups_list', $oldExcludeGroupsList);
// Reset sharing disabled for users cache
- self::invokePrivate(\OC::$server->get(ShareDisableChecker::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
+ self::invokePrivate(Server::get(ShareDisableChecker::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
}
public function testCacheIncompleteFolder(): void {
@@ -845,7 +852,7 @@ class ViewTest extends \Test\TestCase {
* 1024 is the max path length in mac
*/
$folderName = 'abcdefghijklmnopqrstuvwxyz012345678901234567890123456789';
- $tmpdirLength = strlen(\OC::$server->getTempManager()->getTemporaryFolder());
+ $tmpdirLength = strlen(Server::get(ITempManager::class)->getTemporaryFolder());
if (\OC_Util::runningOnMac()) {
$depth = ((1024 - $tmpdirLength) / 57);
} else {
@@ -892,7 +899,7 @@ class ViewTest extends \Test\TestCase {
$info = $view->getFileInfo('/test/test');
$view->touch('/test/test', $past);
- $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
+ $scanner->scanFile('test', Scanner::REUSE_ETAG);
$info2 = $view->getFileInfo('/test/test');
$this->assertSame($info['etag'], $info2['etag']);
@@ -1082,7 +1089,7 @@ class ViewTest extends \Test\TestCase {
* @dataProvider tooLongPathDataProvider
*/
public function testTooLongPath($operation, $param0 = null): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
+ $this->expectException(InvalidPathException::class);
$longPath = '';
@@ -1332,7 +1339,7 @@ class ViewTest extends \Test\TestCase {
* @param string $pathPrefix
*/
public function testReadFromWriteLockedPath($rootPath, $pathPrefix): void {
- $this->expectException(\OCP\Lock\LockedException::class);
+ $this->expectException(LockedException::class);
$rootPath = str_replace('{folder}', 'files', $rootPath);
$pathPrefix = str_replace('{folder}', 'files', $pathPrefix);
@@ -1373,7 +1380,7 @@ class ViewTest extends \Test\TestCase {
* @param string $pathPrefix
*/
public function testWriteToReadLockedFile($rootPath, $pathPrefix): void {
- $this->expectException(\OCP\Lock\LockedException::class);
+ $this->expectException(LockedException::class);
$rootPath = str_replace('{folder}', 'files', $rootPath);
$pathPrefix = str_replace('{folder}', 'files', $pathPrefix);
@@ -1408,7 +1415,7 @@ class ViewTest extends \Test\TestCase {
* Test that locks are on mount point paths instead of mount root
*/
public function testLockLocalMountPointPathInsteadOfStorageRoot(): void {
- $lockingProvider = \OC::$server->get(ILockingProvider::class);
+ $lockingProvider = Server::get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
@@ -1438,7 +1445,7 @@ class ViewTest extends \Test\TestCase {
* Test that locks are on mount point paths and also mount root when requested
*/
public function testLockStorageRootButNotLocalMountPoint(): void {
- $lockingProvider = \OC::$server->get(ILockingProvider::class);
+ $lockingProvider = Server::get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
@@ -1468,7 +1475,7 @@ class ViewTest extends \Test\TestCase {
* Test that locks are on mount point paths and also mount root when requested
*/
public function testLockMountPointPathFailReleasesBoth(): void {
- $lockingProvider = \OC::$server->get(ILockingProvider::class);
+ $lockingProvider = Server::get(ILockingProvider::class);
$view = new View('/testuser/files/');
$storage = new Temporary([]);
Filesystem::mount($storage, [], '/');
@@ -1611,7 +1618,7 @@ class ViewTest extends \Test\TestCase {
->getMock();
$storage->method('getId')->willReturn('non-null-id');
$storage->method('getStorageCache')->willReturnCallback(function () use ($storage) {
- return new \OC\Files\Cache\Storage($storage, true, \OC::$server->get(IDBConnection::class));
+ return new \OC\Files\Cache\Storage($storage, true, Server::get(IDBConnection::class));
});
$mounts[] = $this->getMockBuilder(TestMoveableMountPoint::class)
@@ -1626,7 +1633,7 @@ class ViewTest extends \Test\TestCase {
->method('getMountsForUser')
->willReturn($mounts);
- $mountProviderCollection = \OCP\Server::get(\OCP\Files\Config\IMountProviderCollection::class);
+ $mountProviderCollection = Server::get(IMountProviderCollection::class);
$mountProviderCollection->registerProvider($mountProvider);
return $mounts;
@@ -1723,16 +1730,16 @@ class ViewTest extends \Test\TestCase {
$view->mkdir('shareddir notshared');
$fileId = $view->getFileInfo('shareddir')->getId();
- $userObject = \OC::$server->getUserManager()->createUser('test2', 'IHateNonMockableStaticClasses');
+ $userObject = Server::get(IUserManager::class)->createUser('test2', 'IHateNonMockableStaticClasses');
$userFolder = \OC::$server->getUserFolder($this->user);
$shareDir = $userFolder->get('shareddir');
- $shareManager = \OC::$server->get(IShareManager::class);
+ $shareManager = Server::get(IShareManager::class);
$share = $shareManager->newShare();
$share->setSharedWith('test2')
->setSharedBy($this->user)
->setShareType(IShare::TYPE_USER)
- ->setPermissions(\OCP\Constants::PERMISSION_READ)
+ ->setPermissions(Constants::PERMISSION_READ)
->setNode($shareDir);
$shareManager->createShare($share);
@@ -2117,7 +2124,7 @@ class ViewTest extends \Test\TestCase {
$storage->expects($this->once())
->method($operation)
->willReturnCallback(
- function () {
+ function (): void {
throw new \Exception('Simulated exception');
}
);
@@ -2231,13 +2238,13 @@ class ViewTest extends \Test\TestCase {
$storage->expects($this->any())
->method('getMetaData')
- ->will($this->returnValue([
+ ->willReturn([
'mtime' => 1885434487,
'etag' => '',
'mimetype' => 'text/plain',
'permissions' => Constants::PERMISSION_ALL,
'size' => 3
- ]));
+ ]);
$storage->expects($this->any())
->method('filemtime')
->willReturn(123456789);
@@ -2311,7 +2318,7 @@ class ViewTest extends \Test\TestCase {
$storage->expects($this->once())
->method('copy')
->willReturnCallback(
- function () {
+ function (): void {
throw new \Exception();
}
);
@@ -2426,13 +2433,13 @@ class ViewTest extends \Test\TestCase {
$storage2->expects($this->any())
->method('getMetaData')
- ->will($this->returnValue([
+ ->willReturn([
'mtime' => 1885434487,
'etag' => '',
'mimetype' => 'text/plain',
'permissions' => Constants::PERMISSION_ALL,
'size' => 3
- ]));
+ ]);
$storage2->expects($this->any())
->method('filemtime')
->willReturn(123456789);
@@ -2566,14 +2573,14 @@ class ViewTest extends \Test\TestCase {
$eventHandler->expects($this->any())
->method('preCallback')
->willReturnCallback(
- function () use ($view, $path, $onMountPoint, &$lockTypePre) {
+ function () use ($view, $path, $onMountPoint, &$lockTypePre): void {
$lockTypePre = $this->getFileLockType($view, $path, $onMountPoint);
}
);
$eventHandler->expects($this->any())
->method('postCallback')
->willReturnCallback(
- function () use ($view, $path, $onMountPoint, &$lockTypePost) {
+ function () use ($view, $path, $onMountPoint, &$lockTypePost): void {
$lockTypePost = $this->getFileLockType($view, $path, $onMountPoint);
}
);
@@ -2794,7 +2801,7 @@ class ViewTest extends \Test\TestCase {
$calls = ['/new/folder', '/new/folder/structure'];
$view->expects($this->exactly(2))
->method('mkdir')
- ->willReturnCallback(function ($dir) use (&$calls) {
+ ->willReturnCallback(function ($dir) use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, $dir);
});