Skip to content

Commit e1d8f34

Browse files
committed
test: cover legacy identify methods config
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 286c987 commit e1d8f34

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

tests/php/Unit/Service/IdentifyMethod/IdentifyServiceTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCA\Libresign\Tests\Unit\TestCase;
2222
use OCP\AppFramework\Utility\ITimeFactory;
2323
use OCP\EventDispatcher\IEventDispatcher;
24+
use OCP\Exceptions\AppConfigTypeConflictException;
2425
use OCP\Files\IRootFolder;
2526
use OCP\IAppConfig;
2627
use OCP\IL10N;
@@ -156,6 +157,11 @@ public function testPropagateIdentifiedDateSkipsCurrentRequestAndUpdatesSiblings
156157
}
157158

158159
public function testGetSavedSettingsFallsBackToDefaultWhenStoredValueIsInvalid(): void {
160+
$this->appConfig
161+
->expects($this->once())
162+
->method('clearCache')
163+
->with(true);
164+
159165
$this->appConfig
160166
->expects($this->once())
161167
->method('getValueArray')
@@ -174,4 +180,82 @@ public function testGetSavedSettingsFallsBackToDefaultWhenStoredValueIsInvalid()
174180

175181
$this->assertSame([], $this->service->getSavedSettings());
176182
}
183+
184+
public function testGetSavedSettingsDecodesLegacyJsonStringWhenStoredValueTypeConflicts(): void {
185+
$this->appConfig
186+
->expects($this->once())
187+
->method('clearCache')
188+
->with(true);
189+
190+
$this->appConfig
191+
->expects($this->once())
192+
->method('getValueArray')
193+
->with(Application::APP_ID, 'identify_methods', [])
194+
->willThrowException(new AppConfigTypeConflictException('conflict with value type from database'));
195+
196+
$this->appConfig
197+
->expects($this->once())
198+
->method('getValueString')
199+
->with(Application::APP_ID, 'identify_methods', '')
200+
->willReturn('[{"name":"account","enabled":true}]');
201+
202+
$this->logger
203+
->expects($this->never())
204+
->method('warning');
205+
206+
$this->assertSame([
207+
[
208+
'name' => 'account',
209+
'enabled' => true,
210+
],
211+
], $this->service->getSavedSettings());
212+
}
213+
214+
public function testGetSavedSettingsFallsBackToDefaultWhenLegacyStringIsInvalid(): void {
215+
$this->appConfig
216+
->expects($this->once())
217+
->method('clearCache')
218+
->with(true);
219+
220+
$this->appConfig
221+
->expects($this->once())
222+
->method('getValueArray')
223+
->with(Application::APP_ID, 'identify_methods', [])
224+
->willThrowException(new AppConfigTypeConflictException('conflict with value type from database'));
225+
226+
$this->appConfig
227+
->expects($this->once())
228+
->method('getValueString')
229+
->with(Application::APP_ID, 'identify_methods', '')
230+
->willReturn('invalid');
231+
232+
$this->logger
233+
->expects($this->once())
234+
->method('warning')
235+
->with(
236+
'Invalid identify_methods app config; falling back to defaults.',
237+
$this->callback(static function (array $context): bool {
238+
return isset($context['exception']) && $context['exception'] instanceof AppConfigTypeConflictException;
239+
})
240+
);
241+
242+
$this->assertSame([], $this->service->getSavedSettings());
243+
}
244+
245+
public function testGetSavedSettingsReloadsAppConfigBeforeReading(): void {
246+
$expected = [['name' => 'account', 'enabled' => true]];
247+
248+
$this->appConfig
249+
->expects($this->once())
250+
->method('clearCache')
251+
->with(true);
252+
253+
$this->appConfig
254+
->expects($this->once())
255+
->method('getValueArray')
256+
->with(Application::APP_ID, 'identify_methods', [])
257+
->willReturn($expected);
258+
259+
$this->assertSame($expected, $this->service->getSavedSettings());
260+
}
177261
}

0 commit comments

Comments
 (0)