Skip to content

Commit a8842f2

Browse files
committed
test(footer): cover structured policy and qrcode disabled behavior
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 854f98d commit a8842f2

1 file changed

Lines changed: 88 additions & 5 deletions

File tree

tests/php/Unit/Handler/FooterHandlerTest.php

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCA\Libresign\Service\Policy\Model\ResolvedPolicy;
1717
use OCA\Libresign\Service\Policy\PolicyService;
1818
use OCA\Libresign\Service\Policy\Provider\Footer\AddFooterPolicy;
19+
use OCA\Libresign\Service\Policy\Provider\Footer\SignatureFooterPolicyValue;
1920
use OCP\IAppConfig;
2021
use OCP\IL10N;
2122
use OCP\ITempManager;
@@ -42,7 +43,7 @@ public function setUp(): void {
4243
->method('resolve')
4344
->willReturnCallback(function (string $policyKey): ResolvedPolicy {
4445
$value = match ($policyKey) {
45-
AddFooterPolicy::KEY => $this->appConfig->getValueBool(Application::APP_ID, 'add_footer', true),
46+
AddFooterPolicy::KEY => $this->appConfig->getValueString(Application::APP_ID, 'add_footer', '1'),
4647
default => null,
4748
};
4849

@@ -74,7 +75,16 @@ private function getClass(): FooterHandler {
7475
}
7576

7677
public function testGetFooterWithoutValidationSite(): void {
77-
$this->appConfig->setValueBool(Application::APP_ID, 'add_footer', false);
78+
$this->appConfig->setValueString(
79+
Application::APP_ID,
80+
'add_footer',
81+
SignatureFooterPolicyValue::encode([
82+
'enabled' => false,
83+
'writeQrcodeOnFooter' => true,
84+
'validationSite' => '',
85+
'customizeFooterTemplate' => false,
86+
]),
87+
);
7888
$dimensions = [['w' => 595, 'h' => 842]];
7989
$this->l10n = $this->l10nFactory->get(Application::APP_ID);
8090
$actual = $this->getClass()
@@ -86,6 +96,20 @@ public function testGetFooterWithoutValidationSite(): void {
8696
#[DataProvider('dataGetFooterWithSuccess')]
8797
public function testGetFooterWithSuccess(string $language, array $settings, array $expected): void {
8898
foreach ($settings as $key => $value) {
99+
if ($key === 'add_footer') {
100+
$this->appConfig->setValueString(
101+
Application::APP_ID,
102+
'add_footer',
103+
SignatureFooterPolicyValue::encode([
104+
'enabled' => (bool)$value,
105+
'writeQrcodeOnFooter' => true,
106+
'validationSite' => '',
107+
'customizeFooterTemplate' => false,
108+
]),
109+
);
110+
continue;
111+
}
112+
89113
switch (gettype($value)) {
90114
case 'boolean':
91115
$this->appConfig->setValueBool(Application::APP_ID, $key, $value);
@@ -261,7 +285,16 @@ private function extractPdfContent(string $content, array $keys, string $directi
261285
}
262286

263287
public function testGetFooterWithoutUuid(): void {
264-
$this->appConfig->setValueBool(Application::APP_ID, 'add_footer', true);
288+
$this->appConfig->setValueString(
289+
Application::APP_ID,
290+
'add_footer',
291+
SignatureFooterPolicyValue::encode([
292+
'enabled' => true,
293+
'writeQrcodeOnFooter' => true,
294+
'validationSite' => '',
295+
'customizeFooterTemplate' => false,
296+
]),
297+
);
265298
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', '<div>{{ signedBy|raw }}</div>');
266299

267300
$dimensions = [['w' => 595, 'h' => 100]];
@@ -277,7 +310,16 @@ public function testGetFooterWithoutUuid(): void {
277310
}
278311

279312
public function testCustomValidationSiteNotOverwritten(): void {
280-
$this->appConfig->setValueBool(Application::APP_ID, 'add_footer', true);
313+
$this->appConfig->setValueString(
314+
Application::APP_ID,
315+
'add_footer',
316+
SignatureFooterPolicyValue::encode([
317+
'enabled' => true,
318+
'writeQrcodeOnFooter' => true,
319+
'validationSite' => '',
320+
'customizeFooterTemplate' => false,
321+
]),
322+
);
281323
$this->appConfig->setValueString(Application::APP_ID, 'validation_site', 'https://default.site');
282324
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', '<div>{{ validationSite }}</div>');
283325

@@ -349,7 +391,16 @@ public function testAccentedCharactersInFooterVariablesAreRenderedCorrectly(
349391
array $expectedSubstrings,
350392
array $forbiddenSubstrings,
351393
): void {
352-
$this->appConfig->setValueBool(Application::APP_ID, 'add_footer', true);
394+
$this->appConfig->setValueString(
395+
Application::APP_ID,
396+
'add_footer',
397+
SignatureFooterPolicyValue::encode([
398+
'enabled' => true,
399+
'writeQrcodeOnFooter' => true,
400+
'validationSite' => '',
401+
'customizeFooterTemplate' => false,
402+
]),
403+
);
353404
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
354405

355406
$dimensions = [['w' => 595, 'h' => 100]];
@@ -376,6 +427,38 @@ public function testAccentedCharactersInFooterVariablesAreRenderedCorrectly(
376427
}
377428
}
378429

430+
public function testPolicyCanDisableQrCodeRendering(): void {
431+
$this->appConfig->setValueString(
432+
Application::APP_ID,
433+
'add_footer',
434+
SignatureFooterPolicyValue::encode([
435+
'enabled' => true,
436+
'writeQrcodeOnFooter' => false,
437+
'validationSite' => 'https://validation.example',
438+
'customizeFooterTemplate' => false,
439+
]),
440+
);
441+
$this->appConfig->setValueString(
442+
Application::APP_ID,
443+
'footer_template',
444+
'<div>qrcode:{{ qrcode }} validateIn:{{ validationSite }}</div>',
445+
);
446+
447+
$dimensions = [['w' => 595, 'h' => 100]];
448+
$this->l10n = $this->l10nFactory->get(Application::APP_ID, 'en');
449+
450+
$pdf = $this->getClass()
451+
->setTemplateVar('uuid', 'unit-test-uuid')
452+
->getFooter($dimensions);
453+
454+
$this->assertNotEmpty($pdf);
455+
$parser = new \Smalot\PdfParser\Parser();
456+
$pdfParsed = $parser->parseContent($pdf);
457+
$text = $pdfParsed->getText();
458+
$this->assertStringContainsString('validateIn:https://validation.example/unit-test-uuid', str_replace(' ', '', $text));
459+
$this->assertStringNotContainsString('iVBOR', $text);
460+
}
461+
379462
public static function dataAccentedCharactersInFooter(): array {
380463
return [
381464
'French accents' => [

0 commit comments

Comments
 (0)