Skip to content

Commit 9dc3c7d

Browse files
committed
test(pdf): update TemplateDocumentBuilderTest
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 5d4ec6e commit 9dc3c7d

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

tests/Unit/Pdf/TemplateDocumentBuilderTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use LibreSign\XObjectTemplate\Pdf\TemplateDocumentBuilder;
1616
use PHPUnit\Framework\Attributes\DataProvider;
1717
use PHPUnit\Framework\TestCase;
18+
use ReflectionMethod;
1819

1920
final class TemplateDocumentBuilderTest extends TestCase
2021
{
@@ -483,6 +484,88 @@ public function testBuildContentStreamRendersFillOnlyStrokeOnlyAndEmptyDecoratio
483484
$this->assertStringNotContainsString(' RG', $emptyStream);
484485
}
485486

487+
public function testBuildDecorationCommandRequiresStrokeColorAndPositiveStrokeWidth(): void
488+
{
489+
$builder = new TemplateDocumentBuilder();
490+
$method = new ReflectionMethod($builder, 'buildDecorationCommand');
491+
492+
self::assertSame(
493+
'q\nQ',
494+
$method->invoke(
495+
$builder,
496+
new LayoutDecoration(x: 1.0, y: 2.0, width: 5.0, height: 6.0, strokeWidth: 1.5),
497+
),
498+
);
499+
self::assertSame(
500+
'q\nQ',
501+
$method->invoke(
502+
$builder,
503+
new LayoutDecoration(x: 1.0, y: 2.0, width: 5.0, height: 6.0, strokeColor: '', strokeWidth: 1.5),
504+
),
505+
);
506+
self::assertSame(
507+
'q\nQ',
508+
$method->invoke($builder, new LayoutDecoration(
509+
x: 1.0,
510+
y: 2.0,
511+
width: 5.0,
512+
height: 6.0,
513+
strokeColor: '#040506',
514+
strokeWidth: 0.0,
515+
)),
516+
);
517+
}
518+
519+
public function testBuildDecorationPathClampsRadiusByWidthHalfOnNarrowDecorations(): void
520+
{
521+
$builder = new TemplateDocumentBuilder();
522+
$method = new ReflectionMethod($builder, 'buildDecorationPath');
523+
524+
self::assertSame(
525+
implode("\n", [
526+
'4.000000 0.000000 m',
527+
'4.000000 0.000000 l',
528+
'6.209139 0.000000 8.000000 1.790861 8.000000 4.000000 c',
529+
'8.000000 16.000000 l',
530+
'8.000000 18.209139 6.209139 20.000000 4.000000 20.000000 c',
531+
'4.000000 20.000000 l',
532+
'1.790861 20.000000 0.000000 18.209139 0.000000 16.000000 c',
533+
'0.000000 4.000000 l',
534+
'0.000000 1.790861 1.790861 0.000000 4.000000 0.000000 c',
535+
'h',
536+
]),
537+
$method->invoke(
538+
$builder,
539+
new LayoutDecoration(x: 0.0, y: 0.0, width: 8.0, height: 20.0, borderRadius: 10.0),
540+
),
541+
);
542+
}
543+
544+
public function testBuildDecorationPathClampsRadiusByHeightHalfOnShortDecorations(): void
545+
{
546+
$builder = new TemplateDocumentBuilder();
547+
$method = new ReflectionMethod($builder, 'buildDecorationPath');
548+
549+
self::assertSame(
550+
implode("\n", [
551+
'4.000000 0.000000 m',
552+
'16.000000 0.000000 l',
553+
'18.209139 0.000000 20.000000 1.790861 20.000000 4.000000 c',
554+
'20.000000 4.000000 l',
555+
'20.000000 6.209139 18.209139 8.000000 16.000000 8.000000 c',
556+
'4.000000 8.000000 l',
557+
'1.790861 8.000000 0.000000 6.209139 0.000000 4.000000 c',
558+
'0.000000 4.000000 l',
559+
'0.000000 1.790861 1.790861 0.000000 4.000000 0.000000 c',
560+
'h',
561+
]),
562+
$method->invoke(
563+
$builder,
564+
new LayoutDecoration(x: 0.0, y: 0.0, width: 20.0, height: 8.0, borderRadius: 10.0),
565+
),
566+
);
567+
}
568+
486569
public function testBuildResourcesExposesImageDictionaryAndCustomFontsFromDerivedBuilder(): void
487570
{
488571
$builder = (new TemplateDocumentBuilder())->withFontResources([

0 commit comments

Comments
 (0)