-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathFileSignedTest.php
More file actions
76 lines (61 loc) · 2.34 KB
/
FileSignedTest.php
File metadata and controls
76 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Activity;
use OCA\Libresign\Activity\Settings\FileSigned;
use OCA\Libresign\Events\SignedEvent;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Helper\ValidateHelper;
use OCP\IL10N;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\TestCase;
class FileSignedTest extends TestCase {
private $l10nMock;
private $validateHelperMock;
private $userSessionMock;
protected function setUp(): void {
$this->l10nMock = $this->createMock(IL10N::class);
$this->validateHelperMock = $this->createMock(ValidateHelper::class);
$this->userSessionMock = $this->createMock(IUserSession::class);
}
private function getClass(): FileSigned {
return new FileSigned(
$this->l10nMock,
$this->validateHelperMock,
$this->userSessionMock
);
}
public function testGetIdentifier(): void {
$this->assertSame(SignedEvent::FILE_SIGNED, $this->getClass()->getIdentifier());
}
public function testCanChangeNotificationSuccess(): void {
$userMock = $this->createMock(IUser::class);
$this->userSessionMock->method('getUser')->willReturn($userMock);
$this->validateHelperMock->method('canrequestSign')->with($userMock);
$this->assertTrue($this->getClass()->canChangeNotification());
}
public function testCanChangeNotificationFailure(): void {
$userMock = $this->createMock(IUser::class);
$this->userSessionMock->method('getUser')->willReturn($userMock);
$this->validateHelperMock->method('canrequestSign')
->willThrowException(new LibresignException());
$this->assertFalse($this->getClass()->canChangeNotification());
}
public function testCanChangeMailSuccess(): void {
$userMock = $this->createMock(IUser::class);
$this->userSessionMock->method('getUser')->willReturn($userMock);
$this->validateHelperMock->method('canrequestSign')->with($userMock);
$this->assertTrue($this->getClass()->canChangeMail());
}
public function testCanChangeMailFailure(): void {
$userMock = $this->createMock(IUser::class);
$this->userSessionMock->method('getUser')->willReturn($userMock);
$this->validateHelperMock->method('canrequestSign')
->willThrowException(new LibresignException());
$this->assertFalse($this->getClass()->canChangeMail());
}
}