|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PHPUnitTests\Unit; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnitTests\TestCase; |
|
8
|
|
|
use Smalot\PdfParser\Document; |
|
9
|
|
|
use Smalot\PdfParser\Element; |
|
10
|
|
|
use Smalot\PdfParser\Element\ElementArray; |
|
11
|
|
|
use Smalot\PdfParser\Header; |
|
12
|
|
|
use Smalot\PdfParser\Page; |
|
13
|
|
|
use Smalot\PdfParser\PDFObject; |
|
14
|
|
|
use Smalot\PdfParser\XObject\Image; |
|
15
|
|
|
|
|
16
|
|
|
class PDFObjectTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
public function testGetTextOnNullPage(): void |
|
19
|
|
|
{ |
|
20
|
|
|
static::assertSame(' ', (new PDFObject(new Document()))->getText()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testGetTextOnPageWithoutContent(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$document = new Document(); |
|
26
|
|
|
|
|
27
|
|
|
static::assertSame(' ', (new PDFObject($document, null, null))->getText(new Page($document))); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testTextArrayObjects(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$document = new Document(); |
|
33
|
|
|
$document->init(); |
|
34
|
|
|
|
|
35
|
|
|
$image = new Image($document); |
|
36
|
|
|
$xObject = new PDFObject($document); |
|
37
|
|
|
|
|
38
|
|
|
$header1 = new Header([ |
|
39
|
|
|
'Resources' => new Header([ |
|
40
|
|
|
'XObject' => new Header([ |
|
41
|
|
|
'Im0' => $image, |
|
42
|
|
|
]) |
|
43
|
|
|
]), |
|
44
|
|
|
'Contents' => new ElementArray([new Element('/Imo Do', $document)], $document), |
|
45
|
|
|
]); |
|
46
|
|
|
$page1 = new Page($document, $header1); |
|
47
|
|
|
|
|
48
|
|
|
$header2 = new Header([ |
|
49
|
|
|
'Resources' => new Header([ |
|
50
|
|
|
'XObject' => new Header([ |
|
51
|
|
|
'Ps0' => $xObject, |
|
52
|
|
|
]) |
|
53
|
|
|
]), |
|
54
|
|
|
'Contents' => new ElementArray([new Element('/Ps0 Do', $document)], $document), |
|
55
|
|
|
]); |
|
56
|
|
|
$page2 = new Page($document, $header2); |
|
57
|
|
|
|
|
58
|
|
|
// Page 1 contains an image, which should not appear in the text array. |
|
59
|
|
|
self::assertSame([], $page1->getTextArray()); |
|
60
|
|
|
|
|
61
|
|
|
// Page 2 contains a non-image object, which should appear in the text array. |
|
62
|
|
|
self::assertSame([' '], $page2->getTextArray()); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|