ElementStructTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 1

1 Method

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