aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Storage/Wrapper')
-rw-r--r--tests/lib/Files/Storage/Wrapper/AvailabilityTest.php35
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncodingTest.php92
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncryptionTest.php355
-rw-r--r--tests/lib/Files/Storage/Wrapper/JailTest.php19
-rw-r--r--tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php3
-rw-r--r--tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php47
-rw-r--r--tests/lib/Files/Storage/Wrapper/QuotaTest.php65
-rw-r--r--tests/lib/Files/Storage/Wrapper/WrapperTest.php17
8 files changed, 325 insertions, 308 deletions
diff --git a/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php b/tests/lib/Files/Storage/Wrapper/AvailabilityTest.php
index ef7b457636c..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.
@@ -17,7 +18,7 @@ class AvailabilityTest extends \Test\TestCase {
protected $storageCache;
/** @var \PHPUnit\Framework\MockObject\MockObject|Temporary */
protected $storage;
- /** @var Availability */
+ /** @var Availability */
protected $wrapper;
protected function setUp(): void {
@@ -36,7 +37,7 @@ class AvailabilityTest extends \Test\TestCase {
/**
* Storage is available
*/
- public function testAvailable() {
+ public function testAvailable(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
@@ -52,8 +53,8 @@ class AvailabilityTest extends \Test\TestCase {
* Storage marked unavailable, TTL not expired
*
*/
- public function testUnavailable() {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ public function testUnavailable(): void {
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -69,19 +70,23 @@ class AvailabilityTest extends \Test\TestCase {
/**
* Storage marked unavailable, TTL expired
*/
- public function testUnavailableRecheck() {
+ public function testUnavailableRecheck(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => false, 'last_checked' => 0]);
$this->storage->expects($this->once())
->method('test')
->willReturn(true);
+ $calls = [
+ false, // prevents concurrent rechecks
+ true, // sets correct availability
+ ];
$this->storage->expects($this->exactly(2))
->method('setAvailability')
- ->withConsecutive(
- [$this->equalTo(false)], // prevents concurrent rechecks
- [$this->equalTo(true)] // sets correct availability
- );
+ ->willReturnCallback(function ($value) use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $value);
+ });
$this->storage->expects($this->once())
->method('mkdir');
@@ -92,8 +97,8 @@ class AvailabilityTest extends \Test\TestCase {
* Storage marked available, but throws StorageNotAvailableException
*
*/
- public function testAvailableThrowStorageNotAvailable() {
- $this->expectException(\OCP\Files\StorageNotAvailableException::class);
+ public function testAvailableThrowStorageNotAvailable(): void {
+ $this->expectException(StorageNotAvailableException::class);
$this->storage->expects($this->once())
->method('getAvailability')
@@ -102,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));
@@ -114,7 +119,7 @@ class AvailabilityTest extends \Test\TestCase {
* Storage available, but call fails
* Method failure does not indicate storage unavailability
*/
- public function testAvailableFailure() {
+ public function testAvailableFailure(): void {
$this->storage->expects($this->once())
->method('getAvailability')
->willReturn(['available' => true, 'last_checked' => 0]);
@@ -134,7 +139,7 @@ class AvailabilityTest extends \Test\TestCase {
* Standard exception does not indicate storage unavailability
*
*/
- public function testAvailableThrow() {
+ public function testAvailableThrow(): void {
$this->expectException(\Exception::class);
$this->storage->expects($this->once())
@@ -144,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 bc9355d7bfb..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,43 +33,39 @@ 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
- */
- public function testFputEncoding($accessName) {
+ #[\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
- */
- public function testFopenReadEncoding($accessName) {
+ #[\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');
$data = fgets($fh);
@@ -73,10 +73,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $data);
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFopenOverwriteEncoding($accessName) {
+ #[\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');
$data = fputs($fh, 'test');
@@ -86,42 +84,36 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertFalse($this->sourceStorage->file_exists(self::NFC_NAME));
}
- /**
- * @dataProvider accessNameProvider
- */
- public function testFileExistsEncoding($accessName) {
+ #[\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
- */
- public function testUnlinkEncoding($accessName) {
+ #[\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));
$this->assertFalse($this->sourceStorage->file_exists(self::NFC_NAME));
$this->assertFalse($this->sourceStorage->file_exists(self::NFD_NAME));
}
- public function testNfcHigherPriority() {
+ public function testNfcHigherPriority(): void {
$this->sourceStorage->file_put_contents(self::NFC_NAME, 'nfc');
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'nfd');
$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],
- [self::NFD_NAME . '/' . self::NFC_NAME . '/' .self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME . '/' . self::NFC_NAME],
+ [self::NFD_NAME . '/' . self::NFC_NAME . '/' . self::NFD_NAME, self::NFC_NAME . '/' . self::NFC_NAME . '/' . self::NFC_NAME],
];
}
- /**
- * @dataProvider encodedDirectoriesProvider
- */
- public function testOperationInsideDirectory($sourceDir, $accessDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('encodedDirectoriesProvider')]
+ public function testOperationInsideDirectory($sourceDir, $accessDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->instance->file_put_contents($accessDir . '/test.txt', 'bar');
$this->assertTrue($this->instance->file_exists($accessDir . '/test.txt'));
@@ -138,7 +130,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertTrue($this->instance->file_exists($accessDir . '/' . self::NFC_NAME));
}
- public function testCacheExtraSlash() {
+ public function testCacheExtraSlash(): void {
$this->sourceStorage->file_put_contents(self::NFD_NAME, 'foo');
$this->assertEquals(3, $this->instance->file_put_contents(self::NFC_NAME, 'bar'));
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME));
@@ -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,10 +151,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
];
}
- /**
- * @dataProvider sourceAndTargetDirectoryProvider
- */
- public function testCopyAndMoveEncodedFolder($sourceDir, $targetDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')]
+ public function testCopyAndMoveEncodedFolder($sourceDir, $targetDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->sourceStorage->mkdir($targetDir);
$this->sourceStorage->file_put_contents($sourceDir . '/test.txt', 'bar');
@@ -179,10 +169,8 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt'));
}
- /**
- * @dataProvider sourceAndTargetDirectoryProvider
- */
- public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('sourceAndTargetDirectoryProvider')]
+ public function testCopyAndMoveFromStorageEncodedFolder($sourceDir, $targetDir): void {
$this->sourceStorage->mkdir($sourceDir);
$this->sourceStorage->mkdir($targetDir);
$this->sourceStorage->file_put_contents($sourceDir . '/test.txt', 'bar');
@@ -199,7 +187,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals('bar', $this->instance->file_get_contents(self::NFC_NAME . '2/test2.txt'));
}
- public function testNormalizedDirectoryEntriesOpenDir() {
+ public function testNormalizedDirectoryEntriesOpenDir(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -208,7 +196,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$dh = $this->instance->opendir('/test');
$content = [];
- while ($file = readdir($dh)) {
+ while (($file = readdir($dh)) !== false) {
if ($file != '.' and $file != '..') {
$content[] = $file;
}
@@ -218,7 +206,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals(self::NFC_NAME, $content[0]);
}
- public function testNormalizedDirectoryEntriesGetDirectoryContent() {
+ public function testNormalizedDirectoryEntriesGetDirectoryContent(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -230,7 +218,7 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$this->assertEquals(self::NFC_NAME, $content[0]['name']);
}
- public function testNormalizedGetMetaData() {
+ public function testNormalizedGetMetaData(): void {
$this->sourceStorage->mkdir('/test');
$this->sourceStorage->mkdir('/test/' . self::NFD_NAME);
@@ -240,4 +228,12 @@ class EncodingTest extends \Test\Files\Storage\Storage {
$entry = $this->instance->getMetaData('/test/' . self::NFD_NAME);
$this->assertEquals(self::NFC_NAME, $entry['name']);
}
+
+ /**
+ * Regression test of https://github.com/nextcloud/server/issues/50431
+ */
+ public function testNoMetadata() {
+ $this->assertNull($this->instance->getMetaData('/test/null'));
+ }
+
}
diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
index a6e0260fde6..3e643714300 100644
--- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
@@ -1,15 +1,20 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
+
namespace Test\Files\Storage\Wrapper;
+use Exception;
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
-use OC\Encryption\Update;
+use OC\Encryption\File;
use OC\Encryption\Util;
+use OC\Files\Cache\Cache;
use OC\Files\Cache\CacheEntry;
+use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
@@ -23,6 +28,9 @@ 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;
@@ -30,95 +38,33 @@ class EncryptionTest extends Storage {
/**
* block size will always be 8192 for a PHP stream
* @see https://bugs.php.net/bug.php?id=21641
- * @var integer
- */
- protected $headerSize = 8192;
-
- /**
- * @var Temporary
- */
- private $sourceStorage;
-
- /**
- * @var \OC\Files\Storage\Wrapper\Encryption | \PHPUnit\Framework\MockObject\MockObject
*/
+ protected int $headerSize = 8192;
+ private Temporary $sourceStorage;
+ /** @var Encryption&MockObject */
protected $instance;
-
- /**
- * @var \OC\Encryption\Keys\Storage | \PHPUnit\Framework\MockObject\MockObject
- */
- private $keyStore;
-
- /**
- * @var \OC\Encryption\Util | \PHPUnit\Framework\MockObject\MockObject
- */
- private $util;
-
- /**
- * @var \OC\Encryption\Manager | \PHPUnit\Framework\MockObject\MockObject
- */
- private $encryptionManager;
-
- /**
- * @var \OCP\Encryption\IEncryptionModule | \PHPUnit\Framework\MockObject\MockObject
- */
- private $encryptionModule;
-
- /**
- * @var \OC\Encryption\Update | \PHPUnit\Framework\MockObject\MockObject
- */
- private $update;
-
- /**
- * @var \OC\Files\Cache\Cache | \PHPUnit\Framework\MockObject\MockObject
- */
- private $cache;
-
- /**
- * @var \OC\Log | \PHPUnit\Framework\MockObject\MockObject
- */
- private $logger;
-
- /**
- * @var \OC\Encryption\File | \PHPUnit\Framework\MockObject\MockObject
- */
- private $file;
-
-
- /**
- * @var \OC\Files\Mount\MountPoint | \PHPUnit\Framework\MockObject\MockObject
- */
- private $mount;
-
- /**
- * @var \OC\Files\Mount\Manager | \PHPUnit\Framework\MockObject\MockObject
- */
- private $mountManager;
-
- /**
- * @var \OC\Group\Manager | \PHPUnit\Framework\MockObject\MockObject
- */
- private $groupManager;
-
- /**
- * @var \OCP\IConfig | \PHPUnit\Framework\MockObject\MockObject
- */
- private $config;
-
- /** @var \OC\Memcache\ArrayCache | \PHPUnit\Framework\MockObject\MockObject */
- private $arrayCache;
-
-
- /** @var integer dummy unencrypted size */
- private $dummySize = -1;
+ private \OC\Encryption\Keys\Storage&MockObject $keyStore;
+ private Util&MockObject $util;
+ private \OC\Encryption\Manager&MockObject $encryptionManager;
+ private IEncryptionModule&MockObject $encryptionModule;
+ private Cache&MockObject $cache;
+ private LoggerInterface&MockObject $logger;
+ private File&MockObject $file;
+ private MountPoint&MockObject $mount;
+ private \OC\Files\Mount\Manager&MockObject $mountManager;
+ private \OC\Group\Manager&MockObject $groupManager;
+ private IConfig&MockObject $config;
+ private ArrayCache&MockObject $arrayCache;
+ /** dummy unencrypted size */
+ private int $dummySize = -1;
protected function setUp(): void {
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')
@@ -132,12 +78,13 @@ class EncryptionTest extends Storage {
->disableOriginalConstructor()
->getMock();
- $this->util = $this->getMockBuilder('\OC\Encryption\Util')
- ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded'])
+ $this->util = $this->getMockBuilder(Util::class)
+ ->onlyMethods(['getUidAndFilename', 'isFile', 'isExcluded', 'stripPartialFileExtension'])
->setConstructorArgs([new View(), new Manager(
$this->config,
$this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
+ $this->createMock(IEventDispatcher::class),
+ $this->createMock(LoggerInterface::class),
), $this->groupManager, $this->config, $this->arrayCache])
->getMock();
$this->util->expects($this->any())
@@ -145,10 +92,15 @@ class EncryptionTest extends Storage {
->willReturnCallback(function ($path) {
return ['user1', $path];
});
+ $this->util->expects($this->any())
+ ->method('stripPartialFileExtension')
+ ->willReturnCallback(function ($path) {
+ 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([]);
@@ -156,15 +108,11 @@ class EncryptionTest extends Storage {
$this->sourceStorage = new Temporary([]);
- $this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage')
- ->disableOriginalConstructor()->getMock();
-
- $this->update = $this->getMockBuilder('\OC\Encryption\Update')
- ->disableOriginalConstructor()->getMock();
+ $this->keyStore = $this->createMock(\OC\Encryption\Keys\Storage::class);
- $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) {
@@ -188,7 +136,7 @@ class EncryptionTest extends Storage {
$this->mountManager->method('findByStorageId')
->willReturn([]);
- $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $this->instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -197,10 +145,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $this->util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache
]
)
- ->setMethods(['getMetaData', 'getCache', 'getEncryptionModule'])
+ ->onlyMethods(['getMetaData', 'getCache', 'getEncryptionModule'])
->getMock();
$this->instance->expects($this->any())
@@ -218,13 +173,10 @@ class EncryptionTest extends Storage {
->willReturn($mockModule);
}
- /**
- * @return \PHPUnit\Framework\MockObject\MockObject
- */
- protected function buildMockModule() {
+ 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');
@@ -242,7 +194,6 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestGetMetaData
*
* @param string $path
* @param array $metaData
@@ -251,7 +202,8 @@ class EncryptionTest extends Storage {
* @param int $storedUnencryptedSize
* @param array $expected
*/
- public function testGetMetaData($path, $metaData, $encrypted, $unencryptedSizeSet, $storedUnencryptedSize, $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();
@@ -265,7 +217,7 @@ class EncryptionTest extends Storage {
}
);
- $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $this->instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -274,10 +226,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $this->util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
]
)
- ->setMethods(['getCache', 'verifyUnencryptedSize'])
+ ->onlyMethods(['getCache', 'verifyUnencryptedSize'])
->getMock();
if ($unencryptedSizeSet) {
@@ -320,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],
@@ -329,14 +288,14 @@ class EncryptionTest extends Storage {
];
}
- public function testFilesize() {
+ public function testFilesize(): void {
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
->disableOriginalConstructor()->getMock();
$cache->expects($this->any())
->method('get')
->willReturn(new CacheEntry(['encrypted' => true, 'path' => '/test.txt', 'size' => 0, 'fileid' => 1]));
- $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $this->instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -345,10 +304,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $this->util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
]
)
- ->setMethods(['getCache', 'verifyUnencryptedSize'])
+ ->onlyMethods(['getCache', 'verifyUnencryptedSize'])
->getMock();
$this->instance->expects($this->any())->method('getCache')->willReturn($cache);
@@ -362,18 +328,18 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestVerifyUnencryptedSize
*
* @param int $encryptedSize
* @param int $unencryptedSize
* @param bool $failure
* @param int $expected
*/
- public function testVerifyUnencryptedSize($encryptedSize, $unencryptedSize, $failure, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestVerifyUnencryptedSize')]
+ public function testVerifyUnencryptedSize($encryptedSize, $unencryptedSize, $failure, $expected): void {
$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
- $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $this->instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -382,10 +348,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $this->util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $this->util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
]
)
- ->setMethods(['fixUnencryptedSize'])
+ ->onlyMethods(['fixUnencryptedSize'])
->getMock();
$sourceStorage->expects($this->once())->method('filesize')->willReturn($encryptedSize);
@@ -395,7 +368,7 @@ class EncryptionTest extends Storage {
->willReturnCallback(
function () use ($failure, $expected) {
if ($failure) {
- throw new \Exception();
+ throw new Exception();
} else {
return $expected;
}
@@ -408,7 +381,7 @@ class EncryptionTest extends Storage {
);
}
- public function dataTestVerifyUnencryptedSize() {
+ public static function dataTestVerifyUnencryptedSize(): array {
return [
[120, 80, false, 80],
[120, 120, false, 80],
@@ -418,17 +391,17 @@ 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,
- $renameKeysReturn) {
+ $renameKeysReturn): void {
if ($encryptionEnabled) {
$this->keyStore
->expects($this->once())
@@ -448,7 +421,7 @@ class EncryptionTest extends Storage {
$this->instance->rename($source, $target);
}
- public function testCopyEncryption() {
+ public function testCopyEncryption(): void {
$this->instance->file_put_contents('source.txt', 'bar');
$this->instance->copy('source.txt', 'target.txt');
$this->assertSame('bar', $this->instance->file_get_contents('target.txt'));
@@ -463,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],
@@ -473,38 +446,45 @@ class EncryptionTest extends Storage {
];
}
- public function testIsLocal() {
+ public function testIsLocal(): void {
$this->encryptionManager->expects($this->once())
->method('isEnabled')->willReturn(true);
$this->assertFalse($this->instance->isLocal());
}
/**
- * @dataProvider dataTestRmdir
*
* @param string $path
* @param boolean $rmdirResult
* @param boolean $isExcluded
* @param boolean $encryptionEnabled
*/
- public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRmdir')]
+ public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled): void {
$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
$util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock();
$sourceStorage->expects($this->once())->method('rmdir')->willReturn($rmdirResult);
- $util->expects($this->any())->method('isExcluded')-> willReturn($isExcluded);
+ $util->expects($this->any())->method('isExcluded')->willReturn($isExcluded);
$this->encryptionManager->expects($this->any())->method('isEnabled')->willReturn($encryptionEnabled);
- $encryptionStorage = new \OC\Files\Storage\Wrapper\Encryption(
+ $encryptionStorage = new Encryption(
[
'storage' => $sourceStorage,
'root' => 'foo',
'mountPoint' => '/mountPoint',
'mount' => $this->mount
],
- $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update
+ $this->encryptionManager,
+ $util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
);
@@ -517,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],
@@ -531,12 +511,12 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestCopyKeys
*
* @param boolean $excluded
* @param boolean $expected
*/
- public function testCopyKeys($excluded, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCopyKeys')]
+ public function testCopyKeys($excluded, $expected): void {
$this->util->expects($this->once())
->method('isExcluded')
->willReturn($excluded);
@@ -552,7 +532,7 @@ class EncryptionTest extends Storage {
);
}
- public function dataTestCopyKeys() {
+ public static function dataTestCopyKeys(): array {
return [
[true, false],
[false, true],
@@ -560,13 +540,13 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestGetHeader
*
* @param string $path
* @param bool $strippedPathExists
* @param string $strippedPath
*/
- public function testGetHeader($path, $strippedPathExists, $strippedPath) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetHeader')]
+ public function testGetHeader($path, $strippedPathExists, $strippedPath): void {
$sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
->disableOriginalConstructor()->getMock();
@@ -577,7 +557,8 @@ class EncryptionTest extends Storage {
new Manager(
$this->config,
$this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
+ $this->createMock(IEventDispatcher::class),
+ $this->createMock(LoggerInterface::class),
),
$this->groupManager,
$this->config,
@@ -593,7 +574,7 @@ class EncryptionTest extends Storage {
return ['encrypted' => true, 'path' => $path];
});
- $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -602,10 +583,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
]
)
- ->setMethods(['getCache', 'readFirstBlock'])
+ ->onlyMethods(['getCache', 'readFirstBlock'])
->getMock();
$instance->method('getCache')->willReturn($cache);
@@ -631,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'],
@@ -644,34 +632,40 @@ class EncryptionTest extends Storage {
/**
* test if getHeader adds the default module correctly to the header for
* legacy files
- *
- * @dataProvider dataTestGetHeaderAddLegacyModule
*/
- public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $expected) {
- $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage')
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetHeaderAddLegacyModule')]
+ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $strippedPathExists, $expected): void {
+ $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class)
->disableOriginalConstructor()->getMock();
$sourceStorage->expects($this->once())
->method('is_file')
- ->willReturn($exists);
+ ->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,
$this->createMock(ICacheFactory::class),
- $this->createMock(IEventDispatcher::class)
+ $this->createMock(IEventDispatcher::class),
+ $this->createMock(LoggerInterface::class),
), $this->groupManager, $this->config, $this->arrayCache])
->getMock();
+ $util->expects($this->any())
+ ->method('stripPartialFileExtension')
+ ->willReturnCallback(function ($path) {
+ 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) {
return ['encrypted' => $isEncrypted, 'path' => $path];
});
- $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ $instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -680,10 +674,17 @@ class EncryptionTest extends Storage {
'mountPoint' => '/',
'mount' => $this->mount
],
- $this->encryptionManager, $util, $this->logger, $this->file, null, $this->keyStore, $this->update, $this->mountManager, $this->arrayCache
+ $this->encryptionManager,
+ $util,
+ $this->logger,
+ $this->file,
+ null,
+ $this->keyStore,
+ $this->mountManager,
+ $this->arrayCache,
]
)
- ->setMethods(['readFirstBlock', 'getCache'])
+ ->onlyMethods(['readFirstBlock', 'getCache'])
->getMock();
$instance->method('readFirstBlock')->willReturn('');
@@ -699,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, []],
@@ -708,7 +709,7 @@ class EncryptionTest extends Storage {
];
}
- public function dataCopyBetweenStorage() {
+ public static function dataCopyBetweenStorage(): array {
return [
[true, true, true],
[true, false, false],
@@ -717,7 +718,7 @@ class EncryptionTest extends Storage {
];
}
- public function testCopyBetweenStorageMinimumEncryptedVersion() {
+ public function testCopyBetweenStorageMinimumEncryptedVersion(): void {
$storage2 = $this->createMock(\OC\Files\Storage\Storage::class);
$sourceInternalPath = $targetInternalPath = 'file.txt';
@@ -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,13 +761,13 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataCopyBetweenStorage
*
* @param bool $encryptionEnabled
* @param bool $mountPointEncryptionEnabled
* @param bool $expectedEncrypted
*/
- public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCopyBetweenStorage')]
+ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted): void {
$storage2 = $this->createMock(\OC\Files\Storage\Storage::class);
$sourceInternalPath = $targetInternalPath = 'file.txt';
@@ -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,14 +821,14 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestCopyBetweenStorageVersions
*
* @param string $sourceInternalPath
* @param string $targetInternalPath
* @param bool $copyResult
* @param bool $encrypted
*/
- public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCopyBetweenStorageVersions')]
+ public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted): void {
$sourceStorage = $this->createMock(\OC\Files\Storage\Storage::class);
$targetStorage = $this->createMock(\OC\Files\Storage\Storage::class);
@@ -837,8 +838,8 @@ class EncryptionTest extends Storage {
$mountPoint = '/mountPoint';
- /** @var \OC\Files\Storage\Wrapper\Encryption |\PHPUnit\Framework\MockObject\MockObject $instance */
- $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption')
+ /** @var Encryption |MockObject $instance */
+ $instance = $this->getMockBuilder(Encryption::class)
->setConstructorArgs(
[
[
@@ -853,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')
@@ -900,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],
@@ -915,17 +915,17 @@ class EncryptionTest extends Storage {
}
/**
- * @dataProvider dataTestIsVersion
* @param string $path
* @param bool $expected
*/
- public function testIsVersion($path, $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],
@@ -937,25 +937,23 @@ 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,
$encryptionModuleShouldEncrypt,
- $expected
- ) {
+ $expected,
+ ): void {
$encryptionManager = $this->createMock(\OC\Encryption\Manager::class);
$util = $this->createMock(Util::class);
$fileHelper = $this->createMock(IFile::class);
- $uid = null;
$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);
@@ -971,18 +969,17 @@ class EncryptionTest extends Storage {
$util,
$this->logger,
$fileHelper,
- $uid,
+ null,
$keyStorage,
- $update,
$mountManager,
$arrayCache
]
)
- ->setMethods(['getFullPath', 'getEncryptionModule'])
+ ->onlyMethods(['getFullPath', 'getEncryptionModule'])
->getMock();
if ($encryptionModule === true) {
- /** @var IEncryptionModule|\PHPUnit\Framework\MockObject\MockObject $encryptionModule */
+ /** @var IEncryptionModule|MockObject $encryptionModule */
$encryptionModule = $this->createMock(IEncryptionModule::class);
}
@@ -1020,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 c48f52ecce7..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'
]);
@@ -27,8 +32,8 @@ class JailTest extends \Test\Files\Storage\Storage {
// test that nothing outside our jail is touched
$contents = [];
$dh = $this->sourceStorage->opendir('');
- while ($file = readdir($dh)) {
- if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+ while (($file = readdir($dh)) !== false) {
+ if (!Filesystem::isIgnoredDir($file)) {
$contents[] = $file;
}
}
@@ -37,12 +42,12 @@ class JailTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
- public function testMkDirRooted() {
+ public function testMkDirRooted(): void {
$this->instance->mkdir('bar');
$this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
}
- public function testFilePutContentsRooted() {
+ public function testFilePutContentsRooted(): void {
$this->instance->file_put_contents('bar', 'asd');
$this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
}
diff --git a/tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php b/tests/lib/Files/Storage/Wrapper/KnownMtimeTest.php
index ccc95de1002..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
@@ -50,7 +51,7 @@ class KnownMtimeTest extends Storage {
]);
}
- public function testNewerKnownMtime() {
+ public function testNewerKnownMtime(): void {
$future = time() + 1000;
$this->fakeTime = $future;
diff --git a/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php b/tests/lib/Files/Storage/Wrapper/PermissionsMaskTest.php
index 0b2d444700a..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,19 +35,19 @@ 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
]);
}
- public function testMkdirNoCreate() {
+ public function testMkdirNoCreate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
$this->assertFalse($storage->mkdir('foo'));
$this->assertFalse($storage->file_exists('foo'));
}
- public function testRmdirNoDelete() {
+ public function testRmdirNoDelete(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
$this->assertTrue($storage->mkdir('foo'));
$this->assertTrue($storage->file_exists('foo'));
@@ -52,25 +55,25 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertTrue($storage->file_exists('foo'));
}
- public function testTouchNewFileNoCreate() {
+ public function testTouchNewFileNoCreate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
$this->assertFalse($storage->touch('foo'));
$this->assertFalse($storage->file_exists('foo'));
}
- public function testTouchNewFileNoUpdate() {
+ public function testTouchNewFileNoUpdate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
$this->assertTrue($storage->touch('foo'));
$this->assertTrue($storage->file_exists('foo'));
}
- public function testTouchExistingFileNoUpdate() {
+ public function testTouchExistingFileNoUpdate(): void {
$this->sourceStorage->touch('foo');
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
$this->assertFalse($storage->touch('foo'));
}
- public function testUnlinkNoDelete() {
+ public function testUnlinkNoDelete(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
$this->assertTrue($storage->touch('foo'));
$this->assertTrue($storage->file_exists('foo'));
@@ -78,35 +81,35 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertTrue($storage->file_exists('foo'));
}
- public function testPutContentsNewFileNoUpdate() {
+ public function testPutContentsNewFileNoUpdate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
$this->assertEquals(3, $storage->file_put_contents('foo', 'bar'));
$this->assertEquals('bar', $storage->file_get_contents('foo'));
}
- public function testPutContentsNewFileNoCreate() {
+ public function testPutContentsNewFileNoCreate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
$this->assertFalse($storage->file_put_contents('foo', 'bar'));
}
- public function testPutContentsExistingFileNoUpdate() {
+ public function testPutContentsExistingFileNoUpdate(): void {
$this->sourceStorage->touch('foo');
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
$this->assertFalse($storage->file_put_contents('foo', 'bar'));
}
- public function testFopenExistingFileNoUpdate() {
+ public function testFopenExistingFileNoUpdate(): void {
$this->sourceStorage->touch('foo');
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
$this->assertFalse($storage->fopen('foo', 'w'));
}
- public function testFopenNewFileNoCreate() {
+ public function testFopenNewFileNoCreate(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
$this->assertFalse($storage->fopen('foo', 'w'));
}
- public function testScanNewFiles() {
+ public function testScanNewFiles(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE);
$storage->file_put_contents('foo', 'bar');
$storage->getScanner()->scan('');
@@ -115,7 +118,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
}
- public function testScanNewWrappedFiles() {
+ public function testScanNewWrappedFiles(): void {
$storage = $this->getMaskedStorage(Constants::PERMISSION_READ + Constants::PERMISSION_CREATE);
$wrappedStorage = new Wrapper(['storage' => $storage]);
$wrappedStorage->file_put_contents('foo', 'bar');
@@ -125,9 +128,9 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertEquals(Constants::PERMISSION_READ, $storage->getCache()->get('foo')->getPermissions());
}
- public function testScanNewFilesNested() {
+ 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
]);
@@ -140,7 +143,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertEquals(Constants::PERMISSION_READ, $wrappedStorage->getCache()->get('foo')->getPermissions());
}
- public function testScanUnchanged() {
+ public function testScanUnchanged(): void {
$this->sourceStorage->mkdir('foo');
$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');
@@ -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);
@@ -157,7 +160,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
$this->assertFalse($called);
}
- public function testScanUnchangedWrapped() {
+ public function testScanUnchangedWrapped(): void {
$this->sourceStorage->mkdir('foo');
$this->sourceStorage->file_put_contents('foo/bar.txt', 'bar');
@@ -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 b24b44c6a56..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,30 +46,30 @@ 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() {
+ public function testFilePutContentsNotEnoughSpace(): void {
$instance = $this->getLimitedStorage(3);
$this->assertFalse($instance->file_put_contents('files/foo', 'foobar'));
}
- public function testCopyNotEnoughSpace() {
+ public function testCopyNotEnoughSpace(): void {
$instance = $this->getLimitedStorage(9);
$this->assertEquals(6, $instance->file_put_contents('files/foo', 'foobar'));
$instance->getScanner()->scan('');
$this->assertFalse($instance->copy('files/foo', 'files/bar'));
}
- public function testFreeSpace() {
+ public function testFreeSpace(): void {
$instance = $this->getLimitedStorage(9);
$this->assertEquals(9, $instance->free_space(''));
}
- public function testFreeSpaceWithUsedSpace() {
+ public function testFreeSpaceWithUsedSpace(): void {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
'', ['size' => 3]
@@ -74,9 +77,9 @@ class QuotaTest extends \Test\Files\Storage\Storage {
$this->assertEquals(6, $instance->free_space(''));
}
- public function testFreeSpaceWithUnknownDiskSpace() {
+ 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,14 +87,14 @@ 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]
);
$this->assertEquals(6, $instance->free_space(''));
}
- public function testFreeSpaceWithUsedSpaceAndEncryption() {
+ public function testFreeSpaceWithUsedSpaceAndEncryption(): void {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
'', ['size' => 7]
@@ -99,7 +102,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
$this->assertEquals(2, $instance->free_space(''));
}
- public function testFWriteNotEnoughSpace() {
+ public function testFWriteNotEnoughSpace(): void {
$instance = $this->getLimitedStorage(9);
$stream = $instance->fopen('files/foo', 'w+');
$this->assertEquals(6, fwrite($stream, 'foobar'));
@@ -108,7 +111,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
$this->assertEquals('foobarqwe', $instance->file_get_contents('files/foo'));
}
- public function testStreamCopyWithEnoughSpace() {
+ public function testStreamCopyWithEnoughSpace(): void {
$instance = $this->getLimitedStorage(16);
$inputStream = fopen('data://text/plain,foobarqwerty', 'r');
$outputStream = $instance->fopen('files/foo', 'w+');
@@ -119,7 +122,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
fclose($outputStream);
}
- public function testStreamCopyNotEnoughSpace() {
+ public function testStreamCopyNotEnoughSpace(): void {
$instance = $this->getLimitedStorage(9);
$inputStream = fopen('data://text/plain,foobarqwerty', 'r');
$outputStream = $instance->fopen('files/foo', 'w+');
@@ -130,21 +133,21 @@ class QuotaTest extends \Test\Files\Storage\Storage {
fclose($outputStream);
}
- public function testReturnFalseWhenFopenFailed() {
+ 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'));
}
- public function testReturnRegularStreamOnRead() {
+ public function testReturnRegularStreamOnRead(): void {
$instance = $this->getLimitedStorage(9);
// create test file first
@@ -163,7 +166,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
fclose($stream);
}
- public function testReturnRegularStreamWhenOutsideFiles() {
+ public function testReturnRegularStreamWhenOutsideFiles(): void {
$instance = $this->getLimitedStorage(9);
$instance->mkdir('files_other');
@@ -174,7 +177,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
fclose($stream);
}
- public function testReturnQuotaStreamOnWrite() {
+ public function testReturnQuotaStreamOnWrite(): void {
$instance = $this->getLimitedStorage(9);
$stream = $instance->fopen('files/foo', 'w+');
$meta = stream_get_meta_data($stream);
@@ -183,7 +186,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
fclose($stream);
}
- public function testSpaceRoot() {
+ public function testSpaceRoot(): void {
$storage = $this->getMockBuilder(Local::class)->disableOriginalConstructor()->getMock();
$cache = $this->getMockBuilder('\OC\Files\Cache\Cache')->disableOriginalConstructor()->getMock();
$storage->expects($this->once())
@@ -197,24 +200,24 @@ 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(''));
}
- public function testInstanceOfStorageWrapper() {
+ public function testInstanceOfStorageWrapper(): void {
$this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Local'));
$this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Wrapper'));
$this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota'));
}
- public function testNoMkdirQuotaZero() {
+ public function testNoMkdirQuotaZero(): void {
$instance = $this->getLimitedStorage(0.0);
$this->assertFalse($instance->mkdir('files'));
$this->assertFalse($instance->mkdir('files/foobar'));
}
- public function testMkdirQuotaZeroTrashbin() {
+ public function testMkdirQuotaZeroTrashbin(): void {
$instance = $this->getLimitedStorage(0.0);
$this->assertTrue($instance->mkdir('files_trashbin'));
$this->assertTrue($instance->mkdir('files_trashbin/files'));
@@ -222,7 +225,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
$this->assertTrue($instance->mkdir('cache'));
}
- public function testNoTouchQuotaZero() {
+ public function testNoTouchQuotaZero(): void {
$instance = $this->getLimitedStorage(0.0);
$this->assertFalse($instance->touch('foobar'));
}
diff --git a/tests/lib/Files/Storage/Wrapper/WrapperTest.php b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
index 0244c78da8b..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,17 +23,17 @@ 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();
}
- public function testInstanceOfStorageWrapper() {
+ public function testInstanceOfStorageWrapper(): void {
$this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Local'));
$this->assertTrue($this->instance->instanceOfStorage('\OC\Files\Storage\Wrapper\Wrapper'));
}