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\ElementXRef; |
36
|
|
|
use Tests\Smalot\PdfParser\TestCase; |
37
|
|
|
|
38
|
|
|
class ElementXRefTest extends TestCase |
39
|
|
|
{ |
40
|
|
|
public function testParse() |
41
|
|
|
{ |
42
|
|
|
// Skipped. |
43
|
|
|
$offset = 0; |
44
|
|
|
$element = ElementXRef::parse('ABC', null, $offset); |
45
|
|
|
$this->assertFalse($element); |
46
|
|
|
$this->assertEquals(0, $offset); |
47
|
|
|
|
48
|
|
|
$offset = 0; |
49
|
|
|
$element = ElementXRef::parse(' [ 5 0 R ]', null, $offset); |
50
|
|
|
$this->assertFalse($element); |
51
|
|
|
$this->assertEquals(0, $offset); |
52
|
|
|
|
53
|
|
|
$offset = 0; |
54
|
|
|
$element = ElementXRef::parse(' << 5 0 R >>', null, $offset); |
55
|
|
|
$this->assertFalse($element); |
56
|
|
|
$this->assertEquals(0, $offset); |
57
|
|
|
|
58
|
|
|
$offset = 0; |
59
|
|
|
$element = ElementXRef::parse(' / 5 0 R ', null, $offset); |
60
|
|
|
$this->assertFalse($element); |
61
|
|
|
$this->assertEquals(0, $offset); |
62
|
|
|
|
63
|
|
|
$offset = 0; |
64
|
|
|
$element = ElementXRef::parse(' 0 5 0 R ', null, $offset); |
65
|
|
|
$this->assertFalse($element); |
66
|
|
|
$this->assertEquals(0, $offset); |
67
|
|
|
|
68
|
|
|
$offset = 0; |
69
|
|
|
$element = ElementXRef::parse(" 0 \n 5 0 R ", null, $offset); |
70
|
|
|
$this->assertFalse($element); |
71
|
|
|
$this->assertEquals(0, $offset); |
72
|
|
|
|
73
|
|
|
// Valid. |
74
|
|
|
$offset = 0; |
75
|
|
|
$element = ElementXRef::parse(' 5 0 R ', null, $offset); |
76
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
77
|
|
|
$this->assertEquals(6, $offset); |
78
|
|
|
|
79
|
|
|
$offset = 0; |
80
|
|
|
$element = ElementXRef::parse(' 5 0 R ', null, $offset); |
81
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
82
|
|
|
$this->assertEquals(6, $offset); |
83
|
|
|
|
84
|
|
|
$offset = 0; |
85
|
|
|
$element = ElementXRef::parse(' 5 0 R', null, $offset); |
86
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
87
|
|
|
$this->assertEquals(6, $offset); |
88
|
|
|
|
89
|
|
|
$offset = 0; |
90
|
|
|
$element = ElementXRef::parse('5 0 R', null, $offset); |
91
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
92
|
|
|
$this->assertEquals(5, $offset); |
93
|
|
|
|
94
|
|
|
$offset = 0; |
95
|
|
|
$element = ElementXRef::parse(" \n 5 0 R ", null, $offset); |
96
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
97
|
|
|
$this->assertEquals(8, $offset); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testGetContent() |
101
|
|
|
{ |
102
|
|
|
$element = new ElementXRef('5_0'); |
103
|
|
|
$this->assertEquals('5_0', $element->getContent()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testGetId() |
107
|
|
|
{ |
108
|
|
|
$element = new ElementXRef('5_0'); |
109
|
|
|
$this->assertEquals('5_0', $element->getId()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testEquals() |
113
|
|
|
{ |
114
|
|
|
$element = new ElementXRef('5_0'); |
115
|
|
|
$this->assertTrue($element->equals(5)); |
116
|
|
|
$this->assertFalse($element->equals(8)); |
117
|
|
|
$this->assertTrue($element->equals($element)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testContains() |
121
|
|
|
{ |
122
|
|
|
$element = new ElementXRef('5_0'); |
123
|
|
|
$this->assertTrue($element->contains(5)); |
124
|
|
|
$this->assertFalse($element->contains(8)); |
125
|
|
|
$this->assertTrue($element->contains($element)); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testToString() |
129
|
|
|
{ |
130
|
|
|
$element = new ElementXRef('5_0'); |
131
|
|
|
$this->assertEquals('#Obj#5_0', (string) $element); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|