Passed
Push — master ( c9c2be...722061 )
by Konrad
02:07
created

FilterHelperTest::testDecodeFilterJPXDecode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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