19declare(strict_types=1);
26use PHPUnit\Framework\Attributes\PreserveGlobalState;
27use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
33#[RunTestsInSeparateProcesses]
34#[PreserveGlobalState(false)]
39 protected function setUp(): void
43 if (!defined(
'ILIAS_ABSOLUTE_PATH')) {
44 define(
'ILIAS_ABSOLUTE_PATH', realpath(__DIR__ .
'/../../../../'));
46 if (!defined(
'ILIAS_LOG_ENABLED')) {
47 define(
'ILIAS_LOG_ENABLED',
false);
54 if (isset($this->fixture_directory) && is_dir($this->fixture_directory)) {
55 array_map(
'unlink', glob($this->fixture_directory .
'/*') ?: []);
56 rmdir($this->fixture_directory);
58 if (isset($this->fixture_directory)) {
72 $this->fixture_directory ??= __DIR__ .
'/tmp-plural-txt-fixtures-' . bin2hex(random_bytes(4));
74 $relative_path =
'components/ILIAS/Language/tests/' . basename($this->fixture_directory) .
'/';
75 if ($overlay !==
null) {
86 LanguageFileDirectoryManager::class,
100 $factory = $this->createStub(ilLoggerFactory::class);
101 $factory->method(
'getComponentLogger')->willReturn($this->createStub(ilLogger::class));
108 if (
$DIC->offsetExists(LanguageFileDirectoryManager::class)) {
111 $language = (
new ReflectionClass(ilLanguage::class))->newInstanceWithoutConstructor();
112 $reflected =
new ReflectionObject($language);
113 $reflected->getProperty(
'lang_key')->setValue($language, $lang_key);
114 $reflected->getProperty(
'lang_user')->setValue($language, $lang_key);
115 $reflected->getProperty(
'lang_default')->setValue($language, $lang_key);
116 $reflected->getProperty(
'log')->setValue($language, $this->createStub(ilLogger::class));
125 $catalog->setHeader(
'Content-Type',
'text/plain; charset=UTF-8');
126 if ($header !==
'') {
127 $catalog->setHeader(
'Plural-Forms', $header);
130 $entry->setPlural(
$id .
's', $forms);
131 $catalog->add($entry);
138 $catalog =
self::pluralCatalog(
'ntxt',
'nplurals=2; plural=(n != 1);',
'item', [
'Eintrag',
'Einträge']);
143 $language->loadLanguageModule(
'ntxt');
145 $this->assertSame(
'Eintrag', $language->txt(
'item', 1));
146 $this->assertSame(
'Einträge', $language->txt(
'item', 0));
147 $this->assertSame(
'Einträge', $language->txt(
'item', 5));
148 $this->assertSame(
'Einträge', $language->txt(
'item', -5),
'a negative n counts like its absolute value');
158 $language->loadLanguageModule(
'ntxt');
160 $this->assertSame(
'Einfach', $language->txt(
'plain', 1));
161 $this->assertSame(
'Einfach', $language->txt(
'plain', 5));
168 $this->assertSame($language->txt(
'unknown_topic'), $language->txt(
'unknown_topic', 5));
180 $language->loadLanguageModule(
'ntxt');
182 $this->assertSame(
'Eintrag', $language->txt(
'item', 1));
183 $this->assertSame(
'Einträge', $language->txt(
'item', 5));
189 $catalog =
self::pluralCatalog(
'ntxt',
'nplurals=2; plural=(n != 1);',
'item', [
'Eintrag',
'']);
194 $language->loadLanguageModule(
'ntxt');
197 $this->assertSame(
'Eintrag', $language->txt(
'item'));
198 $this->assertSame(
'Eintrag', $language->txt(
'item', 5));
204 $plural =
self::pluralCatalog(
'ntxt_a',
'nplurals=2; plural=(n != 1);',
'shared', [
'Eintrag',
'Einträge']);
213 $language->loadLanguageModule(
'ntxt_a');
214 $language->loadLanguageModule(
'ntxt_b');
216 $this->assertSame(
'Überschrieben', $language->txt(
'shared', 5));
221 $shipped =
self::pluralCatalog(
'ntxt',
'nplurals=2; plural=(n != 1);',
'item', [
'Eintrag',
'Einträge']);
222 $overlay =
self::pluralCatalog(
'ntxt',
'nplurals=2; plural=(n != 1);',
'item', [
'Datensatz',
'Datensätze']);
227 $language->loadLanguageModule(
'ntxt');
229 $this->assertSame(
'Datensatz', $language->txt(
'item', 1));
230 $this->assertSame(
'Datensätze', $language->txt(
'item', 5));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
An in-memory gettext catalog (header block plus messages) and the only place of the component that re...
One message of a TranslationCatalog (a msgctxt/msgid/msgstr block of a .po file).
static removeShippedDirectory(string $relative_path)
static ensureClientDataDirDefinedOrSkip(\PHPUnit\Framework\TestCase $test)
Guards every fixture that writes under CLIENT_DATA_DIR: a full-suite run may have defined it as the r...
static writePair(string $base_path, TranslationCatalog $catalog)
Writes "<base>.po" and, like MigratedLanguageFileSync::sync(), its compiled revision named by current...
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.
static build(LanguageFileDirectoryManager $manager, string $ilias_absolute_path)
Builds the shipped .po files of $manager below $ilias_absolute_path into the artifact directory of re...
static resetRuntime(?string $artifact_directory=null)
Forgets the static state of the runtime read path and points build and runtime at $artifact_directory...
ilLanguage::txt() with $n, the plural-aware form.
contributeModule(string $module, TranslationCatalog $catalog, ?TranslationCatalog $overlay=null)
Contributes a migrated module whose shipped .po (and, if it differs, overlay .mo) is $catalog,...
registerDirectoryManager(LanguageFileDirectory ... $contributed)
string $fixture_directory
testALaterModuleOverwritingTheIdentifierWinsOverTheEarlierPluralForms()
A later module overwriting the identifier with a plain value must win with $n too.
stubUsageLogDependencies()
testFallsBackToTxtForATopicThatWasNeverLoadedAtAll()
testFallsBackToTxtForAnOrdinarySingularIdentifier()
buildLanguage(string $lang_key='de')
testUsesTheGermanicRuleWhenThePluralFormsHeaderIsMissing()
Without a "Plural-Forms" header the Germanic rule (n==1 -> form 0, else 1) applies instead of failing...
stubComponentLogger()
Logged problems (e.g.
testAnOverlayReplacingThePluralFormsIsUsedForFormSelection()
testSelectsTheFormThePluralRuleOfTheLanguagePicksForN()
testFallsBackToTxtWhenTheSelectedFormIsEmpty()
An empty selected form falls back to txt() rather than returning an empty string.
static pluralCatalog(string $module, string $header, string $id, array $forms)
Class ilLanguageBaseTest.
setGlobalVariable(string $name, $value)
if(!isset($arguments[0])) if(count( $arguments) > 3) if(! $remove_from_lang &&isset($arguments[2]) &&!is_dir($arguments[2])) $module
A directory of language files with a path and a prefix for them.