diff options
-rw-r--r-- | lib/private/Files/Node/Node.php | 12 | ||||
-rw-r--r-- | tests/lib/Files/Node/FileTest.php | 8 | ||||
-rw-r--r-- | tests/lib/Files/Node/FolderTest.php | 36 | ||||
-rw-r--r-- | tests/lib/Files/Node/NodeTest.php | 36 |
4 files changed, 37 insertions, 55 deletions
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 0f4193d0608..03975146dda 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -154,12 +154,11 @@ class Node implements \OCP\Files\Node { } } - /** - * @return \OC\Files\Storage\Storage - * @throws \OCP\Files\NotFoundException - */ public function getStorage() { - [$storage,] = $this->view->resolvePath($this->path); + $storage = $this->getMountPoint()->getStorage(); + if (!$storage) { + throw new \Exception("No storage for node"); + } return $storage; } @@ -174,8 +173,7 @@ class Node implements \OCP\Files\Node { * @return string */ public function getInternalPath() { - [, $internalPath] = $this->view->resolvePath($this->path); - return $internalPath; + return $this->getFileInfo()->getInternalPath(); } /** diff --git a/tests/lib/Files/Node/FileTest.php b/tests/lib/Files/Node/FileTest.php index c381fd9b2be..3305f9ac170 100644 --- a/tests/lib/Files/Node/FileTest.php +++ b/tests/lib/Files/Node/FileTest.php @@ -16,8 +16,12 @@ namespace Test\Files\Node; * @package Test\Files\Node */ class FileTest extends NodeTest { - protected function createTestNode($root, $view, $path) { - return new \OC\Files\Node\File($root, $view, $path); + protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) { + if ($data || $internalPath || $storage) { + return new \OC\Files\Node\File($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage)); + } else { + return new \OC\Files\Node\File($root, $view, $path); + } } protected function getNodeClass() { diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php index d604786905d..05f546874ef 100644 --- a/tests/lib/Files/Node/FolderTest.php +++ b/tests/lib/Files/Node/FolderTest.php @@ -38,8 +38,12 @@ use OCP\Files\Storage; * @package Test\Files\Node */ class FolderTest extends NodeTest { - protected function createTestNode($root, $view, $path) { - return new Folder($root, $view, $path); + protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null) { + if ($data || $internalPath || $storage) { + return new Folder($root, $view, $path, $this->getFileInfo($data, $internalPath, $storage)); + } else { + return new Folder($root, $view, $path); + } } protected function getNodeClass() { @@ -512,9 +516,8 @@ class FolderTest extends NodeTest { ->with('/bar/foo') ->willReturn([]); - $root->method('getMount') - ->with('/bar/foo') - ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); @@ -559,9 +562,8 @@ class FolderTest extends NodeTest { ->with(1) ->willReturn($fileInfo); - $root->method('getMount') - ->with('/bar') - ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar'); $result = $node->getById(1); @@ -606,13 +608,8 @@ class FolderTest extends NodeTest { ->with(1) ->willReturn($fileInfo); - $root->method('getMountsIn') - ->with('/bar/foo') - ->willReturn([]); - - $root->method('getMount') - ->with('/bar/foo') - ->willReturn($mount); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); @@ -661,13 +658,8 @@ class FolderTest extends NodeTest { ->with(1) ->willReturn($fileInfo); - $root->method('getMountsIn') - ->with('/bar/foo') - ->willReturn([$mount2]); - - $root->method('getMount') - ->with('/bar/foo') - ->willReturn($mount1); + $manager->method('getMountsByMountProvider') + ->willReturn([$mount1, $mount2]); $node = new Folder($root, $view, '/bar/foo'); $result = $node->getById(1); diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index cc936baacb0..8c0d4cdb293 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\Manager; use OC\Files\View; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountPoint; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\Storage; @@ -70,7 +71,7 @@ abstract class NodeTest extends \Test\TestCase { * @param string $path * @return Node */ - abstract protected function createTestNode($root, $view, $path); + abstract protected function createTestNode($root, $view, $path, array $data = [], $internalPath = '', $storage = null); /** * @return string @@ -97,8 +98,11 @@ abstract class NodeTest extends \Test\TestCase { return $storage; } - protected function getFileInfo($data) { - return new FileInfo('', $this->getMockStorage(), '', $data, null); + protected function getFileInfo($data, $internalPath = '', $storage = null) { + $mount = $this->createMock(IMountPoint::class); + $mount->method('getStorage') + ->willReturn($storage); + return new FileInfo('', $this->getMockStorage(), $internalPath, $data, $mount); } public function testDelete() { @@ -165,18 +169,13 @@ abstract class NodeTest extends \Test\TestCase { $this->view->expects($this->any()) ->method('getFileInfo') ->with('/bar/foo') - ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'])); + ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'], 'foo')); $this->view->expects($this->once()) ->method($this->getViewDeleteMethod()) ->with('/bar/foo') ->willReturn(true); - $this->view->expects($this->any()) - ->method('resolvePath') - ->with('/bar/foo') - ->willReturn([null, 'foo']); - $node = $this->createTestNode($root, $this->view, '/bar/foo'); $node->delete(); $this->assertEquals(2, $hooksRun); @@ -318,13 +317,7 @@ abstract class NodeTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); - $this->view->expects($this->once()) - ->method('resolvePath') - ->with('/bar/foo') - ->willReturn([$storage, 'foo']); - - - $node = $this->createTestNode($this->root, $this->view, '/bar/foo'); + $node = $this->createTestNode($this->root, $this->view, '/bar/foo', [], 'foo', $storage); $this->assertEquals($storage, $node->getStorage()); } @@ -349,9 +342,9 @@ abstract class NodeTest extends \Test\TestCase { ->getMock(); $this->view->expects($this->once()) - ->method('resolvePath') + ->method('getFileInfo') ->with('/bar/foo') - ->willReturn([$storage, 'foo']); + ->willReturn($this->getFileInfo([], 'foo')); $node = $this->createTestNode($this->root, $this->view, '/bar/foo'); @@ -426,14 +419,9 @@ abstract class NodeTest extends \Test\TestCase { ->willReturn(true); $this->view->expects($this->any()) - ->method('resolvePath') - ->with('/bar/foo') - ->willReturn([null, 'foo']); - - $this->view->expects($this->any()) ->method('getFileInfo') ->with('/bar/foo') - ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL])); + ->willReturn($this->getFileInfo(['permissions' => \OCP\Constants::PERMISSION_ALL], 'foo')); $node = $this->createTestNode($root, $this->view, '/bar/foo'); $node->touch(100); |