Skip to content

Commit 93c22fa

Browse files
committed
test(files_sharing): Ensure mailSend triggers mail functions accordingly
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent d645a8a commit 93c22fa

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
45
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
89

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

0 commit comments

Comments
 (0)