Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Service/ExAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
20 changes: 19 additions & 1 deletion tests/php/Service/ExAppServiceGetAppInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, <<<XML
<?xml version="1.0"?>
<info>
<id>test_app</id>
$names
<external-app>
<environment-variables>
$environmentVariables
Expand All @@ -91,6 +93,22 @@ private function writeInfoXml(string $environmentVariables): string {
return $this->infoXmlPath;
}

#[DataProvider('defaultNameElements')]
public function testLocalizedNamesUseTheDefaultFromInfoXml(string $defaultNameElement): void {
$infoXml = $this->writeInfoXml('', '<name lang="de">Deutscher Name</name>' . $defaultNameElement);

$appInfo = $this->service->getAppInfo('test_app', $infoXml, null);

self::assertSame('Default Name', $appInfo['name']);
}

public static function defaultNameElements(): array {
return [
'without language' => ['<name>Default Name</name>'],
'explicit English' => ['<name lang="en">Default Name</name>'],
];
}

public function testEmptyDefaultElementIsDroppedFromInfoXml(): void {
$infoXml = $this->writeInfoXml(<<<XML
<variable>
Expand Down
Loading