Skip to content

Commit 4d2491f

Browse files
committed
fix: complete stable32 backport coverage for ServerSignatureDate
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent ff902f0 commit 4d2491f

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

lib/Service/SignatureTextService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function getAvailableVariables(): array {
185185
'{{LocalSignerSignatureDateOnly}}' => $this->l10n->t('Date when the signer sent the request to sign (without time, in their local time zone).'),
186186
'{{LocalSignerSignatureDateTime}}' => $this->l10n->t('Date and time when the signer sent the request to sign (in their local time zone).'),
187187
'{{LocalSignerTimezone}}' => $this->l10n->t('Time zone of signer when sent the request to sign (in their local time zone).'),
188-
'{{ServerSignatureDate}}' => $this->l10n->t('Date and time when the signature was applied on the server. Cannot be formatted using Twig.'),
188+
'{{ServerSignatureDate}}' => $this->l10n->t('Date and time when the signature was applied on the server (ISO 8601 format). Can be formatted using the Twig date filter.'),
189189
'{{SignerCommonName}}' => $this->l10n->t('Common Name (CN) used to identify the document signer.'),
190190
'{{SignerEmail}}' => $this->l10n->t('The signer\'s email is optional and can be left blank.'),
191191
'{{SignerIdentifier}}' => $this->l10n->t('Unique information used to identify the signer (such as email, phone number, or username).'),

tests/php/Unit/Handler/SignEngine/JSignPdfHandlerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,14 +733,45 @@ public function testGetSignatureTextWithTwigDateFilterAndTimezone(): void {
733733
$this->assertMatchesRegularExpression('/^"\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2} [A-Z]{3,4}"$/', $actual);
734734
}
735735

736+
public function testGetSignatureTextWithTwigDateFilterWithoutTimezone(): void {
737+
$this->appConfig->setValueString(
738+
'libresign',
739+
'signature_text_template',
740+
'{{ ServerSignatureDate|date("d/m/Y") }}'
741+
);
742+
$this->appConfig->setValueString('libresign', 'signature_render_mode', SignerElementsService::RENDER_MODE_DESCRIPTION_ONLY);
743+
744+
$jSignPdfHandler = $this->getInstance();
745+
$actual = $jSignPdfHandler->getSignatureText();
746+
747+
$this->assertMatchesRegularExpression('/^"\d{2}\/\d{2}\/\d{4}"$/', $actual);
748+
}
749+
750+
public function testGetSignatureTextGraphicOnlyWithTwigDateFilterAlwaysReturnsEmpty(): void {
751+
$this->appConfig->setValueString(
752+
'libresign',
753+
'signature_text_template',
754+
'{{ ServerSignatureDate|date("d/m/Y H:i:s T", "Europe/Paris") }}'
755+
);
756+
$this->appConfig->setValueString('libresign', 'signature_render_mode', SignerElementsService::RENDER_MODE_GRAPHIC_ONLY);
757+
758+
$jSignPdfHandler = $this->getInstance();
759+
$actual = $jSignPdfHandler->getSignatureText();
760+
761+
$this->assertSame('""', $actual);
762+
}
763+
736764
public static function providerGetSignatureText(): array {
737765
return [
738766
['FAKE_RENDER_MODE', '', '""'],
739767
['FAKE_RENDER_MODE', 'a', '"a"'],
740768
['FAKE_RENDER_MODE', "a\na", "\"a\na\""],
741769
['FAKE_RENDER_MODE', 'a"a', '"a\"a"'],
742770
['FAKE_RENDER_MODE', 'a$a', '"a\$a"'],
771+
// Plain {{ServerSignatureDate}} (no spaces) preserves JSign placeholder
743772
['FAKE_RENDER_MODE', '{{ServerSignatureDate}}', '"\${timestamp}"'],
773+
// Plain {{ ServerSignatureDate }} (with spaces) also preserves JSign placeholder
774+
['FAKE_RENDER_MODE', '{{ ServerSignatureDate }}', '"\${timestamp}"'],
744775
['GRAPHIC_ONLY', '', '""'],
745776
['GRAPHIC_ONLY', 'a', '""'],
746777
['GRAPHIC_ONLY', "a\na", '""'],

0 commit comments

Comments
 (0)