diff options
author | Robin Appelman <robin@icewind.nl> | 2022-04-05 15:30:10 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-04-06 15:46:50 +0200 |
commit | ae7205f550d12d713b0b079eb0889c8f3bafb42b (patch) | |
tree | d9ce6b0f1a244f2dac4a39df32c867b87bd5960f /apps | |
parent | 151c80039751bbe74042d7f6f5d58e9f115064e4 (diff) | |
download | nextcloud-server-ae7205f550d12d713b0b079eb0889c8f3bafb42b.tar.gz nextcloud-server-ae7205f550d12d713b0b079eb0889c8f3bafb42b.zip |
use existing node in SharesPlugin
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps')
5 files changed, 82 insertions, 49 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php index d482aa4b510..bbfbfc04a72 100644 --- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php @@ -165,7 +165,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { // if we already cached the folder this file is in we know there are no shares for this file if (array_search($parentPath, $this->cachedFolders) === false) { try { - $node = $this->userFolder->get($sabreNode->getPath()); + $node = $sabreNode->getNode(); } catch (NotFoundException $e) { return []; } @@ -202,7 +202,7 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { ) ) { try { - $folderNode = $this->userFolder->get($sabreNode->getPath()); + $folderNode = $sabreNode->getNode(); } catch (NotFoundException $e) { // If the folder can't be properly found just return return; diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index c88d2302bec..e8297c2ac66 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -29,6 +29,7 @@ namespace OCA\DAV\Tests\Unit\Connector\Sabre; use OC\Files\FileInfo; +use OC\Files\Node\Node; use OC\Files\Storage\Wrapper\Quota; use OCA\DAV\Connector\Sabre\Directory; use OCP\Files\ForbiddenException; @@ -82,9 +83,12 @@ class DirectoryTest extends \Test\TestCase { $this->view = $this->createMock('OC\Files\View'); $this->info = $this->createMock('OC\Files\FileInfo'); - $this->info->expects($this->any()) - ->method('isReadable') + $this->info->method('isReadable') ->willReturn(true); + $this->info->method('getType') + ->willReturn(Node::TYPE_FOLDER); + $this->info->method('getName') + ->willReturn("folder"); } private function getDir($path = '/') { @@ -186,17 +190,17 @@ class DirectoryTest extends \Test\TestCase { $info2 = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->getMock(); - $info1->expects($this->any()) - ->method('getName') + $info1->method('getName') ->willReturn('first'); - $info1->expects($this->any()) - ->method('getEtag') + $info1->method('getPath') + ->willReturn('folder/first'); + $info1->method('getEtag') ->willReturn('abc'); - $info2->expects($this->any()) - ->method('getName') + $info2->method('getName') ->willReturn('second'); - $info2->expects($this->any()) - ->method('getEtag') + $info2->method('getPath') + ->willReturn('folder/second'); + $info2->method('getEtag') ->willReturn('def'); $this->view->expects($this->once()) @@ -403,8 +407,12 @@ class DirectoryTest extends \Test\TestCase { private function moveTest($source, $destination, $updatables, $deletables) { $view = new TestViewDirectory($updatables, $deletables); - $sourceInfo = new FileInfo($source, null, null, [], null); - $targetInfo = new FileInfo(dirname($destination), null, null, [], null); + $sourceInfo = new FileInfo($source, null, null, [ + 'type' => FileInfo::TYPE_FOLDER, + ], null); + $targetInfo = new FileInfo(dirname($destination), null, null, [ + 'type' => FileInfo::TYPE_FOLDER, + ], null); $sourceNode = new Directory($view, $sourceInfo); $targetNode = $this->getMockBuilder(Directory::class) @@ -429,8 +437,8 @@ class DirectoryTest extends \Test\TestCase { $view = new TestViewDirectory($updatables, $deletables); - $sourceInfo = new FileInfo($source, null, null, [], null); - $targetInfo = new FileInfo(dirname($destination), null, null, [], null); + $sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null); + $targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null); $sourceNode = new Directory($view, $sourceInfo); $targetNode = $this->getMockBuilder(Directory::class) diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index d12a86f6e8d..9870a62845c 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -37,6 +37,7 @@ use OC\Files\Storage\Wrapper\PermissionsMask; use OC\Files\View; use OCA\DAV\Connector\Sabre\File; use OCP\Constants; +use OCP\Files\FileInfo; use OCP\Files\ForbiddenException; use OCP\Files\Storage; use OCP\IConfig; @@ -211,7 +212,8 @@ class FileTest extends TestCase { ->willReturnArgument(0); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -272,7 +274,8 @@ class FileTest extends TestCase { $_SERVER['HTTP_OC_CHUNKED'] = true; $info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -282,7 +285,8 @@ class FileTest extends TestCase { $file->releaseLock(ILockingProvider::LOCK_SHARED); $info = new \OC\Files\FileInfo('/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -326,7 +330,10 @@ class FileTest extends TestCase { $viewRoot . '/' . ltrim($path, '/'), $this->getMockStorage(), null, - ['permissions' => \OCP\Constants::PERMISSION_ALL], + [ + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, + ], null ); @@ -690,7 +697,8 @@ class FileTest extends TestCase { $_SERVER['REQUEST_METHOD'] = 'PUT'; $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -723,7 +731,8 @@ class FileTest extends TestCase { $view->lockFile('/test.txt', ILockingProvider::LOCK_EXCLUSIVE); $info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -758,7 +767,8 @@ class FileTest extends TestCase { $_SERVER['HTTP_OC_CHUNKED'] = true; $info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-0', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); $file->acquireLock(ILockingProvider::LOCK_SHARED); @@ -766,7 +776,8 @@ class FileTest extends TestCase { $file->releaseLock(ILockingProvider::LOCK_SHARED); $info = new \OC\Files\FileInfo('/' . $this->user . '/files/test.txt-chunking-12345-2-1', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -797,7 +808,8 @@ class FileTest extends TestCase { ->willReturnArgument(0); $info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -836,7 +848,8 @@ class FileTest extends TestCase { ->willReturnArgument(0); $info = new \OC\Files\FileInfo('/*', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); $file->setName('/super*star.txt'); @@ -863,7 +876,8 @@ class FileTest extends TestCase { $_SERVER['REQUEST_METHOD'] = 'PUT'; $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -897,7 +911,8 @@ class FileTest extends TestCase { ->willReturn(true); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -915,7 +930,8 @@ class FileTest extends TestCase { ->getMock(); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => 0 + 'permissions' => 0, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -938,7 +954,8 @@ class FileTest extends TestCase { ->willReturn(false); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -961,7 +978,8 @@ class FileTest extends TestCase { ->willThrowException(new ForbiddenException('', true)); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -997,7 +1015,10 @@ class FileTest extends TestCase { '/' . $this->user . '/files/' . $path, $this->getMockStorage(), null, - ['permissions' => \OCP\Constants::PERMISSION_ALL], + [ + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, + ], null ); @@ -1129,7 +1150,8 @@ class FileTest extends TestCase { ->willReturn(false); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -1149,7 +1171,8 @@ class FileTest extends TestCase { ->willThrowException(new ForbiddenException('', true)); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_ALL + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -1168,7 +1191,8 @@ class FileTest extends TestCase { ->method('fopen'); $info = new \OC\Files\FileInfo('/test.txt', $this->getMockStorage(), null, [ - 'permissions' => \OCP\Constants::PERMISSION_CREATE // no read perm + 'permissions' => \OCP\Constants::PERMISSION_CREATE, // no read perm + 'type' => FileInfo::TYPE_FOLDER, ], null); $file = new \OCA\DAV\Connector\Sabre\File($view, $info); @@ -1215,7 +1239,10 @@ class FileTest extends TestCase { '/' . $this->user . '/files/' . $path, $this->getMockStorage(), null, - ['permissions' => \OCP\Constants::PERMISSION_ALL], + [ + 'permissions' => \OCP\Constants::PERMISSION_ALL, + 'type' => FileInfo::TYPE_FOLDER, + ], null ); diff --git a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php index 7416cf7a3f7..5f516cec113 100644 --- a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php @@ -167,17 +167,14 @@ class ObjectTreeTest extends \Test\TestCase { $fileInfo = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->getMock(); - $fileInfo->expects($this->once()) - ->method('getType') + $fileInfo->method('getType') ->willReturn($type); - $fileInfo->expects($this->once()) - ->method('getName') + $fileInfo->method('getName') ->willReturn($outputFileName); $fileInfo->method('getStorage') ->willReturn($this->createMock(\OC\Files\Storage\Common::class)); - $view->expects($this->once()) - ->method('getFileInfo') + $view->method('getFileInfo') ->with($fileInfoQueryPath) ->willReturn($fileInfo); diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php index f528310e54c..a81226ccb5e 100644 --- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php @@ -111,9 +111,7 @@ class SharesPluginTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); - $this->userFolder->expects($this->once()) - ->method('get') - ->with('/subdir') + $sabreNode->method('getNode') ->willReturn($node); $this->shareManager->expects($this->any()) @@ -180,16 +178,19 @@ class SharesPluginTest extends \Test\TestCase { $node = $this->createMock(Folder::class); $node->method('getId') ->willReturn(123); - $node1 = $this->createMock(File::class); + $node1 = $this->createMock(\OC\Files\Node\File::class); $node1->method('getId') ->willReturn(111); - $node2 = $this->createMock(File::class); + $node2 = $this->createMock(\OC\Files\Node\File::class); $node2->method('getId') ->willReturn(222); - $this->userFolder->method('get') - ->with('/subdir') + $sabreNode->method('getNode') ->willReturn($node); + $sabreNode1->method('getNode') + ->willReturn($node1); + $sabreNode2->method('getNode') + ->willReturn($node2); $dummyShares = array_map(function ($type) { $share = $this->getMockBuilder(IShare::class)->getMock(); |