Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(files_sharing): Ensure mailSend triggers mail functions accord…
…ingly

Signed-off-by: nfebe <[email protected]>
  • Loading branch information
nfebe committed Jun 4, 2025
commit 67c1683eecd3278187f07135c80c1238a45f6eaa
97 changes: 97 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -5233,4 +5234,100 @@ public function testPopulateTags(): void {
['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
], $result);
}

public function testCreateShareWithMailNotificationEnabled(): void {
$share = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock();
$userFolder = $this->getMockBuilder(Folder::class)->getMock();

$storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
$storage->method('instanceOfStorage')
->willReturnMap([
[\OCA\Files_Sharing\External\Storage::class, false],
[\OCA\Files_Sharing\SharedStorage::class, false],
]);

$node->method('getPath')->willReturn('/testfile.txt');
$node->method('getId')->willReturn(1);
$node->method('getStorage')->willReturn($storage);
$userFolder->method('get')
->with('/testfile.txt')
->willReturn($node);
$userFolder->method('getById')
->with(1)
->willReturn([]);
$this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
$this->userManager->method('userExists')->with('recipient')->willReturn(true);
$this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->with($share)->willReturn($share);
$share->method('getNode')->willReturn($node);

$share->expects($this->once())
->method('setMailSend')
->with(true);

$formattedShare = ['id' => '123'];
$controller = $this->mockFormatShare();
$controller->method('formatShare')
->with($share)
->willReturn($formattedShare);

$result = $controller->createShare(
'/testfile.txt', 1, IShare::TYPE_USER, 'recipient',
null, '', null, null, '', '', null, 'true'
);

$this->assertEquals(\OCP\AppFramework\Http::STATUS_OK, $result->getStatus());
$this->assertEquals($formattedShare, $result->getData());
}

public function testCreateShareWithMailNotificationDisabled(): void {
$share = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock();
$userFolder = $this->getMockBuilder(Folder::class)->getMock();

$storage = $this->createMock(\OCP\Files\Storage\IStorage::class);
$storage->method('instanceOfStorage')
->willReturnMap([
[\OCA\Files_Sharing\External\Storage::class, false],
[\OCA\Files_Sharing\SharedStorage::class, false],
]);

$node->method('getPath')->willReturn('/testfile.txt');
$node->method('getId')->willReturn(1);
$node->method('getStorage')->willReturn($storage);
$userFolder->method('get')
->with('/testfile.txt')
->willReturn($node);
$userFolder->method('getById')
->with(1)
->willReturn([]);
$this->rootFolder->method('getUserFolder')
->with('currentUser')
->willReturn($userFolder);
$this->userManager->method('userExists')->with('recipient')->willReturn(true);
$this->shareManager->method('newShare')->willReturn($share);
$this->shareManager->method('createShare')->with($share)->willReturn($share);
$share->method('getNode')->willReturn($node);

$share->expects($this->once())
->method('setMailSend')
->with(false);

$formattedShare = ['id' => '123'];
$controller = $this->mockFormatShare();
$controller->method('formatShare')
->with($share)
->willReturn($formattedShare);

$result = $controller->createShare(
'/testfile.txt', 1, IShare::TYPE_USER, 'recipient',
null, '', null, null, '', '', null, 'false'
);

$this->assertEquals(\OCP\AppFramework\Http::STATUS_OK, $result->getStatus());
$this->assertEquals($formattedShare, $result->getData());
}
}
Loading