diff options
Diffstat (limited to 'tests/lib/Files/Storage')
-rw-r--r-- | tests/lib/Files/Storage/CommonTest.php | 7 | ||||
-rw-r--r-- | tests/lib/Files/Storage/CopyDirectoryTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Storage/HomeTest.php | 24 | ||||
-rw-r--r-- | tests/lib/Files/Storage/LocalTest.php | 29 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Storage.php | 51 | ||||
-rw-r--r-- | tests/lib/Files/Storage/StorageFactoryTest.php | 8 | ||||
-rw-r--r-- | tests/lib/Files/Storage/StoragesTestCase.php (renamed from tests/lib/Files/Storage/StoragesTest.php) | 8 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/AvailabilityTest.php | 11 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/EncodingTest.php | 54 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/EncryptionTest.php | 112 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/JailTest.php | 13 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php | 1 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php | 15 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/QuotaTest.php | 29 | ||||
-rw-r--r-- | tests/lib/Files/Storage/Wrapper/WrapperTest.php | 15 |
15 files changed, 188 insertions, 193 deletions
diff --git a/tests/lib/Files/Storage/CommonTest.php b/tests/lib/Files/Storage/CommonTest.php index b51b35be8f9..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. @@ -9,10 +10,12 @@ namespace Test\Files\Storage; use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Wrapper; +use OCP\Files; use OCP\Files\IFilenameValidator; use OCP\Files\InvalidCharacterInPathException; use OCP\Files\InvalidPathException; use OCP\ITempManager; +use OCP\Server; use PHPUnit\Framework\MockObject\MockObject; /** @@ -32,12 +35,12 @@ 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]); } protected function tearDown(): void { - \OC_Helper::rmdirr($this->tmpDir); + Files::rmdirr($this->tmpDir); $this->restoreService(IFilenameValidator::class); parent::tearDown(); } diff --git a/tests/lib/Files/Storage/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 b6d0f1aa85a..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,20 +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() { @@ -48,21 +50,21 @@ 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 { - \OC_Helper::rmdirr($this->tmpDir); + Files::rmdirr($this->tmpDir); parent::tearDown(); } diff --git a/tests/lib/Files/Storage/LocalTest.php b/tests/lib/Files/Storage/LocalTest.php index 65bc538ef17..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,7 +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 @@ -25,12 +32,12 @@ 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 { - \OC_Helper::rmdirr($this->tmpDir); + Files::rmdirr($this->tmpDir); parent::tearDown(); } @@ -54,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'; @@ -76,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'); } @@ -90,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); @@ -128,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 36d70965848..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)); @@ -108,7 +108,7 @@ abstract class Storage extends \Test\TestCase { $this->assertEquals([], $content); } - public function fileNameProvider() { + public static function fileNameProvider(): array { return [ ['file.txt'], [' file.txt'], @@ -119,7 +119,7 @@ abstract class Storage extends \Test\TestCase { ]; } - public function directoryProvider() { + public static function directoryProvider(): array { return [ ['folder'], [' folder'], @@ -130,7 +130,7 @@ abstract class Storage extends \Test\TestCase { ]; } - public function loremFileProvider() { + public static function loremFileProvider(): array { $root = \OC::$SERVERROOT . '/tests/data/'; return [ // small file @@ -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); @@ -179,7 +178,7 @@ abstract class Storage extends \Test\TestCase { } - public function copyAndMoveProvider() { + public static function copyAndMoveProvider(): array { return [ ['/source.txt', '/target.txt'], ['/source.txt', '/target with space.txt'], @@ -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'; @@ -414,7 +403,7 @@ abstract class Storage extends \Test\TestCase { $this->assertFalse($this->instance->file_exists('folder')); } - public function hashProvider() { + public static function hashProvider(): array { return [ ['Foobar', 'md5'], ['Foobar', 'sha1'], @@ -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/StoragesTest.php b/tests/lib/Files/Storage/StoragesTestCase.php index 3f8198d331d..565ff1ddfda 100644 --- a/tests/lib/Files/Storage/StoragesTest.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 StoragesTest extends 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 d8b03a891c2..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 ]); } @@ -29,42 +33,38 @@ class EncodingTest extends \Test\Files\Storage\Storage { parent::tearDown(); } - public function directoryProvider() { + public static function directoryProvider(): array { $a = parent::directoryProvider(); $a[] = [self::NFC_NAME]; return $a; } - public function fileNameProvider() { + public static function fileNameProvider(): array { $a = parent::fileNameProvider(); $a[] = [self::NFD_NAME . '.txt']; return $a; } - public function copyAndMoveProvider() { + public static function copyAndMoveProvider(): array { $a = parent::copyAndMoveProvider(); $a[] = [self::NFD_NAME . '.txt', self::NFC_NAME . '-renamed.txt']; return $a; } - public function accessNameProvider() { + public static function accessNameProvider(): array { return [ [self::NFD_NAME], [self::NFC_NAME], ]; } - /** - * @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)); @@ -110,7 +104,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { $this->assertEquals('nfc', $this->instance->file_get_contents(self::NFC_NAME)); } - public function encodedDirectoriesProvider() { + public static function encodedDirectoriesProvider(): array { return [ [self::NFD_NAME, self::NFC_NAME], [self::NFD_NAME . '/' . self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME], @@ -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'); @@ -150,7 +142,7 @@ class EncodingTest extends \Test\Files\Storage\Storage { $this->assertEquals('barbaric', $this->instance->file_get_contents('//' . self::NFC_NAME)); } - public function sourceAndTargetDirectoryProvider() { + public static function sourceAndTargetDirectoryProvider(): array { return [ [self::NFC_NAME . '1', self::NFC_NAME . '2'], [self::NFD_NAME . '1', self::NFC_NAME . '2'], @@ -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 bb3df36dec2..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,10 +9,8 @@ namespace Test\Files\Storage\Wrapper; use Exception; -use OC; use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Encryption\File; -use OC\Encryption\Update; use OC\Encryption\Util; use OC\Files\Cache\Cache; use OC\Files\Cache\CacheEntry; @@ -29,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; @@ -46,7 +47,6 @@ class EncryptionTest extends Storage { private Util&MockObject $util; private \OC\Encryption\Manager&MockObject $encryptionManager; private IEncryptionModule&MockObject $encryptionModule; - private Update&MockObject $update; private Cache&MockObject $cache; private LoggerInterface&MockObject $logger; private File&MockObject $file; @@ -62,9 +62,9 @@ class EncryptionTest extends Storage { parent::setUp(); $mockModule = $this->buildMockModule(); - $this->encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager') + $this->encryptionManager = $this->getMockBuilder(\OC\Encryption\Manager::class) ->disableOriginalConstructor() - ->setMethods(['getEncryptionModule', 'isEnabled']) + ->onlyMethods(['getEncryptionModule', 'isEnabled']) ->getMock(); $this->encryptionManager->expects($this->any()) ->method('getEncryptionModule') @@ -78,8 +78,8 @@ class EncryptionTest extends Storage { ->disableOriginalConstructor() ->getMock(); - $this->util = $this->getMockBuilder('\OC\Encryption\Util') - ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded', 'stripPartialFileExtension']) + $this->util = $this->getMockBuilder(Util::class) + ->onlyMethods(['getUidAndFilename', 'isFile', 'isExcluded', 'stripPartialFileExtension']) ->setConstructorArgs([new View(), new Manager( $this->config, $this->createMock(ICacheFactory::class), @@ -98,9 +98,9 @@ class EncryptionTest extends Storage { return $path; }); - $this->file = $this->getMockBuilder('\OC\Encryption\File') + $this->file = $this->getMockBuilder(File::class) ->disableOriginalConstructor() - ->setMethods(['getAccessList']) + ->onlyMethods(['getAccessList']) ->getMock(); $this->file->expects($this->any())->method('getAccessList')->willReturn([]); @@ -108,15 +108,11 @@ class EncryptionTest extends Storage { $this->sourceStorage = new Temporary([]); - $this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage') - ->disableOriginalConstructor()->getMock(); + $this->keyStore = $this->createMock(\OC\Encryption\Keys\Storage::class); - $this->update = $this->getMockBuilder('\OC\Encryption\Update') - ->disableOriginalConstructor()->getMock(); - - $this->mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint') + $this->mount = $this->getMockBuilder(MountPoint::class) ->disableOriginalConstructor() - ->setMethods(['getOption']) + ->onlyMethods(['getOption']) ->getMock(); $this->mount->expects($this->any())->method('getOption')->willReturnCallback(function ($option, $default) { if ($option === 'encrypt' && $default === true) { @@ -155,12 +151,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache ] ) - ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule']) + ->onlyMethods(['getMetaData', 'getCache', 'getEncryptionModule']) ->getMock(); $this->instance->expects($this->any()) @@ -181,7 +176,7 @@ class EncryptionTest extends Storage { protected function buildMockModule(): IEncryptionModule&MockObject { $this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') ->disableOriginalConstructor() - ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList']) + ->onlyMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser', 'needDetailedAccessList']) ->getMock(); $this->encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE'); @@ -199,7 +194,6 @@ class EncryptionTest extends Storage { } /** - * @dataProvider dataTestGetMetaData * * @param string $path * @param array $metaData @@ -208,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(); @@ -237,12 +232,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ] ) - ->setMethods(['getCache', 'verifyUnencryptedSize']) + ->onlyMethods(['getCache', 'verifyUnencryptedSize']) ->getMock(); if ($unencryptedSizeSet) { @@ -285,7 +279,7 @@ class EncryptionTest extends Storage { } } - public function dataTestGetMetaData() { + public static function dataTestGetMetaData(): array { return [ ['/test.txt', ['size' => 42, 'encrypted' => 2, 'encryptedVersion' => 2, 'fileid' => 1], true, true, 12, ['size' => 12, 'encrypted' => true, 'encryptedVersion' => 2]], ['/test.txt', null, true, true, 12, null], @@ -316,12 +310,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ] ) - ->setMethods(['getCache', 'verifyUnencryptedSize']) + ->onlyMethods(['getCache', 'verifyUnencryptedSize']) ->getMock(); $this->instance->expects($this->any())->method('getCache')->willReturn($cache); @@ -335,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(); @@ -361,12 +354,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ] ) - ->setMethods(['fixUnencryptedSize']) + ->onlyMethods(['fixUnencryptedSize']) ->getMock(); $sourceStorage->expects($this->once())->method('filesize')->willReturn($encryptedSize); @@ -389,7 +381,7 @@ class EncryptionTest extends Storage { ); } - public function dataTestVerifyUnencryptedSize() { + public static function dataTestVerifyUnencryptedSize(): array { return [ [120, 80, false, 80], [120, 120, false, 80], @@ -399,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, @@ -444,7 +436,7 @@ class EncryptionTest extends Storage { * * @return array */ - public function dataTestCopyAndRename() { + public static function dataTestCopyAndRename(): array { return [ ['source', 'target', true, false, false], ['source', 'target', true, true, false], @@ -461,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(); @@ -491,7 +483,6 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ); @@ -506,7 +497,7 @@ class EncryptionTest extends Storage { $encryptionStorage->rmdir($path); } - public function dataTestRmdir() { + public static function dataTestRmdir(): array { return [ ['/file.txt', true, true, true], ['/file.txt', false, true, true], @@ -520,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') @@ -541,7 +532,7 @@ class EncryptionTest extends Storage { ); } - public function dataTestCopyKeys() { + public static function dataTestCopyKeys(): array { return [ [true, false], [false, true], @@ -549,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(); @@ -598,12 +589,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ] ) - ->setMethods(['getCache', 'readFirstBlock']) + ->onlyMethods(['getCache', 'readFirstBlock']) ->getMock(); $instance->method('getCache')->willReturn($cache); @@ -629,7 +619,7 @@ class EncryptionTest extends Storage { $this->invokePrivate($instance, 'getHeader', [$path]); } - public function dataTestGetHeader() { + public static function dataTestGetHeader(): array { return [ ['/foo/bar.txt', false, '/foo/bar.txt'], ['/foo/bar.txt.part', false, '/foo/bar.txt'], @@ -642,11 +632,10 @@ 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') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); $sourceStorage->expects($this->once()) @@ -654,7 +643,7 @@ class EncryptionTest extends Storage { ->with('test.txt') ->willReturn($strippedPathExists); - $util = $this->getMockBuilder('\OC\Encryption\Util') + $util = $this->getMockBuilder(Util::class) ->onlyMethods(['stripPartialFileExtension', 'parseRawHeader']) ->setConstructorArgs([new View(), new Manager( $this->config, @@ -669,8 +658,7 @@ class EncryptionTest extends Storage { return $path; }); - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') - ->disableOriginalConstructor()->getMock(); + $cache = $this->createMock(Cache::class); $cache->expects($this->any()) ->method('get') ->willReturnCallback(function ($path) use ($isEncrypted) { @@ -692,12 +680,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache, ] ) - ->setMethods(['readFirstBlock', 'getCache']) + ->onlyMethods(['readFirstBlock', 'getCache']) ->getMock(); $instance->method('readFirstBlock')->willReturn(''); @@ -713,7 +700,7 @@ class EncryptionTest extends Storage { } } - public function dataTestGetHeaderAddLegacyModule() { + public static function dataTestGetHeaderAddLegacyModule(): array { return [ [['cipher' => 'AES-128'], true, true, ['cipher' => 'AES-128', Util::HEADER_ENCRYPTION_MODULE_KEY => 'OC_DEFAULT_MODULE']], [[], true, false, []], @@ -722,7 +709,7 @@ class EncryptionTest extends Storage { ]; } - public function dataCopyBetweenStorage() { + public static function dataCopyBetweenStorage(): array { return [ [true, true, true], [true, false, false], @@ -740,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') @@ -774,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); @@ -789,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') @@ -834,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); @@ -867,12 +854,11 @@ class EncryptionTest extends Storage { $this->file, null, $this->keyStore, - $this->update, $this->mountManager, $this->arrayCache ] ) - ->setMethods(['updateUnencryptedSize', 'getCache']) + ->onlyMethods(['updateUnencryptedSize', 'getCache']) ->getMock(); $targetStorage->expects($this->once())->method('copyFromStorage') @@ -914,7 +900,7 @@ class EncryptionTest extends Storage { $this->assertSame($copyResult, $result); } - public function dataTestCopyBetweenStorageVersions() { + public static function dataTestCopyBetweenStorageVersions(): array { return [ ['/files/foo.txt', '/files_versions/foo.txt.768743', true, true], ['/files/foo.txt', '/files_versions/foo.txt.768743', true, false], @@ -929,17 +915,17 @@ 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]) ); } - public function dataTestIsVersion() { + public static function dataTestIsVersion(): array { return [ ['files_versions/foo', true], ['/files_versions/foo', true], @@ -951,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, @@ -968,7 +954,6 @@ class EncryptionTest extends Storage { $util = $this->createMock(Util::class); $fileHelper = $this->createMock(IFile::class); $keyStorage = $this->createMock(IStorage::class); - $update = $this->createMock(Update::class); $mountManager = $this->createMock(\OC\Files\Mount\Manager::class); $mount = $this->createMock(IMountPoint::class); $arrayCache = $this->createMock(ArrayCache::class); @@ -986,12 +971,11 @@ class EncryptionTest extends Storage { $fileHelper, null, $keyStorage, - $update, $mountManager, $arrayCache ] ) - ->setMethods(['getFullPath', 'getEncryptionModule']) + ->onlyMethods(['getFullPath', 'getEncryptionModule']) ->getMock(); if ($encryptionModule === true) { @@ -1033,7 +1017,7 @@ class EncryptionTest extends Storage { $this->assertSame($expected, $result); } - public function dataTestShouldEncrypt() { + public static function dataTestShouldEncrypt(): array { return [ [false, false, false, false], [true, false, false, false], 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 f07e6021e4e..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,8 +11,10 @@ namespace Test\Files\Storage\Wrapper; //ensure the constants are loaded use OC\Files\Cache\CacheEntry; use OC\Files\Storage\Local; - -\OC::$loader->load('\OC\Files\Filesystem'); +use OC\Files\Storage\Wrapper\Quota; +use OCP\Files; +use OCP\ITempManager; +use OCP\Server; /** * Class QuotaTest @@ -29,13 +32,13 @@ 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 { - \OC_Helper::rmdirr($this->tmpDir); + Files::rmdirr($this->tmpDir); parent::tearDown(); } @@ -43,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 { @@ -76,7 +79,7 @@ class QuotaTest extends \Test\Files\Storage\Storage { public function testFreeSpaceWithUnknownDiskSpace(): void { $storage = $this->getMockBuilder(Local::class) - ->setMethods(['free_space']) + ->onlyMethods(['free_space']) ->setConstructorArgs([['datadir' => $this->tmpDir]]) ->getMock(); $storage->expects($this->any()) @@ -84,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] ); @@ -132,14 +135,14 @@ class QuotaTest extends \Test\Files\Storage\Storage { public function testReturnFalseWhenFopenFailed(): void { $failStorage = $this->getMockBuilder(Local::class) - ->setMethods(['fopen']) + ->onlyMethods(['fopen']) ->setConstructorArgs([['datadir' => $this->tmpDir]]) ->getMock(); $failStorage->expects($this->any()) ->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')); } @@ -197,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 1d0f41bf3ed..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,6 +8,12 @@ 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 { /** * @var string tmpDir @@ -16,13 +23,13 @@ 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 { - \OC_Helper::rmdirr($this->tmpDir); + Files::rmdirr($this->tmpDir); parent::tearDown(); } |