20declare(strict_types=1);
27 private const string HEADER =
"<!-- language file header -->\n<!-- language file start -->\n";
32 protected function setUp(): void
36 if (!defined(
'ILIAS_ABSOLUTE_PATH')) {
37 define(
'ILIAS_ABSOLUTE_PATH', realpath(__DIR__ .
'/../../../../'));
39 $this->directory = sys_get_temp_dir() .
'/ilias_check_all_' . bin2hex(random_bytes(4));
40 mkdir($this->directory, 0775,
true);
46 if ($this->shipped_directory !==
null) {
53 private function check(
string $content,
string $file_name =
'ilias_de.lang'): string
55 file_put_contents($this->directory .
'/' . $file_name, $content);
56 $lng = $this->createStub(ilLanguage::class);
57 $lng->method(
'txt')->willReturnArgument(0);
58 $folder = (
new ReflectionClass(ilObjLanguageFolder::class))->newInstanceWithoutConstructor();
60 $folder->separator =
'#:#';
61 (
new ReflectionProperty(ilObject::class,
'lng'))->setValue($folder,
$lng);
63 return $folder->checkAllLanguages();
69 $output = $this->
check(self::HEADER);
71 $this->assertStringContainsString(
'file_valid', $output);
72 $this->assertStringNotContainsString(
'err_wrong_header', $output);
77 $output = $this->
check(
"<!-- language file header -->\ncommon#:#yes#:#Ja\n");
79 $this->assertStringContainsString(
'file_not_valid err_wrong_header', $output);
84 $output = $this->
check(self::HEADER .
"common#:#yes\n");
86 $this->assertStringContainsString(
'err_2_param', $output);
87 $this->assertStringContainsString(
'file_not_valid err_count_param', $output);
88 $this->assertStringNotContainsString(
'err_wrong_header', $output);
93 $root = rtrim((
string) ILIAS_ABSOLUTE_PATH,
'/') .
'/';
94 $this->shipped_directory =
'components/ILIAS/Language/tests/tmp-check-all-' . bin2hex(random_bytes(4));
96 file_put_contents($root . $this->shipped_directory .
'/tos_de.po',
"msgid \"x\"\nmsgstr \"\xff\"\n");
103 $output = $this->
check(self::HEADER);
105 $this->assertStringContainsString(
'<br/>file_valid', $output);
106 $this->assertStringContainsString(
'file_not_valid: ' . $this->shipped_directory .
'/tos_de.po', $output);
107 $this->assertStringNotContainsString(
'poll_de.po', $output);
108 $this->assertStringNotContainsString($root, $output);
114 unset(
$DIC[LanguageFileDirectoryManager::class]);
116 $output = $this->
check(self::HEADER);
118 $this->assertStringContainsString(
'<br/>file_valid', $output);
119 $this->assertStringNotContainsString(
'.po', $output);
126 $output = $this->
check(self::HEADER .
"<i>m#:#<u>id#:#<s>v#:#extra\n<i>m#:#<u>id#:#<s>v\n",
'ilias_<b.lang');
128 $this->assertSame($cwd, getcwd());
129 $this->assertStringContainsString(
'langfile_found: ilias_<b.lang', $output);
130 $this->assertStringContainsString(
'module: <i>m, identifier: <u>id, value: <s>v', $output);
131 $this->assertStringNotContainsString(
'<', str_replace([
'<br/>',
'<b/>',
'</b>',
'<b>'],
'', $output));
static removeShippedDirectory(string $relative_path)
static directory(string $prefix, string $path, bool $local=false)
static catalog(string $module, array $entries)
static removeDirectory(string $directory)
static writeShippedPo(string $relative_path, string $module, string $lang_key, TranslationCatalog $catalog)
Writes $catalog as the shipped .po: a module only counts as migrated while that exists.
Class ilLanguageBaseTest.
setGlobalVariable(string $name, $value)
testAFileWithoutTheStartMarkerHasAWrongHeader()
testAHeaderFollowedByAMalformedLineIsAParameterError()
testAFileOfOnlyTheHeaderIsValid()
Every module is shipped in PO files: a file of only the header is valid.
check(string $content, string $file_name='ilias_de.lang')
string $shipped_directory
testHtmlInTheFileNameAndTheLinesIsEscapedAndAnInvalidLanguageKeyKeepsTheWorkingDirectory()
testWithoutAFileDirectoryManagerNoPoIsCheckedAndNothingFails()
testReportsTheUnreadableShippedPoOfAFoundLanguageWithItsPathRelativeToTheRoot()