|
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; |
@@ -1053,4 +1054,64 @@ public function testLeaveShare(): void { |
1053 | 1054 |
|
1054 | 1055 | self::invokePrivate($filesHooks, 'unShareSelf', [$share]); |
1055 | 1056 | } |
| 1057 | + |
| 1058 | + public function testGetUserPathsFromPathFileNotFound(): void { |
| 1059 | + $userFolder = $this->createMock(Folder::class); |
| 1060 | + $userFolder->method('get') |
| 1061 | + ->with('/test/path') |
| 1062 | + ->willThrowException(new NotFoundException()); |
| 1063 | + |
| 1064 | + $this->rootFolder->method('getUserFolder') |
| 1065 | + ->with('owner') |
| 1066 | + ->willReturn($userFolder); |
| 1067 | + |
| 1068 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1069 | + |
| 1070 | + $this->assertSame([], $result['users']); |
| 1071 | + $this->assertSame([], $result['remotes']); |
| 1072 | + } |
| 1073 | + |
| 1074 | + public function testGetUserPathsFromPathNotANode(): void { |
| 1075 | + $userFolder = $this->createMock(Folder::class); |
| 1076 | + $userFolder->method('get') |
| 1077 | + ->with('/test/path') |
| 1078 | + ->willReturn(null); |
| 1079 | + |
| 1080 | + $this->rootFolder->method('getUserFolder') |
| 1081 | + ->with('owner') |
| 1082 | + ->willReturn($userFolder); |
| 1083 | + |
| 1084 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1085 | + |
| 1086 | + $this->assertSame([], $result['users']); |
| 1087 | + $this->assertSame([], $result['remotes']); |
| 1088 | + } |
| 1089 | + |
| 1090 | + public function testGetUserPathsFromPathSuccess(): void { |
| 1091 | + $node = $this->createMock(File::class); |
| 1092 | + $node->method('getPath') |
| 1093 | + ->willReturn('/owner/files/test/path'); |
| 1094 | + |
| 1095 | + $userFolder = $this->createMock(Folder::class); |
| 1096 | + $userFolder->method('get') |
| 1097 | + ->with('/test/path') |
| 1098 | + ->willReturn($node); |
| 1099 | + |
| 1100 | + $this->rootFolder->method('getUserFolder') |
| 1101 | + ->with('owner') |
| 1102 | + ->willReturn($userFolder); |
| 1103 | + |
| 1104 | + $this->shareHelper->method('getPathsForAccessList') |
| 1105 | + ->with($node) |
| 1106 | + ->willReturn([ |
| 1107 | + 'users' => ['user1' => '/path1'], |
| 1108 | + 'remotes' => ['remote1' => ['token' => 'abc']], |
| 1109 | + ]); |
| 1110 | + |
| 1111 | + $result = self::invokePrivate($this->filesHooks, 'getUserPathsFromPath', ['/test/path', 'owner']); |
| 1112 | + |
| 1113 | + $this->assertSame(['user1' => '/path1'], $result['users']); |
| 1114 | + $this->assertSame(['remote1' => ['token' => 'abc']], $result['remotes']); |
| 1115 | + $this->assertSame('/test/path', $result['ownerPath']); |
| 1116 | + } |
1056 | 1117 | } |
0 commit comments