diff options
author | Robin Appelman <robin@icewind.nl> | 2022-03-28 19:53:20 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-04-04 16:40:24 +0300 |
commit | 754603a04e24a40778816d9965fe31ac7b407910 (patch) | |
tree | 418ba20b6656f70c51461f7428178e38fe154aa1 /tests | |
parent | 8b12c75ca258787591d765d301adb57bb4e53d26 (diff) |
dont needlessly resolve path when getting internalPath/storage from Node
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests')
-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 |
3 files changed, 32 insertions, 48 deletions
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); |