From 83b1415906babd3ad521055dd2142fed09250ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 24 Aug 2022 18:01:10 +0200 Subject: Only pass parent if paths match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As the user folder might be initialized by the root from two levels down the hierarchy, passing this as a parent only works if the path matches Signed-off-by: Julius Härtl --- tests/lib/Files/Node/FolderTest.php | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index 2be0257aacb..ddf6c412dcd 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -14,6 +14,7 @@ use OC\Files\Config\CachedMountInfo; use OC\Files\FileInfo; use OC\Files\Mount\Manager; use OC\Files\Mount\MountPoint; +use OC\Files\Node\File; use OC\Files\Node\Folder; use OC\Files\Node\Node; use OC\Files\Node\Root; @@ -105,11 +106,13 @@ class FolderTest extends NodeTest { ->method('getUser') ->willReturn($this->user); + $node = new File($root, $view, '/bar/foo/asd'); $root->method('get') - ->with('/bar/foo/asd'); + ->with('/bar/foo/asd') + ->willReturn($node); - $node = new Folder($root, $view, '/bar/foo'); - $node->get('asd'); + $parentNode = new Folder($root, $view, '/bar/foo'); + self::assertEquals($node, $parentNode->get('asd')); } public function testNodeExists() { @@ -183,6 +186,33 @@ class FolderTest extends NodeTest { $this->assertEquals($child, $result); } + public function testNewFolderDeepParent() { + $manager = $this->createMock(Manager::class); + /** + * @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject $view + */ + $view = $this->createMock(View::class); + $root = $this->getMockBuilder(Root::class) + ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager, $this->eventDispatcher]) + ->getMock(); + $root->expects($this->any()) + ->method('getUser') + ->willReturn($this->user); + + $view->method('getFileInfo') + ->with('/foobar') + ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL])); + + $view->method('mkdir') + ->with('/foobar/asd/sdf') + ->willReturn(true); + + $node = new Folder($root, $view, '/foobar'); + $child = new Folder($root, $view, '/foobar/asd/sdf', null, null); + $result = $node->newFolder('asd/sdf'); + $this->assertEquals($child, $result); + } + public function testNewFolderNotPermitted() { $this->expectException(\OCP\Files\NotPermittedException::class); -- cgit v1.2.3