19declare(strict_types=1);
31use PHPUnit\Framework\Attributes\DataProvider;
32use PHPUnit\Framework\TestCase;
43 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge']], self::TWO_FORMS);
45 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge-few',
'Einträge-viele']], self::THREE_FORMS);
52 $this->assertSame([
'item [0]',
'item [1]',
'item [2]'], array_keys($effective));
53 $this->assertSame(
'LOKAL-VIELE', $effective[
'item [1]'][
'value']);
54 $this->assertTrue($effective[
'item [1]'][
'local_change']);
55 $this->assertSame(
'LOKAL-VIELE', $effective[
'item [2]'][
'value'],
'by meaning: n = 0 and 5+ were served by the local form');
56 $this->assertTrue($effective[
'item [2]'][
'local_change']);
57 $this->assertSame(
'Eintrag', $effective[
'item [0]'][
'value']);
58 $this->assertFalse($effective[
'item [0]'][
'local_change']);
67 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge'],
'plain' =>
'X'], self::TWO_FORMS);
68 $this->
writeLocalOverlay([
'item [0]' =>
'Eintrag',
'item [1]' =>
'LOKAL-VIELE',
'plain' =>
'LOKAL-PLAIN']);
69 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge-few',
'Einträge-viele'],
'plain' =>
'X'], self::THREE_FORMS);
71 $this->assertSame([], $this->
manager()->insertLanguageForInstallation(
'de'));
74 $this->assertSame(self::THREE_FORMS, $overlay->getHeader(
'Plural-Forms'));
75 $item = $overlay->find(
null,
'item');
76 $this->assertNotNull($item);
77 $this->assertCount(3, $item->getPluralTranslations());
78 $this->assertContains(
'LOKAL-VIELE', $item->getPluralTranslations(),
'the local value must not be lost');
79 $this->assertSame(
'LOKAL-PLAIN', $overlay->find(
null,
'plain')?->getTranslation());
85 $this->assertSame(
'LOKAL-PLAIN',
$data[
'pilot|plain'][
'value']);
86 $this->assertNotNull(
$data[
'pilot|plain'][
'local_change']);
87 $this->assertSame(
$data[
'pilot|item'][
'value'], $this->
lngModules()[self::MODULE][
'item']);
88 $this->assertSame(
'LOKAL-PLAIN', $this->
lngModules()[self::MODULE][
'plain']);
90 $forms = $item->getPluralTranslations();
91 $local_change = LocalChangeComments::getLocalChange($item);
92 $this->
manager()->insertLanguageForInstallation(
'de');
93 $again = $this->
overlayPo()->find(
null,
'item');
94 $this->assertSame($forms, $again?->getPluralTranslations(),
'the second run changes no form');
95 $this->assertSame($local_change, LocalChangeComments::getLocalChange($again),
'nor the local change');
103 $this->
shipPluralPo([
'item' => [
'Eintrag']],
'nplurals=1; plural=0;');
105 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge']], self::TWO_FORMS);
107 $this->assertSame([], $this->
manager()->insertLanguageForInstallation(
'de'));
110 $this->assertSame(self::TWO_FORMS, $overlay->getHeader(
'Plural-Forms'));
111 $this->assertSame([
'LOKAL',
'LOKAL'], $overlay->find(
null,
'item')?->getPluralTranslations());
120 $this->expectErrorLog();
121 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge-few',
'Einträge-viele'],
'plain' =>
'X'], self::THREE_FORMS);
123 'item [0]' =>
'Eintrag',
124 'item [1]' =>
'LOKAL-FEW',
125 'item [2]' =>
'LOKAL-VIELE',
126 'plain' =>
'LOKAL-PLAIN',
128 $this->
shipPluralPo([
'item' => [
'Eintrag',
'Einträge'],
'plain' =>
'X'], self::TWO_FORMS);
130 $this->assertSame([], $this->
manager()->insertLanguageForInstallation(
'de'));
133 $this->assertSame(self::TWO_FORMS, $overlay->getHeader(
'Plural-Forms'));
134 $item = $overlay->find(
null,
'item');
135 $this->assertSame([
'Eintrag',
'LOKAL-VIELE'], $item?->getPluralTranslations(),
'the local default form is not lost');
136 $this->assertSame(
'LOKAL-PLAIN', $overlay->find(
null,
'plain')?->getTranslation());
137 $this->assertSame(
'Einträge', LocalChangeComments::getOriginal($item, 1),
'the original is the shipped value of the new rule');
144 $this->assertSame(
'LOKAL-VIELE',
$data[
'pilot|item'][
'value']);
145 $this->assertNotNull(
$data[
'pilot|item'][
'local_change']);
146 $this->assertSame(
'LOKAL-VIELE', $this->
lngModules()[self::MODULE][
'item']);
147 $this->assertSame(
'LOKAL-PLAIN', $this->
lngModules()[self::MODULE][
'plain']);
150 $this->assertStringContainsString(
'item [1]',
$log,
'the value that found no form is logged');
151 $this->assertStringNotContainsString(
'item [2]',
$log);
152 $this->assertStringNotContainsString(
'item [0]',
$log);
154 $po_before = (string) file_get_contents($this->
overlayBase() .
'.po');
155 $this->
manager()->insertLanguageForInstallation(
'de');
156 $this->assertSame($po_before, (
string) file_get_contents($this->
overlayBase() .
'.po'),
'the second run changes nothing');
157 $this->assertSame(
$log, $this->
errorLog(),
'and does not warn again');
An in-memory gettext catalog (header block plus messages) and the only place of the component that re...
Reads the shipped .po of a migrated module and maintains its per-installation overlay: the ....
The module array just written to lng_modules could not be read back - almost always a wrong collation...
Write access to the language installation: installing, flushing and registering languages in the data...
Fixtures of the LanguageInstallationManager tests for modules migrated to PO/MO ("pilot").
effective()
Shipped .po plus overlay delta, as served (MigratedLanguageFileSync::loadModuleTranslations()) - the ...
shipPluralPo(array $entries, string $header)
errorLog()
What error_log() wrote during this test so far - PHPUnit redirects error_log to a capture file per te...
manager(?\Closure $client_data_dir_resolver=null, ?\Closure $language_cache_invalidator=null, bool $with_resolver=true, bool $with_logger=true, ?LoggerInterface $logger=null)
writeLocalOverlay(array $flat_values)
static readMoPluralForms(string $data)
Every form of the plural messages of the .mo $data by identifier (contexts dropped).
static moPluralFormsHeader(string $data)
The "Plural-Forms" header of the .mo $data, null without.
static overlayMo(string $base_path)
The compiled catalog of the revision current names; a non-existing path if there is none.
A directory of language files with a path and a prefix for them.
Read-only access to the installed languages (database) and the available or valid language files (fil...