generated from jric11/baseProject
Initial commit
This commit is contained in:
+151
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* BoxTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class BoxTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetBoxEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->setBox([], 'ERROR', 1, 2, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FormatTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class FormatTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetPageSizeEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->getPageFormatSize('*ERROR*');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ModeTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class ModeTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetLayout(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertEquals('TwoColumnLeft', $page->getLayout('two'));
|
||||
$this->assertEquals('SinglePage', $page->getLayout(''));
|
||||
$this->assertEquals('SinglePage', $page->getLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetDisplay(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertEquals('UseThumbs', $page->getDisplay('usethumbs'));
|
||||
$this->assertEquals('UseAttachments', $page->getDisplay(''));
|
||||
$this->assertEquals('UseNone', $page->getDisplay('something'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* OrientationTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\Orientation;
|
||||
|
||||
/**
|
||||
* Orientation enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class OrientationTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('P', Orientation::Portrait->value);
|
||||
$this->assertSame('L', Orientation::Landscape->value);
|
||||
$this->assertSame('', Orientation::Auto->value);
|
||||
}
|
||||
|
||||
public function testFromLooseCanonical(): void
|
||||
{
|
||||
$this->assertSame(Orientation::Portrait, Orientation::fromLoose('P'));
|
||||
$this->assertSame(Orientation::Landscape, Orientation::fromLoose('L'));
|
||||
$this->assertSame(Orientation::Auto, Orientation::fromLoose(''));
|
||||
}
|
||||
|
||||
public function testFromLooseFallsBackToAuto(): void
|
||||
{
|
||||
// Matching legacy behavior: only exact 'P'/'L' select an orientation.
|
||||
$this->assertSame(Orientation::Auto, Orientation::fromLoose('p'));
|
||||
$this->assertSame(Orientation::Auto, Orientation::fromLoose('portrait'));
|
||||
$this->assertSame(Orientation::Auto, Orientation::fromLoose('X'));
|
||||
}
|
||||
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(Orientation::Landscape, Orientation::fromLoose(Orientation::Landscape));
|
||||
}
|
||||
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (Orientation::cases() as $case) {
|
||||
$this->assertSame($case, Orientation::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened getPageOrientedSize() accepts an Orientation enum.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetPageOrientedSizeAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame(
|
||||
$page->getPageOrientedSize(100, 200, 'L'),
|
||||
$page->getPageOrientedSize(100, 200, Orientation::Landscape),
|
||||
);
|
||||
$this->assertSame(
|
||||
$page->getPageOrientedSize(100, 200, ''),
|
||||
$page->getPageOrientedSize(100, 200, Orientation::Auto),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PageBoxTypeTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\PageBoxType;
|
||||
|
||||
/**
|
||||
* PageBoxType enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class PageBoxTypeTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('MediaBox', PageBoxType::MediaBox->value);
|
||||
$this->assertSame('CropBox', PageBoxType::CropBox->value);
|
||||
$this->assertSame('BleedBox', PageBoxType::BleedBox->value);
|
||||
$this->assertSame('TrimBox', PageBoxType::TrimBox->value);
|
||||
$this->assertSame('ArtBox', PageBoxType::ArtBox->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseCanonical(): void
|
||||
{
|
||||
$this->assertSame(PageBoxType::MediaBox, PageBoxType::fromLoose('MediaBox'));
|
||||
$this->assertSame(PageBoxType::ArtBox, PageBoxType::fromLoose('ArtBox'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(PageBoxType::TrimBox, PageBoxType::fromLoose(PageBoxType::TrimBox));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (PageBoxType::cases() as $case) {
|
||||
$this->assertSame($case, PageBoxType::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Box names are case sensitive, so a wrong-case value is unknown.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseIsCaseSensitive(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
PageBoxType::fromLoose('mediabox');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseUnknownThrows(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
PageBoxType::fromLoose('WobbleBox');
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened setBox() accepts a PageBoxType enum and keys the dimensions
|
||||
* array on the same string as the legacy call.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetBoxAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$fromEnum = $page->setBox([], PageBoxType::CropBox, 0.0, 0.0, 100.0, 200.0);
|
||||
$fromString = $page->setBox([], 'CropBox', 0.0, 0.0, 100.0, 200.0);
|
||||
$this->assertArrayHasKey('CropBox', $fromEnum);
|
||||
$this->assertSame($fromString, $fromEnum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PageDisplayModeTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\PageDisplayMode;
|
||||
|
||||
/**
|
||||
* PageDisplayMode enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class PageDisplayModeTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('UseNone', PageDisplayMode::UseNone->value);
|
||||
$this->assertSame('UseOutlines', PageDisplayMode::UseOutlines->value);
|
||||
$this->assertSame('UseThumbs', PageDisplayMode::UseThumbs->value);
|
||||
$this->assertSame('FullScreen', PageDisplayMode::FullScreen->value);
|
||||
$this->assertSame('UseOC', PageDisplayMode::UseOC->value);
|
||||
$this->assertSame('UseAttachments', PageDisplayMode::UseAttachments->value);
|
||||
}
|
||||
|
||||
public function testFromLooseCanonical(): void
|
||||
{
|
||||
$this->assertSame(PageDisplayMode::UseThumbs, PageDisplayMode::fromLoose('usethumbs'));
|
||||
$this->assertSame(PageDisplayMode::FullScreen, PageDisplayMode::fromLoose('FullScreen'));
|
||||
$this->assertSame(PageDisplayMode::UseOC, PageDisplayMode::fromLoose('USEOC'));
|
||||
}
|
||||
|
||||
public function testFromLooseEmptyMapsToUseAttachments(): void
|
||||
{
|
||||
// Preserves the legacy Mode::DISPLAY quirk: '' maps to UseAttachments.
|
||||
$this->assertSame(PageDisplayMode::UseAttachments, PageDisplayMode::fromLoose(''));
|
||||
}
|
||||
|
||||
public function testFromLooseUnknownFallsBackToUseNone(): void
|
||||
{
|
||||
$this->assertSame(PageDisplayMode::UseNone, PageDisplayMode::fromLoose('nonsense'));
|
||||
}
|
||||
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(PageDisplayMode::UseOutlines, PageDisplayMode::fromLoose(PageDisplayMode::UseOutlines));
|
||||
}
|
||||
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (PageDisplayMode::cases() as $case) {
|
||||
$this->assertSame($case, PageDisplayMode::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened getDisplay() accepts a PageDisplayMode enum.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetDisplayAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame('UseThumbs', $page->getDisplay(PageDisplayMode::UseThumbs));
|
||||
$this->assertSame($page->getDisplay('usethumbs'), $page->getDisplay(PageDisplayMode::UseThumbs));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PageLayoutTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\PageLayout;
|
||||
|
||||
/**
|
||||
* PageLayout enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class PageLayoutTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('SinglePage', PageLayout::SinglePage->value);
|
||||
$this->assertSame('OneColumn', PageLayout::OneColumn->value);
|
||||
$this->assertSame('TwoColumnLeft', PageLayout::TwoColumnLeft->value);
|
||||
$this->assertSame('TwoColumnRight', PageLayout::TwoColumnRight->value);
|
||||
$this->assertSame('TwoPageLeft', PageLayout::TwoPageLeft->value);
|
||||
$this->assertSame('TwoPageRight', PageLayout::TwoPageRight->value);
|
||||
}
|
||||
|
||||
public function testFromLooseCanonicalAndAliases(): void
|
||||
{
|
||||
$this->assertSame(PageLayout::SinglePage, PageLayout::fromLoose('SinglePage'));
|
||||
$this->assertSame(PageLayout::SinglePage, PageLayout::fromLoose('single'));
|
||||
$this->assertSame(PageLayout::SinglePage, PageLayout::fromLoose('default'));
|
||||
$this->assertSame(PageLayout::OneColumn, PageLayout::fromLoose('onecolumn'));
|
||||
$this->assertSame(PageLayout::OneColumn, PageLayout::fromLoose('continuous'));
|
||||
$this->assertSame(PageLayout::TwoColumnLeft, PageLayout::fromLoose('two'));
|
||||
$this->assertSame(PageLayout::TwoColumnRight, PageLayout::fromLoose('TWOCOLUMNRIGHT'));
|
||||
}
|
||||
|
||||
public function testFromLooseFallsBackToSinglePage(): void
|
||||
{
|
||||
$this->assertSame(PageLayout::SinglePage, PageLayout::fromLoose(''));
|
||||
$this->assertSame(PageLayout::SinglePage, PageLayout::fromLoose('nonsense'));
|
||||
}
|
||||
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(PageLayout::TwoPageLeft, PageLayout::fromLoose(PageLayout::TwoPageLeft));
|
||||
}
|
||||
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (PageLayout::cases() as $case) {
|
||||
$this->assertSame($case, PageLayout::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened getLayout() accepts a PageLayout enum, staying consistent with
|
||||
* the legacy alias resolution.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetLayoutAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame('TwoColumnLeft', $page->getLayout(PageLayout::TwoColumnLeft));
|
||||
$this->assertSame($page->getLayout('two'), $page->getLayout(PageLayout::TwoColumnLeft));
|
||||
}
|
||||
}
|
||||
+827
@@ -0,0 +1,827 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PageTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class PageTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* PDF marker for the per-page transparency group.
|
||||
*/
|
||||
private const TRANSPARENCY_GROUP = '/Group << /Type /Group /S /Transparency /CS /DeviceRGB >>';
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getPdfaTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, true, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetKUnit(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->bcAssertEqualsWithDelta(2.83464566929134, $page->getKUnit(), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testEnableSignatureApproval(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$res = $page->enableSignatureApproval(true);
|
||||
$this->assertNotNull($res); // @phpstan-ignore method.alreadyNarrowedType
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testDeleteEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->delete(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testMoveEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->move(1, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetPageEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->getPage(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
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->assertStringContainsString('<< /Type /Pages /Kids [ 3 0 R 4 0 R 5 0 R ] /Count 3 >>', $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testaddAnnotRef(): void
|
||||
{
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$testObj->addAnnotRef(13);
|
||||
$testObj->addAnnotRef(17);
|
||||
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEquals(13, $page['annotrefs'][0] ?? null);
|
||||
$this->assertEquals(17, $page['annotrefs'][1] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPagePHeight(): void
|
||||
{
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEquals(841, (int) $page['pheight']);
|
||||
$testObj->setPagePHeight(123.4);
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEquals(123.4, $page['pheight']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPagePWidth(): void
|
||||
{
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEquals(595, (int) $page['pwidth']);
|
||||
$testObj->setPagePWidth(123.4);
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEquals(123.4, $page['pwidth']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testAddAnnotRefDuplicate(): void
|
||||
{
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$testObj->addAnnotRef(42);
|
||||
$testObj->addAnnotRef(42);
|
||||
|
||||
$page = $testObj->getPage();
|
||||
$this->assertCount(1, $page['annotrefs']);
|
||||
$this->assertEquals(42, $page['annotrefs'][0] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testPopContentEmptyEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$testObj->popContent();
|
||||
$testObj->popContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testPopContentToLastMarkEmpty(): void
|
||||
{
|
||||
$testObj = $this->getTestObject();
|
||||
$testObj->add();
|
||||
$testObj->popContent();
|
||||
$testObj->popContentToLastMark();
|
||||
$page = $testObj->getPage();
|
||||
$this->assertEmpty($page['content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyReturnsStatic(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$this->assertSame($page, $page->setPageTransparency(true, 0));
|
||||
$this->assertSame($page, $page->setPageTransparency(false, 0));
|
||||
// -1 targets the current page, mirroring the rest of the page API.
|
||||
$this->assertSame($page, $page->setPageTransparency(false, -1));
|
||||
}
|
||||
|
||||
/**
|
||||
* setPageTransparency() validates the page index like every other
|
||||
* page-targeting method.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyInvalidPageThrows(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->setPageTransparency(false, 99);
|
||||
}
|
||||
|
||||
/**
|
||||
* The transparency mode is matched case-insensitively.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyGroupModeIsCaseInsensitive(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(true, 0);
|
||||
$page->setPageTransparencyGroupMode('NEVER');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertStringNotContainsString(self::TRANSPARENCY_GROUP, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-page transparency flags stay aligned with the page they were set on
|
||||
* after a page is deleted and the stack is reindexed.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyFollowsPageAfterDelete(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add(); // 0
|
||||
$page->add(); // 1
|
||||
$page->add(); // 2
|
||||
// Flag the last page opaque, then remove the first page so it becomes index 1.
|
||||
$page->setPageTransparency(false, 2);
|
||||
$page->delete(0);
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
// Two pages remain; the opaque flag must still suppress exactly one group.
|
||||
$this->assertEquals(1, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleting a page keeps the current-page pointer valid.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testDeleteKeepsCurrentPageValid(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add(); // 0
|
||||
$page->add(); // 1
|
||||
$page->add(); // 2 (current)
|
||||
$page->delete(0);
|
||||
|
||||
// The current-page pointer must stay within the reindexed stack so that
|
||||
// getPage() resolves instead of throwing "page ... do not exist".
|
||||
$this->assertGreaterThanOrEqual(0, $page->getPageID());
|
||||
$this->assertLessThanOrEqual(1, $page->getPageID());
|
||||
$current = $page->getPage();
|
||||
$this->assertArrayHasKey('time', $current);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyGroupModeReturnsStatic(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame($page, $page->setPageTransparencyGroupMode('auto'));
|
||||
}
|
||||
|
||||
/**
|
||||
* By default (auto mode) pages that are never flagged keep emitting the
|
||||
* transparency group, preserving backward-compatible output.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyAutoDefault(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertEquals(2, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* In auto mode, a page flagged as not using transparency omits the group,
|
||||
* while unflagged pages keep emitting it.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyAutoFlaggedFalse(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(false, 0);
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
// page 0 omits the group, page 1 (unflagged) keeps it.
|
||||
$this->assertEquals(1, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* In auto mode, a page explicitly flagged as using transparency emits the
|
||||
* group.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyAutoFlaggedTrue(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(false, 0);
|
||||
$page->setPageTransparency(true, 1);
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertEquals(1, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'always' mode emits the group on every standard page, even those
|
||||
* flagged as not using transparency.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyAlways(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(false, 0);
|
||||
$page->setPageTransparency(false, 1);
|
||||
$page->setPageTransparencyGroupMode('always');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertEquals(2, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'never' mode never emits the group, even on pages flagged as using
|
||||
* transparency.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyNever(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(true, 0);
|
||||
$page->setPageTransparencyGroupMode('never');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertStringNotContainsString(self::TRANSPARENCY_GROUP, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unknown modes are treated as 'auto'.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyUnknownModeIsAuto(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(false, 0);
|
||||
$page->setPageTransparencyGroupMode('bogus');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
// behaves like auto: page 0 omits, page 1 keeps the group.
|
||||
$this->assertEquals(1, substr_count($out, self::TRANSPARENCY_GROUP));
|
||||
}
|
||||
|
||||
/**
|
||||
* PDF/A documents never emit the transparency group, regardless of the
|
||||
* configured mode or per-page flags.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransparencyPdfa(): void
|
||||
{
|
||||
$page = $this->getPdfaTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->setPageTransparency(true, 0);
|
||||
$page->setPageTransparencyGroupMode('always');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
$this->assertStringNotContainsString(self::TRANSPARENCY_GROUP, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Numeric transition entries (/D, /Di, /SS) must be emitted as PDF numbers,
|
||||
* not as name objects, while name entries (/S) stay names.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransitionNumericEntries(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add([
|
||||
'transition' => [
|
||||
'Dur' => 2,
|
||||
'D' => 3,
|
||||
'S' => 'Glitter',
|
||||
'Di' => 315,
|
||||
'SS' => 1.3,
|
||||
'B' => true,
|
||||
],
|
||||
]);
|
||||
$page->addContent('TEST');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
|
||||
$this->bcAssertStringContainsString('/D 3' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/Di 315' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/SS 1.300000' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/S /Glitter' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/B true' . "\n", $out);
|
||||
|
||||
// Regression guard: numeric keys must not be rendered as name objects.
|
||||
$this->assertStringNotContainsString('/D /3', $out);
|
||||
$this->assertStringNotContainsString('/Di /315', $out);
|
||||
$this->assertStringNotContainsString('/SS /', $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* The /Di direction may legitimately be the name /None (Fly transitions).
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
* @throws \Com\Tecnick\Pdf\Encrypt\Exception
|
||||
*/
|
||||
public function testGetPdfPagesTransitionDiNoneIsName(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add([
|
||||
'transition' => [
|
||||
'S' => 'Fly',
|
||||
'Di' => 'None',
|
||||
'SS' => 0.5,
|
||||
],
|
||||
]);
|
||||
$page->addContent('TEST');
|
||||
|
||||
$pon = 0;
|
||||
$out = $page->getPdfPages($pon);
|
||||
|
||||
$this->bcAssertStringContainsString('/S /Fly' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/Di /None' . "\n", $out);
|
||||
$this->bcAssertStringContainsString('/SS 0.500000' . "\n", $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete() reindexes the stack, so the embedded 'pid' of every remaining page
|
||||
* must keep matching its array index.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testDeleteReindexesPageIds(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->delete(0);
|
||||
|
||||
foreach ($page->getPages() as $idx => $data) {
|
||||
$this->assertSame($idx, $data['pid']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* move() reindexes the stack, so the embedded 'pid' of every page must keep
|
||||
* matching its array index.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testMoveReindexesPageIds(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->move(3, 0);
|
||||
|
||||
foreach ($page->getPages() as $idx => $data) {
|
||||
$this->assertSame($idx, $data['pid']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getNextPage() must decide auto-break based on the queried page, not the
|
||||
* current-page pointer when they differ.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetNextPageUsesQueriedPageAutoBreak(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
$page->add();
|
||||
$page->enableAutoPageBreak(true, 0);
|
||||
$page->enableAutoPageBreak(false, 1);
|
||||
|
||||
// Current pointer is page 0 (auto-break on), but page 1 (auto-break off)
|
||||
// is queried: no new page must be appended.
|
||||
$page->setCurrentPage(0);
|
||||
$page->getNextRegion(1);
|
||||
|
||||
$this->assertCount(2, $page->getPages());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,511 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* RegionTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Page\Page;
|
||||
|
||||
/**
|
||||
* Page Test
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class RegionTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetNoWriteRegionsSideRectangle(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
// Obstacle on the right side blocking x in [150, 210] for y in [100, 200].
|
||||
$res = $page->setNoWriteRegions([
|
||||
['xt' => 150, 'yt' => 100, 'xb' => 150, 'yb' => 200, 'side' => 'R'],
|
||||
], 50.0);
|
||||
|
||||
$this->bcAssertEqualsWithDelta(3, $res['columns']);
|
||||
|
||||
$exp = [
|
||||
[
|
||||
'RW' => 210,
|
||||
'RX' => 0,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 100,
|
||||
'RY' => 0,
|
||||
'RT' => 100,
|
||||
'RB' => 197,
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
],
|
||||
[
|
||||
'RW' => 150,
|
||||
'RX' => 0,
|
||||
'RL' => 150,
|
||||
'RR' => 60,
|
||||
'RH' => 100,
|
||||
'RY' => 100,
|
||||
'RT' => 200,
|
||||
'RB' => 97,
|
||||
'x' => 0,
|
||||
'y' => 100,
|
||||
],
|
||||
[
|
||||
'RW' => 210,
|
||||
'RX' => 0,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 97,
|
||||
'RY' => 200,
|
||||
'RT' => 297,
|
||||
'RB' => 0,
|
||||
'x' => 0,
|
||||
'y' => 200,
|
||||
],
|
||||
];
|
||||
$this->bcAssertEqualsWithDelta($exp, $res['region']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testBuildWritableRegionsSlantedSegment(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
// Slanted right-side segment from (100,100) to (150,200): a staircase approximation.
|
||||
$res = $page->buildWritableRegions([
|
||||
['xt' => 100, 'yt' => 100, 'xb' => 150, 'yb' => 200, 'side' => 'R'],
|
||||
], 50.0);
|
||||
|
||||
$exp = [
|
||||
['RX' => 0, 'RY' => 0, 'RW' => 210, 'RH' => 100],
|
||||
['RX' => 0, 'RY' => 100, 'RW' => 100, 'RH' => 50],
|
||||
['RX' => 0, 'RY' => 150, 'RW' => 125, 'RH' => 50],
|
||||
['RX' => 0, 'RY' => 200, 'RW' => 210, 'RH' => 97],
|
||||
];
|
||||
$this->bcAssertEqualsWithDelta($exp, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testBuildWritableRegionsFloatingBoxKeepsWidestSide(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
// Floating obstacle blocking x in [60, 100] for y in [100, 150]:
|
||||
// the band splits into [0,60] (w=60) and [100,210] (w=110); the widest is kept.
|
||||
$res = $page->buildWritableRegions([
|
||||
['x' => 60, 'y' => 100, 'w' => 40, 'h' => 50],
|
||||
], 50.0);
|
||||
|
||||
$exp = [
|
||||
['RX' => 0, 'RY' => 0, 'RW' => 210, 'RH' => 100],
|
||||
['RX' => 100, 'RY' => 100, 'RW' => 110, 'RH' => 50],
|
||||
['RX' => 0, 'RY' => 150, 'RW' => 210, 'RH' => 147],
|
||||
];
|
||||
$this->bcAssertEqualsWithDelta($exp, $res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testNoWriteRegionsAddGetRemove(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
$page->setNoWriteRegions([
|
||||
['xt' => 150, 'yt' => 100, 'xb' => 150, 'yb' => 200, 'side' => 'R'],
|
||||
], 50.0);
|
||||
$this->assertCount(1, $page->getNoWriteRegions());
|
||||
|
||||
// The added left-side obstacle pushes the bottom region's left edge to x=60.
|
||||
$res = $page->addNoWriteRegion(['xt' => 60, 'yt' => 230, 'xb' => 60, 'yb' => 270, 'side' => 'L']);
|
||||
$this->assertCount(2, $page->getNoWriteRegions());
|
||||
$this->bcAssertEqualsWithDelta(3, $res['columns']);
|
||||
$expAdded = [
|
||||
[
|
||||
'RW' => 210,
|
||||
'RX' => 0,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 100,
|
||||
'RY' => 0,
|
||||
'RT' => 100,
|
||||
'RB' => 197,
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
],
|
||||
[
|
||||
'RW' => 150,
|
||||
'RX' => 0,
|
||||
'RL' => 150,
|
||||
'RR' => 60,
|
||||
'RH' => 100,
|
||||
'RY' => 100,
|
||||
'RT' => 200,
|
||||
'RB' => 97,
|
||||
'x' => 0,
|
||||
'y' => 100,
|
||||
],
|
||||
[
|
||||
'RW' => 150,
|
||||
'RX' => 60,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 97,
|
||||
'RY' => 200,
|
||||
'RT' => 297,
|
||||
'RB' => 0,
|
||||
'x' => 60,
|
||||
'y' => 200,
|
||||
],
|
||||
];
|
||||
$this->bcAssertEqualsWithDelta($expAdded, $res['region']);
|
||||
|
||||
// Removing the first (right) area leaves only the left-side area.
|
||||
$page->removeNoWriteRegion(0);
|
||||
$this->bcAssertEqualsWithDelta([[
|
||||
'xt' => 60,
|
||||
'yt' => 230,
|
||||
'xb' => 60,
|
||||
'yb' => 270,
|
||||
'side' => 'L',
|
||||
]], $page->getNoWriteRegions());
|
||||
|
||||
// Removing the last area leaves the page with a single full content region.
|
||||
$res = $page->removeNoWriteRegion(0);
|
||||
$this->assertCount(0, $page->getNoWriteRegions());
|
||||
$this->bcAssertEqualsWithDelta(1, $res['columns']);
|
||||
$this->bcAssertEqualsWithDelta([[
|
||||
'RW' => 210,
|
||||
'RX' => 0,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 297,
|
||||
'RY' => 0,
|
||||
'RT' => 297,
|
||||
'RB' => 0,
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
]], $res['region']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testNoWriteRegionsResetOnClonedPage(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
$res = $page->setNoWriteRegions([
|
||||
['xt' => 150, 'yt' => 100, 'xb' => 150, 'yb' => 200, 'side' => 'R'],
|
||||
], 50.0);
|
||||
$this->assertGreaterThan(1, $res['columns']);
|
||||
|
||||
// Cloning the page (e.g. an automatic page break) must NOT inherit the no-write bands:
|
||||
// the new page starts with a single default full-content region.
|
||||
$cloned = $page->add();
|
||||
$this->bcAssertEqualsWithDelta(1, $cloned['columns']);
|
||||
$this->assertCount(0, $page->getNoWriteRegions($cloned['pid']));
|
||||
$this->bcAssertEqualsWithDelta([[
|
||||
'RW' => 210,
|
||||
'RX' => 0,
|
||||
'RL' => 210,
|
||||
'RR' => 0,
|
||||
'RH' => 297,
|
||||
'RY' => 0,
|
||||
'RT' => 297,
|
||||
'RB' => 0,
|
||||
'x' => 0,
|
||||
'y' => 0,
|
||||
]], $cloned['region']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testNoWriteRegionsValidation(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add();
|
||||
|
||||
try {
|
||||
$page->setNoWriteRegions([], 0.0);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('band height', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->buildWritableRegions([], -5.0);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('band height', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->addNoWriteRegion(['x' => 10, 'y' => 10, 'w' => 10, 'h' => 10]);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('setNoWriteRegions', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->removeNoWriteRegion(7);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 7', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testDefensiveChecksOnMissingPageAfterForcedSanitizeId(): void
|
||||
{
|
||||
$pdf = new Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
$page = new class('mm', $pdf, $encrypt, false, false) extends Page {
|
||||
public bool $forceSanitizePageId = false;
|
||||
public int $forcedPid = 0;
|
||||
|
||||
protected function sanitizePageID(int $pid = -1): int
|
||||
{
|
||||
if ($this->forceSanitizePageId) {
|
||||
return $this->forcedPid;
|
||||
}
|
||||
|
||||
return parent::sanitizePageID($pid);
|
||||
}
|
||||
};
|
||||
$page->add();
|
||||
$page->forceSanitizePageId = true;
|
||||
$page->forcedPid = 99;
|
||||
|
||||
try {
|
||||
$page->getPage(99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->setPagePHeight(10, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->setPagePWidth(10, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->selectRegion(0, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->getNextRegion(99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->isAutoPageBreakEnabled(99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->enableAutoPageBreak(true, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->setX(1, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$page->setY(1, 99);
|
||||
$this->fail('Expected exception was not thrown.');
|
||||
} catch (\Com\Tecnick\Pdf\Page\Exception $e) {
|
||||
$this->assertStringContainsString('index 99', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An out-of-range region index must clamp to the nearest valid region instead
|
||||
* of selecting a non-existent index (which previously threw).
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSelectRegionClampsOutOfRangeIndex(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$page->add([
|
||||
'columns' => 3,
|
||||
]);
|
||||
|
||||
// Index beyond the last region (valid: 0..2) clamps to the last region.
|
||||
$res = $page->selectRegion(99);
|
||||
$this->bcAssertEqualsWithDelta(2, $page->getPage()['currentRegion']);
|
||||
$this->bcAssertEqualsWithDelta($res, $page->getRegion());
|
||||
|
||||
// Negative index clamps to the first region.
|
||||
$page->selectRegion(-5);
|
||||
$this->bcAssertEqualsWithDelta(0, $page->getPage()['currentRegion']);
|
||||
}
|
||||
}
|
||||
+1015
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* TestUtil.php
|
||||
*
|
||||
* @since 2020-12-19
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2015-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class TestUtil extends TestCase
|
||||
{
|
||||
protected function getEncryptObject(): \Com\Tecnick\Pdf\Encrypt\Encrypt
|
||||
{
|
||||
return new class() extends \Com\Tecnick\Pdf\Encrypt\Encrypt {
|
||||
public function __construct() {}
|
||||
};
|
||||
}
|
||||
|
||||
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(string $exception): void
|
||||
{
|
||||
parent::expectException($exception);
|
||||
}
|
||||
|
||||
public function bcAssertStringContainsString(string $needle, string $haystack): void
|
||||
{
|
||||
parent::assertStringContainsString($needle, $haystack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* TransparencyGroupModeTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\TransparencyGroupMode;
|
||||
|
||||
/**
|
||||
* TransparencyGroupMode enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class TransparencyGroupModeTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('auto', TransparencyGroupMode::Auto->value);
|
||||
$this->assertSame('always', TransparencyGroupMode::Always->value);
|
||||
$this->assertSame('never', TransparencyGroupMode::Never->value);
|
||||
}
|
||||
|
||||
public function testFromLooseCanonical(): void
|
||||
{
|
||||
$this->assertSame(TransparencyGroupMode::Auto, TransparencyGroupMode::fromLoose('auto'));
|
||||
$this->assertSame(TransparencyGroupMode::Always, TransparencyGroupMode::fromLoose('always'));
|
||||
$this->assertSame(TransparencyGroupMode::Never, TransparencyGroupMode::fromLoose('never'));
|
||||
}
|
||||
|
||||
public function testFromLooseIsCaseInsensitive(): void
|
||||
{
|
||||
$this->assertSame(TransparencyGroupMode::Always, TransparencyGroupMode::fromLoose('ALWAYS'));
|
||||
}
|
||||
|
||||
public function testFromLooseUnknownFallsBackToAuto(): void
|
||||
{
|
||||
$this->assertSame(TransparencyGroupMode::Auto, TransparencyGroupMode::fromLoose('sometimes'));
|
||||
$this->assertSame(TransparencyGroupMode::Auto, TransparencyGroupMode::fromLoose(''));
|
||||
}
|
||||
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(TransparencyGroupMode::Never, TransparencyGroupMode::fromLoose(TransparencyGroupMode::Never));
|
||||
}
|
||||
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (TransparencyGroupMode::cases() as $case) {
|
||||
$this->assertSame($case, TransparencyGroupMode::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened setter accepts a TransparencyGroupMode enum and stays chainable.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testSetPageTransparencyGroupModeAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame($page, $page->setPageTransparencyGroupMode(TransparencyGroupMode::Always));
|
||||
$this->assertSame($page, $page->setPageTransparencyGroupMode('never'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UnitEnumTest.php
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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\Pdf\Page\Unit;
|
||||
|
||||
/**
|
||||
* Unit enum test
|
||||
*
|
||||
* @since 2026-07-17
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class UnitEnumTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
public function testCaseBackingValues(): void
|
||||
{
|
||||
$this->assertSame('pt', Unit::Point->value);
|
||||
$this->assertSame('mm', Unit::Millimeter->value);
|
||||
$this->assertSame('cm', Unit::Centimeter->value);
|
||||
$this->assertSame('in', Unit::Inch->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseCanonicalAliasesAndDefault(): void
|
||||
{
|
||||
$this->assertSame(Unit::Point, Unit::fromLoose(''));
|
||||
$this->assertSame(Unit::Point, Unit::fromLoose('pt'));
|
||||
$this->assertSame(Unit::Point, Unit::fromLoose('points'));
|
||||
$this->assertSame(Unit::Point, Unit::fromLoose('px'));
|
||||
$this->assertSame(Unit::Millimeter, Unit::fromLoose('mm'));
|
||||
$this->assertSame(Unit::Millimeter, Unit::fromLoose('millimeters'));
|
||||
$this->assertSame(Unit::Centimeter, Unit::fromLoose('cm'));
|
||||
$this->assertSame(Unit::Centimeter, Unit::fromLoose('centimeters'));
|
||||
$this->assertSame(Unit::Inch, Unit::fromLoose('in'));
|
||||
$this->assertSame(Unit::Inch, Unit::fromLoose('inches'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseIsCaseInsensitive(): void
|
||||
{
|
||||
$this->assertSame(Unit::Millimeter, Unit::fromLoose('MM'));
|
||||
$this->assertSame(Unit::Inch, Unit::fromLoose('Inches'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLoosePassesThroughEnumInstance(): void
|
||||
{
|
||||
$this->assertSame(Unit::Centimeter, Unit::fromLoose(Unit::Centimeter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseRoundTrip(): void
|
||||
{
|
||||
foreach (Unit::cases() as $case) {
|
||||
$this->assertSame($case, Unit::fromLoose($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testFromLooseUnknownThrows(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
Unit::fromLoose('parsec');
|
||||
}
|
||||
|
||||
/**
|
||||
* The widened getUnitRatio()/convertPoints() accept a Unit enum.
|
||||
*
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testUnitRatioAcceptsEnum(): void
|
||||
{
|
||||
$page = $this->getTestObject();
|
||||
$this->assertSame($page->getUnitRatio('in'), $page->getUnitRatio(Unit::Inch));
|
||||
$this->assertSame($page->convertPoints(72, 'in', 3), $page->convertPoints(72, Unit::Inch, 3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* UnitTest.php
|
||||
*
|
||||
* @since 2011-05-23
|
||||
* @category Library
|
||||
* @package PdfPage
|
||||
* @author Nicola Asuni <info@tecnick.com>
|
||||
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @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-2026 Nicola Asuni - Tecnick.com LTD
|
||||
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
|
||||
* @link https://github.com/tecnickcom/tc-lib-pdf-page
|
||||
*/
|
||||
class UnitTest extends TestUtil
|
||||
{
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
protected function getTestObject(): \Com\Tecnick\Pdf\Page\Page
|
||||
{
|
||||
$pdf = new \Com\Tecnick\Color\Pdf();
|
||||
$encrypt = $this->getEncryptObject();
|
||||
return new \Com\Tecnick\Pdf\Page\Page('mm', $pdf, $encrypt, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Com\Tecnick\Pdf\Page\Exception
|
||||
*/
|
||||
public function testGetPageSizeEx(): void
|
||||
{
|
||||
$this->bcExpectException(\Com\Tecnick\Pdf\Page\Exception::class);
|
||||
$page = $this->getTestObject();
|
||||
$page->convertPoints(1, '*ERROR*', 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user