Completed
Pull Request — develop (#14)
by Rimas
03:51
created

SealTest::testGetFileFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
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 View Code Duplication
    public function testGetFileFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $method = new Seal(
26
            'pdf',
27
            [
28
                'files' => [
29
                    __DIR__.'/../data/document.pdf'
30
                ]
31
            ],
32
            false
33
        );
34
        $result = $method->getFields();
35
36
        $this->assertArrayHasKey('pdf', $result);
37
        $this->assertArrayHasKey('files', $result['pdf']);
38
        $this->assertArrayHasKey(0, $result['pdf']['files']);
39
        $file = $result['pdf']['files'][0];
40
        $this->assertArrayHasKey('name', $file);
41
        $this->assertArrayHasKey('digest', $file);
42
        $this->assertArrayHasKey('content', $file);
43
    }
44
45
    /**
46
     * @expectedException \RuntimeException
47
     * @expectedExceptionMessage File "" does not exist
48
     */
49
    public function testGetFileFieldsWithNonExistingFile()
50
    {
51
        $method = new Seal(
52
            'pdf',
53
            [
54
                'files' => [
55
                    ''
56
                ]
57
            ],
58
            false
59
        );
60
        $method->getFields();
61
    }
62
63
    public function testGetAction()
64
    {
65
        $method = new Seal('', [], false);
66
        $this->assertSame('seal', $method->getAction());
67
    }
68
69
    public function testGetMethod()
70
    {
71
        $method = new Seal('', [], false);
72
        $this->assertSame(QueryInterface::POST, $method->getMethod());
73
    }
74
75
    public function testCreateResult()
76
    {
77
        $method = new Seal('', [], false);
78
        $this->assertInstanceOf('Isign\Document\SealResult', $method->createResult());
79
    }
80
81
    public function testHasValidationConstraints()
82
    {
83
        $method = new Seal('', [], false);
84
        $collection = $method->getValidationConstraints();
85
86
        $this->assertInstanceOf(
87
            'Symfony\Component\Validator\Constraints\Collection',
88
            $collection
89
        );
90
    }
91
92
    private function getPdfDocument()
93
    {
94
        return [
95
            'signing_purpose' => '',
96
            'contact' => '',
97
            'reason' => '',
98
            'location' => '',
99
            'files' => [],
100
        ];
101
    }
102
}
103