Test Failed
Push — master ( 70433d...3ef8bc )
by Konrad
02:17
created

FilterHelperTest::testDecodeFilterCrypt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 *
8
 * @date    2020-06-01
9
 *
10
 * @author  Sébastien MALOT <[email protected]>
11
 *
12
 * @date    2017-01-03
13
 *
14
 * @license LGPLv3
15
 *
16
 * @url     <https://github.com/smalot/pdfparser>
17
 *
18
 *  PdfParser is a pdf library written in PHP, extraction oriented.
19
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
20
 *
21
 *  This program is free software: you can redistribute it and/or modify
22
 *  it under the terms of the GNU Lesser General Public License as published by
23
 *  the Free Software Foundation, either version 3 of the License, or
24
 *  (at your option) any later version.
25
 *
26
 *  This program is distributed in the hope that it will be useful,
27
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 *  GNU Lesser General Public License for more details.
30
 *
31
 *  You should have received a copy of the GNU Lesser General Public License
32
 *  along with this program.
33
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
34
 */
35
36
namespace PHPUnitTests\Integration\RawData;
37
38
use PHPUnitTests\TestCase;
39
use Smalot\PdfParser\RawData\FilterHelper;
40
41
class FilterHelperTest extends TestCase
42
{
43
    protected function setUp(): void
44
    {
45
        parent::setUp();
46
47
        $this->fixture = new FilterHelper();
48
    }
49
50
    /*
51
     * Tests for filter ASCII85Decode
52
     */
53
54
    public function testDecodeFilterASCII85Decode(): void
55
    {
56
        $compressed = '6Z6g\Eb0<5ARlp)FE2)5B)'; // = Compressed string
57
        $result = $this->fixture->decodeFilter('ASCII85Decode', $compressed);
58
59
        $this->assertEquals('Compressed string', $result);
60
    }
61
62
    /*
63
     * Tests for filter ASCIIHexDecode
64
     */
65
66
    public function testDecodeFilterASCIIHexDecode(): void
67
    {
68
        $compressed = '43 6f 6d 70 72 65 73 73 65 64 20 73 74 72 69 6e 67'; // = Compressed string
69
        $result = $this->fixture->decodeFilter('ASCIIHexDecode', $compressed);
70
71
        $this->assertEquals('Compressed string', $result);
72
    }
73
74
    /*
75
     * Tests for filter FlateDecode
76
     */
77
78
    public function testDecodeFilterFlateDecode(): void
79
    {
80
        $compressed = gzcompress('Compress me', 9);
81
        $result = $this->fixture->decodeFilter('FlateDecode', $compressed);
82
83
        $this->assertEquals('Compress me', $result);
84
    }
85
86
    /**
87
     * How does function behave if an empty string was given.
88
     */
89
    public function testDecodeFilterFlateDecodeEmptyString(): void
90
    {
91
        $this->expectException(\Exception::class);
92
        $this->expectExceptionMessage('gzuncompress(): data error');
93
94
        $this->fixture->decodeFilter('FlateDecode', '');
95
    }
96
97
    /**
98
     * How does function behave if an uncompressed string was given.
99
     */
100
    public function testDecodeFilterFlateDecodeUncompressedString(): void
101
    {
102
        $this->expectException(\Exception::class);
103
        $this->expectExceptionMessage('gzuncompress(): data error');
104
105
        $this->fixture->decodeFilter('FlateDecode', 'something');
106
    }
107
108
    /**
109
     * How does function behave if an uncompressed string was given.
110
     */
111
    public function testDecodeFilterUnknownFilter(): void
112
    {
113
        $result = $this->fixture->decodeFilter('a string '.rand(), 'something');
114
        $this->assertEquals('something', $result);
115
    }
116
117
    /*
118
     * Test for filters not being implemented yet.
119
     */
120
121
    /**
122
     * CCITTFaxDecode
123
     */
124
    public function testDecodeFilterCCITTFaxDecode(): void
125
    {
126
        $this->expectException(\Exception::class);
127
        $this->expectExceptionMessage('Decode CCITTFaxDecode not implemented yet.');
128
129
        $this->fixture->decodeFilter('CCITTFaxDecode', '');
130
    }
131
132
    /**
133
     * Crypt
134
     */
135
    public function testDecodeFilterCrypt(): void
136
    {
137
        $this->expectException(\Exception::class);
138
        $this->expectExceptionMessage('Decode Crypt not implemented yet.');
139
140
        $this->fixture->decodeFilter('Crypt', '');
141
    }
142
143
    /**
144
     * DCTDecode
145
     */
146
    public function testDecodeFilterDCTDecode(): void
147
    {
148
        $this->expectException(\Exception::class);
149
        $this->expectExceptionMessage('Decode DCTDecode not implemented yet.');
150
151
        $this->fixture->decodeFilter('DCTDecode', '');
152
    }
153
154
    /**
155
     * JBIG2Decode
156
     */
157
    public function testDecodeFilterJBIG2Decode(): void
158
    {
159
        $this->expectException(\Exception::class);
160
        $this->expectExceptionMessage('Decode JBIG2Decode not implemented yet.');
161
162
        $this->fixture->decodeFilter('JBIG2Decode', '');
163
    }
164
165
    /**
166
     * JPXDecode
167
     */
168
    public function testDecodeFilterJPXDecode(): void
169
    {
170
        $this->expectException(\Exception::class);
171
        $this->expectExceptionMessage('Decode JPXDecode not implemented yet.');
172
173
        $this->fixture->decodeFilter('JPXDecode', '');
174
    }
175
}
176