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

Page::testGetFont()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
cc 1
eloc 9
c 3
b 1
f 1
nc 1
nop 0
dl 0
loc 14
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;
32
33
use mageekguy\atoum;
34
35
/**
36
 * Class Page
37
 *
38
 * @package Smalot\PdfParser\Tests\Units
39
 */
40
class Page extends atoum\test
41
{
42
    public function testGetFonts()
43
    {
44
        // Document with text.
45
        $filename = __DIR__ . '/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
46
        $parser   = new \Smalot\PdfParser\Parser();
47
        $document = $parser->parseFile($filename);
48
        $pages    = $document->getPages();
49
        $page     = $pages[0];
50
51
        // the first to load data.
52
        $fonts = $page->getFonts();
53
        $this->assert->array($fonts)->isNotEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Page. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
        foreach ($fonts as $font) {
55
            $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
56
        }
57
        // the second to use cache.
58
        $fonts = $page->getFonts();
59
        $this->assert->array($fonts)->isNotEmpty();
60
61
        // ------------------------------------------------------
62
        // Document without text.
63
        $filename = __DIR__ . '/../../../../../samples/Document3_pdfcreator_nocompressed.pdf';
64
        $document = $parser->parseFile($filename);
65
        $pages    = $document->getPages();
66
        $page     = $pages[0];
67
68
        // the first to load data.
69
        $fonts = $page->getFonts();
70
        $this->assert->array($fonts)->isEmpty();
71
        // the second to use cache.
72
        $fonts = $page->getFonts();
73
        $this->assert->array($fonts)->isEmpty();
74
    }
75
76
    public function testGetFont()
77
    {
78
        // Document with text.
79
        $filename = __DIR__ . '/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
80
        $parser   = new \Smalot\PdfParser\Parser();
81
        $document = $parser->parseFile($filename);
82
        $pages    = $document->getPages();
83
        $page     = $pages[0];
84
85
        // the first to load data.
86
        $font = $page->getFont('R7');
87
        $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Page. Since you implemented __get, consider adding a @property annotation.
Loading history...
88
        $font = $page->getFont('ABC7');
89
        $this->assert->object($font)->isInstanceOf('\Smalot\PdfParser\Font');
90
    }
91
92
    public function testGetText()
93
    {
94
        // Document with text.
95
        $filename = __DIR__ . '/../../../../../samples/Document1_pdfcreator_nocompressed.pdf';
96
        $parser   = new \Smalot\PdfParser\Parser();
97
        $document = $parser->parseFile($filename);
98
        $pages    = $document->getPages();
99
        $page     = $pages[0];
100
        $text     = $page->getText();
101
102
        $this->assert->string($text)->hasLengthGreaterThan(150);
0 ignored issues
show
Bug Best Practice introduced by
The property assert does not exist on Smalot\PdfParser\Tests\Units\Page. Since you implemented __get, consider adding a @property annotation.
Loading history...
103
        $this->assert->string($text)->contains('Document title');
104
        $this->assert->string($text)->contains('Lorem ipsum');
105
106
        $this->assert->string($text)->contains('Calibri');
107
        $this->assert->string($text)->contains('Arial');
108
        $this->assert->string($text)->contains('Times');
109
        $this->assert->string($text)->contains('Courier New');
110
        $this->assert->string($text)->contains('Verdana');
111
    }
112
}
113