diff options
author | Robin Appelman <robin@icewind.nl> | 2024-03-05 17:26:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 17:26:25 +0100 |
commit | fd4ca13867de94e3afc5cac55ac39c4235d6b737 (patch) | |
tree | 55687140e7a7ec2f3612092f5be291ed698d0337 /apps/files_sharing/tests | |
parent | c18ffe0cad13dc5903cbb08ffbdb787f01db5e35 (diff) | |
parent | a9ee278ec6059d164ed2f45b0eb304e940ffd588 (diff) | |
download | nextcloud-server-fd4ca13867de94e3afc5cac55ac39c4235d6b737.tar.gz nextcloud-server-fd4ca13867de94e3afc5cac55ac39c4235d6b737.zip |
Merge pull request #43471 from nextcloud/cache-path-by-id
Cache path by id
Diffstat (limited to 'apps/files_sharing/tests')
4 files changed, 107 insertions, 75 deletions
diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php index ed35c81fb7d..6e1aa65cea8 100644 --- a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php +++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php @@ -77,9 +77,9 @@ class ShareRecipientSorterTest extends TestCase { if ($data['context']['itemType'] === 'files') { $folder->expects($this->once()) - ->method('getById') + ->method('getFirstNodeById') ->with($data['context']['itemId']) - ->willReturn([$node]); + ->willReturn($node); $this->shareManager->expects($this->once()) ->method('getAccessList') @@ -87,7 +87,7 @@ class ShareRecipientSorterTest extends TestCase { ->willReturn($data['accessList']); } else { $folder->expects($this->never()) - ->method('getById'); + ->method('getFirstNodeById'); $this->shareManager->expects($this->never()) ->method('getAccessList'); } @@ -106,8 +106,8 @@ class ShareRecipientSorterTest extends TestCase { ->willReturn($folder); $folder->expects($this->once()) - ->method('getById') - ->willReturn([]); + ->method('getFirstNodeById') + ->willReturn(null); $user = $this->createMock(IUser::class); $user->expects($this->any()) diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 731650d8aee..b9e58d85688 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -367,6 +367,7 @@ class ShareAPIControllerTest extends TestCase { */ public function testDeleteShareFileOwner() { $node = $this->getMockBuilder(File::class)->getMock(); + $node->method('getId')->willReturn(1); $share = $this->newShare(); $share->setShareOwner($this->currentUser) @@ -399,6 +400,7 @@ class ShareAPIControllerTest extends TestCase { */ public function testDeleteSharedWithMyGroup() { $node = $this->getMockBuilder(File::class)->getMock(); + $node->method('getId')->willReturn(1); $share = $this->newShare(); $share->setShareType(IShare::TYPE_GROUP) @@ -435,9 +437,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); $this->shareManager->expects($this->once()) ->method('deleteFromSelf') @@ -461,6 +463,7 @@ class ShareAPIControllerTest extends TestCase { $this->expectExceptionMessage('Wrong share ID, share does not exist'); $node = $this->getMockBuilder(File::class)->getMock(); + $node->method('getId')->willReturn(42); $share = $this->newShare(); $share->setShareType(IShare::TYPE_GROUP) @@ -497,9 +500,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); $this->shareManager->expects($this->never()) ->method('deleteFromSelf'); @@ -813,6 +816,10 @@ class ShareAPIControllerTest extends TestCase { ->with($share->getNodeId()) ->willReturn([$share->getNode()]); + $userFolder->method('getFirstNodeById') + ->with($share->getNodeId()) + ->willReturn($share->getNode()); + $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -1497,9 +1504,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$file]); + ->willReturn($file); $file->method('getPermissions') ->will($this->onConsecutiveCalls(\OCP\Constants::PERMISSION_SHARE, \OCP\Constants::PERMISSION_READ)); @@ -1593,9 +1600,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); if (!$helperAvailable) { $this->appManager->method('isEnabledForUser') @@ -1947,6 +1954,7 @@ class ShareAPIControllerTest extends TestCase { ]); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -1970,6 +1978,7 @@ class ShareAPIControllerTest extends TestCase { $this->expectExceptionMessage('Public upload disabled by the administrator'); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -1994,6 +2003,7 @@ class ShareAPIControllerTest extends TestCase { $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); $path = $this->getMockBuilder(File::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2017,6 +2027,7 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(1); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2055,6 +2066,7 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2093,6 +2105,7 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2138,6 +2151,7 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2176,6 +2190,7 @@ class ShareAPIControllerTest extends TestCase { ]); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2221,6 +2236,7 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2579,6 +2595,8 @@ class ShareAPIControllerTest extends TestCase { ->willReturn($userFolder); $path = $this->getMockBuilder(Folder::class)->getMock(); + $path->method('getId')->willReturn(42); + $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->willReturnMap([ @@ -2628,9 +2646,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); $this->ocs->updateShare(42); } @@ -2721,9 +2739,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $mountPoint = $this->createMock(IMountPoint::class); $node->method('getMountPoint') @@ -2775,9 +2793,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -2825,9 +2843,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -2883,9 +2901,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -2941,9 +2959,9 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); [$userFolder, $folder] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -2988,9 +3006,9 @@ class ShareAPIControllerTest extends TestCase { $ocs = $this->mockFormatShare(); [$userFolder, $folder] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3020,9 +3038,9 @@ class ShareAPIControllerTest extends TestCase { $file->method('getId') ->willReturn(42); [$userFolder, $folder] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3047,9 +3065,9 @@ class ShareAPIControllerTest extends TestCase { [$userFolder, $node] = $this->getNonSharedUserFolder(); $node->method('getId')->willReturn(42); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3098,9 +3116,9 @@ class ShareAPIControllerTest extends TestCase { $date->setTime(0, 0, 0); [$userFolder, $node] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3156,9 +3174,9 @@ class ShareAPIControllerTest extends TestCase { $date->setTime(0, 0, 0); [$userFolder, $node] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3196,9 +3214,9 @@ class ShareAPIControllerTest extends TestCase { $date->setTime(0, 0, 0); [$userFolder, $node] = $this->getNonSharedUserFolder(); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $this->rootFolder->method('getUserFolder') ->with($this->currentUser) ->willReturn($userFolder); @@ -3290,9 +3308,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $mountPoint = $this->createMock(IMountPoint::class); $node->method('getMountPoint') @@ -3358,9 +3376,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$node]); + ->willReturn($node); $mountPoint = $this->createMock(IMountPoint::class); $node->method('getMountPoint') @@ -3419,9 +3437,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -3479,9 +3497,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -3537,9 +3555,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -3585,9 +3603,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$file]); + ->willReturn($file); $mountPoint = $this->createMock(IMountPoint::class); $file->method('getMountPoint') @@ -3651,9 +3669,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -3721,9 +3739,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturn($userFolder); - $userFolder->method('getById') + $userFolder->method('getFirstNodeById') ->with(42) - ->willReturn([$folder]); + ->willReturn($folder); $mountPoint = $this->createMock(IMountPoint::class); $folder->method('getMountPoint') @@ -4651,9 +4669,9 @@ class ShareAPIControllerTest extends TestCase { $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC')); if (!$exception) { - $this->rootFolder->method('getById') + $this->rootFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); $this->rootFolder->method('getRelativePath') ->with($share->getNode()->getPath()) @@ -4846,9 +4864,9 @@ class ShareAPIControllerTest extends TestCase { ->with($this->currentUser) ->willReturnSelf(); - $this->rootFolder->method('getById') + $this->rootFolder->method('getFirstNodeById') ->with($share->getNodeId()) - ->willReturn([$share->getNode()]); + ->willReturn($share->getNode()); $this->rootFolder->method('getRelativePath') ->with($share->getNode()->getPath()) @@ -4890,6 +4908,7 @@ class ShareAPIControllerTest extends TestCase { ]); $userFolder->method('getStorage')->willReturn($storage); $node->method('getStorage')->willReturn($storage); + $node->method('getId')->willReturn(42); return [$userFolder, $node]; } @@ -4904,6 +4923,7 @@ class ShareAPIControllerTest extends TestCase { ]); $userFolder->method('getStorage')->willReturn($storage); $node->method('getStorage')->willReturn($storage); + $node->method('getId')->willReturn(42); return [$userFolder, $node]; } } diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index 3a73862bf77..c8dc6c5de66 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -41,6 +41,7 @@ use OC\Share20\Manager; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Controller\ShareController; use OCA\Files_Sharing\DefaultPublicShareTemplateProvider; +use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountProperty; @@ -258,6 +259,7 @@ class ShareControllerTest extends \Test\TestCase { $file->method('getSize')->willReturn(33); $file->method('isReadable')->willReturn(true); $file->method('isShareable')->willReturn(true); + $file->method('getId')->willReturn(111); $accountName = $this->createMock(IAccountProperty::class); $accountName->method('getScope') @@ -330,13 +332,15 @@ class ShareControllerTest extends \Test\TestCase { return null; }); - $this->eventDispatcher->expects($this->exactly(2)) - ->method('dispatchTyped') - ->with( - $this->callback(function ($event) use ($share) { + $this->eventDispatcher->method('dispatchTyped')->with( + $this->callback(function ($event) use ($share) { + if ($event instanceof BeforeTemplateRenderedEvent) { return $event->getShare() === $share; - }) - ); + } else { + return true; + } + }) + ); $this->l10n->expects($this->any()) ->method('t') @@ -416,6 +420,7 @@ class ShareControllerTest extends \Test\TestCase { $file->method('getSize')->willReturn(33); $file->method('isReadable')->willReturn(true); $file->method('isShareable')->willReturn(true); + $file->method('getId')->willReturn(111); $accountName = $this->createMock(IAccountProperty::class); $accountName->method('getScope') @@ -488,13 +493,15 @@ class ShareControllerTest extends \Test\TestCase { return null; }); - $this->eventDispatcher->expects($this->exactly(2)) - ->method('dispatchTyped') - ->with( - $this->callback(function ($event) use ($share) { + $this->eventDispatcher->method('dispatchTyped')->with( + $this->callback(function ($event) use ($share) { + if ($event instanceof BeforeTemplateRenderedEvent) { return $event->getShare() === $share; - }) - ); + } else { + return true; + } + }) + ); $this->l10n->expects($this->any()) ->method('t') @@ -574,6 +581,7 @@ class ShareControllerTest extends \Test\TestCase { $file->method('getSize')->willReturn(33); $file->method('isReadable')->willReturn(true); $file->method('isShareable')->willReturn(true); + $file->method('getId')->willReturn(111); $accountName = $this->createMock(IAccountProperty::class); $accountName->method('getScope') @@ -650,13 +658,15 @@ class ShareControllerTest extends \Test\TestCase { return null; }); - $this->eventDispatcher->expects($this->exactly(2)) - ->method('dispatchTyped') - ->with( - $this->callback(function ($event) use ($share) { + $this->eventDispatcher->method('dispatchTyped')->with( + $this->callback(function ($event) use ($share) { + if ($event instanceof BeforeTemplateRenderedEvent) { return $event->getShare() === $share; - }) - ); + } else { + return true; + } + }) + ); $this->l10n->expects($this->any()) ->method('t') @@ -741,6 +751,7 @@ class ShareControllerTest extends \Test\TestCase { $folder->method('getStorage')->willReturn($storage); $folder->method('get')->with('')->willReturn($folder); $folder->method('getSize')->willReturn(1337); + $folder->method('getId')->willReturn(111); $accountName = $this->createMock(IAccountProperty::class); $accountName->method('getScope') diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index 8e69c5a0f65..5209a30634a 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -586,6 +586,7 @@ class SharedStorageTest extends TestCase { public function testInitWithNotFoundSource() { $share = $this->createMock(IShare::class); $share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1); + $share->method('getNodeId')->willReturn(1); $ownerView = $this->createMock(View::class); $ownerView->method('getPath')->will($this->throwException(new NotFoundException())); $storage = new SharedStorage([ |