aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php')
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php63
1 files changed, 38 insertions, 25 deletions
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
index 8ffd27f0069..3387808445a 100644
--- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,6 +11,7 @@ namespace Test\Files\ObjectStore;
use OC\Files\ObjectStore\StorageObjectStore;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\Jail;
+use OCP\Constants;
use OCP\Files\ObjectStore\IObjectStore;
use Test\Files\Storage\Storage;
@@ -43,7 +45,7 @@ class ObjectStoreStorageTest extends Storage {
parent::tearDown();
}
- public function testStat() {
+ public function testStat(): void {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
$ctimeStart = time();
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
@@ -67,29 +69,27 @@ class ObjectStoreStorageTest extends Storage {
}
}
- public function testCheckUpdate() {
+ public function testCheckUpdate(): void {
$this->markTestSkipped('Detecting external changes is not supported on object storages');
}
- /**
- * @dataProvider copyAndMoveProvider
- */
- public function testMove($source, $target) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('copyAndMoveProvider')]
+ public function testMove($source, $target): void {
$this->initSourceAndTarget($source);
- $sourceId = $this->instance->getCache()->getId(ltrim('/', $source));
+ $sourceId = $this->instance->getCache()->getId(ltrim($source, '/'));
$this->assertNotEquals(-1, $sourceId);
$this->instance->rename($source, $target);
- $this->assertTrue($this->instance->file_exists($target), $target.' was not created');
- $this->assertFalse($this->instance->file_exists($source), $source.' still exists');
+ $this->assertTrue($this->instance->file_exists($target), $target . ' was not created');
+ $this->assertFalse($this->instance->file_exists($source), $source . ' still exists');
$this->assertSameAsLorem($target);
- $targetId = $this->instance->getCache()->getId(ltrim('/', $target));
+ $targetId = $this->instance->getCache()->getId(ltrim($target, '/'));
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameDirectory() {
+ public function testRenameDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
@@ -118,7 +118,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameOverWriteDirectory() {
+ public function testRenameOverWriteDirectory(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$sourceId = $this->instance->getCache()->getId('source');
@@ -138,7 +138,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testRenameOverWriteDirectoryOverFile() {
+ public function testRenameOverWriteDirectoryOverFile(): void {
$this->instance->mkdir('source');
$this->instance->file_put_contents('source/test1.txt', 'foo');
$sourceId = $this->instance->getCache()->getId('source');
@@ -155,7 +155,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
}
- public function testWriteObjectSilentFailure() {
+ public function testWriteObjectSilentFailure(): void {
$objectStore = $this->instance->getObjectStore();
$this->instance->setObjectStore(new FailWriteObjectStore($objectStore));
@@ -168,7 +168,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertFalse($this->instance->file_exists('test.txt'));
}
- public function testWriteObjectSilentFailureNoCheck() {
+ public function testWriteObjectSilentFailureNoCheck(): void {
$objectStore = $this->instance->getObjectStore();
$this->instance->setObjectStore(new FailWriteObjectStore($objectStore));
$this->instance->setValidateWrites(false);
@@ -177,7 +177,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($this->instance->file_exists('test.txt'));
}
- public function testDeleteObjectFailureKeepCache() {
+ public function testDeleteObjectFailureKeepCache(): void {
$objectStore = $this->instance->getObjectStore();
$this->instance->setObjectStore(new FailDeleteObjectStore($objectStore));
$cache = $this->instance->getCache();
@@ -202,7 +202,7 @@ class ObjectStoreStorageTest extends Storage {
$this->assertTrue($cache->inCache('foo/test.txt'));
}
- public function testCopyBetweenJails() {
+ public function testCopyBetweenJails(): void {
$this->instance->mkdir('a');
$this->instance->mkdir('b');
$jailA = new Jail([
@@ -225,26 +225,26 @@ class ObjectStoreStorageTest extends Storage {
$this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt'));
}
- public function testCopyPreservesPermissions() {
+ public function testCopyPreservesPermissions(): void {
$cache = $this->instance->getCache();
$this->instance->file_put_contents('test.txt', 'foo');
$this->assertTrue($cache->inCache('test.txt'));
- $cache->update($cache->getId('test.txt'), ['permissions' => \OCP\Constants::PERMISSION_READ]);
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('test.txt'));
$this->assertTrue($this->instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_READ, $this->instance->getPermissions('new.txt'));
}
/**
* Test that copying files will drop permissions like local storage does
* TODO: Drop this and fix local storage
*/
- public function testCopyGrantsPermissions() {
+ public function testCopyGrantsPermissions(): void {
$config['objectstore'] = $this->objectStorage;
$config['handleCopiesAsOwned'] = true;
$instance = new ObjectStoreStorageOverwrite($config);
@@ -254,12 +254,25 @@ class ObjectStoreStorageTest extends Storage {
$instance->file_put_contents('test.txt', 'foo');
$this->assertTrue($cache->inCache('test.txt'));
- $cache->update($cache->getId('test.txt'), ['permissions' => \OCP\Constants::PERMISSION_READ]);
- $this->assertEquals(\OCP\Constants::PERMISSION_READ, $instance->getPermissions('test.txt'));
+ $cache->update($cache->getId('test.txt'), ['permissions' => Constants::PERMISSION_READ]);
+ $this->assertEquals(Constants::PERMISSION_READ, $instance->getPermissions('test.txt'));
$this->assertTrue($instance->copy('test.txt', 'new.txt'));
$this->assertTrue($cache->inCache('new.txt'));
- $this->assertEquals(\OCP\Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
+ $this->assertEquals(Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
+ }
+
+ public function testCopyFolderSize(): void {
+ $cache = $this->instance->getCache();
+
+ $this->instance->mkdir('source');
+ $this->instance->file_put_contents('source/test.txt', 'foo');
+ $this->instance->getUpdater()->update('source/test.txt');
+ $this->assertEquals(3, $cache->get('source')->getSize());
+
+ $this->assertTrue($this->instance->copy('source', 'target'));
+
+ $this->assertEquals(3, $cache->get('target')->getSize());
}
}