ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LanguageInstallationManagerMigratedPluralFormsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31use PHPUnit\Framework\Attributes\DataProvider;
32use PHPUnit\Framework\TestCase;
33
35{
42 {
43 $this->shipPluralPo(['item' => ['Eintrag', 'Einträge']], self::TWO_FORMS);
44 $this->writeLocalOverlay(['item [0]' => 'Eintrag', 'item [1]' => 'LOKAL-VIELE']);
45 $this->shipPluralPo(['item' => ['Eintrag', 'Einträge-few', 'Einträge-viele']], self::THREE_FORMS);
46
47 $served = (string) file_get_contents(MigratedPoFixture::overlayMo($this->overlayBase()));
48 $this->assertSame(self::TWO_FORMS, MigratedPoFixture::moPluralFormsHeader($served));
49 $this->assertSame(['item' => ['Eintrag', 'LOKAL-VIELE']], MigratedPoFixture::readMoPluralForms($served));
50
51 $effective = $this->effective();
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']);
59 }
60
66 {
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);
70
71 $this->assertSame([], $this->manager()->insertLanguageForInstallation('de'));
72
73 $overlay = $this->overlayPo();
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());
80 $served = (string) file_get_contents(MigratedPoFixture::overlayMo($this->overlayBase()));
81 $this->assertSame(self::THREE_FORMS, MigratedPoFixture::moPluralFormsHeader($served));
82 $this->assertCount(3, MigratedPoFixture::readMoPluralForms($served)['item']);
83
84 $data = $this->lngData();
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']);
89
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');
96 }
97
102 {
103 $this->shipPluralPo(['item' => ['Eintrag']], 'nplurals=1; plural=0;');
104 $this->writeLocalOverlay(['item [0]' => 'LOKAL']);
105 $this->shipPluralPo(['item' => ['Eintrag', 'Einträge']], self::TWO_FORMS);
106
107 $this->assertSame([], $this->manager()->insertLanguageForInstallation('de'));
108
109 $overlay = $this->overlayPo();
110 $this->assertSame(self::TWO_FORMS, $overlay->getHeader('Plural-Forms'));
111 $this->assertSame(['LOKAL', 'LOKAL'], $overlay->find(null, 'item')?->getPluralTranslations());
112 }
113
119 {
120 $this->expectErrorLog();
121 $this->shipPluralPo(['item' => ['Eintrag', 'Einträge-few', 'Einträge-viele'], 'plain' => 'X'], self::THREE_FORMS);
122 $this->writeLocalOverlay([
123 'item [0]' => 'Eintrag',
124 'item [1]' => 'LOKAL-FEW',
125 'item [2]' => 'LOKAL-VIELE',
126 'plain' => 'LOKAL-PLAIN',
127 ]);
128 $this->shipPluralPo(['item' => ['Eintrag', 'Einträge'], 'plain' => 'X'], self::TWO_FORMS);
129
130 $this->assertSame([], $this->manager()->insertLanguageForInstallation('de'));
131
132 $overlay = $this->overlayPo();
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');
138
139 $served = (string) file_get_contents(MigratedPoFixture::overlayMo($this->overlayBase()));
140 $this->assertSame(self::TWO_FORMS, MigratedPoFixture::moPluralFormsHeader($served));
141 $this->assertSame(['item' => ['Eintrag', 'LOKAL-VIELE']], MigratedPoFixture::readMoPluralForms($served));
142
143 $data = $this->lngData();
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']);
148
149 $log = $this->errorLog();
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);
153
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');
158 }
159}
An in-memory gettext catalog (header block plus messages) and the only place of the component that re...
Tracks per overlay entry whether the current value still matches the value of the shipped ....
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 ...
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)
testInstallAfterTheNumberOfPluralFormsGrewRewritesTheOverlayWithTheNewRuleAndKeepsLocalValues()
After the write the overlay follows the new rule: new header, exactly the new number of forms,...
testInstallAfterASingleFormLanguageGotASecondFormGivesTheLocalValueToBothForms()
1 -> 2 forms (CLDR 49 change of "vi"): both new forms carry the local value.
testAnExistingOverlayIsServedWithItsOwnRuleUntilTheNextReconcilingWrite()
If the plural rule changes with an update (2 -> 3 forms, e.g.
testInstallAfterTheNumberOfPluralFormsShrankKeepsTheLocalDefaultFormAndLogsTheLostValue()
3 -> 2 forms: the local default form survives, the middle form's local value has no equivalent form a...
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...
$log
Definition: ltiauth.php:50
$data
Definition: storeScorm.php:45