Skip to content

Commit de01f7f

Browse files
authored
Merge pull request #5997 from LibreSign/feat/footer-template-improvements
feat: footer template improvements
2 parents 2d0c593 + 935d0d2 commit de01f7f

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

lib/Handler/FooterHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function prepareTemplateVars(): array {
171171
return $vars;
172172
}
173173

174-
private function getTemplate(): string {
174+
public function getTemplate(): string {
175175
$footerTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
176176
if ($footerTemplate) {
177177
return $footerTemplate;

lib/Service/FooterService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function isDefaultTemplate(): bool {
2525
}
2626

2727
public function getTemplate(): string {
28-
return $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
28+
return $this->footerHandler->getTemplate();
2929
}
3030

3131
public function saveTemplate(string $template): void {

tests/php/Unit/Handler/FooterHandlerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,36 @@ public function testCustomValidationSiteNotOverwritten(): void {
274274
$this->assertStringContainsString('https://custom.validation.site', $text);
275275
$this->assertStringNotContainsString('https://default.site', $text);
276276
}
277+
278+
public function testGetTemplateReturnsCustomTemplate(): void {
279+
$customTemplate = '<div>Custom footer template {{ uuid }}</div>';
280+
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', $customTemplate);
281+
$this->l10n = $this->l10nFactory->get(Application::APP_ID, 'en');
282+
283+
$template = $this->getClass()->getTemplate();
284+
285+
$this->assertSame($customTemplate, $template);
286+
}
287+
288+
public function testGetTemplateReturnsDefaultWhenNotSet(): void {
289+
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
290+
$this->l10n = $this->l10nFactory->get(Application::APP_ID, 'en');
291+
292+
$template = $this->getClass()->getTemplate();
293+
294+
$defaultTemplate = file_get_contents(__DIR__ . '/../../../../lib/Handler/Templates/footer.twig');
295+
$this->assertNotEmpty($template);
296+
$this->assertSame($defaultTemplate, $template);
297+
}
298+
299+
public function testGetTemplateReturnsDefaultWhenEmpty(): void {
300+
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', '');
301+
$this->l10n = $this->l10nFactory->get(Application::APP_ID, 'en');
302+
303+
$template = $this->getClass()->getTemplate();
304+
305+
$this->assertNotEmpty($template);
306+
$defaultTemplate = file_get_contents(__DIR__ . '/../../../../lib/Handler/Templates/footer.twig');
307+
$this->assertSame($defaultTemplate, $template);
308+
}
277309
}

tests/php/Unit/Service/FooterServiceTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,24 @@ public function testGetTemplate(): void {
5858
$template = '<div>Custom template</div>';
5959
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', $template);
6060

61+
$this->footerHandler
62+
->expects($this->once())
63+
->method('getTemplate')
64+
->willReturn($template);
65+
6166
$this->assertSame($template, $this->service->getTemplate());
6267
}
6368

64-
public function testGetTemplateReturnsEmptyWhenNotSet(): void {
69+
public function testGetTemplateReturnsDefaultWhenNotSet(): void {
6570
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
6671

67-
$this->assertSame('', $this->service->getTemplate());
72+
$defaultTemplate = '<div>Default footer template</div>';
73+
$this->footerHandler
74+
->expects($this->once())
75+
->method('getTemplate')
76+
->willReturn($defaultTemplate);
77+
78+
$this->assertSame($defaultTemplate, $this->service->getTemplate());
6879
}
6980

7081
#[DataProvider('provideRenderPreviewPdfScenarios')]

0 commit comments

Comments
 (0)