1
|
|
|
<?php |
2
|
|
|
namespace Isign\Tests\Document; |
3
|
|
|
|
4
|
|
|
use Isign\QueryInterface; |
5
|
|
|
use Isign\Document\Seal; |
6
|
|
|
use Isign\Tests\TestCase; |
7
|
|
|
|
8
|
|
|
class SealTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testGetFields() |
11
|
|
|
{ |
12
|
|
|
$document = $this->getPdfDocument(); |
13
|
|
|
|
14
|
|
|
$method = new Seal('pdf', $document, false); |
15
|
|
|
|
16
|
|
|
$result = $method->getFields(); |
17
|
|
|
|
18
|
|
|
$this->assertSame('pdf', $result['type']); |
19
|
|
|
$this->assertSame($document, $result['pdf']); |
20
|
|
|
$this->assertSame(false, $result['timestamp']); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testGetFileFields() |
24
|
|
|
{ |
25
|
|
|
$method = new Seal( |
26
|
|
|
'asic', |
27
|
|
|
[ |
28
|
|
|
'files' => [ |
29
|
|
|
[ |
30
|
|
|
'name' => 'filename.pdf', |
31
|
|
|
'digest' => 'some digest', |
32
|
|
|
'content' => 'some content' |
33
|
|
|
], |
34
|
|
|
__DIR__.'/../data/document.pdf' |
35
|
|
|
] |
36
|
|
|
], |
37
|
|
|
false |
38
|
|
|
); |
39
|
|
|
$result = $method->getFields(); |
40
|
|
|
|
41
|
|
|
$this->assertArrayHasKey('asic', $result); |
42
|
|
|
$this->assertArrayHasKey('files', $result['asic']); |
43
|
|
|
$this->assertArrayHasKey(0, $result['asic']['files']); |
44
|
|
|
$file0 = $result['asic']['files'][0]; |
45
|
|
|
$this->assertArrayHasKey('name', $file0); |
46
|
|
|
$this->assertArrayHasKey('digest', $file0); |
47
|
|
|
$this->assertArrayHasKey('content', $file0); |
48
|
|
|
$this->assertArrayHasKey(1, $result['asic']['files']); |
49
|
|
|
$file1 = $result['asic']['files'][1]; |
50
|
|
|
$this->assertArrayHasKey('name', $file1); |
51
|
|
|
$this->assertArrayHasKey('digest', $file1); |
52
|
|
|
$this->assertArrayHasKey('content', $file1); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @expectedException \RuntimeException |
57
|
|
|
* @expectedExceptionMessage File "" does not exist |
58
|
|
|
*/ |
59
|
|
|
public function testGetFileFieldsWithNonExistingFile() |
60
|
|
|
{ |
61
|
|
|
$method = new Seal( |
62
|
|
|
'pdf', |
63
|
|
|
[ |
64
|
|
|
'files' => [ |
65
|
|
|
'' |
66
|
|
|
] |
67
|
|
|
], |
68
|
|
|
false |
69
|
|
|
); |
70
|
|
|
$method->getFields(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testGetAction() |
74
|
|
|
{ |
75
|
|
|
$method = new Seal('', [], false); |
76
|
|
|
$this->assertSame('seal', $method->getAction()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGetMethod() |
80
|
|
|
{ |
81
|
|
|
$method = new Seal('', [], false); |
82
|
|
|
$this->assertSame(QueryInterface::POST, $method->getMethod()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testCreateResult() |
86
|
|
|
{ |
87
|
|
|
$method = new Seal('', [], false); |
88
|
|
|
$this->assertInstanceOf('Isign\Document\SealResult', $method->createResult()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testHasValidationConstraints() |
92
|
|
|
{ |
93
|
|
|
$method = new Seal('', [], false); |
94
|
|
|
$collection = $method->getValidationConstraints(); |
95
|
|
|
|
96
|
|
|
$this->assertInstanceOf( |
97
|
|
|
'Symfony\Component\Validator\Constraints\Collection', |
98
|
|
|
$collection |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function getPdfDocument() |
103
|
|
|
{ |
104
|
|
|
return [ |
105
|
|
|
'signing_purpose' => '', |
106
|
|
|
'contact' => '', |
107
|
|
|
'reason' => '', |
108
|
|
|
'location' => '', |
109
|
|
|
'files' => [], |
110
|
|
|
]; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|