Test Failed
Pull Request — master (#597)
by Konrad
03:09 queued 01:08
created

FontTest::testDecodeTextIssue597()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 23
rs 9.9332
1
<?php
2
3
/**
4
 * @file This file is part of the PdfParser library.
5
 *
6
 * @author  Konrad Abicht <[email protected]>
7
 *
8
 * @date    2023-07-19
9
 *
10
 * @license LGPLv3
11
 *
12
 * @url     <https://github.com/smalot/pdfparser>
13
 *
14
 *  PdfParser is a pdf library written in PHP, extraction oriented.
15
 *  Copyright (C) 2017 - Sébastien MALOT <[email protected]>
16
 *
17
 *  This program is free software: you can redistribute it and/or modify
18
 *  it under the terms of the GNU Lesser General Public License as published by
19
 *  the Free Software Foundation, either version 3 of the License, or
20
 *  (at your option) any later version.
21
 *
22
 *  This program is distributed in the hope that it will be useful,
23
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 *  GNU Lesser General Public License for more details.
26
 *
27
 *  You should have received a copy of the GNU Lesser General Public License
28
 *  along with this program.
29
 *  If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>.
30
 */
31
32
namespace PHPUnitTests\Unit;
33
34
use PHPUnitTests\TestCase;
35
use Smalot\PdfParser\Config;
36
use Smalot\PdfParser\Document;
37
use Smalot\PdfParser\Font;
38
use Smalot\PdfParser\PDFObject;
39
40
class FontTest extends TestCase
41
{
42
    /**
43
     * decodeText must decode \b.
44
     *
45
     * @see https://github.com/smalot/pdfparser/pull/597
46
     */
47
    public function testDecodeTextIssue597(): void
48
    {
49
        $config = $this->createMock(Config::class);
50
        $config->method('getFontSpaceLimit')->willReturn(1);
51
52
        $document = $this->createMock(Document::class);
53
        $sut = new Font($document, null, null, $config);
54
55
        $commands = [
56
            [
57
                PDFObject::TYPE => '<',
58
                PDFObject::COMMAND => "<ab>\b",
59
            ],
60
        ];
61
62
        // result is a binary string and looks like: 0x3cc2ab083e
63
        $result = $sut->decodeText($commands);
64
65
        // check that \b is not part of the result anymore
66
        self::assertFalse(strpos($result, "\b>"));
67
68
        // compare result with expected value
69
        self::assertEquals('3cc2ab083e', bin2hex($result));
70
    }
71
}
72