Skip to content

Commit 97d3ffe

Browse files
authored
Merge pull request #5998 from LibreSign/backport/5997/stable31
[stable31] feat: footer template improvements
2 parents c4bf826 + a64776b commit 97d3ffe

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
@@ -173,7 +173,7 @@ private function prepareTemplateVars(): array {
173173
return $vars;
174174
}
175175

176-
private function getTemplate(): string {
176+
public function getTemplate(): string {
177177
$footerTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
178178
if ($footerTemplate) {
179179
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)