Skip to content

Commit 67c1683

Browse files
committed
test(files_sharing): Ensure mailSend triggers mail functions accordingly
Signed-off-by: nfebe <[email protected]>
1 parent 9688857 commit 67c1683

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

apps/files_sharing/tests/Controller/ShareAPIControllerTest.php

Lines changed: 97 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.
@@ -5233,4 +5234,100 @@ public function testPopulateTags(): void {
52335234
['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
52345235
], $result);
52355236
}
5237+
5238+
public function testCreateShareWithMailNotificationEnabled(): void {
5239+
$share = $this->createMock(IShare::class);
5240+
$node = $this->getMockBuilder(File::class)->getMock();
5241+
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
5242+
5243+
$storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
5244+
$storage->method('instanceOfStorage')
5245+
->willReturnMap([
5246+
[\OCA\Files_Sharing\External\Storage::class, false],
5247+
[\OCA\Files_Sharing\SharedStorage::class, false],
5248+
]);
5249+
5250+
$node->method('getPath')->willReturn('/testfile.txt');
5251+
$node->method('getId')->willReturn(1);
5252+
$node->method('getStorage')->willReturn($storage);
5253+
$userFolder->method('get')
5254+
->with('/testfile.txt')
5255+
->willReturn($node);
5256+
$userFolder->method('getById')
5257+
->with(1)
5258+
->willReturn([]);
5259+
$this->rootFolder->method('getUserFolder')
5260+
->with('currentUser')
5261+
->willReturn($userFolder);
5262+
$this->userManager->method('userExists')->with('recipient')->willReturn(true);
5263+
$this->shareManager->method('newShare')->willReturn($share);
5264+
$this->shareManager->method('createShare')->with($share)->willReturn($share);
5265+
$share->method('getNode')->willReturn($node);
5266+
5267+
$share->expects($this->once())
5268+
->method('setMailSend')
5269+
->with(true);
5270+
5271+
$formattedShare = ['id' => '123'];
5272+
$controller = $this->mockFormatShare();
5273+
$controller->method('formatShare')
5274+
->with($share)
5275+
->willReturn($formattedShare);
5276+
5277+
$result = $controller->createShare(
5278+
'/testfile.txt', 1, IShare::TYPE_USER, 'recipient',
5279+
null, '', null, null, '', '', null, 'true'
5280+
);
5281+
5282+
$this->assertEquals(\OCP\AppFramework\Http::STATUS_OK, $result->getStatus());
5283+
$this->assertEquals($formattedShare, $result->getData());
5284+
}
5285+
5286+
public function testCreateShareWithMailNotificationDisabled(): void {
5287+
$share = $this->createMock(IShare::class);
5288+
$node = $this->getMockBuilder(File::class)->getMock();
5289+
$userFolder = $this->getMockBuilder(Folder::class)->getMock();
5290+
5291+
$storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
5292+
$storage->method('instanceOfStorage')
5293+
->willReturnMap([
5294+
[\OCA\Files_Sharing\External\Storage::class, false],
5295+
[\OCA\Files_Sharing\SharedStorage::class, false],
5296+
]);
5297+
5298+
$node->method('getPath')->willReturn('/testfile.txt');
5299+
$node->method('getId')->willReturn(1);
5300+
$node->method('getStorage')->willReturn($storage);
5301+
$userFolder->method('get')
5302+
->with('/testfile.txt')
5303+
->willReturn($node);
5304+
$userFolder->method('getById')
5305+
->with(1)
5306+
->willReturn([]);
5307+
$this->rootFolder->method('getUserFolder')
5308+
->with('currentUser')
5309+
->willReturn($userFolder);
5310+
$this->userManager->method('userExists')->with('recipient')->willReturn(true);
5311+
$this->shareManager->method('newShare')->willReturn($share);
5312+
$this->shareManager->method('createShare')->with($share)->willReturn($share);
5313+
$share->method('getNode')->willReturn($node);
5314+
5315+
$share->expects($this->once())
5316+
->method('setMailSend')
5317+
->with(false);
5318+
5319+
$formattedShare = ['id' => '123'];
5320+
$controller = $this->mockFormatShare();
5321+
$controller->method('formatShare')
5322+
->with($share)
5323+
->willReturn($formattedShare);
5324+
5325+
$result = $controller->createShare(
5326+
'/testfile.txt', 1, IShare::TYPE_USER, 'recipient',
5327+
null, '', null, null, '', '', null, 'false'
5328+
);
5329+
5330+
$this->assertEquals(\OCP\AppFramework\Http::STATUS_OK, $result->getStatus());
5331+
$this->assertEquals($formattedShare, $result->getData());
5332+
}
52365333
}

0 commit comments

Comments
 (0)