diff --git a/lib/Service/ExAppService.php b/lib/Service/ExAppService.php index a77c3719..3cd83b2b 100644 --- a/lib/Service/ExAppService.php +++ b/lib/Service/ExAppService.php @@ -284,6 +284,10 @@ public function getAppInfo(string $appId, ?string $infoXml, ?string $jsonInfo, ? } } $appInfo = json_decode(json_encode((array)$xmlAppInfo), true); + if (is_array($appInfo['name'] ?? null)) { + $defaultNames = $xmlAppInfo->xpath('name[not(@lang) or @lang="en"]'); + $appInfo['name'] = (string)($defaultNames[0] ?? $xmlAppInfo->name); + } if (isset($appInfo['external-app']['routes']['route'])) { if (isset($appInfo['external-app']['routes']['route'][0])) { $appInfo['external-app']['routes'] = $appInfo['external-app']['routes']['route']; diff --git a/tests/php/Service/ExAppServiceGetAppInfoTest.php b/tests/php/Service/ExAppServiceGetAppInfoTest.php index 8e052df8..c59653a2 100644 --- a/tests/php/Service/ExAppServiceGetAppInfoTest.php +++ b/tests/php/Service/ExAppServiceGetAppInfoTest.php @@ -27,6 +27,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IUserManager; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -75,12 +76,13 @@ protected function tearDown(): void { parent::tearDown(); } - private function writeInfoXml(string $environmentVariables): string { + private function writeInfoXml(string $environmentVariables, string $names = ''): string { $this->infoXmlPath = tempnam(sys_get_temp_dir(), 'appapi-test-info-'); file_put_contents($this->infoXmlPath, << test_app +$names $environmentVariables @@ -91,6 +93,22 @@ private function writeInfoXml(string $environmentVariables): string { return $this->infoXmlPath; } + #[DataProvider('defaultNameElements')] + public function testLocalizedNamesUseTheDefaultFromInfoXml(string $defaultNameElement): void { + $infoXml = $this->writeInfoXml('', 'Deutscher Name' . $defaultNameElement); + + $appInfo = $this->service->getAppInfo('test_app', $infoXml, null); + + self::assertSame('Default Name', $appInfo['name']); + } + + public static function defaultNameElements(): array { + return [ + 'without language' => ['Default Name'], + 'explicit English' => ['Default Name'], + ]; + } + public function testEmptyDefaultElementIsDroppedFromInfoXml(): void { $infoXml = $this->writeInfoXml(<<