|
39 | 39 | use OCP\Files\Folder; |
40 | 40 | use OCP\Files\IRootFolder; |
41 | 41 | use OCP\Files\Node; |
| 42 | +use OCP\Files\NotFoundException; |
42 | 43 | use OCP\IConfig; |
43 | 44 | use OCP\IDBConnection; |
44 | 45 | use OCP\IGroup; |
@@ -991,4 +992,64 @@ public function testLeaveShare(): void { |
991 | 992 |
|
992 | 993 | self::invokePrivate($filesHooks, 'unShareSelf', [$share]); |
993 | 994 | } |
| 995 | + |
| 996 | + public function testGetUserPathsFromPathFileNotFound(): void { |
| 997 | + $userFolder = $this->createMock(Folder::class); |
| 998 | + $userFolder->method('get') |
| 999 | + ->with('/test/path') |
| 1000 | + ->willThrowException(new NotFoundException()); |
| 1001 | + |
| 1002 | + $this->rootFolder->method('getUserFolder') |
| 1003 | + ->with('owner') |
| 1004 | + ->willReturn($userFolder); |
| 1005 | + |
| 1006 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1007 | + |
| 1008 | + $this->assertSame([], $result['users']); |
| 1009 | + $this->assertSame([], $result['remotes']); |
| 1010 | + } |
| 1011 | + |
| 1012 | + public function testGetUserPathsFromPathNotANode(): void { |
| 1013 | + $userFolder = $this->createMock(Folder::class); |
| 1014 | + $userFolder->method('get') |
| 1015 | + ->with('/test/path') |
| 1016 | + ->willReturn(null); |
| 1017 | + |
| 1018 | + $this->rootFolder->method('getUserFolder') |
| 1019 | + ->with('owner') |
| 1020 | + ->willReturn($userFolder); |
| 1021 | + |
| 1022 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1023 | + |
| 1024 | + $this->assertSame([], $result['users']); |
| 1025 | + $this->assertSame([], $result['remotes']); |
| 1026 | + } |
| 1027 | + |
| 1028 | + public function testGetUserPathsFromPathSuccess(): void { |
| 1029 | + $node = $this->createMock(File::class); |
| 1030 | + $node->method('getPath') |
| 1031 | + ->willReturn('/owner/files/test/path'); |
| 1032 | + |
| 1033 | + $userFolder = $this->createMock(Folder::class); |
| 1034 | + $userFolder->method('get') |
| 1035 | + ->with('/test/path') |
| 1036 | + ->willReturn($node); |
| 1037 | + |
| 1038 | + $this->rootFolder->method('getUserFolder') |
| 1039 | + ->with('owner') |
| 1040 | + ->willReturn($userFolder); |
| 1041 | + |
| 1042 | + $this->shareHelper->method('getPathsForAccessList') |
| 1043 | + ->with($node) |
| 1044 | + ->willReturn([ |
| 1045 | + 'users' => ['user1' => '/path1'], |
| 1046 | + 'remotes' => ['remote1' => ['token' => 'abc']], |
| 1047 | + ]); |
| 1048 | + |
| 1049 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1050 | + |
| 1051 | + $this->assertSame(['user1' => '/path1'], $result['users']); |
| 1052 | + $this->assertSame(['remote1' => ['token' => 'abc']], $result['remotes']); |
| 1053 | + $this->assertSame('/test/path', $result['ownerPath']); |
| 1054 | + } |
994 | 1055 | } |
0 commit comments