|
9 | 9 | use OCA\Files_Sharing\Controller\ShareAPIController; |
10 | 10 | use OCP\App\IAppManager; |
11 | 11 | use OCP\AppFramework\Http\DataResponse; |
| 12 | +use OCP\AppFramework\Http; |
12 | 13 | use OCP\AppFramework\OCS\OCSBadRequestException; |
13 | 14 | use OCP\AppFramework\OCS\OCSException; |
14 | 15 | use OCP\AppFramework\OCS\OCSForbiddenException; |
@@ -5138,4 +5139,70 @@ private function getNonSharedUserFile(): array { |
5138 | 5139 | $node->method('getId')->willReturn(42); |
5139 | 5140 | return [$userFolder, $node]; |
5140 | 5141 | } |
| 5142 | + |
| 5143 | + public function testCreateShareWithMailNotificationEnabled(): void { |
| 5144 | + $share = $this->createMock(IShare::class); |
| 5145 | + $node = $this->createMock(File::class); |
| 5146 | + $userFolder = $this->createMock('\\OCP\\Files\\Folder'); |
| 5147 | + |
| 5148 | + $node->method('getPath')->willReturn('/testfile.txt'); |
| 5149 | + $userFolder->method('get') |
| 5150 | + ->with('/testfile.txt') |
| 5151 | + ->willReturn($node); |
| 5152 | + $this->rootFolder->method('getUserFolder') |
| 5153 | + ->with('currentUser') |
| 5154 | + ->willReturn($userFolder); |
| 5155 | + $this->shareManager->method('newShare')->willReturn($share); |
| 5156 | + |
| 5157 | + $share->expects($this->once()) |
| 5158 | + ->method('setMailSend') |
| 5159 | + ->with(true); |
| 5160 | + |
| 5161 | + $formattedShare = ['id' => '123']; |
| 5162 | + $controller = $this->mockFormatShare(); |
| 5163 | + $controller->method('formatShare') |
| 5164 | + ->with($share) |
| 5165 | + ->willReturn($formattedShare); |
| 5166 | + |
| 5167 | + $result = $controller->createShare( |
| 5168 | + '/testfile.txt', 1, IShare::TYPE_USER, 'recipient', |
| 5169 | + null, '', null, null, '', '', null, 'true' |
| 5170 | + ); |
| 5171 | + |
| 5172 | + $this->assertEquals(Http::STATUS_OK, $result->getStatus()); |
| 5173 | + $this->assertEquals($formattedShare, $result->getData()); |
| 5174 | + } |
| 5175 | + |
| 5176 | + public function testCreateShareWithMailNotificationDisabled(): void { |
| 5177 | + $share = $this->createMock(IShare::class); |
| 5178 | + $node = $this->createMock(File::class); |
| 5179 | + $userFolder = $this->createMock('\\OCP\\Files\\Folder'); |
| 5180 | + |
| 5181 | + $node->method('getPath')->willReturn('/testfile.txt'); |
| 5182 | + $userFolder->method('get') |
| 5183 | + ->with('/testfile.txt') |
| 5184 | + ->willReturn($node); |
| 5185 | + $this->rootFolder->method('getUserFolder') |
| 5186 | + ->with('currentUser') |
| 5187 | + ->willReturn($userFolder); |
| 5188 | + $this->shareManager->method('newShare')->willReturn($share); |
| 5189 | + |
| 5190 | + $share->expects($this->once()) |
| 5191 | + ->method('setMailSend') |
| 5192 | + ->with(false); |
| 5193 | + |
| 5194 | + $formattedShare = ['id' => '123']; |
| 5195 | + $controller = $this->mockFormatShare(); |
| 5196 | + $controller->method('formatShare') |
| 5197 | + ->with($share) |
| 5198 | + ->willReturn($formattedShare); |
| 5199 | + |
| 5200 | + $result = $controller->createShare( |
| 5201 | + '/testfile.txt', 1, IShare::TYPE_USER, 'recipient', |
| 5202 | + null, '', null, null, '', '', null, 'false' |
| 5203 | + ); |
| 5204 | + |
| 5205 | + $this->assertEquals(Http::STATUS_OK, $result->getStatus()); |
| 5206 | + $this->assertEquals($formattedShare, $result->getData()); |
| 5207 | + } |
5141 | 5208 | } |
0 commit comments