diff --git a/lib/Service/LockService.php b/lib/Service/LockService.php index 31f60360..9f508564 100644 --- a/lib/Service/LockService.php +++ b/lib/Service/LockService.php @@ -174,9 +174,9 @@ public function update(FileLock $lock): void { } public function getAppName(string $appId): ?string { - /** @var array{name: null}|null $appInfo */ $appInfo = $this->appManager->getAppInfo($appId); - return $appInfo['name'] ?? null; + $name = $appInfo['name'] ?? null; + return is_string($name) ? $name : null; } /** diff --git a/tests/Unit/Service/LockServiceTest.php b/tests/Unit/Service/LockServiceTest.php new file mode 100644 index 00000000..a0143d20 --- /dev/null +++ b/tests/Unit/Service/LockServiceTest.php @@ -0,0 +1,60 @@ +createMock(IAppManager::class); + $appManager->method('getAppInfo')->with('richdocuments')->willReturn($appInfo); + + $service = new LockService( + $this->createMock(IL10N::class), + $this->createMock(IUserManager::class), + $this->createMock(LocksRequest::class), + $this->createMock(FileService::class), + $this->createMock(IAppConfig::class), + $appManager, + $this->createMock(IEventDispatcher::class), + $this->createMock(IUserSession::class), + $this->createMock(IRequest::class), + $this->createMock(LoggerInterface::class), + $this->createMock(IRootFolder::class), + ); + + $this->assertSame($expected, $service->getAppName('richdocuments')); + } + + public static function appInfoProvider(): array { + return [ + 'name' => [['name' => 'Nextcloud Office'], 'Nextcloud Office'], + 'missing app' => [null, null], + 'no name' => [[], null], + 'untranslated name' => [['name' => [['@value' => 'Nextcloud Office']]], null], + ]; + } +}