diff options
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php | 151 |
1 files changed, 37 insertions, 114 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php index 8d6bfc1764b..b07778e4fbd 100644 --- a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php @@ -1,38 +1,22 @@ <?php + +declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. 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-only */ namespace OCA\DAV\Tests\unit\Connector\Sabre; use OC\Files\FileInfo; use OC\Files\Filesystem; use OC\Files\Mount\Manager; +use OC\Files\Storage\Common; use OC\Files\Storage\Temporary; use OC\Files\View; use OCA\DAV\Connector\Sabre\Directory; +use OCA\DAV\Connector\Sabre\Exception\InvalidPath; +use OCA\DAV\Connector\Sabre\File; use OCA\DAV\Connector\Sabre\ObjectTree; use OCP\Files\Mount\IMountManager; @@ -44,7 +28,7 @@ use OCP\Files\Mount\IMountManager; * @package OCA\DAV\Tests\Unit\Connector\Sabre */ class ObjectTreeTest extends \Test\TestCase { - public function copyDataProvider() { + public static function copyDataProvider(): array { return [ // copy into same dir ['a', 'b', ''], @@ -55,10 +39,8 @@ class ObjectTreeTest extends \Test\TestCase { ]; } - /** - * @dataProvider copyDataProvider - */ - public function testCopy($sourcePath, $targetPath, $targetParent): void { + #[\PHPUnit\Framework\Attributes\DataProvider('copyDataProvider')] + public function testCopy(string $sourcePath, string $targetPath, string $targetParent): void { $view = $this->createMock(View::class); $view->expects($this->once()) ->method('verifyPath') @@ -84,7 +66,7 @@ class ObjectTreeTest extends \Test\TestCase { $rootDir = new Directory($view, $info); $objectTree = $this->getMockBuilder(ObjectTree::class) - ->setMethods(['nodeExists', 'getNodeForPath']) + ->onlyMethods(['nodeExists', 'getNodeForPath']) ->setConstructorArgs([$rootDir, $view]) ->getMock(); @@ -93,15 +75,13 @@ class ObjectTreeTest extends \Test\TestCase { ->with($this->identicalTo($sourcePath)) ->willReturn(false); - /** @var $objectTree \OCA\DAV\Connector\Sabre\ObjectTree */ + /** @var ObjectTree $objectTree */ $mountManager = Filesystem::getMountManager(); $objectTree->init($rootDir, $view, $mountManager); $objectTree->copy($sourcePath, $targetPath); } - /** - * @dataProvider copyDataProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('copyDataProvider')] public function testCopyFailNotCreatable($sourcePath, $targetPath, $targetParent): void { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); @@ -127,57 +107,42 @@ class ObjectTreeTest extends \Test\TestCase { $rootDir = new Directory($view, $info); $objectTree = $this->getMockBuilder(ObjectTree::class) - ->setMethods(['nodeExists', 'getNodeForPath']) + ->onlyMethods(['nodeExists', 'getNodeForPath']) ->setConstructorArgs([$rootDir, $view]) ->getMock(); $objectTree->expects($this->never()) ->method('getNodeForPath'); - /** @var $objectTree \OCA\DAV\Connector\Sabre\ObjectTree */ + /** @var ObjectTree $objectTree */ $mountManager = Filesystem::getMountManager(); $objectTree->init($rootDir, $view, $mountManager); $objectTree->copy($sourcePath, $targetPath); } - /** - * @dataProvider nodeForPathProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('nodeForPathProvider')] public function testGetNodeForPath( - $inputFileName, - $fileInfoQueryPath, - $outputFileName, - $type, - $enableChunkingHeader + string $inputFileName, + string $fileInfoQueryPath, + string $outputFileName, + string $type, ): void { - if ($enableChunkingHeader) { - $_SERVER['HTTP_OC_CHUNKED'] = true; - } - - $rootNode = $this->getMockBuilder(Directory::class) - ->disableOriginalConstructor() - ->getMock(); - $mountManager = $this->getMockBuilder(Manager::class) - ->disableOriginalConstructor() - ->getMock(); - $view = $this->getMockBuilder(View::class) - ->disableOriginalConstructor() - ->getMock(); - $fileInfo = $this->getMockBuilder(FileInfo::class) - ->disableOriginalConstructor() - ->getMock(); + $rootNode = $this->createMock(Directory::class); + $mountManager = $this->createMock(Manager::class); + $view = $this->createMock(View::class); + $fileInfo = $this->createMock(FileInfo::class); $fileInfo->method('getType') ->willReturn($type); $fileInfo->method('getName') ->willReturn($outputFileName); $fileInfo->method('getStorage') - ->willReturn($this->createMock(\OC\Files\Storage\Common::class)); + ->willReturn($this->createMock(Common::class)); $view->method('getFileInfo') ->with($fileInfoQueryPath) ->willReturn($fileInfo); - $tree = new \OCA\DAV\Connector\Sabre\ObjectTree(); + $tree = new ObjectTree(); $tree->init($rootNode, $view, $mountManager); $node = $tree->getNodeForPath($inputFileName); @@ -186,15 +151,13 @@ class ObjectTreeTest extends \Test\TestCase { $this->assertEquals($outputFileName, $node->getName()); if ($type === 'file') { - $this->assertTrue($node instanceof \OCA\DAV\Connector\Sabre\File); + $this->assertInstanceOf(File::class, $node); } else { - $this->assertTrue($node instanceof \OCA\DAV\Connector\Sabre\Directory); + $this->assertInstanceOf(Directory::class, $node); } - - unset($_SERVER['HTTP_OC_CHUNKED']); } - public function nodeForPathProvider() { + public static function nodeForPathProvider(): array { return [ // regular file [ @@ -202,7 +165,6 @@ class ObjectTreeTest extends \Test\TestCase { 'regularfile.txt', 'regularfile.txt', 'file', - false ], // regular directory [ @@ -210,31 +172,6 @@ class ObjectTreeTest extends \Test\TestCase { 'regulardir', 'regulardir', 'dir', - false - ], - // regular file with chunking - [ - 'regularfile.txt', - 'regularfile.txt', - 'regularfile.txt', - 'file', - true - ], - // regular directory with chunking - [ - 'regulardir', - 'regulardir', - 'regulardir', - 'dir', - true - ], - // file with chunky file name - [ - 'regularfile.txt-chunking-123566789-10-1', - 'regularfile.txt', - 'regularfile.txt', - 'file', - true ], // regular file in subdir [ @@ -242,7 +179,6 @@ class ObjectTreeTest extends \Test\TestCase { 'subdir/regularfile.txt', 'regularfile.txt', 'file', - false ], // regular directory in subdir [ @@ -250,22 +186,13 @@ class ObjectTreeTest extends \Test\TestCase { 'subdir/regulardir', 'regulardir', 'dir', - false - ], - // file with chunky file name in subdir - [ - 'subdir/regularfile.txt-chunking-123566789-10-1', - 'subdir/regularfile.txt', - 'regularfile.txt', - 'file', - true ], ]; } public function testGetNodeForPathInvalidPath(): void { - $this->expectException(\OCA\DAV\Connector\Sabre\Exception\InvalidPath::class); + $this->expectException(InvalidPath::class); $path = '/foo\bar'; @@ -273,7 +200,7 @@ class ObjectTreeTest extends \Test\TestCase { $storage = new Temporary([]); $view = $this->getMockBuilder(View::class) - ->setMethods(['resolvePath']) + ->onlyMethods(['resolvePath']) ->getMock(); $view->expects($this->once()) ->method('resolvePath') @@ -281,12 +208,10 @@ class ObjectTreeTest extends \Test\TestCase { return [$storage, ltrim($path, '/')]; }); - $rootNode = $this->getMockBuilder(Directory::class) - ->disableOriginalConstructor() - ->getMock(); + $rootNode = $this->createMock(Directory::class); $mountManager = $this->createMock(IMountManager::class); - $tree = new \OCA\DAV\Connector\Sabre\ObjectTree(); + $tree = new ObjectTree(); $tree->init($rootNode, $view, $mountManager); $tree->getNodeForPath($path); @@ -299,7 +224,7 @@ class ObjectTreeTest extends \Test\TestCase { $storage = new Temporary([]); $view = $this->getMockBuilder(View::class) - ->setMethods(['resolvePath']) + ->onlyMethods(['resolvePath']) ->getMock(); $view->expects($this->any()) ->method('resolvePath') @@ -307,12 +232,10 @@ class ObjectTreeTest extends \Test\TestCase { return [$storage, ltrim($path, '/')]; }); - $rootNode = $this->getMockBuilder(Directory::class) - ->disableOriginalConstructor() - ->getMock(); + $rootNode = $this->createMock(Directory::class); $mountManager = $this->createMock(IMountManager::class); - $tree = new \OCA\DAV\Connector\Sabre\ObjectTree(); + $tree = new ObjectTree(); $tree->init($rootNode, $view, $mountManager); $this->assertInstanceOf('\Sabre\DAV\INode', $tree->getNodeForPath($path)); |