diff options
Diffstat (limited to 'tests/lib/Files')
73 files changed, 920 insertions, 794 deletions
diff --git a/tests/lib/Files/AppData/AppDataTest.php b/tests/lib/Files/AppData/AppDataTest.php index 494096d1ac3..ed006622504 100644 --- a/tests/lib/Files/AppData/AppDataTest.php +++ b/tests/lib/Files/AppData/AppDataTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/AppData/FactoryTest.php b/tests/lib/Files/AppData/FactoryTest.php index dff999d8b48..6092c931091 100644 --- a/tests/lib/Files/AppData/FactoryTest.php +++ b/tests/lib/Files/AppData/FactoryTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 2815003a996..383962b7224 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -11,13 +12,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(); } @@ -32,30 +38,30 @@ class LongId extends \OC\Files\Storage\Temporary { */ class CacheTest extends \Test\TestCase { /** - * @var \OC\Files\Storage\Temporary $storage ; + * @var Temporary $storage ; */ protected $storage; /** - * @var \OC\Files\Storage\Temporary $storage2 ; + * @var Temporary $storage2 ; */ protected $storage2; /** - * @var \OC\Files\Cache\Cache $cache + * @var Cache $cache */ protected $cache; /** - * @var \OC\Files\Cache\Cache $cache2 + * @var Cache $cache2 */ protected $cache2; 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]); } @@ -156,14 +162,12 @@ class CacheTest extends \Test\TestCase { $this->assertEquals(new CacheEntry(['size' => 12, 'mtime' => 15]), $this->cache->get($file1)); } - /** - * @dataProvider folderDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('folderDataProvider')] 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 +315,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 { @@ -329,11 +333,11 @@ class CacheTest extends \Test\TestCase { } /** - * @dataProvider putWithAllKindOfQuotesData * @param $fileName */ + #[\PHPUnit\Framework\Attributes\DataProvider('putWithAllKindOfQuotesData')] 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 +375,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 +397,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 +422,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(); @@ -464,9 +468,7 @@ class CacheTest extends \Test\TestCase { ]; } - /** - * @dataProvider movePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('movePathProvider')] public function testMove($sourceFolder, $targetFolder, $children): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar']; $folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; @@ -550,7 +552,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 +579,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)); } /** @@ -591,7 +593,7 @@ class CacheTest extends \Test\TestCase { $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e"; /** - * @var \OC\Files\Cache\Cache | \PHPUnit\Framework\MockObject\MockObject $cacheMock + * @var Cache|\PHPUnit\Framework\MockObject\MockObject $cacheMock */ $cacheMock = $this->getMockBuilder(Cache::class) ->onlyMethods(['normalize']) @@ -676,9 +678,8 @@ class CacheTest extends \Test\TestCase { /** * Test bogus paths with leading or doubled slashes - * - * @dataProvider bogusPathNamesProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('bogusPathNamesProvider')] public function testBogusPaths($bogusPath, $fixedBogusPath): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]; $parentId = $this->cache->getId(''); @@ -720,8 +721,8 @@ class CacheTest extends \Test\TestCase { /** * @param string $name - * @dataProvider escapingProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('escapingProvider')] public function testEscaping($name): void { $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain']; $this->cache->put($name, $data); diff --git a/tests/lib/Files/Cache/HomeCacheTest.php b/tests/lib/Files/Cache/HomeCacheTest.php index ad069de1fef..86fda615fd7 100644 --- a/tests/lib/Files/Cache/HomeCacheTest.php +++ b/tests/lib/Files/Cache/HomeCacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,24 +8,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, + ) { } /** @@ -61,15 +58,15 @@ class HomeCacheTest extends \Test\TestCase { private $cache; /** - * @var \OC\User\User $user + * @var User $user */ private $user; 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..d580cdca4b9 100644 --- a/tests/lib/Files/Cache/MoveFromCacheTraitTest.php +++ b/tests/lib/Files/Cache/MoveFromCacheTraitTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,10 +8,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 +26,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/PropagatorTest.php b/tests/lib/Files/Cache/PropagatorTest.php index e88816dfccc..2ab213e9567 100644 --- a/tests/lib/Files/Cache/PropagatorTest.php +++ b/tests/lib/Files/Cache/PropagatorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index dc5ba5d3cdf..123c13893f7 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -14,6 +15,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 +70,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 +340,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 +366,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(); @@ -383,11 +386,11 @@ class ScannerTest extends TestCase { } /** - * @dataProvider dataTestIsPartialFile * * @param string $path * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsPartialFile')] public function testIsPartialFile($path, $expected): void { $this->assertSame($expected, $this->scanner->isPartialFile($path) diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php index 28af199639a..ee097044e3b 100644 --- a/tests/lib/Files/Cache/SearchBuilderTest.php +++ b/tests/lib/Files/Cache/SearchBuilderTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -16,6 +17,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 +42,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 +79,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 +112,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) { @@ -175,11 +178,11 @@ class SearchBuilderTest extends TestCase { } /** - * @dataProvider comparisonProvider * * @param ISearchOperator $operator * @param array $fileIds */ + #[\PHPUnit\Framework\Attributes\DataProvider('comparisonProvider')] public function testComparison(ISearchOperator $operator, array $fileIds): void { $fileId = []; $fileId[] = $this->addCacheEntry([ diff --git a/tests/lib/Files/Cache/UpdaterLegacyTest.php b/tests/lib/Files/Cache/UpdaterLegacyTest.php index 0f7e9d78d77..c71fac2d2dc 100644 --- a/tests/lib/Files/Cache/UpdaterLegacyTest.php +++ b/tests/lib/Files/Cache/UpdaterLegacyTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,9 +8,15 @@ namespace Test\Files\Cache; +use OC\Files\Cache\Cache; +use OC\Files\Cache\Scanner; use OC\Files\Filesystem as Filesystem; +use OC\Files\Storage\Storage; +use OC\Files\Storage\Temporary; use OC\Files\View; use OCP\Files\Mount\IMountManager; +use OCP\IUserManager; +use OCP\Server; /** * Class UpdaterLegacyTest @@ -20,17 +27,17 @@ use OCP\Files\Mount\IMountManager; */ class UpdaterLegacyTest extends \Test\TestCase { /** - * @var \OC\Files\Storage\Storage $storage + * @var Storage $storage */ private $storage; /** - * @var \OC\Files\Cache\Scanner $scanner + * @var Scanner $scanner */ private $scanner; /** - * @var \OC\Files\Cache\Cache $cache + * @var Cache $cache */ private $cache; @@ -39,7 +46,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 +63,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 +83,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 +129,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 +190,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 +246,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/UpdaterTest.php b/tests/lib/Files/Cache/UpdaterTest.php index bc4b39a5dc4..65c47cb9ae6 100644 --- a/tests/lib/Files/Cache/UpdaterTest.php +++ b/tests/lib/Files/Cache/UpdaterTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,10 +8,13 @@ namespace Test\Files\Cache; +use OC\Files\Cache\Cache; use OC\Files\Filesystem; use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\ObjectStore\StorageObjectStore; +use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; +use OC\Files\View; use OCP\Files\Storage\IStorage; /** @@ -22,17 +26,17 @@ use OCP\Files\Storage\IStorage; */ class UpdaterTest extends \Test\TestCase { /** - * @var \OC\Files\Storage\Storage + * @var Storage */ protected $storage; /** - * @var \OC\Files\Cache\Cache + * @var Cache */ protected $cache; /** - * @var \OC\Files\View + * @var View */ protected $view; @@ -312,9 +316,7 @@ class UpdaterTest extends \Test\TestCase { ]; } - /** - * @dataProvider changeExtensionProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('changeExtensionProvider')] public function testChangeExtension(IStorage $storage) { $updater = $storage->getUpdater(); $cache = $storage->getCache(); diff --git a/tests/lib/Files/Cache/WatcherTest.php b/tests/lib/Files/Cache/WatcherTest.php index 7319aa9b68d..6d0a8e0886b 100644 --- a/tests/lib/Files/Cache/WatcherTest.php +++ b/tests/lib/Files/Cache/WatcherTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,10 @@ namespace Test\Files\Cache; +use OC\Files\Cache\Watcher; +use OC\Files\Storage\Storage; +use OC\Files\Storage\Temporary; + /** * Class WatcherTest * @@ -16,7 +21,7 @@ namespace Test\Files\Cache; */ class WatcherTest extends \Test\TestCase { /** - * @var \OC\Files\Storage\Storage[] $storages + * @var Storage[] $storages */ private $storages = []; @@ -44,7 +49,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 +90,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 +107,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 +129,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 +147,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 +165,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')); @@ -172,10 +177,10 @@ class WatcherTest extends \Test\TestCase { /** * @param bool $scan - * @return \OC\Files\Storage\Storage + * @return 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..8ac3492fbd2 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,7 @@ namespace Test\Files\Cache\Wrapper; +use OC\Files\Cache\Cache; use OC\Files\Cache\Wrapper\CacheJail; use OC\Files\Cache\Wrapper\CacheWrapper; use OC\Files\Search\SearchComparison; @@ -27,7 +29,7 @@ use Test\Files\Cache\CacheTest; */ class CacheJailTest extends CacheTest { /** - * @var \OC\Files\Cache\Cache $sourceCache + * @var Cache $sourceCache */ protected $sourceCache; @@ -35,7 +37,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 +132,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 +202,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 +220,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..4fbeafc9270 100644 --- a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php +++ b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Files\Cache\Wrapper; +use OC\Files\Cache\Cache; +use OC\Files\Cache\Wrapper\CachePermissionsMask; use OCP\Constants; use Test\Files\Cache\CacheTest; @@ -19,7 +22,7 @@ use Test\Files\Cache\CacheTest; */ class CachePermissionsMaskTest extends CacheTest { /** - * @var \OC\Files\Cache\Cache $sourceCache + * @var Cache $sourceCache */ protected $sourceCache; @@ -31,7 +34,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 { @@ -44,9 +47,9 @@ class CachePermissionsMaskTest extends CacheTest { } /** - * @dataProvider maskProvider * @param int $mask */ + #[\PHPUnit\Framework\Attributes\DataProvider('maskProvider')] public function testGetMasked($mask): void { $cache = $this->getMaskedCached($mask); $data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'permissions' => Constants::PERMISSION_ALL]; @@ -61,9 +64,9 @@ class CachePermissionsMaskTest extends CacheTest { } /** - * @dataProvider maskProvider * @param int $mask */ + #[\PHPUnit\Framework\Attributes\DataProvider('maskProvider')] public function testGetFolderContentMasked($mask): void { $this->storage->mkdir('foo'); $this->storage->file_put_contents('foo/bar', 'asd'); @@ -80,9 +83,9 @@ class CachePermissionsMaskTest extends CacheTest { } /** - * @dataProvider maskProvider * @param int $mask */ + #[\PHPUnit\Framework\Attributes\DataProvider('maskProvider')] public function testSearchMasked($mask): void { $this->storage->mkdir('foo'); $this->storage->file_put_contents('foo/bar', 'asd'); diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 88c0ceaef08..6a3dc6a6d7e 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -26,6 +27,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 +47,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..d1b344ee997 100644 --- a/tests/lib/Files/EtagTest.php +++ b/tests/lib/Files/EtagTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,8 +9,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 +44,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 +57,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 +77,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/FileInfoTest.php b/tests/lib/Files/FileInfoTest.php index 2979252f78a..b3d3c9f0fec 100644 --- a/tests/lib/Files/FileInfoTest.php +++ b/tests/lib/Files/FileInfoTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/FilenameValidatorTest.php b/tests/lib/Files/FilenameValidatorTest.php index db7874b0bd5..162275a2cf8 100644 --- a/tests/lib/Files/FilenameValidatorTest.php +++ b/tests/lib/Files/FilenameValidatorTest.php @@ -48,9 +48,7 @@ class FilenameValidatorTest extends TestCase { $this->database->method('supports4ByteText')->willReturn(true); } - /** - * @dataProvider dataValidateFilename - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateFilename')] public function testValidateFilename( string $filename, array $forbiddenNames, @@ -87,9 +85,7 @@ class FilenameValidatorTest extends TestCase { $validator->validateFilename($filename); } - /** - * @dataProvider dataValidateFilename - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateFilename')] public function testIsFilenameValid( string $filename, array $forbiddenNames, @@ -189,9 +185,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider data4ByteUnicode - */ + #[\PHPUnit\Framework\Attributes\DataProvider('data4ByteUnicode')] public function testDatabaseDoesNotSupport4ByteText($filename): void { $database = $this->createMock(IDBConnection::class); $database->expects($this->once()) @@ -209,9 +203,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataInvalidAsciiCharacters - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataInvalidAsciiCharacters')] public function testInvalidAsciiCharactersAreAlwaysForbidden(string $filename): void { $this->expectException(InvalidPathException::class); $validator = new FilenameValidator($this->l10n, $this->database, $this->config, $this->logger); @@ -255,9 +247,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataIsForbidden - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataIsForbidden')] public function testIsForbidden(string $filename, array $forbiddenNames, bool $expected): void { /** @var FilenameValidator&MockObject */ $validator = $this->getMockBuilder(FilenameValidator::class) @@ -291,9 +281,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataGetForbiddenExtensions - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForbiddenExtensions')] public function testGetForbiddenExtensions(array $configValue, array $expectedValue): void { $validator = new FilenameValidator($this->l10n, $this->database, $this->config, $this->logger); $this->config @@ -317,9 +305,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataGetForbiddenFilenames - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForbiddenFilenames')] public function testGetForbiddenFilenames(array $configValue, array $legacyValue, array $expectedValue): void { $validator = new FilenameValidator($this->l10n, $this->database, $this->config, $this->logger); $this->config @@ -349,9 +335,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataGetForbiddenBasenames - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetForbiddenBasenames')] public function testGetForbiddenBasenames(array $configValue, array $expectedValue): void { $validator = new FilenameValidator($this->l10n, $this->database, $this->config, $this->logger); $this->config @@ -375,9 +359,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataSanitizeFilename - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSanitizeFilename')] public function testSanitizeFilename( string $filename, array $forbiddenNames, @@ -409,7 +391,7 @@ class FilenameValidatorTest extends TestCase { $this->assertEquals($expected, $validator->sanitizeFilename($filename)); } - public function dataSanitizeFilename(): array { + public static function dataSanitizeFilename(): array { return [ 'valid name' => [ 'a * b.txt', ['.htaccess'], [], [], [], 'a * b.txt' @@ -438,7 +420,7 @@ class FilenameValidatorTest extends TestCase { '.thumbs.db', ['.htaccess'], ['.thumbs'], [], [], '.thumbs (renamed).db' ], 'invalid character' => [ - 'a: b.txt', ['.htaccess'], [], [], [':'], 'a b.txt', + 'a: b.txt', ['.htaccess'], [], [], [':'], 'a_ b.txt', ], 'invalid extension' => [ 'a: b.txt', ['.htaccess'], [], ['.txt'], [], 'a: b' @@ -452,9 +434,7 @@ class FilenameValidatorTest extends TestCase { ]; } - /** - * @dataProvider dataSanitizeFilenameCharacterReplacement - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSanitizeFilenameCharacterReplacement')] public function testSanitizeFilenameCharacterReplacement( string $filename, array $forbiddenCharacters, @@ -492,13 +472,13 @@ class FilenameValidatorTest extends TestCase { public static function dataSanitizeFilenameCharacterReplacement(): array { return [ 'default' => [ - 'foo*bar', ['*'], null, 'foo bar' + 'foo*bar', ['*'], null, 'foo_bar' ], - 'default - space not allowed' => [ - 'foo*bar', ['*', ' '], null, 'foo_bar' + 'default - underscore not allowed' => [ + 'foo*bar', ['*', '_'], null, 'foo-bar' ], - 'default - space and underscore not allowed' => [ - 'foo*bar', ['*', ' ', '_'], null, 'foo-bar' + 'default - dash and underscore not allowed' => [ + 'foo*bar', ['*', '-', '_'], null, 'foo bar' ], 'default - no replacement' => [ 'foo*bar', ['*', ' ', '_', '-'], null, null diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php index 529b4f58428..a819acb1620 100644 --- a/tests/lib/Files/FilesystemTest.php +++ b/tests/lib/Files/FilesystemTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,24 +8,30 @@ 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\Mount\IMountPoint; 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, + ) { } /** @@ -32,7 +39,7 @@ class DummyMountProvider implements IMountProvider { * * @param IUser $user * @param IStorageFactory $loader - * @return \OCP\Files\Mount\IMountPoint[] + * @return IMountPoint[] */ public function getMountsForUser(IUser $user, IStorageFactory $loader) { return isset($this->mounts[$user->getUID()]) ? $this->mounts[$user->getUID()] : []; @@ -59,7 +66,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 +76,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 +91,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); } @@ -195,11 +202,9 @@ class FilesystemTest extends \Test\TestCase { ]; } - /** - * @dataProvider normalizePathData - */ + #[\PHPUnit\Framework\Attributes\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 { @@ -213,19 +218,17 @@ class FilesystemTest extends \Test\TestCase { ]; } - /** - * @dataProvider normalizePathKeepUnicodeData - */ + #[\PHPUnit\Framework\Attributes\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 { @@ -254,11 +257,9 @@ class FilesystemTest extends \Test\TestCase { ]; } - /** - * @dataProvider isValidPathData - */ + #[\PHPUnit\Framework\Attributes\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 { @@ -276,11 +277,9 @@ class FilesystemTest extends \Test\TestCase { ]; } - /** - * @dataProvider isFileBlacklistedData - */ + #[\PHPUnit\Framework\Attributes\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 +287,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 +327,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 +364,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 +384,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 +397,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 +405,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 +413,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 +443,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 +468,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..e6cf3348664 100644 --- a/tests/lib/Files/Mount/ManagerTest.php +++ b/tests/lib/Files/Mount/ManagerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,7 @@ namespace Test\Files\Mount; +use OC\Files\Mount\MountPoint; use OC\Files\SetupManagerFactory; use OC\Files\Storage\Temporary; @@ -28,33 +30,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..bcbcc96e3a3 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,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 +25,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 +45,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..05c8a7d58e7 100644 --- a/tests/lib/Files/Mount/MountTest.php +++ b/tests/lib/Files/Mount/MountTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,7 @@ namespace Test\Files\Mount; +use OC\Files\Mount\MountPoint; use OC\Files\Storage\StorageFactory; use OC\Files\Storage\Wrapper\Wrapper; @@ -15,12 +17,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 +40,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 3daf82461cb..dd696279b86 100644 --- a/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php +++ b/tests/lib/Files/Mount/ObjectHomeMountProviderTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,9 @@ namespace Test\Files\Mount; use OC\Files\Mount\ObjectHomeMountProvider; +use OC\Files\ObjectStore\PrimaryObjectStoreConfig; +use OCP\App\IAppManager; +use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\Storage\IStorageFactory; use OCP\IConfig; use OCP\IUser; @@ -31,51 +35,54 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->user = $this->createMock(IUser::class); $this->loader = $this->createMock(IStorageFactory::class); - $this->provider = new ObjectHomeMountProvider($this->config); + $objectStoreConfig = new PrimaryObjectStoreConfig($this->config, $this->createMock(IAppManager::class)); + $this->provider = new ObjectHomeMountProvider($objectStoreConfig); } public function testSingleBucket(): void { - $this->config->expects($this->once()) - ->method('getSystemValue') - ->with($this->equalTo('objectstore'), '') - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - ]); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'objectstore') { + return [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar' + ], + ]; + } else { + return $default; + } + }); - $this->user->expects($this->never())->method($this->anything()); - $this->loader->expects($this->never())->method($this->anything()); - - $config = $this->invokePrivate($this->provider, 'getSingleBucketObjectStoreConfig', [$this->user, $this->loader]); + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); + $arguments = $this->invokePrivate($mount, 'arguments'); - $this->assertArrayHasKey('class', $config); - $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore'); - $this->assertArrayHasKey('arguments', $config); - $this->assertArrayHasKey('user', $config['arguments']); - $this->assertSame($this->user, $config['arguments']['user']); - $this->assertArrayHasKey('objectstore', $config['arguments']); - $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); + $objectStore = $arguments['objectstore']; + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); + $this->assertEquals(['foo' => 'bar', 'multibucket' => false], $objectStore->getArguments()); } public function testMultiBucket(): void { - $this->config->expects($this->exactly(2)) - ->method('getSystemValue') - ->with($this->equalTo('objectstore_multibucket'), '') - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - ]); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'objectstore_multibucket') { + return [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar' + ], + ]; + } else { + return $default; + } + }); $this->user->method('getUID') ->willReturn('uid'); $this->loader->expects($this->never())->method($this->anything()); - $this->config->expects($this->once()) - ->method('getUserValue') - ->with( - $this->equalTo('uid'), - $this->equalTo('homeobjectstore'), - $this->equalTo('bucket'), - $this->equalTo(null) - )->willReturn(null); + $this->config->method('getUserValue') + ->willReturn(null); $this->config->expects($this->once()) ->method('setUserValue') @@ -87,42 +94,37 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->equalTo(null) ); - $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]); + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); + $arguments = $this->invokePrivate($mount, 'arguments'); - $this->assertArrayHasKey('class', $config); - $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore'); - $this->assertArrayHasKey('arguments', $config); - $this->assertArrayHasKey('user', $config['arguments']); - $this->assertSame($this->user, $config['arguments']['user']); - $this->assertArrayHasKey('objectstore', $config['arguments']); - $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); - $this->assertArrayHasKey('bucket', $config['arguments']); - $this->assertEquals('49', $config['arguments']['bucket']); + $objectStore = $arguments['objectstore']; + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); + $this->assertEquals(['foo' => 'bar', 'bucket' => 49, 'multibucket' => true], $objectStore->getArguments()); } public function testMultiBucketWithPrefix(): void { - $this->config->expects($this->exactly(2)) - ->method('getSystemValue') - ->with('objectstore_multibucket') - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - 'arguments' => [ - 'bucket' => 'myBucketPrefix', - ], - ]); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'objectstore_multibucket') { + return [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar', + 'bucket' => 'myBucketPrefix', + ], + ]; + } else { + return $default; + } + }); $this->user->method('getUID') ->willReturn('uid'); $this->loader->expects($this->never())->method($this->anything()); - $this->config->expects($this->once()) + $this->config ->method('getUserValue') - ->with( - $this->equalTo('uid'), - $this->equalTo('homeobjectstore'), - $this->equalTo('bucket'), - $this->equalTo(null) - )->willReturn(null); + ->willReturn(null); $this->config->expects($this->once()) ->method('setUserValue') @@ -134,66 +136,70 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { $this->equalTo(null) ); - $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]); + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); + $arguments = $this->invokePrivate($mount, 'arguments'); - $this->assertArrayHasKey('class', $config); - $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore'); - $this->assertArrayHasKey('arguments', $config); - $this->assertArrayHasKey('user', $config['arguments']); - $this->assertSame($this->user, $config['arguments']['user']); - $this->assertArrayHasKey('objectstore', $config['arguments']); - $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); - $this->assertArrayHasKey('bucket', $config['arguments']); - $this->assertEquals('myBucketPrefix49', $config['arguments']['bucket']); + $objectStore = $arguments['objectstore']; + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); + $this->assertEquals(['foo' => 'bar', 'bucket' => 'myBucketPrefix49', 'multibucket' => true], $objectStore->getArguments()); } public function testMultiBucketBucketAlreadySet(): void { - $this->config->expects($this->once()) - ->method('getSystemValue') - ->with('objectstore_multibucket') - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - 'arguments' => [ - 'bucket' => 'myBucketPrefix', - ], - ]); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'objectstore_multibucket') { + return [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar', + 'bucket' => 'myBucketPrefix', + ], + ]; + } else { + return $default; + } + }); $this->user->method('getUID') ->willReturn('uid'); $this->loader->expects($this->never())->method($this->anything()); - $this->config->expects($this->once()) + $this->config ->method('getUserValue') - ->with( - $this->equalTo('uid'), - $this->equalTo('homeobjectstore'), - $this->equalTo('bucket'), - $this->equalTo(null) - )->willReturn('awesomeBucket1'); + ->willReturnCallback(function ($uid, $app, $key, $default) { + if ($uid === 'uid' && $app === 'homeobjectstore' && $key === 'bucket') { + return 'awesomeBucket1'; + } else { + return $default; + } + }); $this->config->expects($this->never()) ->method('setUserValue'); - $config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]); + $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); + $arguments = $this->invokePrivate($mount, 'arguments'); - $this->assertArrayHasKey('class', $config); - $this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore'); - $this->assertArrayHasKey('arguments', $config); - $this->assertArrayHasKey('user', $config['arguments']); - $this->assertSame($this->user, $config['arguments']['user']); - $this->assertArrayHasKey('objectstore', $config['arguments']); - $this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']); - $this->assertArrayHasKey('bucket', $config['arguments']); - $this->assertEquals('awesomeBucket1', $config['arguments']['bucket']); + $objectStore = $arguments['objectstore']; + $this->assertInstanceOf(FakeObjectStore::class, $objectStore); + $this->assertEquals(['foo' => 'bar', 'bucket' => 'awesomeBucket1', 'multibucket' => true], $objectStore->getArguments()); } public function testMultiBucketConfigFirst(): void { - $this->config->expects($this->exactly(2)) - ->method('getSystemValue') - ->with('objectstore_multibucket') - ->willReturn([ - 'class' => 'Test\Files\Mount\FakeObjectStore', - ]); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + if ($key === 'objectstore_multibucket') { + return [ + 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar', + 'bucket' => 'myBucketPrefix', + ], + ]; + } else { + return $default; + } + }); $this->user->method('getUID') ->willReturn('uid'); @@ -204,11 +210,15 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { } public function testMultiBucketConfigFirstFallBackSingle(): void { - $this->config->expects($this->exactly(2)) + $this->config ->method('getSystemValue')->willReturnMap([ - ['objectstore_multibucket', '', ''], - ['objectstore', '', [ + ['objectstore_multibucket', null, null], + ['objectstore', null, [ 'class' => 'Test\Files\Mount\FakeObjectStore', + 'arguments' => [ + 'foo' => 'bar', + 'bucket' => 'myBucketPrefix', + ], ]], ]); @@ -221,23 +231,41 @@ class ObjectHomeMountProviderTest extends \Test\TestCase { } public function testNoObjectStore(): void { - $this->config->expects($this->exactly(2)) - ->method('getSystemValue') - ->willReturn(''); + $this->config->method('getSystemValue') + ->willReturnCallback(function ($key, $default) { + return $default; + }); $mount = $this->provider->getHomeMountForUser($this->user, $this->loader); $this->assertNull($mount); } } -class FakeObjectStore { - private $arguments; - - public function __construct(array $arguments) { - $this->arguments = $arguments; +class FakeObjectStore implements IObjectStore { + public function __construct( + private array $arguments, + ) { } public function getArguments() { return $this->arguments; } + + public function getStorageId() { + } + + public function readObject($urn) { + } + + public function writeObject($urn, $stream, ?string $mimetype = null) { + } + + public function deleteObject($urn) { + } + + public function objectExists($urn) { + } + + public function copyObject($from, $to) { + } } diff --git a/tests/lib/Files/Mount/RootMountProviderTest.php b/tests/lib/Files/Mount/RootMountProviderTest.php index 2613cfd4b7b..bf29bfa070a 100644 --- a/tests/lib/Files/Mount/RootMountProviderTest.php +++ b/tests/lib/Files/Mount/RootMountProviderTest.php @@ -10,11 +10,12 @@ namespace Test\Files\Mount; use OC\Files\Mount\RootMountProvider; use OC\Files\ObjectStore\ObjectStoreStorage; +use OC\Files\ObjectStore\PrimaryObjectStoreConfig; use OC\Files\ObjectStore\S3; use OC\Files\Storage\LocalRootStorage; use OC\Files\Storage\StorageFactory; +use OCP\App\IAppManager; use OCP\IConfig; -use Psr\Log\LoggerInterface; use Test\TestCase; /** @@ -40,8 +41,8 @@ class RootMountProviderTest extends TestCase { private function getProvider(array $systemConfig): RootMountProvider { $config = $this->getConfig($systemConfig); - $provider = new RootMountProvider($config, $this->createMock(LoggerInterface::class)); - return $provider; + $objectStoreConfig = new PrimaryObjectStoreConfig($config, $this->createMock(IAppManager::class)); + return new RootMountProvider($objectStoreConfig, $config); } public function testLocal(): void { diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index 74a23520344..eec34d156ad 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,7 +8,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 +23,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 +47,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 +62,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 +86,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 +103,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 +126,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 +143,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 +152,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 +163,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 +178,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 +189,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 +200,7 @@ class FileTest extends NodeTestCase { $this->cacheFactory, ); $hooksCalled = 0; - $hook = function ($file) use (&$hooksCalled) { + $hook = function ($file) use (&$hooksCalled): void { $hooksCalled++; }; @@ -211,9 +215,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 +228,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 +240,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 +249,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 +267,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 +294,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..439535cf2c1 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -21,12 +22,17 @@ 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 OC\Files\View; +use OCP\Constants; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\InvalidPathException; 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; @@ -67,7 +73,7 @@ class FolderTest extends NodeTestCase { public function testGetDirectoryContent(): void { $manager = $this->createMock(Manager::class); /** - * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + * @var View|\PHPUnit\Framework\MockObject\MockObject $view */ $root = $this->getMockBuilder(Root::class) ->setConstructorArgs([$manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) @@ -150,7 +156,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 +174,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 +198,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 +212,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 +224,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 +242,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 +268,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 +508,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 +557,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 +602,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 +646,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(''); @@ -690,9 +696,7 @@ class FolderTest extends NodeTestCase { ]; } - /** - * @dataProvider uniqueNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('uniqueNameProvider')] public function testGetUniqueName($name, $existingFiles, $expected): void { $manager = $this->createMock(Manager::class); $folderPath = '/bar/foo'; @@ -726,7 +730,7 @@ class FolderTest extends NodeTestCase { ->onlyMethods(['getUser', 'getMountsIn', 'getMount']) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) ->getMock(); - /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ + /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); @@ -753,14 +757,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 +777,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); @@ -795,7 +799,7 @@ class FolderTest extends NodeTestCase { ->onlyMethods(['getUser', 'getMountsIn', 'getMount']) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) ->getMock(); - /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ + /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); @@ -830,7 +834,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 +842,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); @@ -862,7 +866,7 @@ class FolderTest extends NodeTestCase { ->onlyMethods(['getUser', 'getMountsIn', 'getMount']) ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory]) ->getMock(); - /** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */ + /** @var \PHPUnit\Framework\MockObject\MockObject|FileInfo $folderInfo */ $folderInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor()->getMock(); @@ -891,7 +895,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', [ @@ -931,14 +935,14 @@ class FolderTest extends NodeTestCase { } /** - * @dataProvider offsetLimitProvider * @param int $offset * @param int $limit * @param string[] $expectedPaths * @param ISearchOrder[] $ordering * @throws NotFoundException - * @throws \OCP\Files\InvalidPathException + * @throws InvalidPathException */ + #[\PHPUnit\Framework\Attributes\DataProvider('offsetLimitProvider')] public function testSearchSubStoragesLimitOffset(int $offset, int $limit, array $expectedPaths, array $ordering): void { if (!$ordering) { $ordering = [new SearchOrder(ISearchOrder::DIRECTION_ASCENDING, 'fileid')]; diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php index 87e83fd0a3b..3f3957bab1d 100644 --- a/tests/lib/Files/Node/HookConnectorTest.php +++ b/tests/lib/Files/Node/HookConnectorTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -15,6 +16,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 +34,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 +82,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 +101,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], @@ -150,8 +153,8 @@ class HookConnectorTest extends TestCase { /** * @param callable $operation * @param string $expectedHook - * @dataProvider viewToNodeProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('viewToNodeProvider')] public function testViewToNode(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent): void { $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher, $this->logger); $connector->viewToNode(); @@ -159,7 +162,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 +170,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 +178,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 +200,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], @@ -219,8 +222,8 @@ class HookConnectorTest extends TestCase { /** * @param callable $operation * @param string $expectedHook - * @dataProvider viewToNodeProviderCopyRename */ + #[\PHPUnit\Framework\Attributes\DataProvider('viewToNodeProviderCopyRename')] public function testViewToNodeCopyRename(callable $operation, $expectedHook, $expectedLegacyEvent, $expectedEvent): void { $connector = new HookConnector($this->root, $this->view, $this->eventDispatcher, $this->logger); $connector->viewToNode(); @@ -230,7 +233,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 +244,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 +255,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 +286,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 +294,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 +303,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..f059afa1625 100644 --- a/tests/lib/Files/Node/IntegrationTest.php +++ b/tests/lib/Files/Node/IntegrationTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,7 @@ namespace Test\Files\Node; use OC\Files\Node\Root; +use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; use OC\Files\View; use OC\Memcache\ArrayCache; @@ -16,6 +18,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; @@ -35,19 +38,19 @@ class IntegrationTest extends \Test\TestCase { private $root; /** - * @var \OC\Files\Storage\Storage[] + * @var Storage[] */ private $storages; /** - * @var \OC\Files\View $view + * @var View $view */ private $view; protected function setUp(): void { parent::setUp(); - $manager = \OCP\Server::get(IMountManager::class); + $manager = Server::get(IMountManager::class); \OC_Hook::clear('OC_Filesystem'); @@ -64,7 +67,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..4aecd0fef11 100644 --- a/tests/lib/Files/Node/NodeTestCase.php +++ b/tests/lib/Files/Node/NodeTestCase.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,14 +10,22 @@ 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\Storage\Storage; use OC\Files\View; use OC\Memcache\ArrayCache; +use OC\User\User; +use OCP\Constants; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IUserMountCache; +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; @@ -29,15 +38,15 @@ use Psr\Log\LoggerInterface; * @package Test\Files\Node */ abstract class NodeTestCase extends \Test\TestCase { - /** @var \OC\User\User */ + /** @var User */ protected $user; /** @var \OC\Files\Mount\Manager */ protected $manager; - /** @var \OC\Files\View|\PHPUnit\Framework\MockObject\MockObject */ + /** @var View|\PHPUnit\Framework\MockObject\MockObject */ protected $view; /** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject */ protected $root; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */ protected $userMountCache; /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; @@ -78,7 +87,7 @@ abstract class NodeTestCase extends \Test\TestCase { } /** - * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + * @return View|\PHPUnit\Framework\MockObject\MockObject $view */ protected function getRootViewMock() { $view = $this->createMock(View::class); @@ -139,7 +148,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 +165,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 +176,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 +185,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 +202,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 +216,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 +225,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(); @@ -335,7 +344,7 @@ abstract class NodeTestCase extends \Test\TestCase { ->method('getUser') ->willReturn($this->user); /** - * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage + * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() @@ -359,7 +368,7 @@ abstract class NodeTestCase extends \Test\TestCase { ->method('getUser') ->willReturn($this->user); /** - * @var \OC\Files\Storage\Storage | \PHPUnit\Framework\MockObject\MockObject $storage + * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() @@ -397,7 +406,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 +419,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 +428,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 +455,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 +464,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 +473,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 +481,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 +495,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,10 +514,10 @@ 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 + * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->createMock('\OC\Files\Storage\Storage'); @@ -520,10 +529,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 +545,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 +555,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 +587,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') @@ -601,12 +610,12 @@ abstract class NodeTestCase extends \Test\TestCase { } /** - * @dataProvider moveOrCopyProvider * @param string $operationMethod * @param string $viewMethod * @param string $preHookName * @param string $postHookName */ + #[\PHPUnit\Framework\Attributes\DataProvider('moveOrCopyProvider')] public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName): void { /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */ $root = $this->getMockBuilder(Root::class) @@ -621,13 +630,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 +645,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 +653,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 +662,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 +685,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,10 +707,10 @@ 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 + * @var Storage|\PHPUnit\Framework\MockObject\MockObject $storage */ $storage = $this->createMock('\OC\Files\Storage\Storage'); @@ -713,20 +722,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 +747,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 +756,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 +770,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 +779,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..d90e6a2cc6e 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,10 +11,17 @@ 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\Storage\Storage; use OC\Files\View; use OC\Memcache\ArrayCache; +use OC\User\NoUserException; +use OC\User\User; use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Config\IUserMountCache; +use OCP\Files\NotFoundException; +use OCP\Files\NotPermittedException; use OCP\ICacheFactory; use OCP\IUser; use OCP\IUserManager; @@ -25,11 +33,11 @@ use Psr\Log\LoggerInterface; * @package Test\Files\Node */ class RootTest extends \Test\TestCase { - /** @var \OC\User\User */ + /** @var User */ private $user; /** @var \OC\Files\Mount\Manager */ private $manager; - /** @var \OCP\Files\Config\IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IUserMountCache|\PHPUnit\Framework\MockObject\MockObject */ private $userMountCache; /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $logger; @@ -61,7 +69,7 @@ class RootTest extends \Test\TestCase { } /** - * @return \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + * @return View|\PHPUnit\Framework\MockObject\MockObject $view */ protected function getRootViewMock() { $view = $this->createMock(View::class); @@ -77,13 +85,13 @@ class RootTest extends \Test\TestCase { public function testGet(): void { /** - * @var \OC\Files\Storage\Storage $storage + * @var Storage $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() ->getMock(); $view = $this->getRootViewMock(); - $root = new \OC\Files\Node\Root( + $root = new Root( $this->manager, $view, $this->user, @@ -107,16 +115,16 @@ 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 + * @var Storage $storage */ $storage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor() ->getMock(); $view = $this->getRootViewMock(); - $root = new \OC\Files\Node\Root( + $root = new Root( $this->manager, $view, $this->user, @@ -138,10 +146,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 +165,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 +183,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 +222,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..52d2b9e8657 100644 --- a/tests/lib/Files/ObjectStore/AzureTest.php +++ b/tests/lib/Files/ObjectStore/AzureTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,13 +8,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/FailDeleteObjectStore.php b/tests/lib/Files/ObjectStore/FailDeleteObjectStore.php index b84ee1a1b64..767125d42aa 100644 --- a/tests/lib/Files/ObjectStore/FailDeleteObjectStore.php +++ b/tests/lib/Files/ObjectStore/FailDeleteObjectStore.php @@ -11,10 +11,9 @@ namespace Test\Files\ObjectStore; use OCP\Files\ObjectStore\IObjectStore; class FailDeleteObjectStore implements IObjectStore { - private $objectStore; - - public function __construct(IObjectStore $objectStore) { - $this->objectStore = $objectStore; + public function __construct( + private IObjectStore $objectStore, + ) { } public function getStorageId() { diff --git a/tests/lib/Files/ObjectStore/FailWriteObjectStore.php b/tests/lib/Files/ObjectStore/FailWriteObjectStore.php index b84b123244e..924bbdada4f 100644 --- a/tests/lib/Files/ObjectStore/FailWriteObjectStore.php +++ b/tests/lib/Files/ObjectStore/FailWriteObjectStore.php @@ -11,10 +11,9 @@ namespace Test\Files\ObjectStore; use OCP\Files\ObjectStore\IObjectStore; class FailWriteObjectStore implements IObjectStore { - private $objectStore; - - public function __construct(IObjectStore $objectStore) { - $this->objectStore = $objectStore; + public function __construct( + private IObjectStore $objectStore, + ) { } public function getStorageId() { diff --git a/tests/lib/Files/ObjectStore/LocalTest.php b/tests/lib/Files/ObjectStore/LocalTest.php index 3b561c01049..d3e9ad56164 100644 --- a/tests/lib/Files/ObjectStore/LocalTest.php +++ b/tests/lib/Files/ObjectStore/LocalTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -8,10 +9,11 @@ namespace Test\Files\ObjectStore; use OC\Files\ObjectStore\StorageObjectStore; use OC\Files\Storage\Temporary; +use OCP\Files\ObjectStore\IObjectStore; class LocalTest extends ObjectStoreTestCase { /** - * @return \OCP\Files\ObjectStore\IObjectStore + * @return IObjectStore */ protected function getInstance() { $storage = new Temporary(); diff --git a/tests/lib/Files/ObjectStore/MapperTest.php b/tests/lib/Files/ObjectStore/MapperTest.php index 77416eae09a..6448d5ce1f5 100644 --- a/tests/lib/Files/ObjectStore/MapperTest.php +++ b/tests/lib/Files/ObjectStore/MapperTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -42,11 +43,11 @@ class MapperTest extends \Test\TestCase { } /** - * @dataProvider dataGetBucket * @param string $username * @param int $numBuckets * @param string $expectedBucket */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetBucket')] public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void { $this->user->expects($this->once()) ->method('getUID') diff --git a/tests/lib/Files/ObjectStore/ObjectStoreScannerTest.php b/tests/lib/Files/ObjectStore/ObjectStoreScannerTest.php index 11c913cd232..ea6ac682c70 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreScannerTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreScannerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php index 3dbdc3afc27..3387808445a 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,6 +11,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; @@ -71,9 +73,7 @@ class ObjectStoreStorageTest extends Storage { $this->markTestSkipped('Detecting external changes is not supported on object storages'); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testMove($source, $target): void { $this->initSourceAndTarget($source); $sourceId = $this->instance->getCache()->getId(ltrim($source, '/')); @@ -231,13 +231,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,12 +254,25 @@ 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 { + $cache = $this->instance->getCache(); + + $this->instance->mkdir('source'); + $this->instance->file_put_contents('source/test.txt', 'foo'); + $this->instance->getUpdater()->update('source/test.txt'); + $this->assertEquals(3, $cache->get('source')->getSize()); + + $this->assertTrue($this->instance->copy('source', 'target')); + + $this->assertEquals(3, $cache->get('target')->getSize()); } } diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php index a1befd4e79d..d39426ee821 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,6 +10,7 @@ namespace Test\Files\ObjectStore; use OC\Files\ObjectStore\StorageObjectStore; use OC\Files\Storage\Temporary; +use OCP\Files\ObjectStore\IObjectStore; use Test\Files\Storage\StoragesTestCase; /** @@ -16,12 +18,12 @@ use Test\Files\Storage\StoragesTestCase; */ class ObjectStoreStoragesDifferentBucketTest extends StoragesTestCase { /** - * @var \OCP\Files\ObjectStore\IObjectStore + * @var IObjectStore */ private $objectStore1; /** - * @var \OCP\Files\ObjectStore\IObjectStore + * @var IObjectStore */ private $objectStore2; diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php index 5505ee1dac1..4e42668cd3f 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,6 +10,7 @@ namespace Test\Files\ObjectStore; use OC\Files\ObjectStore\StorageObjectStore; use OC\Files\Storage\Temporary; +use OCP\Files\ObjectStore\IObjectStore; use Test\Files\Storage\StoragesTestCase; /** @@ -16,7 +18,7 @@ use Test\Files\Storage\StoragesTestCase; */ class ObjectStoreStoragesSameBucketTest extends StoragesTestCase { /** - * @var \OCP\Files\ObjectStore\IObjectStore + * @var IObjectStore */ private $objectStore; diff --git a/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php index ecbfd9a37e6..03e7b9545e0 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php @@ -7,6 +7,7 @@ namespace Test\Files\ObjectStore; +use OCP\Files\ObjectStore\IObjectStore; use Test\TestCase; abstract class ObjectStoreTestCase extends TestCase { @@ -16,7 +17,7 @@ abstract class ObjectStoreTestCase extends TestCase { private $instance = null; /** - * @return \OCP\Files\ObjectStore\IObjectStore + * @return IObjectStore */ abstract protected function getInstance(); diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php index 76fc80c975f..2915ada0aab 100644 --- a/tests/lib/Files/ObjectStore/S3Test.php +++ b/tests/lib/Files/ObjectStore/S3Test.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -8,6 +9,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 +55,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'); } @@ -132,7 +135,7 @@ class S3Test extends ObjectStoreTestCase { ]; } - /** @dataProvider dataFileSizes */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataFileSizes')] public function testFileSizes($size): void { if (str_starts_with(PHP_VERSION, '8.3') && getenv('CI')) { $this->markTestSkipped('Test is unreliable and skipped on 8.3'); diff --git a/tests/lib/Files/ObjectStore/SwiftTest.php b/tests/lib/Files/ObjectStore/SwiftTest.php index 9fb8c9bb68e..3f919c0dd48 100644 --- a/tests/lib/Files/ObjectStore/SwiftTest.php +++ b/tests/lib/Files/ObjectStore/SwiftTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,16 +9,19 @@ namespace Test\Files\ObjectStore; use OC\Files\ObjectStore\Swift; +use OCP\Files\ObjectStore\IObjectStore; +use OCP\IConfig; +use OCP\Server; /** * @group PRIMARY-swift */ class SwiftTest extends ObjectStoreTestCase { /** - * @return \OCP\Files\ObjectStore\IObjectStore + * @return 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..e13dbe4f207 100644 --- a/tests/lib/Files/PathVerificationTest.php +++ b/tests/lib/Files/PathVerificationTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,6 +11,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 @@ -20,7 +23,7 @@ use OCP\Files\InvalidPathException; */ class PathVerificationTest extends \Test\TestCase { /** - * @var \OC\Files\View + * @var View */ private $view; @@ -31,7 +34,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); @@ -39,11 +42,9 @@ class PathVerificationTest extends \Test\TestCase { } - /** - * @dataProvider providesEmptyFiles - */ + #[\PHPUnit\Framework\Attributes\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); @@ -56,11 +57,9 @@ class PathVerificationTest extends \Test\TestCase { ]; } - /** - * @dataProvider providesDotFiles - */ + #[\PHPUnit\Framework\Attributes\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); @@ -79,11 +78,9 @@ class PathVerificationTest extends \Test\TestCase { ]; } - /** - * @dataProvider providesAstralPlane - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesAstralPlane')] public function testPathVerificationAstralPlane($fileName): void { - $connection = \OC::$server->getDatabaseConnection(); + $connection = Server::get(IDBConnection::class); if (!$connection->supports4ByteText()) { $this->expectException(InvalidPathException::class); @@ -106,9 +103,7 @@ class PathVerificationTest extends \Test\TestCase { ]; } - /** - * @dataProvider providesValidPosixPaths - */ + #[\PHPUnit\Framework\Attributes\DataProvider('providesValidPosixPaths')] public function testPathVerificationValidPaths($fileName): void { $storage = new Local(['datadir' => '']); diff --git a/tests/lib/Files/Search/QueryOptimizer/CombinedTests.php b/tests/lib/Files/Search/QueryOptimizer/CombinedTests.php index e6cb11a7eba..665224cb63e 100644 --- a/tests/lib/Files/Search/QueryOptimizer/CombinedTests.php +++ b/tests/lib/Files/Search/QueryOptimizer/CombinedTests.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Search/QueryOptimizer/FlattenNestedBoolTest.php b/tests/lib/Files/Search/QueryOptimizer/FlattenNestedBoolTest.php index 6777047d68b..1d43541a5a0 100644 --- a/tests/lib/Files/Search/QueryOptimizer/FlattenNestedBoolTest.php +++ b/tests/lib/Files/Search/QueryOptimizer/FlattenNestedBoolTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Search/QueryOptimizer/MergeDistributiveOperationsTest.php b/tests/lib/Files/Search/QueryOptimizer/MergeDistributiveOperationsTest.php index 4f933d0c371..9aaa7030aac 100644 --- a/tests/lib/Files/Search/QueryOptimizer/MergeDistributiveOperationsTest.php +++ b/tests/lib/Files/Search/QueryOptimizer/MergeDistributiveOperationsTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Search/QueryOptimizer/OrEqualsToInTest.php b/tests/lib/Files/Search/QueryOptimizer/OrEqualsToInTest.php index 8b1c3b992b2..d51fe3d0d16 100644 --- a/tests/lib/Files/Search/QueryOptimizer/OrEqualsToInTest.php +++ b/tests/lib/Files/Search/QueryOptimizer/OrEqualsToInTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Search/SearchIntegrationTest.php b/tests/lib/Files/Search/SearchIntegrationTest.php index 0ca67285fd5..e3e99bbfadd 100644 --- a/tests/lib/Files/Search/SearchIntegrationTest.php +++ b/tests/lib/Files/Search/SearchIntegrationTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/SimpleFS/SimpleFileTest.php b/tests/lib/Files/SimpleFS/SimpleFileTest.php index d0676eae70f..6ce5ddad351 100644 --- a/tests/lib/Files/SimpleFS/SimpleFileTest.php +++ b/tests/lib/Files/SimpleFS/SimpleFileTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/SimpleFS/SimpleFolderTest.php b/tests/lib/Files/SimpleFS/SimpleFolderTest.php index 6897aab1f02..50038b286a9 100644 --- a/tests/lib/Files/SimpleFS/SimpleFolderTest.php +++ b/tests/lib/Files/SimpleFS/SimpleFolderTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Storage/CommonTest.php b/tests/lib/Files/Storage/CommonTest.php index 529615f3733..c5ff6bb0b5f 100644 --- a/tests/lib/Files/Storage/CommonTest.php +++ b/tests/lib/Files/Storage/CommonTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -14,6 +15,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 +35,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..b593b7c984f 100644 --- a/tests/lib/Files/Storage/CopyDirectoryTest.php +++ b/tests/lib/Files/Storage/CopyDirectoryTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,7 @@ namespace Test\Files\Storage; +use OC\Files\Storage\PolyFill\CopyDirectory; use OC\Files\Storage\Temporary; class StorageNoRecursiveCopy extends Temporary { @@ -19,7 +21,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..84a9816cb0c 100644 --- a/tests/lib/Files/Storage/HomeTest.php +++ b/tests/lib/Files/Storage/HomeTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,21 +8,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() { @@ -49,17 +50,17 @@ class HomeTest extends Storage { private $userId; /** - * @var \OC\User\User $user + * @var User $user */ private $user; 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..89449a51351 100644 --- a/tests/lib/Files/Storage/LocalTest.php +++ b/tests/lib/Files/Storage/LocalTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,8 +8,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 +32,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 +61,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 +83,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 +97,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 +135,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 c6f051fb7e1..51bb5b7c8ad 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,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; @@ -49,9 +51,7 @@ abstract class Storage extends \Test\TestCase { $this->assertTrue($this->instance->test()); } - /** - * @dataProvider directoryProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('directoryProvider')] public function testDirectories($directory): void { $this->assertFalse($this->instance->file_exists('/' . $directory)); @@ -142,9 +142,8 @@ abstract class Storage extends \Test\TestCase { /** * test the various uses of file_get_contents and file_put_contents - * - * @dataProvider loremFileProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('loremFileProvider')] public function testGetPutContents($sourceFile): void { $sourceText = file_get_contents($sourceFile); @@ -210,9 +209,7 @@ abstract class Storage extends \Test\TestCase { ); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testCopy($source, $target): void { $this->initSourceAndTarget($source); @@ -223,9 +220,7 @@ abstract class Storage extends \Test\TestCase { $this->assertTrue($this->instance->file_exists($source), $source . ' was deleted'); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testMove($source, $target): void { $this->initSourceAndTarget($source); @@ -237,9 +232,7 @@ abstract class Storage extends \Test\TestCase { $this->assertSameAsLorem($target); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testCopyOverwrite($source, $target): void { $this->initSourceAndTarget($source, $target); @@ -251,9 +244,7 @@ abstract class Storage extends \Test\TestCase { $this->assertSameAsLorem($source); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testMoveOverwrite($source, $target): void { $this->initSourceAndTarget($source, $target); @@ -327,7 +318,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'; @@ -350,9 +341,7 @@ abstract class Storage extends \Test\TestCase { $this->assertFalse($this->instance->file_exists('/lorem.txt')); } - /** - * @dataProvider fileNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('fileNameProvider')] public function testFOpen($fileName): void { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; @@ -422,9 +411,7 @@ abstract class Storage extends \Test\TestCase { ]; } - /** - * @dataProvider hashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('hashProvider')] public function testHash($data, $type): void { $this->instance->file_put_contents('hash.txt', $data); $this->assertEquals(hash($type, $data), $this->instance->hash($type, 'hash.txt')); @@ -557,7 +544,7 @@ abstract class Storage extends \Test\TestCase { $this->instance->copy('source', 'target'); - $this->assertFalse($this->instance->file_exists('target/test2.txt')); + $this->assertFalse($this->instance->file_exists('target/test2.txt'), 'File target/test2.txt should no longer exist, but does'); $this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt')); } @@ -578,9 +565,7 @@ abstract class Storage extends \Test\TestCase { $this->assertFalse($this->instance->instanceOfStorage('\OC')); } - /** - * @dataProvider copyAndMoveProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')] public function testCopyFromSameStorage($source, $target): void { $this->initSourceAndTarget($source); diff --git a/tests/lib/Files/Storage/StorageFactoryTest.php b/tests/lib/Files/Storage/StorageFactoryTest.php index 83e8a7bf6eb..0bb9cbf5824 100644 --- a/tests/lib/Files/Storage/StorageFactoryTest.php +++ b/tests/lib/Files/Storage/StorageFactoryTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,6 +9,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 +28,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 +41,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 +52,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/StoragesTestCase.php b/tests/lib/Files/Storage/StoragesTestCase.php index 18fe78a93d1..565ff1ddfda 100644 --- a/tests/lib/Files/Storage/StoragesTestCase.php +++ b/tests/lib/Files/Storage/StoragesTestCase.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,16 +8,17 @@ namespace Test\Files\Storage; +use OC\Files\Storage\Storage; use Test\TestCase; abstract class StoragesTestCase extends TestCase { /** - * @var \OC\Files\Storage\Storage + * @var Storage */ protected $storage1; /** - * @var \OC\Files\Storage\Storage + * @var Storage */ protected $storage2; diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php index 29277772358..d890081cbb6 100644 --- a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php +++ b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -53,7 +54,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 +83,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 +98,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 +107,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 +149,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..cb6b6de0fb7 100644 --- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,19 +8,22 @@ 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'; /** - * @var \OC\Files\Storage\Temporary + * @var Temporary */ private $sourceStorage; 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 ]); } @@ -54,17 +58,13 @@ class EncodingTest extends \Test\Files\Storage\Storage { ]; } - /** - * @dataProvider accessNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')] public function testFputEncoding($accessName): void { $this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar'); $this->assertEquals('bar', $this->instance->file_get_contents($accessName)); } - /** - * @dataProvider accessNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')] public function testFopenReadEncoding($accessName): void { $this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar'); $fh = $this->instance->fopen($accessName, 'r'); @@ -73,9 +73,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { $this->assertEquals('bar', $data); } - /** - * @dataProvider accessNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')] public function testFopenOverwriteEncoding($accessName): void { $this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar'); $fh = $this->instance->fopen($accessName, 'w'); @@ -86,17 +84,13 @@ class EncodingTest extends \Test\Files\Storage\Storage { $this->assertFalse($this->sourceStorage->file_exists(self::NFC_NAME)); } - /** - * @dataProvider accessNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')] public function testFileExistsEncoding($accessName): void { $this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar'); $this->assertTrue($this->instance->file_exists($accessName)); } - /** - * @dataProvider accessNameProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('accessNameProvider')] public function testUnlinkEncoding($accessName): void { $this->sourceStorage->file_put_contents(self::NFD_NAME, 'bar'); $this->assertTrue($this->instance->unlink($accessName)); @@ -118,9 +112,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { ]; } - /** - * @dataProvider encodedDirectoriesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('encodedDirectoriesProvider')] public function testOperationInsideDirectory($sourceDir, $accessDir): void { $this->sourceStorage->mkdir($sourceDir); $this->instance->file_put_contents($accessDir . '/test.txt', 'bar'); @@ -159,9 +151,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { ]; } - /** - * @dataProvider sourceAndTargetDirectoryProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')] public function testCopyAndMoveEncodedFolder($sourceDir, $targetDir): void { $this->sourceStorage->mkdir($sourceDir); $this->sourceStorage->mkdir($targetDir); @@ -179,9 +169,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { $this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt')); } - /** - * @dataProvider sourceAndTargetDirectoryProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')] public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir): void { $this->sourceStorage->mkdir($sourceDir); $this->sourceStorage->mkdir($targetDir); diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index 1c299fa989f..3e643714300 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -8,7 +9,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 +28,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; @@ -192,7 +194,6 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestGetMetaData * * @param string $path * @param array $metaData @@ -201,6 +202,7 @@ class EncryptionTest extends Storage { * @param int $storedUnencryptedSize * @param array $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetMetaData')] public function testGetMetaData($path, $metaData, $encrypted, $unencryptedSizeSet, $storedUnencryptedSize, $expected): void { $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); @@ -326,13 +328,13 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestVerifyUnencryptedSize * * @param int $encryptedSize * @param int $unencryptedSize * @param bool $failure * @param int $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestVerifyUnencryptedSize')] public function testVerifyUnencryptedSize($encryptedSize, $unencryptedSize, $failure, $expected): void { $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); @@ -389,13 +391,13 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestCopyAndRename * * @param string $source * @param string $target * @param $encryptionEnabled * @param boolean $renameKeysReturn */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCopyAndRename')] public function testRename($source, $target, $encryptionEnabled, @@ -451,13 +453,13 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestRmdir * * @param string $path * @param boolean $rmdirResult * @param boolean $isExcluded * @param boolean $encryptionEnabled */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRmdir')] public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled): void { $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); @@ -509,11 +511,11 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestCopyKeys * * @param boolean $excluded * @param boolean $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCopyKeys')] public function testCopyKeys($excluded, $expected): void { $this->util->expects($this->once()) ->method('isExcluded') @@ -538,12 +540,12 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestGetHeader * * @param string $path * @param bool $strippedPathExists * @param string $strippedPath */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetHeader')] public function testGetHeader($path, $strippedPathExists, $strippedPath): void { $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') ->disableOriginalConstructor()->getMock(); @@ -630,9 +632,8 @@ class EncryptionTest extends Storage { /** * test if getHeader adds the default module correctly to the header for * legacy files - * - * @dataProvider dataTestGetHeaderAddLegacyModule */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetHeaderAddLegacyModule')] public function testGetHeaderAddLegacyModule($header, $isEncrypted, $strippedPathExists, $expected): void { $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); @@ -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') @@ -760,12 +761,12 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataCopyBetweenStorage * * @param bool $encryptionEnabled * @param bool $mountPointEncryptionEnabled * @param bool $expectedEncrypted */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataCopyBetweenStorage')] public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted): void { $storage2 = $this->createMock(\OC\Files\Storage\Storage::class); @@ -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') @@ -820,13 +821,13 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestCopyBetweenStorageVersions * * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $copyResult * @param bool $encrypted */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCopyBetweenStorageVersions')] public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted): void { $sourceStorage = $this->createMock(\OC\Files\Storage\Storage::class); @@ -914,10 +915,10 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestIsVersion * @param string $path * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestIsVersion')] public function testIsVersion($path, $expected): void { $this->assertSame($expected, $this->invokePrivate($this->instance, 'isVersion', [$path]) @@ -936,13 +937,13 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestShouldEncrypt * * @param bool $encryptMountPoint * @param mixed $encryptionModule * @param bool $encryptionModuleShouldEncrypt * @param bool $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestShouldEncrypt')] public function testShouldEncrypt( $encryptMountPoint, $encryptionModule, diff --git a/tests/lib/Files/Storage/Wrapper/JailTest.php b/tests/lib/Files/Storage/Wrapper/JailTest.php index fbc4e1d09ee..0043e37ba33 100644 --- a/tests/lib/Files/Storage/Wrapper/JailTest.php +++ b/tests/lib/Files/Storage/Wrapper/JailTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,17 +8,21 @@ 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 + * @var Temporary */ private $sourceStorage; 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 +33,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/KnownMtimeTest.php b/tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php index bbeb48c5cef..b1b5582b4ed 100644 --- a/tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php +++ b/tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php index 5c0a035d094..a2f3460c58c 100644 --- a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php +++ b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,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; @@ -16,13 +19,13 @@ use OCP\Files\Cache\IScanner; */ class PermissionsMaskTest extends \Test\Files\Storage\Storage { /** - * @var \OC\Files\Storage\Temporary + * @var Temporary */ private $sourceStorage; 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 +35,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 +130,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 +152,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 +170,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 791e8047f7f..2878fe6ca92 100644 --- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php +++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,9 +11,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; - -\OC::$loader->load('\OC\Files\Filesystem'); +use OCP\ITempManager; +use OCP\Server; /** * Class QuotaTest @@ -30,9 +32,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 { @@ -44,10 +46,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 { @@ -85,7 +87,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] ); @@ -140,7 +142,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')); } @@ -198,7 +200,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..60f139450c7 100644 --- a/tests/lib/Files/Storage/Wrapper/WrapperTest.php +++ b/tests/lib/Files/Storage/Wrapper/WrapperTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,7 +8,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 +23,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..89904e6de73 100644 --- a/tests/lib/Files/Stream/DummyEncryptionWrapper.php +++ b/tests/lib/Files/Stream/DummyEncryptionWrapper.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,7 +8,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/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php index c676358ad71..62eaab3cc7e 100644 --- a/tests/lib/Files/Stream/EncryptionTest.php +++ b/tests/lib/Files/Stream/EncryptionTest.php @@ -101,9 +101,7 @@ class EncryptionTest extends \Test\TestCase { ); } - /** - * @dataProvider dataProviderStreamOpen() - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataProviderStreamOpen')] public function testStreamOpen( $isMasterKeyUsed, $mode, @@ -277,9 +275,7 @@ class EncryptionTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataFilesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilesProvider')] public function testWriteReadBigFile($testFile): void { $expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile); // write it @@ -314,9 +310,8 @@ class EncryptionTest extends \Test\TestCase { /** * simulate a non-seekable storage - * - * @dataProvider dataFilesProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataFilesProvider')] public function testWriteToNonSeekableStorage($testFile): void { $wrapper = $this->getMockBuilder(Encryption::class) ->onlyMethods(['parentStreamSeek']) diff --git a/tests/lib/Files/Stream/HashWrapperTest.php b/tests/lib/Files/Stream/HashWrapperTest.php index 1e9bbd8f289..459bc5c4318 100644 --- a/tests/lib/Files/Stream/HashWrapperTest.php +++ b/tests/lib/Files/Stream/HashWrapperTest.php @@ -12,9 +12,7 @@ use OC\Files\Stream\HashWrapper; use Test\TestCase; class HashWrapperTest extends TestCase { - /** - * @dataProvider hashProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('hashProvider')] public function testHashStream($data, string $algo, string $hash): void { if (!is_resource($data)) { $tmpData = fopen('php://temp', 'r+'); @@ -25,7 +23,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..4248d14f5a1 100644 --- a/tests/lib/Files/Stream/QuotaTest.php +++ b/tests/lib/Files/Stream/QuotaTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,8 @@ namespace Test\Files\Stream; +use OC\Files\Stream\Quota; + class QuotaTest extends \Test\TestCase { /** * @param string $mode @@ -15,7 +18,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 +63,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 +72,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..c30b21de401 100644 --- a/tests/lib/Files/Type/DetectionTest.php +++ b/tests/lib/Files/Type/DetectionTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,6 +10,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 +20,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/' ); @@ -45,11 +47,11 @@ class DetectionTest extends \Test\TestCase { } /** - * @dataProvider dataDetectPath * * @param string $path * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataDetectPath')] public function testDetectPath(string $path, string $expected): void { $this->assertEquals($expected, $this->detection->detectPath($path)); } @@ -65,11 +67,11 @@ class DetectionTest extends \Test\TestCase { } /** - * @dataProvider dataDetectContent * * @param string $path * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataDetectContent')] public function testDetectContent(string $path, string $expected): void { $this->assertEquals($expected, $this->detection->detectContent(\OC::$SERVERROOT . '/tests/data' . $path)); } @@ -85,11 +87,11 @@ class DetectionTest extends \Test\TestCase { } /** - * @dataProvider dataDetect * * @param string $path * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataDetect')] public function testDetect(string $path, string $expected): void { $this->assertEquals($expected, $this->detection->detect(\OC::$SERVERROOT . '/tests/data' . $path)); } @@ -109,11 +111,11 @@ class DetectionTest extends \Test\TestCase { } /** - * @dataProvider dataMimeTypeCustom * * @param string $ext * @param string $mime */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataMimeTypeCustom')] public function testDetectMimeTypeCustom(string $ext, string $mime): void { $confDir = sys_get_temp_dir(); file_put_contents($confDir . '/mimetypemapping.dist.json', json_encode([])); @@ -143,11 +145,11 @@ class DetectionTest extends \Test\TestCase { } /** - * @dataProvider dataGetSecureMimeType * * @param string $mimeType * @param string $expected */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetSecureMimeType')] public function testGetSecureMimeType(string $mimeType, string $expected): void { $this->assertEquals($expected, $this->detection->getSecureMimeType($mimeType)); } diff --git a/tests/lib/Files/Type/LoaderTest.php b/tests/lib/Files/Type/LoaderTest.php index 6eaf6ac2013..44745a50dc0 100644 --- a/tests/lib/Files/Type/LoaderTest.php +++ b/tests/lib/Files/Type/LoaderTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -9,6 +10,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 +18,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..49399ef70a6 100644 --- a/tests/lib/Files/Utils/ScannerTest.php +++ b/tests/lib/Files/Utils/ScannerTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -10,20 +11,25 @@ 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 + * @var MountPoint[] $mounts */ private $mounts = []; /** - * @param \OC\Files\Mount\MountPoint $mount + * @param MountPoint $mount */ public function addMount($mount) { $this->mounts[] = $mount; @@ -51,13 +57,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 +77,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 +99,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 +130,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'); @@ -153,14 +159,14 @@ class ScannerTest extends \Test\TestCase { } /** - * @dataProvider invalidPathProvider * @param string $invalidPath */ + #[\PHPUnit\Framework\Attributes\DataProvider('invalidPathProvider')] public function testInvalidPathScanning($invalidPath): void { $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 +180,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 +206,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..c490cd08dae 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,6 +8,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 +22,21 @@ 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\IGroup; +use OCP\IGroupManager; +use OCP\ITempManager; +use OCP\IUser; use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -87,7 +97,7 @@ class ViewTest extends \Test\TestCase { use UserTrait; /** - * @var \OC\Files\Storage\Storage[] $storages + * @var Storage[] $storages */ private $storages = []; @@ -97,16 +107,16 @@ class ViewTest extends \Test\TestCase { private $user; /** - * @var \OCP\IUser + * @var IUser */ private $userObject; /** - * @var \OCP\IGroup + * @var IGroup */ private $groupObject; - /** @var \OC\Files\Storage\Storage */ + /** @var Storage */ private $tempStorage; protected function setUp(): void { @@ -117,8 +127,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 +138,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 +159,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 +285,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, [], '/'); @@ -310,14 +320,12 @@ class ViewTest extends \Test\TestCase { ]; } - /** - * @dataProvider sharingDisabledPermissionProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('sharingDisabledPermissionProvider')] 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 +348,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 { @@ -559,9 +567,7 @@ class ViewTest extends \Test\TestCase { return [['rmdir'], ['unlink']]; } - /** - * @dataProvider rmdirOrUnlinkDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('rmdirOrUnlinkDataProvider')] public function testRmdir($method): void { $storage1 = $this->getTestStorage(); Filesystem::mount($storage1, [], '/'); @@ -682,11 +688,11 @@ class ViewTest extends \Test\TestCase { /** * @param bool $scan * @param string $class - * @return \OC\Files\Storage\Storage + * @return Storage */ private function getTestStorage($scan = true, $class = Temporary::class) { /** - * @var \OC\Files\Storage\Storage $storage + * @var Storage $storage */ $storage = new $class([]); $textData = "dummy file data\n"; @@ -768,9 +774,7 @@ class ViewTest extends \Test\TestCase { \OC_Hook::clear('OC_Filesystem', 'post_write'); } - /** - * @dataProvider resolvePathTestProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('resolvePathTestProvider')] public function testResolvePath($expected, $pathToTest): void { $storage1 = $this->getTestStorage(); Filesystem::mount($storage1, [], '/'); @@ -845,7 +849,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 +896,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']); @@ -930,9 +934,7 @@ class ViewTest extends \Test\TestCase { $this->assertNotEquals($newFolderInfo->getEtag(), $oldEtag); } - /** - * @dataProvider absolutePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('absolutePathProvider')] public function testGetAbsolutePath($expectedPath, $relativePath): void { $view = new View('/files'); $this->assertEquals($expectedPath, $view->getAbsolutePath($relativePath)); @@ -966,9 +968,7 @@ class ViewTest extends \Test\TestCase { ]; } - /** - * @dataProvider chrootRelativePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('chrootRelativePathProvider')] public function testChrootGetRelativePath($root, $absolutePath, $expectedPath): void { $view = new View('/files'); $view->chroot($root); @@ -979,9 +979,7 @@ class ViewTest extends \Test\TestCase { return self::relativePathProvider('/'); } - /** - * @dataProvider initRelativePathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('initRelativePathProvider')] public function testInitGetRelativePath($root, $absolutePath, $expectedPath): void { $view = new View($root); $this->assertEquals($expectedPath, $view->getRelativePath($absolutePath)); @@ -1078,11 +1076,9 @@ class ViewTest extends \Test\TestCase { $this->assertEquals('foo', $view->file_get_contents('')); } - /** - * @dataProvider tooLongPathDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('tooLongPathDataProvider')] public function testTooLongPath($operation, $param0 = null): void { - $this->expectException(\OCP\Files\InvalidPathException::class); + $this->expectException(InvalidPathException::class); $longPath = ''; @@ -1266,9 +1262,9 @@ class ViewTest extends \Test\TestCase { } /** - * @dataProvider directoryTraversalProvider * @param string $root */ + #[\PHPUnit\Framework\Attributes\DataProvider('directoryTraversalProvider')] public function testConstructDirectoryTraversalException($root): void { $this->expectException(\Exception::class); @@ -1291,7 +1287,7 @@ class ViewTest extends \Test\TestCase { public function testSetMountOptionsInStorage(): void { $mount = new MountPoint(Temporary::class, '/asd/', [[]], Filesystem::getLoader(), ['foo' => 'bar']); Filesystem::getMountManager()->addMount($mount); - /** @var \OC\Files\Storage\Common $storage */ + /** @var Common $storage */ $storage = $mount->getStorage(); $this->assertEquals($storage->getMountOption('foo'), 'bar'); } @@ -1299,7 +1295,7 @@ class ViewTest extends \Test\TestCase { public function testSetMountOptionsWatcherPolicy(): void { $mount = new MountPoint(Temporary::class, '/asd/', [[]], Filesystem::getLoader(), ['filesystem_check_changes' => Watcher::CHECK_NEVER]); Filesystem::getMountManager()->addMount($mount); - /** @var \OC\Files\Storage\Common $storage */ + /** @var Common $storage */ $storage = $mount->getStorage(); $watcher = $storage->getWatcher(); $this->assertEquals(Watcher::CHECK_NEVER, $watcher->getPolicy()); @@ -1326,13 +1322,13 @@ class ViewTest extends \Test\TestCase { * e.g. reading from a folder that's being renamed * * - * @dataProvider dataLockPaths * * @param string $rootPath * @param string $pathPrefix */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataLockPaths')] 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); @@ -1347,11 +1343,11 @@ class ViewTest extends \Test\TestCase { /** * Reading from a files_encryption folder that's being renamed * - * @dataProvider dataLockPaths * * @param string $rootPath * @param string $pathPrefix */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataLockPaths')] public function testReadFromWriteUnlockablePath($rootPath, $pathPrefix): void { $rootPath = str_replace('{folder}', 'files_encryption', $rootPath); $pathPrefix = str_replace('{folder}', 'files_encryption', $pathPrefix); @@ -1367,13 +1363,13 @@ class ViewTest extends \Test\TestCase { * e.g. writing a file that's being downloaded * * - * @dataProvider dataLockPaths * * @param string $rootPath * @param string $pathPrefix */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataLockPaths')] 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); @@ -1388,11 +1384,11 @@ class ViewTest extends \Test\TestCase { /** * Writing a file that's being downloaded * - * @dataProvider dataLockPaths * * @param string $rootPath * @param string $pathPrefix */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataLockPaths')] public function testWriteToReadUnlockableFile($rootPath, $pathPrefix): void { $rootPath = str_replace('{folder}', 'files_encryption', $rootPath); $pathPrefix = str_replace('{folder}', 'files_encryption', $pathPrefix); @@ -1408,7 +1404,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 +1434,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 +1464,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, [], '/'); @@ -1515,9 +1511,7 @@ class ViewTest extends \Test\TestCase { ]; } - /** - * @dataProvider pathRelativeToFilesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('pathRelativeToFilesProvider')] public function testGetPathRelativeToFiles($path, $expectedPath): void { $view = new View(); $this->assertEquals($expectedPath, $view->getPathRelativeToFiles($path)); @@ -1534,9 +1528,9 @@ class ViewTest extends \Test\TestCase { } /** - * @dataProvider pathRelativeToFilesProviderExceptionCases * @param string $path */ + #[\PHPUnit\Framework\Attributes\DataProvider('pathRelativeToFilesProviderExceptionCases')] public function testGetPathRelativeToFilesWithInvalidArgument($path): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('$absolutePath must be relative to "files"'); @@ -1579,11 +1573,11 @@ class ViewTest extends \Test\TestCase { } /** - * @dataProvider hookPathProvider * @param $root * @param $path * @param $shouldEmit */ + #[\PHPUnit\Framework\Attributes\DataProvider('hookPathProvider')] public function testHookPaths($root, $path, $shouldEmit): void { $filesystemReflection = new \ReflectionClass(Filesystem::class); $defaultRootValue = $filesystemReflection->getProperty('defaultInstance'); @@ -1611,7 +1605,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 +1620,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 +1717,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); @@ -1918,7 +1912,6 @@ class ViewTest extends \Test\TestCase { /** * Test whether locks are set before and after the operation * - * @dataProvider basicOperationProviderForLocks * * @param string $operation operation name on the view * @param array $operationArgs arguments for the operation @@ -1930,6 +1923,7 @@ class ViewTest extends \Test\TestCase { * @param int $expectedStrayLock expected lock after returning, should * be null (unlock) for most operations */ + #[\PHPUnit\Framework\Attributes\DataProvider('basicOperationProviderForLocks')] public function testLockBasicOperation( $operation, $operationArgs, @@ -2079,12 +2073,12 @@ class ViewTest extends \Test\TestCase { /** * Test locks for fopen with fclose at the end * - * @dataProvider basicOperationProviderForLocks * * @param string $operation operation name on the view * @param array $operationArgs arguments for the operation * @param string $path path of the locked item to check */ + #[\PHPUnit\Framework\Attributes\DataProvider('basicOperationProviderForLocks')] public function testLockBasicOperationUnlocksAfterException( $operation, $operationArgs, @@ -2117,7 +2111,7 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method($operation) ->willReturnCallback( - function () { + function (): void { throw new \Exception('Simulated exception'); } ); @@ -2170,13 +2164,13 @@ class ViewTest extends \Test\TestCase { /** * Test locks for fopen with fclose at the end * - * @dataProvider basicOperationProviderForLocks * * @param string $operation operation name on the view * @param array $operationArgs arguments for the operation * @param string $path path of the locked item to check * @param string $hookType hook type */ + #[\PHPUnit\Framework\Attributes\DataProvider('basicOperationProviderForLocks')] public function testLockBasicOperationUnlocksAfterCancelledHook( $operation, $operationArgs, @@ -2215,12 +2209,12 @@ class ViewTest extends \Test\TestCase { /** * Test locks for rename or copy operation * - * @dataProvider lockFileRenameOrCopyDataProvider * * @param string $operation operation to be done on the view * @param int $expectedLockTypeSourceDuring expected lock type on source file during * the operation */ + #[\PHPUnit\Framework\Attributes\DataProvider('lockFileRenameOrCopyDataProvider')] public function testLockFileRename($operation, $expectedLockTypeSourceDuring): void { $view = new View('/' . $this->user . '/files/'); @@ -2231,13 +2225,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 +2305,7 @@ class ViewTest extends \Test\TestCase { $storage->expects($this->once()) ->method('copy') ->willReturnCallback( - function () { + function (): void { throw new \Exception(); } ); @@ -2405,13 +2399,13 @@ class ViewTest extends \Test\TestCase { /** * Test locks for rename or copy operation cross-storage * - * @dataProvider lockFileRenameOrCopyCrossStorageDataProvider * * @param string $viewOperation operation to be done on the view * @param string $storageOperation operation to be mocked on the storage * @param int $expectedLockTypeSourceDuring expected lock type on source file during * the operation */ + #[\PHPUnit\Framework\Attributes\DataProvider('lockFileRenameOrCopyCrossStorageDataProvider')] public function testLockFileRenameCrossStorage($viewOperation, $storageOperation, $expectedLockTypeSourceDuring): void { $view = new View('/' . $this->user . '/files/'); @@ -2426,13 +2420,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 +2560,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); } ); @@ -2673,8 +2667,8 @@ class ViewTest extends \Test\TestCase { /** * @param string $filter * @param string[] $expected - * @dataProvider mimeFilterProvider */ + #[\PHPUnit\Framework\Attributes\DataProvider('mimeFilterProvider')] public function testGetDirectoryContentMimeFilter($filter, $expected): void { $storage1 = new Temporary(); $root = self::getUniqueID('/'); @@ -2794,7 +2788,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); }); |