Passed
Branch master (f7fac8)
by Sebastien
02:47
created

ElementString::testEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 9
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9666
1
<?php
2
3
/**
4
 * @file
5
 *          This file is part of the PdfParser library.
6
 *
7
 * @author  Sébastien MALOT <[email protected]>
8
 * @date    2017-01-03
9
 * @license LGPLv3
10
 * @url     <https://github.com/smalot/pdfparser>
11
 *
12
 *  PdfParser is a pdf library written in PHP, extraction oriented.
13
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
14
 *
15
 *  This program is free software: you can redistribute it and/or modify
16
 *  it under the terms of the GNU Lesser General Public License as published by
17
 *  the Free Software Foundation, either version 3 of the License, or
18
 *  (at your option) any later version.
19
 *
20
 *  This program is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU Lesser General Public License for more details.
24
 *
25
 *  You should have received a copy of the GNU Lesser General Public License
26
 *  along with this program.
27
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
28
 *
29
 */
30
31
namespace Smalot\PdfParser\Tests\Units\Element;
32
33
use mageekguy\atoum;
34
35
/**
36
 * Class ElementString
37
 *
38
 * @package Smalot\PdfParser\Tests\Units\Element
39
 */
40
class ElementString extends atoum\test
41
{
42
    public function testParse()
43
    {
44
        // Skipped.
45
        $offset  = 0;
46
        $element = \Smalot\PdfParser\Element\ElementString::parse('ABC', null, $offset);
47
        $this->assert->boolean($element)->isEqualTo(false);
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Element\ElementString. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
        $this->assert->integer($offset)->isEqualTo(0);
49
        $offset  = 0;
50
        $element = \Smalot\PdfParser\Element\ElementString::parse(' [ (ABC) 5 6 ]', null, $offset);
51
        $this->assert->boolean($element)->isEqualTo(false);
52
        $this->assert->integer($offset)->isEqualTo(0);
53
        $offset  = 0;
54
        $element = \Smalot\PdfParser\Element\ElementString::parse(' << (invalid) >>', null, $offset);
55
        $this->assert->boolean($element)->isEqualTo(false);
56
        $this->assert->integer($offset)->isEqualTo(0);
57
        $offset  = 0;
58
        $element = \Smalot\PdfParser\Element\ElementString::parse(' / (FlateDecode) ', null, $offset);
59
        $this->assert->boolean($element)->isEqualTo(false);
60
        $this->assert->integer($offset)->isEqualTo(0);
61
        $offset  = 0;
62
        $element = \Smalot\PdfParser\Element\ElementString::parse(' 0 (FlateDecode) ', null, $offset);
63
        $this->assert->boolean($element)->isEqualTo(false);
64
        $this->assert->integer($offset)->isEqualTo(0);
65
        $offset  = 0;
66
        $element = \Smalot\PdfParser\Element\ElementString::parse(" 0 \n (FlateDecode) ", null, $offset);
67
        $this->assert->boolean($element)->isEqualTo(false);
68
        $this->assert->integer($offset)->isEqualTo(0);
69
70
        // Valid.
71
        $offset  = 0;
72
        $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright) ', null, $offset);
73
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
74
        $this->assert->integer($offset)->isEqualTo(12);
75
        $offset  = 0;
76
        $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright) ', null, $offset);
77
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
78
        $this->assert->integer($offset)->isEqualTo(12);
79
        $offset  = 0;
80
        $element = \Smalot\PdfParser\Element\ElementString::parse(' (Copyright)', null, $offset);
81
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
82
        $this->assert->integer($offset)->isEqualTo(12);
83
        $offset  = 0;
84
        $element = \Smalot\PdfParser\Element\ElementString::parse('(Copyright)', null, $offset);
85
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
86
        $this->assert->integer($offset)->isEqualTo(11);
87
        $offset  = 0;
88
        $element = \Smalot\PdfParser\Element\ElementString::parse('(Copy-right2)', null, $offset);
89
        $this->assert->string($element->getContent())->isEqualTo('Copy-right2');
