Feature: Labelprint für Kistenetiketten hinzugefügt

This commit is contained in:
2025-10-27 12:14:44 +01:00
parent 43bc416554
commit 14bae6c9ef
1068 changed files with 229014 additions and 1807 deletions

View File

@@ -0,0 +1,153 @@
<?php
/**
* BoxTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Box Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class BoxTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
}
public function testSetBox(): void
{
$page = $this->getTestObject();
$dims = $page->setBox([], 'CropBox', 2, 4, 6, 8);
$this->bcAssertEqualsWithDelta(
[
'CropBox' => [
'llx' => 2,
'lly' => 4,
'urx' => 6,
'ury' => 8,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [3],
],
],
],
$dims
);
$dims = $page->setBox(
[],
'TrimBox',
3,
5,
7,
11,
[
'color' => 'aquamarine',
'width' => 2,
'style' => 'D',
'dash' => [2, 3, 5, 7],
]
);
$this->bcAssertEqualsWithDelta(
[
'TrimBox' => [
'llx' => 3,
'lly' => 5,
'urx' => 7,
'ury' => 11,
'bci' => [
'color' => 'aquamarine',
'width' => 2,
'style' => 'D',
'dash' => [2, 3, 5, 7],
],
],
],
$dims
);
}
public function testSetBoxEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->setBox([], 'ERROR', 1, 2, 3, 4);
}
public function testSwapCoordinates(): void
{
$page = $this->getTestObject();
$dims = [
'CropBox' => [
'llx' => 2,
'lly' => 4,
'urx' => 6,
'ury' => 8,
],
];
$newpagedim = $page->swapCoordinates($dims);
$this->assertEquals(
[
'CropBox' => [
'llx' => 4,
'lly' => 2,
'urx' => 8,
'ury' => 6,
],
],
$newpagedim
);
}
public function testSetPageBoxes(): void
{
$page = $this->getTestObject();
$dims = $page->setPageBoxes(100, 200);
$exp = [
'llx' => 0,
'lly' => 0,
'urx' => 100,
'ury' => 200,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [3],
],
];
$this->bcAssertEqualsWithDelta(
[
'MediaBox' => $exp,
'CropBox' => $exp,
'BleedBox' => $exp,
'TrimBox' => $exp,
'ArtBox' => $exp,
],
$dims
);
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* FormatTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Format Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class FormatTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
}
public function testGetPageSize(): void
{
$page = $this->getTestObject();
$dims = $page->getPageFormatSize('A0');
$this->assertEquals([2383.937, 3370.394, 'P'], $dims);
$dims = $page->getPageFormatSize('A4', '', 'in', 2);
$this->assertEquals([8.27, 11.69, 'P'], $dims);
$dims = $page->getPageFormatSize('LEGAL', '', 'mm', 0);
$this->assertEquals([216, 356, 'P'], $dims);
$dims = $page->getPageFormatSize('LEGAL', 'P', 'mm', 0);
$this->assertEquals([216, 356, 'P'], $dims);
$dims = $page->getPageFormatSize('LEGAL', 'L', 'mm', 0);
$this->assertEquals([356, 216, 'L'], $dims);
}
public function testGetPageSizeEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->getPageFormatSize('*ERROR*');
}
public function testGetPageOrientedSize(): void
{
$page = $this->getTestObject();
$dims = $page->getPageOrientedSize(10, 20);
$this->assertEquals([10, 20, 'P'], $dims);
$dims = $page->getPageOrientedSize(10, 20, 'P');
$this->assertEquals([10, 20, 'P'], $dims);
$dims = $page->getPageOrientedSize(10, 20, 'L');
$this->assertEquals([20, 10, 'L'], $dims);
$dims = $page->getPageOrientedSize(20, 10, 'P');
$this->assertEquals([10, 20, 'P'], $dims);
$dims = $page->getPageOrientedSize(20, 10, 'L');
$this->assertEquals([20, 10, 'L'], $dims);
$dims = $page->getPageOrientedSize(20, 10);
$this->assertEquals([20, 10, 'L'], $dims);
}
public function testGetPageOrientation(): void
{
$page = $this->getTestObject();
$orient = $page->getPageOrientation(10, 20);
$this->assertEquals('P', $orient);
$orient = $page->getPageOrientation(20, 10);
$this->assertEquals('L', $orient);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* ModeTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Mode Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class ModeTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
}
public function testGetLayout(): void
{
$page = $this->getTestObject();
$this->assertEquals('TwoColumnLeft', $page->getLayout('two'));
$this->assertEquals('SinglePage', $page->getLayout(''));
$this->assertEquals('SinglePage', $page->getLayout());
}
public function testGetDisplay(): void
{
$page = $this->getTestObject();
$this->assertEquals('UseThumbs', $page->getDisplay('usethumbs'));
$this->assertEquals('UseAttachments', $page->getDisplay(''));
$this->assertEquals('UseNone', $page->getDisplay('something'));
}
}

View File

@@ -0,0 +1,351 @@
<?php
/**
* PageTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Page Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class PageTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, true, false);
}
public function testGetKUnit(): void
{
$page = $this->getTestObject();
$this->bcAssertEqualsWithDelta(2.83464566929134, $page->getKUnit(), 0.001);
}
public function testEnableSignatureApproval(): void
{
$page = $this->getTestObject();
$res = $page->enableSignatureApproval(true);
$this->assertNotNull($res); // @phpstan-ignore method.alreadyNarrowedType
}
public function testAdd(): void
{
$page = $this->getTestObject();
// 1
$res = $page->add();
$box = [
'llx' => 0,
'lly' => 0,
'urx' => 595.2765,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
];
$exp = [
'group' => 0,
'rotation' => 0,
'zoom' => 1,
'orientation' => 'P',
'format' => 'A4',
'pheight' => 841.890,
'pwidth' => 595.2765,
'width' => 210,
'height' => 297,
'box' => [
'MediaBox' => $box,
'CropBox' => $box,
'BleedBox' => $box,
'TrimBox' => $box,
'ArtBox' => $box,
],
'margin' => [
'booklet' => false,
'PL' => 0,
'PR' => 0,
'PT' => 0,
'HB' => 0,
'CT' => 0,
'CB' => 0,
'FT' => 0,
'PB' => 0,
],
'ContentWidth' => 210,
'ContentHeight' => 297,
'HeaderHeight' => 0,
'FooterHeight' => 0,
'region' => [[
'RX' => 0,
'RY' => 0,
'RW' => 210,
'RH' => 297,
'RL' => 210,
'RR' => 0.0,
'RT' => 297,
'RB' => 0.0,
'x' => 0.0,
'y' => 0.0,
]],
'currentRegion' => 0,
'columns' => 1,
'content' => [
0 => '',
],
'annotrefs' => [],
'content_mark' => [
0 => 0,
],
'autobreak' => true,
];
unset($res['time']);
$exp['pid'] = 0;
$this->bcAssertEqualsWithDelta($exp, $res);
// 2
$res = $page->add();
unset($res['time']);
$exp['pid'] = 1;
$this->bcAssertEqualsWithDelta($exp, $res);
// 3
$res = $page->add(
[
'group' => 1,
]
);
unset($res['time']);
$exp['pid'] = 2;
$exp['group'] = 1;
$this->bcAssertEqualsWithDelta($exp, $res);
// 3
$res = $page->add(
[
'columns' => 2,
]
);
unset($res['time']);
$exp['pid'] = 3;
$exp['group'] = 0;
$exp['columns'] = 2;
$exp['region'] = [
0 => [
'RX' => 0,
'RY' => 0,
'RW' => 105,
'RH' => 297,
'RL' => 105,
'RR' => 105,
'RT' => 297,
'RB' => 0,
'x' => 0,
'y' => 0,
],
1 => [
'RX' => 105,
'RY' => 0,
'RW' => 105,
'RH' => 297,
'RL' => 210,
'RR' => 0.0,
'RT' => 297,
'RB' => 0,
'x' => 105,
'y' => 0,
],
];
$this->bcAssertEqualsWithDelta($exp, $res);
$pid = $page->getPageID();
$this->assertEquals(3, $pid);
}
public function testGetNextPage(): void
{
$page = $this->getTestObject();
$page->add();
$page->add();
$page->add();
$page->add();
$page->setCurrentPage(2);
$page->getNextPage();
$page->enableAutoPageBreak(false);
$page->getNextPage();
$page->enableAutoPageBreak(true);
$page->getNextPage();
$page->getNextPage();
$this->assertCount(6, $page->getPages());
}
public function testDelete(): void
{
$page = $this->getTestObject();
$page->add();
$page->add();
$page->add();
$this->assertCount(3, $page->getPages());
$res = $page->delete(1);
$this->assertCount(2, $page->getPages());
$this->assertArrayHasKey('time', $res);
}
public function testDeleteEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->delete(2);
}
public function testPop(): void
{
$page = $this->getTestObject();
$page->add();
$page->add();
$page->add();
$this->assertCount(3, $page->getPages());
$res = $page->pop();
$this->assertCount(2, $page->getPages());
$this->assertArrayHasKey('time', $res);
}
public function testMove(): void
{
$page = $this->getTestObject();
$page->add();
$page->add(
[
'group' => 1,
]
);
$page->add(
[
'group' => 2,
]
);
$page->add(
[
'group' => 3,
]
);
$this->assertEquals($page->getPage(3), $page->getPage());
$page->move(3, 0);
$this->assertCount(4, $page->getPages());
$res = $page->getPage(0);
$this->assertEquals(3, $res['group']);
}
public function testMoveEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->move(1, 2);
}
public function testGetPageEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->getPage(2);
}
public function testContent(): void
{
$testObj = $this->getTestObject();
$testObj->add();
$testObj->addContent('Lorem');
$testObj->addContent('ipsum');
$testObj->addContentMark();
$testObj->addContent('dolor');
$testObj->addContent('sit');
$testObj->addContent('amet');
$this->assertEquals('amet', $testObj->popContent());
$page = $testObj->getPage();
$this->assertEquals([0, 3], $page['content_mark']);
$this->assertEquals(['', 'Lorem', 'ipsum', 'dolor', 'sit'], $page['content']);
$testObj->popContentToLastMark();
$page = $testObj->getPage();
$this->assertEquals([0], $page['content_mark']);
$this->assertEquals(['', 'Lorem', 'ipsum'], $page['content']);
}
public function testGetPdfPages(): void
{
$page = $this->getTestObject();
$page->add();
$page->addContent('TEST1');
$page->add();
$page->addContent('TEST2');
$page->add(
[
'group' => 1,
'transition' => [
'Dur' => 2,
'D' => 3,
'Dm' => 'V',
'S' => 'Glitter',
'M' => 'O',
'Di' => 315,
'SS' => 1.3,
'B' => true,
],
'annotrefs' => [10, 20],
]
);
$page->addContent('TEST2');
$pon = 0;
$out = $page->getPdfPages($pon);
$this->assertEquals(1, $page->getResourceDictObjID());
$this->assertEquals(2, $page->getRootObjID());
$this->bcAssertStringContainsString('<< /Type /Pages /Kids [ 3 0 R 4 0 R 5 0 R ] /Count 3 >>', $out);
}
public function testaddAnnotRef(): void
{
$testObj = $this->getTestObject();
$testObj->add();
$testObj->addAnnotRef(13);
$testObj->addAnnotRef(17);
$page = $testObj->getPage();
$this->assertEquals(13, $page['annotrefs'][0]);
$this->assertEquals(17, $page['annotrefs'][1]);
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* RegionTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
use Com\Tecnick\Color\Pdf;
use Com\Tecnick\Pdf\Encrypt\Encrypt;
use Com\Tecnick\Pdf\Page\Page;
/**
* Page Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class RegionTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new Pdf();
$encrypt = new Encrypt(false);
return new Page('mm', $pdf, $encrypt, false, false);
}
public function testRegion(): void
{
$page = $this->getTestObject();
$page->add(
[
'columns' => 3,
]
);
$res = $page->selectRegion(1);
$exp = [
'RX' => 70,
'RY' => 0,
'RW' => 70,
'RH' => 297,
'RL' => 140,
'RR' => 70,
'RT' => 297,
'RB' => 0,
'x' => 70,
'y' => 0,
];
$this->bcAssertEqualsWithDelta($exp, $res);
$res = $page->getRegion();
$this->bcAssertEqualsWithDelta($exp, $res);
$res = $page->getNextRegion();
$this->bcAssertEqualsWithDelta(2, $res['currentRegion']);
$res = $page->getNextRegion();
$this->bcAssertEqualsWithDelta(0, $res['currentRegion']);
$page->setCurrentPage(0);
$res = $page->getNextRegion();
$this->bcAssertEqualsWithDelta(0, $res['currentRegion']);
$res = $page->checkRegionBreak(1000);
$this->bcAssertEqualsWithDelta(1, $res['currentRegion']);
$res = $page->checkRegionBreak();
$this->bcAssertEqualsWithDelta(1, $res['currentRegion']);
$page->setX(13)->setY(17);
$this->bcAssertEqualsWithDelta(13, $page->getX());
$this->bcAssertEqualsWithDelta(17, $page->getY());
}
public function testRegionBoundaries(): void
{
$page = $this->getTestObject();
$page->add(
[
'columns' => 3,
]
);
$region = $page->getRegion();
$res = $page->isYOutRegion(null, 1);
$this->assertFalse($res);
$res = $page->isYOutRegion(-1);
$this->assertTrue($res);
$res = $page->isYOutRegion($region['RY']);
$this->assertFalse($res);
$res = $page->isYOutRegion(0);
$this->assertFalse($res);
$res = $page->isYOutRegion(100);
$this->assertFalse($res);
$res = $page->isYOutRegion(297);
$this->assertFalse($res);
$res = $page->isYOutRegion($region['RT']);
$this->assertFalse($res);
$res = $page->isYOutRegion(298);
$this->assertTrue($res);
$page->getNextRegion();
$region = $page->getRegion();
$res = $page->isXOutRegion(null, 1);
$this->assertFalse($res);
$res = $page->isXOutRegion(69);
$this->assertTrue($res);
$res = $page->isXOutRegion($region['RX']);
$this->assertFalse($res);
$res = $page->isXOutRegion(70);
$this->assertFalse($res);
$res = $page->isXOutRegion(90);
$this->assertFalse($res);
$res = $page->isXOutRegion(140);
$this->assertFalse($res);
$res = $page->isXOutRegion($region['RL']);
$this->assertFalse($res);
$res = $page->isXOutRegion(141);
$this->assertTrue($res);
$pid = $page->getPageID();
$this->assertEquals(0, $pid);
}
}

View File

@@ -0,0 +1,779 @@
<?php
/**
* SettingsTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Settings Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class SettingsTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
}
public function testGetPageID(): void
{
$page = $this->getTestObject();
$pid = $page->getPageID();
$this->assertEquals(-1, $pid);
}
public function testSanitizePageNumber(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizePageNumber($data);
$this->assertEquals([], $data);
$data = [
'num' => -1,
];
$page->sanitizePageNumber($data);
$this->assertEquals(
[
'num' => 0,
],
$data
);
$data = [
'num' => 0,
];
$page->sanitizePageNumber($data);
$this->assertEquals(
[
'num' => 0,
],
$data
);
$data = [
'num' => 1,
];
$page->sanitizePageNumber($data);
$this->assertEquals(
[
'num' => 1,
],
$data
);
}
public function testSanitizeTime(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeTime($data);
$this->assertArrayHasKey('time', $data);
$this->assertNotEmpty($data['time']); // @phpstan-ignore offsetAccess.notFound
$data = [
'time' => -1,
];
$page->sanitizeTime($data);
$this->assertEquals(
[
'time' => 0,
],
$data
);
$data = [
'time' => 0,
];
$page->sanitizeTime($data);
$this->assertArrayHasKey('time', $data);
$this->assertNotEmpty($data['time']); // @phpstan-ignore offsetAccess.notFound
$data = [
'time' => 1,
];
$page->sanitizeTime($data);
$this->assertEquals(
[
'time' => 1,
],
$data
);
}
public function testSanitizeGroup(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeGroup($data);
$this->assertEquals(
[
'group' => 0,
],
$data
);
$data = [
'group' => -1,
];
$page->sanitizeGroup($data);
$this->assertEquals(
[
'group' => 0,
],
$data
);
$data = [
'group' => 0,
];
$page->sanitizeGroup($data);
$this->assertEquals(
[
'group' => 0,
],
$data
);
$data = [
'group' => 1,
];
$page->sanitizeGroup($data);
$this->assertEquals(
[
'group' => 1,
],
$data
);
}
public function testSanitizeContent(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeContent($data);
$this->assertEquals(
[
'content' => [''],
],
$data
);
$data = [
'content' => 'test',
];
$page->sanitizeContent($data); // @phpstan-ignore argument.type
$this->assertEquals(
[
'content' => ['test'],
],
$data
);
}
public function testSanitizeAnnotRefs(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeAnnotRefs($data);
$this->assertEquals(
[
'annotrefs' => [],
],
$data
);
}
public function testSanitizeRotation(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 0,
],
$data
);
$data = [
'rotation' => 0,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 0,
],
$data
);
$data = [
'rotation' => 100,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 0,
],
$data
);
$data = [
'rotation' => 90,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 90,
],
$data
);
$data = [
'rotation' => 180,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 180,
],
$data
);
$data = [
'rotation' => 270,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 270,
],
$data
);
$data = [
'rotation' => 360,
];
$page->sanitizeRotation($data);
$this->assertEquals(
[
'rotation' => 360,
],
$data
);
}
public function testSanitizeZoom(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeZoom($data);
$this->assertEquals(
[
'zoom' => 1,
],
$data
);
$data = [
'zoom' => 1.2,
];
$page->sanitizeZoom($data);
$this->assertEquals(
[
'zoom' => 1.2,
],
$data
);
}
public function testSanitizeTransitions(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeTransitions($data);
$this->assertEquals([], $data);
$data = [
'transition' => [
'Dur' => 0,
],
];
$page->sanitizeTransitions($data);
$exp = [
'transition' => [
'S' => 'R',
'D' => 1,
'B' => false,
],
];
$this->assertEquals($exp, $data);
$data = [
'transition' => [
'Dur' => 2,
'D' => 3,
'Dm' => 'V',
'S' => 'Glitter',
'M' => 'O',
'Di' => 315,
'SS' => 1.3,
'B' => true,
],
];
$page->sanitizeTransitions($data);
$exp = [
'transition' => [
'Dur' => 2,
'D' => 3,
'S' => 'Glitter',
'Di' => 315,
'SS' => 1.3,
'B' => true,
],
];
$this->assertEquals($exp, $data);
}
public function testSanitizeMargins(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeMargins($data);
$exp = [
'margin' => [
'booklet' => false,
'PL' => 0,
'PR' => 0,
'PT' => 0,
'HB' => 0,
'CT' => 0,
'CB' => 0,
'FT' => 0,
'PB' => 0,
],
'orientation' => 'P',
'height' => 297,
'width' => 210,
'ContentWidth' => 210,
'ContentHeight' => 297,
'HeaderHeight' => 0,
'FooterHeight' => 0,
];
$this->bcAssertEqualsWithDelta($exp, $data);
$data = [
'margin' => [
'booklet' => false,
'PL' => 11,
'PR' => 12,
'PT' => 13,
'HB' => 14,
'CT' => 15,
'CB' => 15,
'FT' => 13,
'PB' => 11,
],
'orientation' => 'P',
'height' => 297,
'width' => 210,
];
$page->sanitizeMargins($data);
$exp = [
'margin' => [
'booklet' => false,
'PL' => 11,
'PR' => 12,
'PT' => 13,
'HB' => 14,
'CT' => 15,
'CB' => 15,
'FT' => 13,
'PB' => 11,
],
'orientation' => 'P',
'height' => 297,
'width' => 210,
'ContentWidth' => 187,
'ContentHeight' => 267,
'HeaderHeight' => 1,
'FooterHeight' => 2,
];
$this->bcAssertEqualsWithDelta($exp, $data);
}
public function testSanitizeBoxData(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizeBoxData($data);
$exp = [
'orientation' => 'P',
'pheight' => 841.890,
'pwidth' => 595.276,
'box' => [
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'CropBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'BleedBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'TrimBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'ArtBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
];
$this->bcAssertEqualsWithDelta($exp, $data);
$data = [
'format' => 'MediaBox',
'orientation' => 'L',
'box' => [
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
];
$page->sanitizeBoxData($data);
$exp = [
'format' => 'CUSTOM',
'orientation' => 'L',
'box' => [
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 841.890,
'ury' => 595.276,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'CropBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 841.890,
'ury' => 595.276,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'BleedBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 841.890,
'ury' => 595.276,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'TrimBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 841.890,
'ury' => 595.276,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'ArtBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 841.890,
'ury' => 595.276,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
'width' => 297,
'height' => 210,
'pwidth' => 841.890,
'pheight' => 595.276,
];
$this->bcAssertEqualsWithDelta($exp, $data);
$data = [
'width' => 210,
'height' => 297,
'pwidth' => 595.276,
'pheight' => 841.890,
'box' => [
'CropBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
];
$page->sanitizeBoxData($data);
$exp = [
'width' => 210,
'height' => 297,
'pwidth' => 595.276,
'pheight' => 841.890,
'box' => [
'CropBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'BleedBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'TrimBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
'ArtBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
'orientation' => 'P',
];
$this->bcAssertEqualsWithDelta($exp, $data);
}
public function testSanitizePageFormat(): void
{
$page = $this->getTestObject();
$data = [];
$page->sanitizePageFormat($data);
$exp = [
'orientation' => 'P',
'format' => 'A4',
'pheight' => 841.890,
'pwidth' => 595.276,
'width' => 210,
'height' => 297,
];
$this->bcAssertEqualsWithDelta($exp, $data);
$data = [
'box' => [
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
];
$page->sanitizePageFormat($data);
$exp = [
'box' => [
'MediaBox' => [
'llx' => 0,
'lly' => 0,
'urx' => 595.276,
'ury' => 841.890,
'bci' => [
'color' => '#000000',
'width' => 0.353,
'style' => 'S',
'dash' => [
0 => 3,
],
],
],
],
'orientation' => 'P',
'format' => 'A4',
'pwidth' => 595.276,
'pheight' => 841.890,
'width' => 210.000,
'height' => 297.000,
];
$this->bcAssertEqualsWithDelta($exp, $data);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* TestUtil.php
*
* @since 2020-12-19
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-color software library.
*/
namespace Test;
use PHPUnit\Framework\TestCase;
/**
* Web Color class test
*
* @since 2020-12-19
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2015-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class TestUtil extends TestCase
{
public function bcAssertEqualsWithDelta(
mixed $expected,
mixed $actual,
float $delta = 0.01,
string $message = ''
): void {
parent::assertEqualsWithDelta($expected, $actual, $delta, $message);
}
/**
* @param class-string<\Throwable> $exception
*/
public function bcExpectException($exception): void
{
parent::expectException($exception);
}
public function bcAssertStringContainsString(string $needle, string $haystack): void
{
parent::assertStringContainsString($needle, $haystack);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* UnitTest.php
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*
* This file is part of tc-lib-pdf-page software library.
*/
namespace Test;
/**
* Unit Test
*
* @since 2011-05-23
* @category Library
* @package PdfPage
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2011-2024 Nicola Asuni - Tecnick.com LTD
* @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf-page
*/
class UnitTest extends TestUtil
{
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
{
$pdf = new \Com\Tecnick\Color\Pdf();
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(false);
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
}
public function testGetPageSize(): void
{
$page = $this->getTestObject();
$val = $page->convertPoints(72, 'in', 3);
$this->assertEquals(1, $val);
$val = $page->convertPoints(72, 'mm', 3);
$this->assertEquals(25.4, $val);
}
public function testGetPageSizeEx(): void
{
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Page\Exception::class);
$page = $this->getTestObject();
$page->convertPoints(1, '*ERROR*', 2);
}
}