diff options
Diffstat (limited to 'tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php')
-rw-r--r-- | tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php index 2f835747077..3387808445a 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php @@ -1,21 +1,9 @@ <?php + /** - * @author Jörn Friedrich Dreyer - * @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * + * 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; @@ -23,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; @@ -56,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)); @@ -80,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'); @@ -131,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'); @@ -151,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'); @@ -168,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)); @@ -181,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); @@ -190,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(); @@ -215,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([ @@ -238,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); @@ -267,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()); } } |