90
        $this->assert->integer($offset)->isEqualTo(13);
91
        $offset  = 0;
92
        $element = \Smalot\PdfParser\Element\ElementString::parse(" \n (Copyright) ", null, $offset);
93
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
94
        $this->assert->integer($offset)->isEqualTo(14);
95
        $offset  = 0;
96
        $element = \Smalot\PdfParser\Element\ElementString::parse('()', null, $offset);
97
        $this->assert->string($element->getContent())->isEqualTo('');
98
        $this->assert->integer($offset)->isEqualTo(2);
99
100
        // Complex study case : Unicode + octal.
101
        $offset  = 0;
102
        $element = \Smalot\PdfParser\Element\ElementString::parse("(ABC\\))", null, $offset);
103
        $this->assert->string($element->getContent())->isEqualTo('ABC)');
104
        $this->assert->integer($offset)->isEqualTo(7);
105
        $offset  = 0;
106
        $element = \Smalot\PdfParser\Element\ElementString::parse("(\xFE\xFF\\000M)", null, $offset);
107
        $this->assert->string($element->getContent())->isEqualTo('M');
108
        $this->assert->integer($offset)->isEqualTo(9);
109
        $offset  = 0;
110
        $element = \Smalot\PdfParser\Element\ElementString::parse("(<20>)", null, $offset);
111
        $this->assert->string($element->getContent())->isEqualTo(' ');
112
        $this->assert->integer($offset)->isEqualTo(6);
113
        $offset  = 0;
114
        $element = \Smalot\PdfParser\Element\ElementString::parse("(Gutter\\ console\\ assembly)", null, $offset);
115
        $this->assert->string($element->getContent())->isEqualTo('Gutter console assembly');
116
        $this->assert->integer($offset)->isEqualTo(27);
117
    }
118
119
    public function testGetContent()
120
    {
121
        $element = new \Smalot\PdfParser\Element\ElementString('Copyright');
122
        $this->assert->string($element->getContent())->isEqualTo('Copyright');
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Element\ElementString. Since you implemented __get, consider adding a @property annotation.
Loading history...
123
    }
124
125
    public function testEquals()
126
    {
127
        $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
128
        $this->assert->boolean($element->equals('CopyRight'))->isEqualTo(true);
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Element\ElementString. Since you implemented __get, consider adding a @property annotation.
Loading history...
129
        $this->assert->boolean($element->equals('Flatedecode'))->isEqualTo(false);
130
131
        $element = new \Smalot\PdfParser\Element\ElementString('CopyRight2');
132
        $this->assert->boolean($element->equals('CopyRight2'))->isEqualTo(true);
133
        $this->assert->boolean($element->equals('CopyRight3'))->isEqualTo(false);
134
135
        $element = new \Smalot\PdfParser\Element\ElementString('Flate-Decode2');
136
        $this->assert->boolean($element->equals('Flate-Decode2'))->isEqualTo(true);
137
        $this->assert->boolean($element->equals('Flate-Decode3'))->isEqualTo(false);
138
    }
139
140
    public function testContains()
141
    {
142
        $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
143
        $this->assert->boolean($element->contains('CopyRight'))->isEqualTo(true);
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Element\ElementString. Since you implemented __get, consider adding a @property annotation.
Loading history...
144
        $this->assert->boolean($element->contains('Copyright'))->isEqualTo(false);
145
146
        $element = new \Smalot\PdfParser\Element\ElementString('CopyRight2');
147
        $this->assert->boolean($element->contains('CopyRight2'))->isEqualTo(true);
148
        $this->assert->boolean($element->contains('CopyRight3'))->isEqualTo(false);
149
    }
150
151
    public function test__toString()
152
    {
153
        $element = new \Smalot\PdfParser\Element\ElementString('CopyRight');
154
        $this->assert->castToString($element)->isEqualTo('CopyRight');
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Element\ElementString. Since you implemented __get, consider adding a @property annotation.
Loading history...
155
    }
156
}
157