Test Failed
Push — master ( fff98f...fc01f2 )
by Konrad
01:57
created

FilterHelperTest::testDecodeFilterFlateDecode()   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
    public function testDecodeFilterASCII85DecodeInitSequence(): void
63
    {
64
        $compressed = '<~6Z6g\Eb0<5ARlp)FE2)5B)'; // = Compressed string
65
        $result = $this->fixture->decodeFilter('ASCII85Decode', $compressed);
66
67
        $this->assertEquals('Compressed string', $result);
68
    }
69
70
    public function testDecodeFilterASCII85DecodeEndSequence(): void
71
    {
72
        $compressed = '6Z6g\Eb0<5ARlp)FE2)5B)~>'; // = Compressed string
73
        $result = $this->fixture->decodeFilter('ASCII85Decode', $compressed);
74
75
        $this->assertEquals('Compressed string', $result);
76
    }
77
78
    public function testDecodeFilterASCII85DecodeSpecificEndSequence(): void
79
    {
80
        $compressed = '+^6b<~>'; // = 0x215B33C0 = "![3\xC0"
81
        $result = $this->fixture->decodeFilter('ASCII85Decode', $compressed);
82
83
        $this->assertEquals("\x21\x5B\x33\xC0", $result);
84
    }
85
86
    /*
87
     * Tests for filter ASCIIHexDecode
88
     */
89
90
    public function testDecodeFilterASCIIHexDecode(): void
91
    {
92
        $compressed = '43 6f 6d 70 72 65 73 73 65 64 20 73 74 72 69 6e 67'; // = Compressed string
93
        $result = $this->fixture->decodeFilter('ASCIIHexDecode', $compressed);
94
95
        $this->assertEquals('Compressed string', $result);
96
    }
97
98
    /*
99
     * Tests for filter FlateDecode
100
     */
101
102
    public function testDecodeFilterFlateDecode(): void
103
    {
104
        $compressed = gzcompress('Compress me', 9);
105
        $result = $this->fixture->decodeFilter('FlateDecode', $compressed);
106
107
        $this->assertEquals('Compress me', $result);
108
    }
109
110
    /**
111
     * How does function behave if an empty string was given.
112
     */
113
    public function testDecodeFilterFlateDecodeEmptyString(): void
114
    {
115
        $this->expectException(\Exception::class);
116
        $this->expectExceptionMessage('gzuncompress(): data error');
117
118
        $this->fixture->decodeFilter('FlateDecode', '');
119
    }
120
121
    /**
122
     * How does function behave if an uncompressed string was given.
123
     */
124
    public function testDecodeFilterFlateDecodeUncompressedString(): void
125
    {
126
        $this->expectException(\Exception::class);
127
        $this->expectExceptionMessage('gzuncompress(): data error');
128
129
        $this->fixture->decodeFilter('FlateDecode', 'something');
130
    }
131
132
    /**
133
     * How does function behave if an uncompressed string was given.
134
     */
135
    public function testDecodeFilterUnknownFilter(): void
136
    {
137
        $result = $this->fixture->decodeFilter('a string '.rand(), 'something');
138
        $this->assertEquals('something', $result);
139
    }
140
141
    /*
142
     * Test for filters not being implemented yet.
143
     */
144
145
    /**
146
     * CCITTFaxDecode
147
     */
148
    public function testDecodeFilterCCITTFaxDecode(): void
149
    {
150
        $this->expectException(\Exception::class);
151
        $this->expectExceptionMessage('Decode CCITTFaxDecode not implemented yet.');
152
153
        $this->fixture->decodeFilter('CCITTFaxDecode', '');
154
    }
155
156
    /**
157
     * Crypt
158
     */
159
    public function testDecodeFilterCrypt(): void
160
    {
161
        $this->expectException(\Exception::class);
162
        $this->expectExceptionMessage('Decode Crypt not implemented yet.');
163
164
        $this->fixture->decodeFilter('Crypt', '');
165
    }
166
167
    /**
168
     * DCTDecode
169
     */
170
    public function testDecodeFilterDCTDecode(): void
171
    {
172
        $this->expectException(\Exception::class);
173
        $this->expectExceptionMessage('Decode DCTDecode not implemented yet.');
174
175
        $this->fixture->decodeFilter('DCTDecode', '');
176
    }
177
178
    /**
179
     * JBIG2Decode
180
     */
181
    public function testDecodeFilterJBIG2Decode(): void
182
    {
183
        $this->expectException(\Exception::class);
184
        $this->expectExceptionMessage('Decode JBIG2Decode not implemented yet.');
185
186
        $this->fixture->decodeFilter('JBIG2Decode', '');
187
    }
188
189
    /**
190
     * JPXDecode
191
     */
192
    public function testDecodeFilterJPXDecode(): void
193
    {
194
        $this->expectException(\Exception::class);
195
        $this->expectExceptionMessage('Decode JPXDecode not implemented yet.');
196
197
        $this->fixture->decodeFilter('JPXDecode', '');
198
    }
199
}
200