| 
25 | 25 | use ChristophWurst\Nextcloud\Testing\TestCase;  | 
26 | 26 | use Horde_Imap_Client_Socket;  | 
27 | 27 | use OC\Files\Node\File;  | 
 | 28 | +use OCA\Files_Sharing\SharedStorage;  | 
28 | 29 | use OCA\Mail\Account;  | 
29 | 30 | use OCA\Mail\Contracts\IMailManager;  | 
30 | 31 | use OCA\Mail\Db\LocalAttachment;  | 
 | 
40 | 41 | use OCP\AppFramework\Db\DoesNotExistException;  | 
41 | 42 | use OCP\Files\Folder;  | 
42 | 43 | use OCP\Files\NotPermittedException;  | 
 | 44 | +use OCP\Share\IAttributes;  | 
 | 45 | +use OCP\Share\IShare;  | 
43 | 46 | use PHPUnit\Framework\MockObject\MockObject;  | 
44 | 47 | use Psr\Log\LoggerInterface;  | 
45 | 48 | 
 
  | 
@@ -389,12 +392,63 @@ public function testHandleAttachmentsForwardedAttachment(): void {  | 
389 | 392 | 		$this->service->handleAttachments($account, [$attachments], $client);  | 
390 | 393 | 	}  | 
391 | 394 | 
 
  | 
 | 395 | +	public function testHandleAttachmentsCloudAttachmentNoDownloadPermission(): void {  | 
 | 396 | +		$userId = 'linus';  | 
 | 397 | +		$storage = $this->createMock(SharedStorage::class);  | 
 | 398 | +		$storage->expects(self::once())  | 
 | 399 | +			->method('instanceOfStorage')  | 
 | 400 | +			->with(SharedStorage::class)  | 
 | 401 | +			->willReturn(true);  | 
 | 402 | +		$share = $this->createMock(IShare::class);  | 
 | 403 | +		$attributes = $this->createMock(IAttributes::class);  | 
 | 404 | +		$attributes->expects(self::once())  | 
 | 405 | +			->method('getAttribute')  | 
 | 406 | +			->with('permissions', 'download')  | 
 | 407 | +			->willReturn(false);  | 
 | 408 | +		$share->expects(self::once())  | 
 | 409 | +			->method('getAttributes')  | 
 | 410 | +			->willReturn($attributes);  | 
 | 411 | +		$storage->expects(self::once())  | 
 | 412 | +			->method('getShare')  | 
 | 413 | +			->willReturn($share);  | 
 | 414 | +		  | 
 | 415 | +		$file = $this->createConfiguredMock(File::class, [  | 
 | 416 | +			'getName' => 'cat.jpg',  | 
 | 417 | +			'getMimeType' => 'text/plain',  | 
 | 418 | +			'getContent' => 'sjdhfkjsdhfkjsdhfkjdshfjhdskfjhds',  | 
 | 419 | +			'getStorage' => $storage  | 
 | 420 | +		]);  | 
 | 421 | +		$account = $this->createConfiguredMock(Account::class, [  | 
 | 422 | +			'getUserId' => $userId  | 
 | 423 | +		]);  | 
 | 424 | +		$client = $this->createMock(Horde_Imap_Client_Socket::class);  | 
 | 425 | +		$attachments = [  | 
 | 426 | +			'type' => 'cloud',  | 
 | 427 | +			'messageId' => 999,  | 
 | 428 | +			'fileName' => 'cat.jpg',  | 
 | 429 | +			'mimeType' => 'text/plain',  | 
 | 430 | +		];  | 
 | 431 | +		$this->userFolder->expects(self::once())  | 
 | 432 | +			->method('nodeExists')  | 
 | 433 | +			->with('cat.jpg')  | 
 | 434 | +			->willReturn(true);  | 
 | 435 | +		$this->userFolder->expects(self::once())  | 
 | 436 | +			->method('get')  | 
 | 437 | +			->with('cat.jpg')  | 
 | 438 | +			->willReturn($file);  | 
 | 439 | + | 
 | 440 | +		$result = $this->service->handleAttachments($account, [$attachments], $client);  | 
 | 441 | +		$this->assertEquals([], $result);  | 
 | 442 | + | 
 | 443 | +	}  | 
 | 444 | + | 
392 | 445 | 	public function testHandleAttachmentsCloudAttachment(): void {  | 
393 | 446 | 		$userId = 'linus';  | 
394 | 447 | 		$file = $this->createConfiguredMock(File::class, [  | 
395 | 448 | 			'getName' => 'cat.jpg',  | 
396 | 449 | 			'getMimeType' => 'text/plain',  | 
397 |  | -			'getContent' => 'sjdhfkjsdhfkjsdhfkjdshfjhdskfjhds'  | 
 | 450 | +			'getContent' => 'sjdhfkjsdhfkjsdhfkjdshfjhdskfjhds',  | 
 | 451 | +			'getStorage' => $this->createMock(SharedStorage::class)  | 
398 | 452 | 		]);  | 
399 | 453 | 		$account = $this->createConfiguredMock(Account::class, [  | 
400 | 454 | 			'getUserId' => $userId  | 
 | 
0 commit comments