aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files
diff options
context:
space:
mode:
authorKate <26026535+provokateurin@users.noreply.github.com>2024-09-20 10:06:14 +0200
committerGitHub <noreply@github.com>2024-09-20 10:06:14 +0200
commitae7241f6c8cd811c817dbf4b3e68d2e3d3203405 (patch)
tree6ac3303d4e9ef0ad99701b4b9660b1fbd9394c6e /tests/lib/Files
parent5f32c2f79f00e16a3ae96378d22cb5b152ca3b00 (diff)
parent656e32c6c1eb5441785e762d32bef18f2a7e0a33 (diff)
downloadnextcloud-server-ae7241f6c8cd811c817dbf4b3e68d2e3d3203405.tar.gz
nextcloud-server-ae7241f6c8cd811c817dbf4b3e68d2e3d3203405.zip
Merge pull request #48221 from nextcloud/backport/30/fix_move_on_same_bucket
Diffstat (limited to 'tests/lib/Files')
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php41
-rw-r--r--tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php33
-rw-r--r--tests/lib/Files/Storage/StoragesTest.php108
3 files changed, 182 insertions, 0 deletions
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
new file mode 100644
index 00000000000..a0e18a5557b
--- /dev/null
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesDifferentBucketTest.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Files\ObjectStore;
+
+use OC\Files\ObjectStore\StorageObjectStore;
+use OC\Files\Storage\Temporary;
+use Test\Files\Storage\StoragesTest;
+
+/**
+ * @group DB
+ */
+class ObjectStoreStoragesDifferentBucketTest extends StoragesTest {
+ /**
+ * @var \OCP\Files\ObjectStore\IObjectStore
+ */
+ private $objectStore1;
+
+ /**
+ * @var \OCP\Files\ObjectStore\IObjectStore
+ */
+ private $objectStore2;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $baseStorage1 = new Temporary();
+ $this->objectStore1 = new StorageObjectStore($baseStorage1);
+ $config['objectstore'] = $this->objectStore1;
+ $this->storage1 = new ObjectStoreStorageOverwrite($config);
+
+ $baseStorage2 = new Temporary();
+ $this->objectStore2 = new StorageObjectStore($baseStorage2);
+ $config['objectstore'] = $this->objectStore2;
+ $this->storage2 = new ObjectStoreStorageOverwrite($config);
+ }
+}
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
new file mode 100644
index 00000000000..19a1f4b7bc5
--- /dev/null
+++ b/tests/lib/Files/ObjectStore/ObjectStoreStoragesSameBucketTest.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Files\ObjectStore;
+
+use OC\Files\ObjectStore\StorageObjectStore;
+use OC\Files\Storage\Temporary;
+use Test\Files\Storage\StoragesTest;
+
+/**
+ * @group DB
+ */
+class ObjectStoreStoragesSameBucketTest extends StoragesTest {
+ /**
+ * @var \OCP\Files\ObjectStore\IObjectStore
+ */
+ private $objectStore;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $baseStorage = new Temporary();
+ $this->objectStore = new StorageObjectStore($baseStorage);
+ $config['objectstore'] = $this->objectStore;
+ // storage1 and storage2 share the same object store.
+ $this->storage1 = new ObjectStoreStorageOverwrite($config);
+ $this->storage2 = new ObjectStoreStorageOverwrite($config);
+ }
+}
diff --git a/tests/lib/Files/Storage/StoragesTest.php b/tests/lib/Files/Storage/StoragesTest.php
new file mode 100644
index 00000000000..d157d288f2c
--- /dev/null
+++ b/tests/lib/Files/Storage/StoragesTest.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Files\Storage;
+
+use Test\TestCase;
+
+abstract class StoragesTest extends TestCase {
+ /**
+ * @var \OC\Files\Storage\Storage
+ */
+ protected $storage1;
+
+ /**
+ * @var \OC\Files\Storage\Storage
+ */
+ protected $storage2;
+
+ protected function tearDown(): void {
+ if (is_null($this->storage1) && is_null($this->storage2)) {
+ return;
+ }
+ $this->storage1->getCache()->clear();
+ $this->storage2->getCache()->clear();
+
+ parent::tearDown();
+ }
+
+ public function testMoveFileFromStorage() {
+ $source = 'source.txt';
+ $target = 'target.txt';
+ $this->storage2->file_put_contents($source, 'foo');
+
+ $this->storage1->moveFromStorage($this->storage2, $source, $target);
+
+ $this->assertTrue($this->storage1->file_exists($target), $target.' was not created');
+ $this->assertFalse($this->storage2->file_exists($source), $source.' still exists');
+ $this->assertEquals('foo', $this->storage1->file_get_contents($target));
+ }
+
+ public function testMoveDirectoryFromStorage() {
+ $this->storage2->mkdir('source');
+ $this->storage2->file_put_contents('source/test1.txt', 'foo');
+ $this->storage2->file_put_contents('source/test2.txt', 'qwerty');
+ $this->storage2->mkdir('source/subfolder');
+ $this->storage2->file_put_contents('source/subfolder/test.txt', 'bar');
+
+ $this->storage1->moveFromStorage($this->storage2, 'source', 'target');
+
+ $this->assertTrue($this->storage1->file_exists('target'));
+ $this->assertTrue($this->storage1->file_exists('target/test1.txt'));
+ $this->assertTrue($this->storage1->file_exists('target/test2.txt'));
+ $this->assertTrue($this->storage1->file_exists('target/subfolder'));
+ $this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt'));
+
+ $this->assertFalse($this->storage2->file_exists('source'));
+ $this->assertFalse($this->storage2->file_exists('source/test1.txt'));
+ $this->assertFalse($this->storage2->file_exists('source/test2.txt'));
+ $this->assertFalse($this->storage2->file_exists('source/subfolder'));
+ $this->assertFalse($this->storage2->file_exists('source/subfolder/test.txt'));
+
+ $this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt'));
+ $this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt'));
+ $this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt'));
+ }
+
+ public function testCopyFileFromStorage() {
+ $source = 'source.txt';
+ $target = 'target.txt';
+ $this->storage2->file_put_contents($source, 'foo');
+
+ $this->storage1->copyFromStorage($this->storage2, $source, $target);
+
+ $this->assertTrue($this->storage1->file_exists($target), $target.' was not created');
+ $this->assertTrue($this->storage2->file_exists($source), $source.' was deleted');
+ $this->assertEquals('foo', $this->storage1->file_get_contents($target));
+ }
+
+ public function testCopyDirectoryFromStorage() {
+ $this->storage2->mkdir('source');
+ $this->storage2->file_put_contents('source/test1.txt', 'foo');
+ $this->storage2->file_put_contents('source/test2.txt', 'qwerty');
+ $this->storage2->mkdir('source/subfolder');
+ $this->storage2->file_put_contents('source/subfolder/test.txt', 'bar');
+
+ $this->storage1->copyFromStorage($this->storage2, 'source', 'target');
+
+ $this->assertTrue($this->storage1->file_exists('target'));
+ $this->assertTrue($this->storage1->file_exists('target/test1.txt'));
+ $this->assertTrue($this->storage1->file_exists('target/test2.txt'));
+ $this->assertTrue($this->storage1->file_exists('target/subfolder'));
+ $this->assertTrue($this->storage1->file_exists('target/subfolder/test.txt'));
+
+ $this->assertTrue($this->storage2->file_exists('source'));
+ $this->assertTrue($this->storage2->file_exists('source/test1.txt'));
+ $this->assertTrue($this->storage2->file_exists('source/test2.txt'));
+ $this->assertTrue($this->storage2->file_exists('source/subfolder'));
+ $this->assertTrue($this->storage2->file_exists('source/subfolder/test.txt'));
+
+ $this->assertEquals('foo', $this->storage1->file_get_contents('target/test1.txt'));
+ $this->assertEquals('qwerty', $this->storage1->file_get_contents('target/test2.txt'));
+ $this->assertEquals('bar', $this->storage1->file_get_contents('target/subfolder/test.txt'));
+ }
+}