Skip to content

Commit 6f6728e

Browse files
committed
test(migration): cover legacy footer settings migration to structured payload
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 7d20444 commit 6f6728e

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Libresign\Tests\Unit\Migration;
10+
11+
require_once __DIR__ . '/../../../../lib/Migration/Version18002Date20260410000000.php';
12+
13+
use OCA\Libresign\AppInfo\Application;
14+
use OCA\Libresign\Migration\Version18002Date20260410000000;
15+
use OCA\Libresign\Service\Policy\Provider\Footer\SignatureFooterPolicyValue;
16+
use OCP\Exceptions\AppConfigTypeConflictException;
17+
use OCP\IAppConfig;
18+
use OCP\Migration\IOutput;
19+
use PHPUnit\Framework\MockObject\MockObject;
20+
use PHPUnit\Framework\TestCase;
21+
22+
final class Version18002Date20260410000000Test extends TestCase {
23+
private IAppConfig&MockObject $appConfig;
24+
25+
protected function setUp(): void {
26+
parent::setUp();
27+
$this->appConfig = $this->createMock(IAppConfig::class);
28+
}
29+
30+
public function testMigratesLegacyFooterSettingsIntoStructuredPayload(): void {
31+
$this->appConfig
32+
->expects($this->exactly(4))
33+
->method('getValueString')
34+
->willReturnMap([
35+
[Application::APP_ID, 'add_footer', '', '1'],
36+
[Application::APP_ID, 'write_qrcode_on_footer', '', '0'],
37+
[Application::APP_ID, 'validation_site', '', 'https://validator.example/base/'],
38+
[Application::APP_ID, 'footer_template_is_default', '', '0'],
39+
]);
40+
41+
$this->appConfig
42+
->expects($this->once())
43+
->method('deleteKey')
44+
->with(Application::APP_ID, 'add_footer');
45+
46+
$this->appConfig
47+
->expects($this->once())
48+
->method('setValueString')
49+
->with(
50+
Application::APP_ID,
51+
'add_footer',
52+
SignatureFooterPolicyValue::encode([
53+
'enabled' => true,
54+
'writeQrcodeOnFooter' => false,
55+
'validationSite' => 'https://validator.example/base/',
56+
'customizeFooterTemplate' => true,
57+
]),
58+
);
59+
60+
$migration = new Version18002Date20260410000000($this->appConfig);
61+
$migration->preSchemaChange($this->createMock(IOutput::class), static fn () => null, []);
62+
}
63+
64+
public function testReadsLegacyBooleanWhenAddFooterHasTypedBoolValue(): void {
65+
$this->appConfig
66+
->expects($this->exactly(4))
67+
->method('getValueString')
68+
->willReturnCallback(static function (string $app, string $key, string $default): string {
69+
if ($app !== Application::APP_ID) {
70+
return $default;
71+
}
72+
73+
if ($key === 'add_footer') {
74+
throw new AppConfigTypeConflictException('bool stored');
75+
}
76+
77+
if ($key === 'write_qrcode_on_footer') {
78+
return '1';
79+
}
80+
81+
if ($key === 'validation_site') {
82+
return '';
83+
}
84+
85+
if ($key === 'footer_template_is_default') {
86+
return '1';
87+
}
88+
89+
return $default;
90+
});
91+
92+
$this->appConfig
93+
->expects($this->once())
94+
->method('getValueBool')
95+
->with(Application::APP_ID, 'add_footer', true)
96+
->willReturn(false);
97+
98+
$this->appConfig
99+
->expects($this->once())
100+
->method('deleteKey')
101+
->with(Application::APP_ID, 'add_footer');
102+
103+
$this->appConfig
104+
->expects($this->once())
105+
->method('setValueString')
106+
->with(
107+
Application::APP_ID,
108+
'add_footer',
109+
SignatureFooterPolicyValue::encode([
110+
'enabled' => false,
111+
'writeQrcodeOnFooter' => true,
112+
'validationSite' => '',
113+
'customizeFooterTemplate' => false,
114+
]),
115+
);
116+
117+
$migration = new Version18002Date20260410000000($this->appConfig);
118+
$migration->preSchemaChange($this->createMock(IOutput::class), static fn () => null, []);
119+
}
120+
}

0 commit comments

Comments
 (0)