Skip to content

Commit 4a4cb19

Browse files
committed
wip_test(files_sharing): Test mailSend triggers mail sending accordingly
Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 2705ebc commit 4a4cb19

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use OCA\Files_Sharing\Controller\ShareAPIController;
1010
use OCP\App\IAppManager;
1111
use OCP\AppFramework\Http\DataResponse;
12+
use OCP\AppFramework\Http;
1213
use OCP\AppFramework\OCS\OCSBadRequestException;
1314
use OCP\AppFramework\OCS\OCSException;
1415
use OCP\AppFramework\OCS\OCSForbiddenException;
@@ -5138,4 +5139,70 @@ private function getNonSharedUserFile(): array {
51385139
$node->method('getId')->willReturn(42);
51395140
return [$userFolder, $node];
51405141
}
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+
}
51415208
}

0 commit comments

Comments
 (0)