|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | use bovigo\vfs\vfsStream;
|
| 10 | +use OC\User\NoUserException; |
10 | 11 | use OCA\Libresign\Db\AccountFileMapper;
|
11 | 12 | use OCA\Libresign\Db\File;
|
12 | 13 | use OCA\Libresign\Db\FileElement;
|
|
38 | 39 | use OCP\EventDispatcher\IEventDispatcher;
|
39 | 40 | use OCP\Files\IRootFolder;
|
40 | 41 | use OCP\Files\NotFoundException;
|
| 42 | +use OCP\Files\NotPermittedException; |
41 | 43 | use OCP\Http\Client\IClientService;
|
42 | 44 | use OCP\IAppConfig;
|
43 | 45 | use OCP\IDateTimeZone;
|
@@ -1076,4 +1078,75 @@ private static function createScenarioSetVisibleElements(
|
1076 | 1078 | $isAuthenticatedSigner,
|
1077 | 1079 | ];
|
1078 | 1080 | }
|
| 1081 | + |
| 1082 | + #[DataProvider('providerGetSignedFile')] |
| 1083 | + public function testGetSignedFile( |
| 1084 | + int $timesCalled, |
| 1085 | + string $managerUid, |
| 1086 | + ?string $ownerUid = null, |
| 1087 | + ?int $nodeId = null, |
| 1088 | + ): void { |
| 1089 | + $service = $this->getService(['getNodeByIdUsingUid']); |
| 1090 | + |
| 1091 | + $libreSignFile = new \OCA\Libresign\Db\File(); |
| 1092 | + $libreSignFile->setSignedNodeId($nodeId); |
| 1093 | + $libreSignFile->setUserId($managerUid); |
| 1094 | + $service->setLibreSignFile($libreSignFile); |
| 1095 | + |
| 1096 | + $fileToSign = $this->createMock(\OCP\Files\File::class); |
| 1097 | + $user = $this->createMock(\OCP\IUser::class); |
| 1098 | + $user->method('getUID')->willReturn($ownerUid); |
| 1099 | + $fileToSign->method('getOwner')->willReturn($user); |
| 1100 | + $service |
| 1101 | + ->expects($this->exactly($timesCalled)) |
| 1102 | + ->method('getNodeByIdUsingUid') |
| 1103 | + ->willReturn($fileToSign); |
| 1104 | + |
| 1105 | + $this->invokePrivate($service, 'getSignedFile'); |
| 1106 | + } |
| 1107 | + |
| 1108 | + public static function providerGetSignedFile(): array { |
| 1109 | + return [ |
| 1110 | + [0, 'managerUid', '', null], |
| 1111 | + [1, 'managerUid', 'managerUid', 1], |
| 1112 | + [2, 'managerUid', 'johndoe', 1], |
| 1113 | + ]; |
| 1114 | + } |
| 1115 | + |
| 1116 | + #[DataProvider('providerGetNodeByIdUsingUid')] |
| 1117 | + public function testGetNodeByIdUsingUid( |
| 1118 | + string $typeOfNode, |
| 1119 | + string $exceptionMessage, |
| 1120 | + ): void { |
| 1121 | + $service = $this->getService(); |
| 1122 | + if ($exceptionMessage) { |
| 1123 | + $this->expectExceptionMessageMatches($exceptionMessage); |
| 1124 | + } |
| 1125 | + $leaf = $this->createMock($typeOfNode); |
| 1126 | + $userFolder = $this->createMock(\OCP\Files\Folder::class); |
| 1127 | + $userFolder->method('getFirstNodeById')->willReturn($leaf); |
| 1128 | + $this->root->method('getUserFolder')->willReturnCallback(function () use ($userFolder, $exceptionMessage) { |
| 1129 | + switch ($exceptionMessage) { |
| 1130 | + case '/User not found/': |
| 1131 | + throw new NoUserException(); |
| 1132 | + case '/not have permission/': |
| 1133 | + throw new NotPermittedException(); |
| 1134 | + case '/File not found/': |
| 1135 | + return $userFolder; |
| 1136 | + default: |
| 1137 | + return $userFolder; |
| 1138 | + } |
| 1139 | + }); |
| 1140 | + $actual = $this->invokePrivate($service, 'getNodeByIdUsingUid', ['', 1]); |
| 1141 | + $this->assertEquals($leaf, $actual); |
| 1142 | + } |
| 1143 | + |
| 1144 | + public static function providerGetNodeByIdUsingUid(): array { |
| 1145 | + return [ |
| 1146 | + [\OCP\Files\Folder::class, '/User not found/'], |
| 1147 | + [\OCP\Files\Folder::class, '/not have permission/'], |
| 1148 | + [\OCP\Files\Folder::class, '/File not found/'], |
| 1149 | + [\OCP\Files\File::class, ''], |
| 1150 | + ]; |
| 1151 | + } |
1079 | 1152 | }
|
0 commit comments