Skip to content

Commit 24f7ca9

Browse files
committed
test(sign-file-service): add tests for PageDimensions propagation in signature params
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 9509f4d commit 24f7ca9

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

tests/php/Unit/Service/SignFileServiceTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,50 @@ public static function providerGetSignatureParamsMetadata(): array {
14021402
];
14031403
}
14041404

1405+
#[DataProvider('providerGetSignatureParamsPageDimensions')]
1406+
public function testGetSignatureParamsPageDimensions(
1407+
?array $fileMetadata,
1408+
bool $expectPageDimensions,
1409+
): void {
1410+
$service = $this->getService(['readCertificate']);
1411+
$service->method('readCertificate')->willReturn([]);
1412+
1413+
$signRequest = $this->createMock(SignRequest::class);
1414+
$signRequest->method('__call')->willReturnCallback(fn (string $method) => match ($method) {
1415+
'getId' => 1,
1416+
'getMetadata' => [],
1417+
default => null,
1418+
});
1419+
$service->setSignRequest($signRequest);
1420+
1421+
$libreSignFile = new File();
1422+
if ($fileMetadata !== null) {
1423+
$libreSignFile->setMetadata($fileMetadata);
1424+
}
1425+
$service->setLibreSignFile($libreSignFile);
1426+
1427+
$actual = $this->invokePrivate($service, 'getSignatureParams');
1428+
1429+
if ($expectPageDimensions) {
1430+
$this->assertArrayHasKey('PageDimensions', $actual);
1431+
$this->assertSame($fileMetadata['d'], $actual['PageDimensions']);
1432+
} else {
1433+
$this->assertArrayNotHasKey('PageDimensions', $actual);
1434+
}
1435+
}
1436+
1437+
public static function providerGetSignatureParamsPageDimensions(): array {
1438+
return [
1439+
'file entity is null' => [null, false],
1440+
'metadata has no d key' => [['other' => 'data'], false],
1441+
'metadata with empty d array' => [['d' => []], false],
1442+
'metadata with page dimensions populates PageDimensions' => [
1443+
['d' => [['w' => 800, 'h' => 600]]],
1444+
true,
1445+
],
1446+
];
1447+
}
1448+
14051449
#[DataProvider('providerSetVisibleElements')]
14061450
public function testSetVisibleElements(
14071451
array $signerList,

0 commit comments

Comments
 (0)