-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathAEnvironmentPageAwareControllerTest.php
More file actions
105 lines (92 loc) · 2.9 KB
/
AEnvironmentPageAwareControllerTest.php
File metadata and controls
105 lines (92 loc) · 2.9 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Tests\Unit\Controller;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Controller\AEnvironmentPageAwareController;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Service\SignFileService;
use OCA\Libresign\Tests\Unit\TestCase;
use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10NFactory;
use PHPUnit\Framework\MockObject\MockObject;
class MockController extends AEnvironmentPageAwareController {
}
/**
* @group DB
*/
final class AEnvironmentPageAwareControllerTest extends TestCase {
private IRequest&MockObject $request;
private SignFileService $signFileService;
private IL10N $l10n;
private IUserSession $userSession;
private MockController $controller;
public function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->getMockAppConfig()->setValueArray(Application::APP_ID, 'identify_methods', [
[
'name' => 'email',
'enabled' => 1,
],
]);
$this->signFileService = \OCP\Server::get(SignFileService::class);
$this->l10n = \OCP\Server::get(IL10NFactory::class)->get(Application::APP_ID);
$this->userSession = \OCP\Server::get(IUserSession::class);
$this->controller = new MockController(
$this->request,
$this->signFileService,
$this->l10n,
$this->userSession,
);
parent::setUp();
}
public function testLoadFileUuidWithEmptyUuid(): void {
$this->expectException(LibresignException::class);
$this->expectExceptionCode(404);
$this->expectExceptionMessage(json_encode([
'action' => 2000,
'errors' => [['message' => 'Invalid UUID']],
]));
$this->controller->loadNextcloudFileFromSignRequestUuid('');
}
/**
* @runInSeparateProcess
*/
public function testLoadFileUuidWhenFileNotFound(): void {
$user = $this->createAccount('username', 'password');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'signers' => [
[
'identifyMethods' => [[
'method' => 'account',
'mandatory' => 0,
'value' => 'username',
]],
],
],
'userManager' => $user,
]);
$this->userSession->setUser($user);
$root = \OCP\Server::get(IRootFolder::class);
$nextcloudFile = $root->getFirstNodeById($file->getNodeId());
$trashManager = \OCP\Server::get(ITrashManager::class);
$trashManager->pauseTrash();
$nextcloudFile->delete();
$this->expectException(LibresignException::class);
$this->expectExceptionCode(404);
$this->expectExceptionMessage(json_encode([
'action' => 2000,
'errors' => [['message' => 'Invalid UUID']],
]));
$this->controller->validateSignRequestUuid($file->getUuid());
}
}