-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathFileElementControllerTest.php
More file actions
117 lines (110 loc) · 2.98 KB
/
FileElementControllerTest.php
File metadata and controls
117 lines (110 loc) · 2.98 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
106
107
108
109
110
111
112
113
114
115
116
117
<?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\Api\Controller;
use DateTime;
use OCA\Libresign\Tests\Api\ApiTestCase;
/**
* @internal
* @group DB
*/
final class FileElementControllerTest extends ApiTestCase {
/**
* @runInSeparateProcess
*/
public function testPostSuccess():array {
$user = $this->createAccount('username', 'password');
$user->setEMailAddress('person@test.coop');
$file = $this->requestSignFile([
'file' => ['base64' => base64_encode(file_get_contents(__DIR__ . '/../../fixtures/pdfs/small_valid.pdf'))],
'name' => 'test',
'users' => [
[
'identify' => [
'email' => 'person@test.coop',
],
],
],
'userManager' => $user,
]);
$signers = $this->getSignersFromFileId($file->getId());
$signers[0]->setSigned(new DateTime());
$this->getMockAppConfig();
$this->request
->withPath('/api/v1/file-element/' . $file->getUuid())
->withMethod('POST')
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('username:password'),
'Content-Type' => 'application/json'
])
->withRequestBody([
'coordinates' => [
'top' => 188,
'left' => 4,
'width' => 370,
'height' => 90,
'page' => 1,
],
'type' => 'signature',
'signRequestId' => $signers[0]->getId(),
]);
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
return [
'file' => $file,
'fileElementId' => $body['ocs']['data']['fileElementId'],
];
}
/**
* @runInSeparateProcess
* @depends testPostSuccess
*/
public function testPatchSuccess($params):array {
$this->createAccount('username', 'password');
extract($params);
$signers = $this->getSignersFromFileId($file->getId());
$this->request
->withPath('/api/v1/file-element/' . $file->getUuid() . '/' . $fileElementId)
->withMethod('PATCH')
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('username:password'),
'Content-Type' => 'application/json'
])
->withRequestBody([
'coordinates' => [
'top' => 189,
'left' => 5,
'width' => 371,
'height' => 91,
'page' => 1,
],
'type' => 'signature',
'signRequestId' => $signers[0]->getId(),
]);
$response = $this->assertRequest();
$body = json_decode($response->getBody()->getContents(), true);
return [
'file' => $file,
'fileElementId' => $body['ocs']['data']['fileElementId'],
];
}
/**
* @runInSeparateProcess
* @depends testPostSuccess
* @depends testPatchSuccess
*/
public function testDeleteSuccess($params):void {
$this->createAccount('username', 'password');
extract($params);
$this->request
->withPath('/api/v1/file-element/' . $file->getUuid() . '/' . $fileElementId)
->withMethod('DELETE')
->withRequestHeader([
'Authorization' => 'Basic ' . base64_encode('username:password'),
]);
$this->assertRequest();
}
}