aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files')
-rw-r--r--tests/lib/Files/Cache/CacheTest.php50
-rw-r--r--tests/lib/Files/Cache/ScannerTest.php2
-rw-r--r--tests/lib/Files/Cache/SearchBuilderTest.php2
-rw-r--r--tests/lib/Files/Cache/UpdaterTest.php2
-rw-r--r--tests/lib/Files/Cache/Wrapper/CacheJailTest.php11
-rw-r--r--tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php2
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php23
-rw-r--r--tests/lib/Files/FilenameValidatorTest.php142
-rw-r--r--tests/lib/Files/FilesystemTest.php11
-rw-r--r--tests/lib/Files/Node/FileTest.php14
-rw-r--r--tests/lib/Files/Node/FolderTest.php24
-rw-r--r--tests/lib/Files/Node/HookConnectorTest.php4
-rw-r--r--tests/lib/Files/Node/NodeTestCase.php (renamed from tests/lib/Files/Node/NodeTest.php)11
-rw-r--r--tests/lib/Files/ObjectStore/AzureTest.php2
-rw-r--r--tests/lib/Files/ObjectStore/LocalTest.php2
-rw-r--r--tests/lib/Files/ObjectStore/MapperTest.php2
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php4
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php4
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreTestCase.php (renamed from tests/lib/Files/ObjectStore/ObjectStoreTest.php)21
-rw-r--r--tests/lib/Files/ObjectStore/S3Test.php4
-rw-r--r--tests/lib/Files/ObjectStore/SwiftTest.php2
-rw-r--r--tests/lib/Files/PathVerificationTest.php8
-rw-r--r--tests/lib/Files/Storage/CommonTest.php3
-rw-r--r--tests/lib/Files/Storage/HomeTest.php3
-rw-r--r--tests/lib/Files/Storage/LocalTest.php3
-rw-r--r--tests/lib/Files/Storage/Storage.php10
-rw-r--r--tests/lib/Files/Storage/StoragesTestCase.php (renamed from tests/lib/Files/Storage/StoragesTest.php)2
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncodingTest.php12
-rw-r--r--tests/lib/Files/Storage/Wrapper/EncryptionTest.php81
-rw-r--r--tests/lib/Files/Storage/Wrapper/QuotaTest.php7
-rw-r--r--tests/lib/Files/Storage/Wrapper/WrapperTest.php4
-rw-r--r--tests/lib/Files/Stream/EncryptionTest.php44
-rw-r--r--tests/lib/Files/Stream/HashWrapperTest.php2
-rw-r--r--tests/lib/Files/Utils/ScannerTest.php5
-rw-r--r--tests/lib/Files/ViewTest.php24
35 files changed, 354 insertions, 193 deletions
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index 204f87d6a18..55b210a1e2d 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -49,6 +49,25 @@ class CacheTest extends \Test\TestCase {
*/
protected $cache2;
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->storage = new \OC\Files\Storage\Temporary([]);
+ $this->storage2 = new \OC\Files\Storage\Temporary([]);
+ $this->cache = new \OC\Files\Cache\Cache($this->storage);
+ $this->cache2 = new \OC\Files\Cache\Cache($this->storage2);
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
+ }
+
+ protected function tearDown(): void {
+ if ($this->cache) {
+ $this->cache->clear();
+ }
+
+ parent::tearDown();
+ }
+
public function testGetNumericId(): void {
$this->assertNotNull($this->cache->getNumericStorageId());
}
@@ -208,7 +227,7 @@ class CacheTest extends \Test\TestCase {
}
}
- public function folderDataProvider() {
+ public static function folderDataProvider(): array {
return [
['folder'],
// that was too easy, try something harder
@@ -301,7 +320,7 @@ class CacheTest extends \Test\TestCase {
$this->assertEquals(\OC\Files\Cache\Cache::COMPLETE, $this->cache->getStatus('foo'));
}
- public function putWithAllKindOfQuotesData() {
+ public static function putWithAllKindOfQuotesData(): array {
return [
['`backtick`'],
['´forward´'],
@@ -437,7 +456,7 @@ class CacheTest extends \Test\TestCase {
new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100), 10, 0, [], $user)));
}
- public function movePathProvider() {
+ public static function movePathProvider(): array {
return [
['folder/foo', 'folder/foobar', ['1', '2']],
['folder/foo', 'foo', ['1', '2']],
@@ -575,7 +594,7 @@ class CacheTest extends \Test\TestCase {
* @var \OC\Files\Cache\Cache | \PHPUnit\Framework\MockObject\MockObject $cacheMock
*/
$cacheMock = $this->getMockBuilder(Cache::class)
- ->setMethods(['normalize'])
+ ->onlyMethods(['normalize'])
->setConstructorArgs([$this->storage])
->getMock();
@@ -646,7 +665,7 @@ class CacheTest extends \Test\TestCase {
$this->assertEquals(1, count($this->cache->getFolderContents('folder')));
}
- public function bogusPathNamesProvider() {
+ public static function bogusPathNamesProvider(): array {
return [
['/bogus.txt', 'bogus.txt'],
['//bogus.txt', 'bogus.txt'],
@@ -691,7 +710,7 @@ class CacheTest extends \Test\TestCase {
$this->assertNotEquals($fileId, $fileId2);
}
- public function escapingProvider() {
+ public static function escapingProvider(): array {
return [
['foo'],
['o%'],
@@ -807,23 +826,4 @@ class CacheTest extends \Test\TestCase {
$this->cache->remove('sub');
}
-
- protected function tearDown(): void {
- if ($this->cache) {
- $this->cache->clear();
- }
-
- parent::tearDown();
- }
-
- protected function setUp(): void {
- parent::setUp();
-
- $this->storage = new \OC\Files\Storage\Temporary([]);
- $this->storage2 = new \OC\Files\Storage\Temporary([]);
- $this->cache = new \OC\Files\Cache\Cache($this->storage);
- $this->cache2 = new \OC\Files\Cache\Cache($this->storage2);
- $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
- $this->cache2->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
- }
}
diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php
index d78b7100d43..dc5ba5d3cdf 100644
--- a/tests/lib/Files/Cache/ScannerTest.php
+++ b/tests/lib/Files/Cache/ScannerTest.php
@@ -394,7 +394,7 @@ class ScannerTest extends TestCase {
);
}
- public function dataTestIsPartialFile() {
+ public static function dataTestIsPartialFile(): array {
return [
['foo.txt.part', true],
['/sub/folder/foo.txt.part', true],
diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php
index 17285d44209..28af199639a 100644
--- a/tests/lib/Files/Cache/SearchBuilderTest.php
+++ b/tests/lib/Files/Cache/SearchBuilderTest.php
@@ -134,7 +134,7 @@ class SearchBuilderTest extends TestCase {
return $rows;
}
- public function comparisonProvider() {
+ public static function comparisonProvider(): array {
return [
[new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'mtime', 125), [1]],
[new SearchComparison(ISearchComparison::COMPARE_LESS_THAN, 'mtime', 125), [0]],
diff --git a/tests/lib/Files/Cache/UpdaterTest.php b/tests/lib/Files/Cache/UpdaterTest.php
index ab46bdd4141..bc4b39a5dc4 100644
--- a/tests/lib/Files/Cache/UpdaterTest.php
+++ b/tests/lib/Files/Cache/UpdaterTest.php
@@ -305,7 +305,7 @@ class UpdaterTest extends \Test\TestCase {
}
}
- public function changeExtensionProvider(): array {
+ public static function changeExtensionProvider(): array {
return [
[new Temporary()],
[new ObjectStoreStorage(['objectstore' => new StorageObjectStore(new Temporary())])]
diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
index aed13c41ac0..57024e2eb79 100644
--- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Cache\Wrapper;
use OC\Files\Cache\Wrapper\CacheJail;
+use OC\Files\Cache\Wrapper\CacheWrapper;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Wrapper\Jail;
@@ -252,4 +253,14 @@ class CacheJailTest extends CacheTest {
$storage->getWatcher()->update('bar', ['mimetype' => 'text/plain']);
$this->assertTrue($this->cache->inCache('bar'));
}
+
+ public function testUnJailedRoot(): void {
+ $jail1 = new CacheJail($this->sourceCache, 'foo');
+ $jail2 = new CacheJail($jail1, 'bar');
+ $this->assertEquals('foo/bar', $jail2->getGetUnjailedRoot());
+
+ $middleWrapper = new CacheWrapper($jail1);
+ $jail3 = new CacheJail($middleWrapper, 'bar');
+ $this->assertEquals('foo/bar', $jail3->getGetUnjailedRoot());
+ }
}
diff --git a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
index afb5c6a5d4d..9aa1ee5b723 100644
--- a/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
+++ b/tests/lib/Files/Cache/Wrapper/CachePermissionsMaskTest.php
@@ -34,7 +34,7 @@ class CachePermissionsMaskTest extends CacheTest {
return new \OC\Files\Cache\Wrapper\CachePermissionsMask($this->sourceCache, $mask);
}
- public function maskProvider() {
+ public static function maskProvider(): array {
return [
[Constants::PERMISSION_ALL],
[Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE],
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index 1efc56c1908..88b8b7767dd 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -9,6 +9,7 @@ namespace Test\Files\Config;
use OC\DB\Exceptions\DbalException;
use OC\DB\QueryBuilder\Literal;
+use OC\Files\Cache\Cache;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OC\User\Manager;
@@ -88,25 +89,19 @@ class UserMountCacheTest extends TestCase {
private function getStorage($storageId, $rootInternalPath = '') {
$rootId = $this->createCacheEntry($rootInternalPath, $storageId);
- $storageCache = $this->getMockBuilder('\OC\Files\Cache\Storage')
- ->disableOriginalConstructor()
- ->getMock();
+ $storageCache = $this->createMock(\OC\Files\Cache\Storage::class);
$storageCache->expects($this->any())
->method('getNumericId')
->willReturn($storageId);
- $cache = $this->getMockBuilder('\OC\Files\Cache\Cache')
- ->disableOriginalConstructor()
- ->getMock();
+ $cache = $this->createMock(Cache::class);
$cache->expects($this->any())
->method('getId')
->willReturn($rootId);
$cache->method('getNumericStorageId')
->willReturn($storageId);
- $storage = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()
- ->getMock();
+ $storage = $this->createMock(Storage::class);
$storage->expects($this->any())
->method('getStorageCache')
->willReturn($storageCache);
@@ -427,9 +422,9 @@ class UserMountCacheTest extends TestCase {
$fileId = $this->createCacheEntry('/foo/bar', 2);
- $mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ $mount1 = $this->getMockBuilder(MountPoint::class)
->setConstructorArgs([$storage1, '/'])
- ->setMethods(['getStorageRootId'])
+ ->onlyMethods(['getStorageRootId'])
->getMock();
$mount1->expects($this->any())
@@ -460,9 +455,9 @@ class UserMountCacheTest extends TestCase {
$folderId = $this->createCacheEntry('/foo', 2);
$fileId = $this->createCacheEntry('/bar/asd', 2);
- $mount1 = $this->getMockBuilder('\OC\Files\Mount\MountPoint')
+ $mount1 = $this->getMockBuilder(MountPoint::class)
->setConstructorArgs([$storage1, '/foo/'])
- ->setMethods(['getStorageRootId'])
+ ->onlyMethods(['getStorageRootId'])
->getMock();
$mount1->expects($this->any())
@@ -509,7 +504,7 @@ class UserMountCacheTest extends TestCase {
$mount1 = $this->getMockBuilder(MountPoint::class)
->setConstructorArgs([$storage1, '/u1/'])
- ->setMethods(['getStorageRootId', 'getNumericStorageId'])
+ ->onlyMethods(['getStorageRootId', 'getNumericStorageId'])
->getMock();
$mount1->expects($this->any())
diff --git a/tests/lib/Files/FilenameValidatorTest.php b/tests/lib/Files/FilenameValidatorTest.php
index 45f681bd453..db7874b0bd5 100644
--- a/tests/lib/Files/FilenameValidatorTest.php
+++ b/tests/lib/Files/FilenameValidatorTest.php
@@ -122,7 +122,7 @@ class FilenameValidatorTest extends TestCase {
$this->assertEquals($exception === null, $validator->isFilenameValid($filename));
}
- public function dataValidateFilename(): array {
+ public static function dataValidateFilename(): array {
return [
'valid name' => [
'a: b.txt', ['.htaccess'], [], [], [], null
@@ -202,7 +202,7 @@ class FilenameValidatorTest extends TestCase {
$validator->validateFilename($filename);
}
- public function data4ByteUnicode(): array {
+ public static function data4ByteUnicode(): array {
return [
['plane 1 𐪅'],
['emoji 😶‍🌫️'],
@@ -218,7 +218,7 @@ class FilenameValidatorTest extends TestCase {
$validator->validateFilename($filename);
}
- public function dataInvalidAsciiCharacters(): array {
+ public static function dataInvalidAsciiCharacters(): array {
return [
[\chr(0)],
[\chr(1)],
@@ -271,7 +271,7 @@ class FilenameValidatorTest extends TestCase {
$this->assertEquals($expected, $validator->isForbidden($filename));
}
- public function dataIsForbidden(): array {
+ public static function dataIsForbidden(): array {
return [
'valid name' => [
'a: b.txt', ['.htaccess'], false
@@ -374,4 +374,138 @@ class FilenameValidatorTest extends TestCase {
[['AuX', 'COM1'], ['aux', 'com1']],
];
}
+
+ /**
+ * @dataProvider dataSanitizeFilename
+ */
+ public function testSanitizeFilename(
+ string $filename,
+ array $forbiddenNames,
+ array $forbiddenBasenames,
+ array $forbiddenExtensions,
+ array $forbiddenCharacters,
+ string $expected,
+ ): void {
+ /** @var FilenameValidator&MockObject */
+ $validator = $this->getMockBuilder(FilenameValidator::class)
+ ->onlyMethods([
+ 'getForbiddenBasenames',
+ 'getForbiddenExtensions',
+ 'getForbiddenFilenames',
+ 'getForbiddenCharacters',
+ ])
+ ->setConstructorArgs([$this->l10n, $this->database, $this->config, $this->logger])
+ ->getMock();
+
+ $validator->method('getForbiddenBasenames')
+ ->willReturn($forbiddenBasenames);
+ $validator->method('getForbiddenCharacters')
+ ->willReturn($forbiddenCharacters);
+ $validator->method('getForbiddenExtensions')
+ ->willReturn($forbiddenExtensions);
+ $validator->method('getForbiddenFilenames')
+ ->willReturn($forbiddenNames);
+
+ $this->assertEquals($expected, $validator->sanitizeFilename($filename));
+ }
+
+ public function dataSanitizeFilename(): array {
+ return [
+ 'valid name' => [
+ 'a * b.txt', ['.htaccess'], [], [], [], 'a * b.txt'
+ ],
+ 'forbidden name in the middle is ok' => [
+ 'a.htaccess.txt', ['.htaccess'], [], [], [], 'a.htaccess.txt'
+ ],
+ 'forbidden name on the beginning' => [
+ '.htaccess.sample', ['.htaccess'], [], [], [], '.htaccess.sample'
+ ],
+ 'forbidden name' => [
+ '.htaccess', ['.htaccess'], [], [], [], '.htaccess (renamed)'
+ ],
+ 'forbidden name - name is case insensitive' => [
+ 'COM1', ['.htaccess', 'com1'], [], [], [], 'COM1 (renamed)'
+ ],
+ 'forbidden basename' => [
+ 'com1.suffix', ['.htaccess'], ['com1'], [], [], 'com1 (renamed).suffix'
+ ],
+ 'forbidden basename case insensitive' => [
+ // needed for Windows namespaces
+ 'COM1.suffix', ['.htaccess'], ['com1'], [], [], 'COM1 (renamed).suffix'
+ ],
+ 'forbidden basename for hidden files' => [
+ // needed for Windows namespaces
+ '.thumbs.db', ['.htaccess'], ['.thumbs'], [], [], '.thumbs (renamed).db'
+ ],
+ 'invalid character' => [
+ 'a: b.txt', ['.htaccess'], [], [], [':'], 'a b.txt',
+ ],
+ 'invalid extension' => [
+ 'a: b.txt', ['.htaccess'], [], ['.txt'], [], 'a: b'
+ ],
+ 'invalid extension case insensitive' => [
+ 'a: b.TXT', ['.htaccess'], [], ['.txt'], [], 'a: b'
+ ],
+ 'empty filename' => [
+ '', [], [], [], [], 'renamed file'
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataSanitizeFilenameCharacterReplacement
+ */
+ public function testSanitizeFilenameCharacterReplacement(
+ string $filename,
+ array $forbiddenCharacters,
+ ?string $characterReplacement,
+ ?string $expected,
+ ): void {
+ /** @var FilenameValidator&MockObject */
+ $validator = $this->getMockBuilder(FilenameValidator::class)
+ ->onlyMethods([
+ 'getForbiddenBasenames',
+ 'getForbiddenExtensions',
+ 'getForbiddenFilenames',
+ 'getForbiddenCharacters',
+ ])
+ ->setConstructorArgs([$this->l10n, $this->database, $this->config, $this->logger])
+ ->getMock();
+
+ $validator->method('getForbiddenBasenames')
+ ->willReturn([]);
+ $validator->method('getForbiddenCharacters')
+ ->willReturn($forbiddenCharacters);
+ $validator->method('getForbiddenExtensions')
+ ->willReturn([]);
+ $validator->method('getForbiddenFilenames')
+ ->willReturn([]);
+
+ if ($expected === null) {
+ $this->expectException(\InvalidArgumentException::class);
+ $validator->sanitizeFilename($filename, $characterReplacement);
+ } else {
+ $this->assertEquals($expected, $validator->sanitizeFilename($filename, $characterReplacement));
+ }
+ }
+
+ public static function dataSanitizeFilenameCharacterReplacement(): array {
+ return [
+ 'default' => [
+ 'foo*bar', ['*'], null, 'foo bar'
+ ],
+ 'default - space not allowed' => [
+ 'foo*bar', ['*', ' '], null, 'foo_bar'
+ ],
+ 'default - space and underscore not allowed' => [
+ 'foo*bar', ['*', ' ', '_'], null, 'foo-bar'
+ ],
+ 'default - no replacement' => [
+ 'foo*bar', ['*', ' ', '_', '-'], null, null
+ ],
+ 'custom replacement' => [
+ 'foo*bar', ['*'], 'x', 'fooxbar'
+ ],
+ ];
+ }
}
diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php
index a920dc662da..966f6f34cee 100644
--- a/tests/lib/Files/FilesystemTest.php
+++ b/tests/lib/Files/FilesystemTest.php
@@ -10,6 +10,7 @@ namespace Test\Files;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Temporary;
use OC\User\NoUserException;
+use OCP\Files;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
@@ -74,7 +75,7 @@ class FilesystemTest extends \Test\TestCase {
protected function tearDown(): void {
foreach ($this->tmpDirs as $dir) {
- \OC_Helper::rmdirr($dir);
+ Files::rmdirr($dir);
}
$this->logout();
@@ -100,7 +101,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals('folder', $internalPath);
}
- public function normalizePathData() {
+ public static function normalizePathData(): array {
return [
['/', ''],
['/', '/'],
@@ -201,7 +202,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals($expected, \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash));
}
- public function normalizePathKeepUnicodeData() {
+ public static function normalizePathKeepUnicodeData(): array {
$nfdName = 'ümlaut';
$nfcName = 'ümlaut';
return [
@@ -227,7 +228,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals('/' . $nfdName, \OC\Files\Filesystem::normalizePath($nfdName, true, false, true));
}
- public function isValidPathData() {
+ public static function isValidPathData(): array {
return [
['/', true],
['/path', true],
@@ -260,7 +261,7 @@ class FilesystemTest extends \Test\TestCase {
$this->assertSame($expected, \OC\Files\Filesystem::isValidPath($path));
}
- public function isFileBlacklistedData() {
+ public static function isFileBlacklistedData(): array {
return [
['/etc/foo/bar/foo.txt', false],
['\etc\foo/bar\foo.txt', false],
diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php
index a67c9433663..74a23520344 100644
--- a/tests/lib/Files/Node/FileTest.php
+++ b/tests/lib/Files/Node/FileTest.php
@@ -7,6 +7,8 @@
namespace Test\Files\Node;
+use OC\Files\Node\Root;
+
/**
* Class FileTest
*
@@ -14,7 +16,7 @@ namespace Test\Files\Node;
*
* @package Test\Files\Node
*/
-class FileTest extends NodeTest {
+class FileTest extends NodeTestCase {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
if ($data || $internalPath || $storage) {
return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage));
@@ -37,7 +39,7 @@ class FileTest extends NodeTest {
public function testGetContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
@@ -67,7 +69,7 @@ class FileTest extends NodeTest {
$this->expectException(\OCP\Files\NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
@@ -86,7 +88,7 @@ class FileTest extends NodeTest {
public function testPutContent(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
@@ -113,7 +115,7 @@ class FileTest extends NodeTest {
$this->expectException(\OCP\Files\NotPermittedException::class);
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
@@ -128,7 +130,7 @@ class FileTest extends NodeTest {
public function testGetMimeType(): void {
/** @var \OC\Files\Node\Root|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index e3edf202f8e..25f555e7068 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -40,7 +40,7 @@ use PHPUnit\Framework\MockObject\MockObject;
*
* @package Test\Files\Node
*/
-class FolderTest extends NodeTest {
+class FolderTest extends NodeTestCase {
protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) {
$view->expects($this->any())
->method('getRoot')
@@ -337,7 +337,7 @@ class FolderTest extends NodeTest {
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$root->expects($this->any())
@@ -499,7 +499,7 @@ class FolderTest extends NodeTest {
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
+ ->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
@@ -548,7 +548,7 @@ class FolderTest extends NodeTest {
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
+ ->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
@@ -593,7 +593,7 @@ class FolderTest extends NodeTest {
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
+ ->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
@@ -637,7 +637,7 @@ class FolderTest extends NodeTest {
$manager = $this->createMock(Manager::class);
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getMountsIn', 'getMount'])
+ ->onlyMethods(['getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
$storage = $this->createMock(\OC\Files\Storage\Storage::class);
@@ -681,7 +681,7 @@ class FolderTest extends NodeTest {
$this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath());
}
- public function uniqueNameProvider() {
+ public static function uniqueNameProvider(): array {
return [
// input, existing, expected
['foo', [], 'foo'],
@@ -698,7 +698,7 @@ class FolderTest extends NodeTest {
$folderPath = '/bar/foo';
$view = $this->getRootViewMock();
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
@@ -723,7 +723,7 @@ class FolderTest extends NodeTest {
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
@@ -792,7 +792,7 @@ class FolderTest extends NodeTest {
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
@@ -859,7 +859,7 @@ class FolderTest extends NodeTest {
$view = $this->getRootViewMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\Node\Root $root */
$root = $this->getMockBuilder(Root::class)
- ->setMethods(['getUser', 'getMountsIn', 'getMount'])
+ ->onlyMethods(['getUser', 'getMountsIn', 'getMount'])
->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
/** @var \PHPUnit\Framework\MockObject\MockObject|\OC\Files\FileInfo $folderInfo */
@@ -910,7 +910,7 @@ class FolderTest extends NodeTest {
$this->assertEquals([$id1], $ids);
}
- public function offsetLimitProvider() {
+ public static function offsetLimitProvider(): array {
return [
[0, 10, ['/bar/foo/foo1', '/bar/foo/foo2', '/bar/foo/foo3', '/bar/foo/foo4', '/bar/foo/sub1/foo5', '/bar/foo/sub1/foo6', '/bar/foo/sub2/foo7', '/bar/foo/sub2/foo8'], []],
[0, 5, ['/bar/foo/foo1', '/bar/foo/foo2', '/bar/foo/foo3', '/bar/foo/foo4', '/bar/foo/sub1/foo5'], []],
diff --git a/tests/lib/Files/Node/HookConnectorTest.php b/tests/lib/Files/Node/HookConnectorTest.php
index 1a3337b9ddc..b9e16299dd0 100644
--- a/tests/lib/Files/Node/HookConnectorTest.php
+++ b/tests/lib/Files/Node/HookConnectorTest.php
@@ -96,7 +96,7 @@ class HookConnectorTest extends TestCase {
\OC_Util::tearDownFS();
}
- public function viewToNodeProvider() {
+ public static function viewToNodeProvider(): array {
return [
[function () {
Filesystem::file_put_contents('test.txt', 'asd');
@@ -195,7 +195,7 @@ class HookConnectorTest extends TestCase {
$this->assertEquals('/' . $this->userId . '/files/test.txt', $newDispatcherNode->getPath());
}
- public function viewToNodeProviderCopyRename() {
+ public static function viewToNodeProviderCopyRename(): array {
return [
[function () {
Filesystem::file_put_contents('source', 'asd');
diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTestCase.php
index db87aa925d3..a2b8a3ddffe 100644
--- a/tests/lib/Files/Node/NodeTest.php
+++ b/tests/lib/Files/Node/NodeTestCase.php
@@ -9,6 +9,7 @@ namespace Test\Files\Node;
use OC\Files\FileInfo;
use OC\Files\Mount\Manager;
+use OC\Files\Node\Root;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\EventDispatcher\IEventDispatcher;
@@ -27,7 +28,7 @@ use Psr\Log\LoggerInterface;
*
* @package Test\Files\Node
*/
-abstract class NodeTest extends \Test\TestCase {
+abstract class NodeTestCase extends \Test\TestCase {
/** @var \OC\User\User */
protected $user;
/** @var \OC\Files\Mount\Manager */
@@ -71,7 +72,7 @@ abstract class NodeTest extends \Test\TestCase {
->willReturnCallback(function () {
return new ArrayCache();
});
- $this->root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $this->root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
->getMock();
}
@@ -592,7 +593,7 @@ abstract class NodeTest extends \Test\TestCase {
$this->assertEquals('/bar/asd', $node->getPath());
}
- public function moveOrCopyProvider() {
+ public static function moveOrCopyProvider(): array {
return [
['move', 'rename', 'preRename', 'postRename'],
['copy', 'copy', 'preCopy', 'postCopy'],
@@ -608,9 +609,9 @@ abstract class NodeTest extends \Test\TestCase {
*/
public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $postHookName): void {
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject $root */
- $root = $this->getMockBuilder('\OC\Files\Node\Root')
+ $root = $this->getMockBuilder(Root::class)
->setConstructorArgs([$this->manager, $this->view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher, $this->cacheFactory])
- ->setMethods(['get'])
+ ->onlyMethods(['get'])
->getMock();
$this->view->expects($this->any())
diff --git a/tests/lib/Files/ObjectStore/AzureTest.php b/tests/lib/Files/ObjectStore/AzureTest.php
index c82ed988434..1103b15ecd2 100644
--- a/tests/lib/Files/ObjectStore/AzureTest.php
+++ b/tests/lib/Files/ObjectStore/AzureTest.php
@@ -11,7 +11,7 @@ use OC\Files\ObjectStore\Azure;
/**
* @group PRIMARY-azure
*/
-class AzureTest extends ObjectStoreTest {
+class AzureTest extends ObjectStoreTestCase {
protected function getInstance() {
$config = \OC::$server->getConfig()->getSystemValue('objectstore');
if (!is_array($config) || $config['class'] !== 'OC\\Files\\ObjectStore\\Azure') {
diff --git a/tests/lib/Files/ObjectStore/LocalTest.php b/tests/lib/Files/ObjectStore/LocalTest.php
index 99c5b61534f..3b561c01049 100644
--- a/tests/lib/Files/ObjectStore/LocalTest.php
+++ b/tests/lib/Files/ObjectStore/LocalTest.php
@@ -9,7 +9,7 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
-class LocalTest extends ObjectStoreTest {
+class LocalTest extends ObjectStoreTestCase {
/**
* @return \OCP\Files\ObjectStore\IObjectStore
*/
diff --git a/tests/lib/Files/ObjectStore/MapperTest.php b/tests/lib/Files/ObjectStore/MapperTest.php
index 15a2d497fc3..77416eae09a 100644
--- a/tests/lib/Files/ObjectStore/MapperTest.php
+++ b/tests/lib/Files/ObjectStore/MapperTest.php
@@ -29,7 +29,7 @@ class MapperTest extends \Test\TestCase {
$this->mapper = new Mapper($this->user, $this->config);
}
- public function dataGetBucket() {
+ public static function dataGetBucket(): array {
return [
['user', 64, 0, '17'],
['USER', 64, 0, '0'],
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
index a0e18a5557b..a1befd4e79d 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
@@ -9,12 +9,12 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
-use Test\Files\Storage\StoragesTest;
+use Test\Files\Storage\StoragesTestCase;
/**
* @group DB
*/
-class ObjectStoreStoragesDifferentBucketTest extends StoragesTest {
+class ObjectStoreStoragesDifferentBucketTest extends StoragesTestCase {
/**
* @var \OCP\Files\ObjectStore\IObjectStore
*/
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
index 19a1f4b7bc5..5505ee1dac1 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
@@ -9,12 +9,12 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
-use Test\Files\Storage\StoragesTest;
+use Test\Files\Storage\StoragesTestCase;
/**
* @group DB
*/
-class ObjectStoreStoragesSameBucketTest extends StoragesTest {
+class ObjectStoreStoragesSameBucketTest extends StoragesTestCase {
/**
* @var \OCP\Files\ObjectStore\IObjectStore
*/
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreTest.php b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php
index 4a4f85dfb91..ecbfd9a37e6 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreTestCase.php
@@ -9,10 +9,12 @@ namespace Test\Files\ObjectStore;
use Test\TestCase;
-abstract class ObjectStoreTest extends TestCase {
+abstract class ObjectStoreTestCase extends TestCase {
/** @var string[] */
private $cleanup = [];
+ private $instance = null;
+
/**
* @return \OCP\Files\ObjectStore\IObjectStore
*/
@@ -22,13 +24,20 @@ abstract class ObjectStoreTest extends TestCase {
$this->cleanup[] = $urn;
}
- public function tearDown(): void {
- parent::tearDown();
+ public function setUp(): void {
+ parent::setUp();
- $instance = $this->getInstance();
- foreach ($this->cleanup as $urn) {
- $instance->deleteObject($urn);
+ $this->instance = $this->getInstance();
+ }
+
+ public function tearDown(): void {
+ if ($this->instance) {
+ foreach ($this->cleanup as $urn) {
+ $this->instance->deleteObject($urn);
+ }
}
+
+ parent::tearDown();
}
protected function stringToStream($data) {
diff --git a/tests/lib/Files/ObjectStore/S3Test.php b/tests/lib/Files/ObjectStore/S3Test.php
index 1501f575f9a..76fc80c975f 100644
--- a/tests/lib/Files/ObjectStore/S3Test.php
+++ b/tests/lib/Files/ObjectStore/S3Test.php
@@ -44,7 +44,7 @@ class NonSeekableStream extends Wrapper {
/**
* @group PRIMARY-s3
*/
-class S3Test extends ObjectStoreTest {
+class S3Test extends ObjectStoreTestCase {
public function setUp(): void {
parent::setUp();
$s3 = $this->getInstance();
@@ -126,7 +126,7 @@ class S3Test extends ObjectStoreTest {
}
/** File size to upload in bytes */
- public function dataFileSizes() {
+ public static function dataFileSizes(): array {
return [
[1000000], [2000000], [5242879], [5242880], [5242881], [10000000]
];
diff --git a/tests/lib/Files/ObjectStore/SwiftTest.php b/tests/lib/Files/ObjectStore/SwiftTest.php
index 8a34d25e57b..9fb8c9bb68e 100644
--- a/tests/lib/Files/ObjectStore/SwiftTest.php
+++ b/tests/lib/Files/ObjectStore/SwiftTest.php
@@ -12,7 +12,7 @@ use OC\Files\ObjectStore\Swift;
/**
* @group PRIMARY-swift
*/
-class SwiftTest extends ObjectStoreTest {
+class SwiftTest extends ObjectStoreTestCase {
/**
* @return \OCP\Files\ObjectStore\IObjectStore
*/
diff --git a/tests/lib/Files/PathVerificationTest.php b/tests/lib/Files/PathVerificationTest.php
index fcbe0a6957f..d6dff445c0f 100644
--- a/tests/lib/Files/PathVerificationTest.php
+++ b/tests/lib/Files/PathVerificationTest.php
@@ -49,7 +49,7 @@ class PathVerificationTest extends \Test\TestCase {
$this->view->verifyPath('', $fileName);
}
- public function providesEmptyFiles() {
+ public static function providesEmptyFiles(): array {
return [
[''],
[' '],
@@ -66,7 +66,7 @@ class PathVerificationTest extends \Test\TestCase {
$this->view->verifyPath('', $fileName);
}
- public function providesDotFiles() {
+ public static function providesDotFiles(): array {
return [
['.'],
['..'],
@@ -95,7 +95,7 @@ class PathVerificationTest extends \Test\TestCase {
$this->view->verifyPath('', $fileName);
}
- public function providesAstralPlane() {
+ public static function providesAstralPlane(): array {
return [
// this is the monkey emoji - http://en.wikipedia.org/w/index.php?title=%F0%9F%90%B5&redirect=no
['🐵'],
@@ -117,7 +117,7 @@ class PathVerificationTest extends \Test\TestCase {
$this->addToAssertionCount(1);
}
- public function providesValidPosixPaths() {
+ public static function providesValidPosixPaths(): array {
return [
['simple'],
['simple.txt'],
diff --git a/tests/lib/Files/Storage/CommonTest.php b/tests/lib/Files/Storage/CommonTest.php
index b51b35be8f9..529615f3733 100644
--- a/tests/lib/Files/Storage/CommonTest.php
+++ b/tests/lib/Files/Storage/CommonTest.php
@@ -9,6 +9,7 @@ namespace Test\Files\Storage;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Wrapper;
+use OCP\Files;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidPathException;
@@ -37,7 +38,7 @@ class CommonTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
$this->restoreService(IFilenameValidator::class);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/HomeTest.php b/tests/lib/Files/Storage/HomeTest.php
index b6d0f1aa85a..26b81c6f1a0 100644
--- a/tests/lib/Files/Storage/HomeTest.php
+++ b/tests/lib/Files/Storage/HomeTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\User\User;
+use OCP\Files;
class DummyUser extends User {
private $home;
@@ -62,7 +63,7 @@ class HomeTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/LocalTest.php b/tests/lib/Files/Storage/LocalTest.php
index 65bc538ef17..13317fad7bb 100644
--- a/tests/lib/Files/Storage/LocalTest.php
+++ b/tests/lib/Files/Storage/LocalTest.php
@@ -8,6 +8,7 @@
namespace Test\Files\Storage;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Files;
/**
* Class LocalTest
@@ -30,7 +31,7 @@ class LocalTest extends Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php
index 36d70965848..c6f051fb7e1 100644
--- a/tests/lib/Files/Storage/Storage.php
+++ b/tests/lib/Files/Storage/Storage.php
@@ -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
@@ -179,7 +179,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'],
@@ -414,7 +414,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'],
diff --git a/tests/lib/Files/Storage/StoragesTest.php b/tests/lib/Files/Storage/StoragesTestCase.php
index 3f8198d331d..18fe78a93d1 100644
--- a/tests/lib/Files/Storage/StoragesTest.php
+++ b/tests/lib/Files/Storage/StoragesTestCase.php
@@ -9,7 +9,7 @@ namespace Test\Files\Storage;
use Test\TestCase;
-abstract class StoragesTest extends TestCase {
+abstract class StoragesTestCase extends TestCase {
/**
* @var \OC\Files\Storage\Storage
*/
diff --git a/tests/lib/Files/Storage/Wrapper/EncodingTest.php b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
index d8b03a891c2..9d8a1e16145 100644
--- a/tests/lib/Files/Storage/Wrapper/EncodingTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncodingTest.php
@@ -29,25 +29,25 @@ 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],
@@ -110,7 +110,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],
@@ -150,7 +150,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'],
diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
index bb3df36dec2..1c299fa989f 100644
--- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
+++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php
@@ -11,7 +11,6 @@ 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;
@@ -46,7 +45,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 +60,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 +76,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 +96,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 +106,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) {
@@ -155,12 +149,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 +174,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');
@@ -237,12 +230,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 +277,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 +308,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);
@@ -361,12 +352,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 +379,7 @@ class EncryptionTest extends Storage {
);
}
- public function dataTestVerifyUnencryptedSize() {
+ public static function dataTestVerifyUnencryptedSize(): array {
return [
[120, 80, false, 80],
[120, 120, false, 80],
@@ -444,7 +434,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],
@@ -491,7 +481,6 @@ class EncryptionTest extends Storage {
$this->file,
null,
$this->keyStore,
- $this->update,
$this->mountManager,
$this->arrayCache,
);
@@ -506,7 +495,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],
@@ -541,7 +530,7 @@ class EncryptionTest extends Storage {
);
}
- public function dataTestCopyKeys() {
+ public static function dataTestCopyKeys(): array {
return [
[true, false],
[false, true],
@@ -598,12 +587,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 +617,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'],
@@ -646,7 +634,7 @@ class EncryptionTest extends Storage {
* @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 +642,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 +657,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 +679,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 +699,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 +708,7 @@ class EncryptionTest extends Storage {
];
}
- public function dataCopyBetweenStorage() {
+ public static function dataCopyBetweenStorage(): array {
return [
[true, true, true],
[true, false, false],
@@ -867,12 +853,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 +899,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],
@@ -939,7 +924,7 @@ class EncryptionTest extends Storage {
);
}
- public function dataTestIsVersion() {
+ public static function dataTestIsVersion(): array {
return [
['files_versions/foo', true],
['/files_versions/foo', true],
@@ -968,7 +953,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 +970,11 @@ class EncryptionTest extends Storage {
$fileHelper,
null,
$keyStorage,
- $update,
$mountManager,
$arrayCache
]
)
- ->setMethods(['getFullPath', 'getEncryptionModule'])
+ ->onlyMethods(['getFullPath', 'getEncryptionModule'])
->getMock();
if ($encryptionModule === true) {
@@ -1033,7 +1016,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/QuotaTest.php b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
index f07e6021e4e..791e8047f7f 100644
--- a/tests/lib/Files/Storage/Wrapper/QuotaTest.php
+++ b/tests/lib/Files/Storage/Wrapper/QuotaTest.php
@@ -10,6 +10,7 @@ namespace Test\Files\Storage\Wrapper;
//ensure the constants are loaded
use OC\Files\Cache\CacheEntry;
use OC\Files\Storage\Local;
+use OCP\Files;
\OC::$loader->load('\OC\Files\Filesystem');
@@ -35,7 +36,7 @@ class QuotaTest extends \Test\Files\Storage\Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
@@ -76,7 +77,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())
@@ -132,7 +133,7 @@ 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())
diff --git a/tests/lib/Files/Storage/Wrapper/WrapperTest.php b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
index 1d0f41bf3ed..4cbae1762fc 100644
--- a/tests/lib/Files/Storage/Wrapper/WrapperTest.php
+++ b/tests/lib/Files/Storage/Wrapper/WrapperTest.php
@@ -7,6 +7,8 @@
namespace Test\Files\Storage\Wrapper;
+use OCP\Files;
+
class WrapperTest extends \Test\Files\Storage\Storage {
/**
* @var string tmpDir
@@ -22,7 +24,7 @@ class WrapperTest extends \Test\Files\Storage\Storage {
}
protected function tearDown(): void {
- \OC_Helper::rmdirr($this->tmpDir);
+ Files::rmdirr($this->tmpDir);
parent::tearDown();
}
diff --git a/tests/lib/Files/Stream/EncryptionTest.php b/tests/lib/Files/Stream/EncryptionTest.php
index 36e72ea764a..c676358ad71 100644
--- a/tests/lib/Files/Stream/EncryptionTest.php
+++ b/tests/lib/Files/Stream/EncryptionTest.php
@@ -9,8 +9,12 @@ declare(strict_types=1);
*/
namespace Test\Files\Stream;
+use OC\Encryption\File;
+use OC\Encryption\Util;
use OC\Files\Cache\CacheEntry;
+use OC\Files\Storage\Storage;
use OC\Files\Storage\Wrapper\Wrapper;
+use OC\Files\Stream\Encryption;
use OC\Files\View;
use OC\Memcache\ArrayCache;
use OCP\Encryption\IEncryptionModule;
@@ -53,11 +57,11 @@ class EncryptionTest extends \Test\TestCase {
->getMock();
$file = $this->getMockBuilder('\OC\Encryption\File')
->disableOriginalConstructor()
- ->setMethods(['getAccessList'])
+ ->onlyMethods(['getAccessList'])
->getMock();
$file->expects($this->any())->method('getAccessList')->willReturn([]);
$util = $this->getMockBuilder('\OC\Encryption\Util')
- ->setMethods(['getUidAndFilename'])
+ ->onlyMethods(['getUidAndFilename'])
->setConstructorArgs([new View(), new \OC\User\Manager(
$config,
$this->createMock(ICacheFactory::class),
@@ -111,20 +115,17 @@ class EncryptionTest extends \Test\TestCase {
$expectedReadOnly,
): void {
// build mocks
- $encryptionModuleMock = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
- ->disableOriginalConstructor()->getMock();
+ $encryptionModuleMock = $this->createMock(IEncryptionModule::class);
$encryptionModuleMock->expects($this->any())->method('needDetailedAccessList')->willReturn(!$isMasterKeyUsed);
$encryptionModuleMock->expects($this->once())
->method('getUnencryptedBlockSize')->willReturn(99);
$encryptionModuleMock->expects($this->once())
->method('begin')->willReturn([]);
- $storageMock = $this->getMockBuilder('\OC\Files\Storage\Storage')
- ->disableOriginalConstructor()->getMock();
+ $storageMock = $this->createMock(Storage::class);
$storageMock->expects($this->once())->method('file_exists')->willReturn($fileExists);
- $fileMock = $this->getMockBuilder('\OC\Encryption\File')
- ->disableOriginalConstructor()->getMock();
+ $fileMock = $this->createMock(File::class);
if ($isMasterKeyUsed) {
$fileMock->expects($this->never())->method('getAccessList');
} else {
@@ -134,18 +135,20 @@ class EncryptionTest extends \Test\TestCase {
return [];
});
}
- $utilMock = $this->getMockBuilder('\OC\Encryption\Util')
+ $utilMock = $this->getMockBuilder(Util::class)
->disableOriginalConstructor()->getMock();
$utilMock->expects($this->any())
->method('getHeaderSize')
->willReturn(8192);
// get a instance of the stream wrapper
- $streamWrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
- ->setMethods(['loadContext', 'writeHeader', 'skipHeader'])->disableOriginalConstructor()->getMock();
+ $streamWrapper = $this->getMockBuilder(Encryption::class)
+ ->onlyMethods(['loadContext', 'writeHeader', 'skipHeader'])
+ ->disableOriginalConstructor()
+ ->getMock();
// set internal properties of the stream wrapper
- $stream = new \ReflectionClass('\OC\Files\Stream\Encryption');
+ $stream = new \ReflectionClass(Encryption::class);
$encryptionModule = $stream->getProperty('encryptionModule');
$encryptionModule->setAccessible(true);
$encryptionModule->setValue($streamWrapper, $encryptionModuleMock);
@@ -195,7 +198,7 @@ class EncryptionTest extends \Test\TestCase {
$readOnly->setAccessible(false);
}
- public function dataProviderStreamOpen() {
+ public static function dataProviderStreamOpen(): array {
return [
[false, 'r', '/foo/bar/test.txt', true, '/foo/bar/test.txt', null, null, true],
[false, 'r', '/foo/bar/test.txt', false, '/foo/bar', null, null, true],
@@ -266,7 +269,7 @@ class EncryptionTest extends \Test\TestCase {
unlink($fileName);
}
- public function dataFilesProvider() {
+ public static function dataFilesProvider(): array {
return [
['lorem-big.txt'],
['block-aligned.txt'],
@@ -315,9 +318,12 @@ class EncryptionTest extends \Test\TestCase {
* @dataProvider dataFilesProvider
*/
public function testWriteToNonSeekableStorage($testFile): void {
- $wrapper = $this->getMockBuilder('\OC\Files\Stream\Encryption')
- ->setMethods(['parentSeekStream'])->getMock();
- $wrapper->expects($this->any())->method('parentSeekStream')->willReturn(false);
+ $wrapper = $this->getMockBuilder(Encryption::class)
+ ->onlyMethods(['parentStreamSeek'])
+ ->getMock();
+ $wrapper->expects($this->any())
+ ->method('parentStreamSeek')
+ ->willReturn(false);
$expectedData = file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $testFile);
// write it
@@ -351,9 +357,9 @@ class EncryptionTest extends \Test\TestCase {
}
protected function buildMockModule(): IEncryptionModule&MockObject {
- $encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule')
+ $encryptionModule = $this->getMockBuilder(IEncryptionModule::class)
->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();
$encryptionModule->expects($this->any())->method('getId')->willReturn('UNIT_TEST_MODULE');
diff --git a/tests/lib/Files/Stream/HashWrapperTest.php b/tests/lib/Files/Stream/HashWrapperTest.php
index ee50fe3b13a..1e9bbd8f289 100644
--- a/tests/lib/Files/Stream/HashWrapperTest.php
+++ b/tests/lib/Files/Stream/HashWrapperTest.php
@@ -31,7 +31,7 @@ class HashWrapperTest extends TestCase {
stream_get_contents($wrapper);
}
- public function hashProvider() {
+ public static function hashProvider(): array {
return [
['foo', 'md5', 'acbd18db4cc2f85cedef654fccc4a4d8'],
['foo', 'sha1', '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'],
diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php
index f66bb72e865..51089e5560c 100644
--- a/tests/lib/Files/Utils/ScannerTest.php
+++ b/tests/lib/Files/Utils/ScannerTest.php
@@ -138,10 +138,7 @@ class ScannerTest extends \Test\TestCase {
$this->assertTrue($cache->inCache('folder/bar.txt'));
}
- /**
- * @return array
- */
- public function invalidPathProvider() {
+ public static function invalidPathProvider(): array {
return [
[
'../',
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 53e5855d0e9..b790c9ed6e8 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -25,6 +25,7 @@ use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Storage\IStorage;
+use OCP\Files\Storage\IStorageFactory;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
@@ -518,10 +519,10 @@ class ViewTest extends \Test\TestCase {
}
public function moveBetweenStorages($storage1, $storage2) {
- Filesystem::mount($storage1, [], '/');
- Filesystem::mount($storage2, [], '/substorage');
+ Filesystem::mount($storage1, [], '/' . $this->user . '/');
+ Filesystem::mount($storage2, [], '/' . $this->user . '/substorage');
- $rootView = new View('');
+ $rootView = new View('/' . $this->user);
$rootView->rename('foo.txt', 'substorage/folder/foo.txt');
$this->assertFalse($rootView->file_exists('foo.txt'));
$this->assertTrue($rootView->file_exists('substorage/folder/foo.txt'));
@@ -941,14 +942,16 @@ class ViewTest extends \Test\TestCase {
$storage = new Temporary([]);
$scanner = $storage->getScanner();
Filesystem::mount($storage, [], '/test/');
- $storage->file_put_contents('test.part', 'foobar');
+ $sizeWritten = $storage->file_put_contents('test.part', 'foobar');
$scanner->scan('');
$view = new View('/test');
$info = $view->getFileInfo('test.part');
$this->assertInstanceOf('\OCP\Files\FileInfo', $info);
$this->assertNull($info->getId());
+ $this->assertEquals(6, $sizeWritten);
$this->assertEquals(6, $info->getSize());
+ $this->assertEquals('foobar', $view->file_get_contents('test.part'));
}
public static function absolutePathProvider(): array {
@@ -1947,6 +1950,8 @@ class ViewTest extends \Test\TestCase {
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
Server::get(ITrashManager::class)->pauseTrash();
+ /* Same thing with encryption wrapper */
+ Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption');
Filesystem::mount($storage, [], $this->user . '/');
@@ -2097,6 +2102,8 @@ class ViewTest extends \Test\TestCase {
/* Pause trash to avoid the trashbin intercepting rmdir and unlink calls */
Server::get(ITrashManager::class)->pauseTrash();
+ /* Same thing with encryption wrapper */
+ Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption');
Filesystem::mount($storage, [], $this->user . '/');
@@ -2238,6 +2245,9 @@ class ViewTest extends \Test\TestCase {
$sourcePath = 'original.txt';
$targetPath = 'target.txt';
+ /* Disable encryption wrapper to avoid it intercepting mocked call */
+ Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption');
+
Filesystem::mount($storage, [], $this->user . '/');
$storage->mkdir('files');
$view->file_put_contents($sourcePath, 'meh');
@@ -2291,6 +2301,9 @@ class ViewTest extends \Test\TestCase {
$sourcePath = 'original.txt';
$targetPath = 'target.txt';
+ /* Disable encryption wrapper to avoid it intercepting mocked call */
+ Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption');
+
Filesystem::mount($storage, [], $this->user . '/');
$storage->mkdir('files');
$view->file_put_contents($sourcePath, 'meh');
@@ -2427,6 +2440,9 @@ class ViewTest extends \Test\TestCase {
$sourcePath = 'original.txt';
$targetPath = 'substorage/target.txt';
+ /* Disable encryption wrapper to avoid it intercepting mocked call */
+ Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption');
+
Filesystem::mount($storage, [], $this->user . '/');
Filesystem::mount($storage2, [], $this->user . '/files/substorage');
$storage->mkdir('files');