Skip to content

Commit 1d9498e

Browse files
committed
test(migration): cover signature_flow legacy key migration
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent fc39762 commit 1d9498e

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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/Version18001Date20260320000000.php';
12+
13+
use OCA\Libresign\AppInfo\Application;
14+
use OCA\Libresign\Migration\Version18001Date20260320000000;
15+
use OCA\Libresign\Service\Policy\Provider\Signature\SignatureFlowPolicy;
16+
use OCP\IAppConfig;
17+
use OCP\Migration\IOutput;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
final class Version18001Date20260320000000Test extends TestCase {
22+
private IAppConfig&MockObject $appConfig;
23+
24+
protected function setUp(): void {
25+
parent::setUp();
26+
$this->appConfig = $this->createMock(IAppConfig::class);
27+
}
28+
29+
public function testMigratesLegacySignatureFlowSystemKeysAndDeletesOldOnes(): void {
30+
$newSystemKey = SignatureFlowPolicy::SYSTEM_APP_CONFIG_KEY;
31+
$newAllowOverrideKey = $newSystemKey . '.allow_child_override';
32+
33+
$this->appConfig
34+
->expects($this->exactly(4))
35+
->method('getValueString')
36+
->willReturnMap([
37+
[Application::APP_ID, 'signature_flow', '', 'ordered_numeric'],
38+
[Application::APP_ID, $newSystemKey, '', ''],
39+
[Application::APP_ID, 'signature_flow.allow_child_override', '', '1'],
40+
[Application::APP_ID, $newAllowOverrideKey, '', ''],
41+
]);
42+
43+
$this->appConfig
44+
->expects($this->exactly(2))
45+
->method('setValueString')
46+
->willReturnCallback(static function (string $appId, string $key, string $value) use ($newSystemKey, $newAllowOverrideKey): bool {
47+
if ($appId !== Application::APP_ID) {
48+
return false;
49+
}
50+
if ($key === $newSystemKey && $value === 'ordered_numeric') {
51+
return true;
52+
}
53+
if ($key === $newAllowOverrideKey && $value === '1') {
54+
return true;
55+
}
56+
return false;
57+
});
58+
59+
$deletedKeys = [];
60+
$this->appConfig
61+
->expects($this->exactly(2))
62+
->method('deleteKey')
63+
->willReturnCallback(static function (string $appId, string $key) use (&$deletedKeys): bool {
64+
if ($appId !== Application::APP_ID) {
65+
return false;
66+
}
67+
$deletedKeys[] = $key;
68+
return true;
69+
});
70+
71+
$migration = new Version18001Date20260320000000($this->appConfig);
72+
$migration->preSchemaChange($this->createMock(IOutput::class), static fn () => null, []);
73+
74+
$this->assertSame([
75+
'signature_flow',
76+
'signature_flow.allow_child_override',
77+
], $deletedKeys);
78+
}
79+
80+
public function testDeletesLegacyKeysWithoutOverwritingNewValues(): void {
81+
$newSystemKey = SignatureFlowPolicy::SYSTEM_APP_CONFIG_KEY;
82+
$newAllowOverrideKey = $newSystemKey . '.allow_child_override';
83+
84+
$this->appConfig
85+
->expects($this->exactly(4))
86+
->method('getValueString')
87+
->willReturnMap([
88+
[Application::APP_ID, 'signature_flow', '', 'ordered_numeric'],
89+
[Application::APP_ID, $newSystemKey, '', 'parallel'],
90+
[Application::APP_ID, 'signature_flow.allow_child_override', '', '1'],
91+
[Application::APP_ID, $newAllowOverrideKey, '', '0'],
92+
]);
93+
94+
$this->appConfig
95+
->expects($this->never())
96+
->method('setValueString');
97+
98+
$deletedKeys = [];
99+
$this->appConfig
100+
->expects($this->exactly(2))
101+
->method('deleteKey')
102+
->willReturnCallback(static function (string $appId, string $key) use (&$deletedKeys): bool {
103+
if ($appId !== Application::APP_ID) {
104+
return false;
105+
}
106+
$deletedKeys[] = $key;
107+
return true;
108+
});
109+
110+
$migration = new Version18001Date20260320000000($this->appConfig);
111+
$migration->preSchemaChange($this->createMock(IOutput::class), static fn () => null, []);
112+
113+
$this->assertSame([
114+
'signature_flow',
115+
'signature_flow.allow_child_override',
116+
], $deletedKeys);
117+
}
118+
}

0 commit comments

Comments
 (0)