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-02 |
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\Element; |
34
|
|
|
|
35
|
|
|
use Smalot\PdfParser\Element\ElementStruct; |
36
|
|
|
use Smalot\PdfParser\Header; |
37
|
|
|
use Test\Smalot\PdfParser\TestCase; |
38
|
|
|
|
39
|
|
|
class ElementStructTest extends TestCase |
40
|
|
|
{ |
41
|
|
|
public function testParse() |
42
|
|
|
{ |
43
|
|
|
$document = $this->getDocumentInstance(); |
44
|
|
|
|
45
|
|
|
// Skipped. |
46
|
|
|
$offset = 0; |
47
|
|
|
$element = ElementStruct::parse('ABC', $document, $offset); |
48
|
|
|
$this->assertFalse($element); |
|
|
|
|
49
|
|
|
$this->assertEquals(0, $offset); |
50
|
|
|
|
51
|
|
|
$offset = 0; |
52
|
|
|
$element = ElementStruct::parse(' [ << /Filter /FlateDecode >> ]', $document, $offset); |
53
|
|
|
$this->assertFalse($element); |
54
|
|
|
$this->assertEquals(0, $offset); |
55
|
|
|
|
56
|
|
|
$offset = 0; |
57
|
|
|
$element = ElementStruct::parse(' / << /Filter /FlateDecode >> ', $document, $offset); |
58
|
|
|
$this->assertFalse($element); |
59
|
|
|
$this->assertEquals(0, $offset); |
60
|
|
|
|
61
|
|
|
$offset = 0; |
62
|
|
|
$element = ElementStruct::parse(' 0 << /Filter /FlateDecode >> ', $document, $offset); |
63
|
|
|
$this->assertFalse($element); |
64
|
|
|
$this->assertEquals(0, $offset); |
65
|
|
|
|
66
|
|
|
$offset = 0; |
67
|
|
|
$element = ElementStruct::parse(" 0 \n << /Filter /FlateDecode >> ", $document, $offset); |
68
|
|
|
$this->assertFalse($element); |
69
|
|
|
$this->assertEquals(0, $offset); |
70
|
|
|
|
71
|
|
|
// Valid. |
72
|
|
|
$offset = 0; |
73
|
|
|
$element = ElementStruct::parse(' << /Filter /FlateDecode >> ', $document, $offset); |
74
|
|
|
$this->assertTrue($element instanceof Header); |
75
|
|
|
$this->assertEquals(27, $offset); |
76
|
|
|
|
77
|
|
|
$offset = 0; |
78
|
|
|
$element = ElementStruct::parse(' << /Filter /FlateDecode >>', $document, $offset); |
79
|
|
|
$this->assertTrue($element instanceof Header); |
80
|
|
|
$this->assertEquals(27, $offset); |
81
|
|
|
|
82
|
|
|
$offset = 0; |
83
|
|
|
$element = ElementStruct::parse('<< /Filter /FlateDecode >>', $document, $offset); |
84
|
|
|
$this->assertTrue($element instanceof Header); |
85
|
|
|
$this->assertEquals(26, $offset); |
86
|
|
|
|
87
|
|
|
$offset = 0; |
88
|
|
|
$element = ElementStruct::parse(" \n << /Filter /FlateDecode >> ", $document, $offset); |
89
|
|
|
$this->assertTrue($element instanceof Header); |
90
|
|
|
$this->assertEquals(29, $offset); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|