ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilObjLanguageFolderCheckAllLanguagesTest.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
24
26{
27 private const string HEADER = "<!-- language file header -->\n<!-- language file start -->\n";
28
29 private string $directory;
30 private ?string $shipped_directory = null;
31
32 protected function setUp(): void
33 {
35
36 if (!defined('ILIAS_ABSOLUTE_PATH')) {
37 define('ILIAS_ABSOLUTE_PATH', realpath(__DIR__ . '/../../../../'));
38 }
39 $this->directory = sys_get_temp_dir() . '/ilias_check_all_' . bin2hex(random_bytes(4));
40 mkdir($this->directory, 0775, true);
41 }
42
43 protected function tearDown(): void
44 {
45 MigratedPoFixture::removeDirectory($this->directory);
46 if ($this->shipped_directory !== null) {
47 MigratedPoFixture::removeShippedDirectory($this->shipped_directory);
48 }
49
51 }
52
53 private function check(string $content, string $file_name = 'ilias_de.lang'): string
54 {
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();
59 $folder->lang_path = $this->directory;
60 $folder->separator = '#:#';
61 (new ReflectionProperty(ilObject::class, 'lng'))->setValue($folder, $lng);
62
63 return $folder->checkAllLanguages();
64 }
65
67 public function testAFileOfOnlyTheHeaderIsValid(): void
68 {
69 $output = $this->check(self::HEADER);
70
71 $this->assertStringContainsString('file_valid', $output);
72 $this->assertStringNotContainsString('err_wrong_header', $output);
73 }
74
76 {
77 $output = $this->check("<!-- language file header -->\ncommon#:#yes#:#Ja\n");
78
79 $this->assertStringContainsString('file_not_valid err_wrong_header', $output);
80 }
81
83 {
84 $output = $this->check(self::HEADER . "common#:#yes\n");
85
86 $this->assertStringContainsString('err_2_param', $output);
87 $this->assertStringContainsString('file_not_valid err_count_param', $output);
88 $this->assertStringNotContainsString('err_wrong_header', $output);
89 }
90
92 {
93 $root = rtrim((string) ILIAS_ABSOLUTE_PATH, '/') . '/';
94 $this->shipped_directory = 'components/ILIAS/Language/tests/tmp-check-all-' . bin2hex(random_bytes(4));
95 MigratedPoFixture::writeShippedPo($this->shipped_directory, 'poll', 'de', MigratedPoFixture::catalog('poll', ['item' => 'Eintrag']));
96 file_put_contents($root . $this->shipped_directory . '/tos_de.po', "msgid \"x\"\nmsgstr \"\xff\"\n");
97 $this->setGlobalVariable(LanguageFileDirectoryManager::class, new LanguageFileDirectoryManager(
99 MigratedPoFixture::directory('poll', $this->shipped_directory . '/'),
100 MigratedPoFixture::directory('tos', $this->shipped_directory . '/')
101 ));
102
103 $output = $this->check(self::HEADER);
104
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);
109 }
110
112 {
113 global $DIC;
114 unset($DIC[LanguageFileDirectoryManager::class]);
115
116 $output = $this->check(self::HEADER);
117
118 $this->assertStringContainsString('<br/>file_valid', $output);
119 $this->assertStringNotContainsString('.po', $output);
120 }
121
123 {
124 $cwd = getcwd();
125
126 $output = $this->check(self::HEADER . "<i>m#:#<u>id#:#<s>v#:#extra\n<i>m#:#<u>id#:#<s>v\n", 'ilias_<b.lang');
127
128 $this->assertSame($cwd, getcwd());
129 $this->assertStringContainsString('langfile_found: ilias_&lt;b.lang', $output);
130 $this->assertStringContainsString('module: &lt;i&gt;m, identifier: &lt;u&gt;id, value: &lt;s&gt;v', $output);
131 $this->assertStringNotContainsString('<', str_replace(['<br/>', '<b/>', '</b>', '<b>'], '', $output));
132 }
133}
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)
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')
global $lng
Definition: privfeed.php:26
global $DIC
Definition: shib_login.php:26