ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LanguageInstallationManagerDatabaseRowsOfMigratedModuleTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use PHPUnit\Framework\TestCase;
23
30{
32
41 private function call(array $rows, array $final_entries, array $shipped_entries, array $remarks = []): array
42 {
43 $method = (new ReflectionClass(LanguageInstallationManager::class))->getMethod('databaseRowsOfMigratedModule');
44
45 return $method->invoke(null, $rows, $final_entries, $shipped_entries, $remarks);
46 }
47
48 private const SHIPPED = [
49 'poll_population [0]' => 'Eine Stimmabgabe',
50 'poll_population [1]' => '%s Stimmabgaben',
51 'poll_population_singular' => 'Eine Stimmabgabe',
52 ];
53
59 {
60 $rows = [
61 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
62 'poll_population [1]' => ['%s NEUE Stimmabgaben', null, null],
63 ];
64 $final_entries = [
65 'poll_population [0]' => 'Eine Stimmabgabe',
66 'poll_population [1]' => '%s NEUE Stimmabgaben',
67 ];
68
69 $result = $this->call($rows, $final_entries, self::SHIPPED);
70
71 $this->assertSame(['poll_population' => ['%s NEUE Stimmabgaben', null, null]], $result);
72 }
73
79 {
80 $rows = ['poll_population_singular' => ['Eine Stimmabgabe', '2024-01-01 00:00:00', 'Anmerkung']];
81
82 $result = $this->call($rows, ['poll_population_singular' => 'Eine Stimmabgabe'], self::SHIPPED);
83
84 $this->assertSame(
85 ['poll_population_singular' => ['Eine Stimmabgabe', '2024-01-01 00:00:00', 'Anmerkung']],
86 $result
87 );
88 }
89
95 {
96 $rows = ['poll_population_singular' => ['Eine Stimmabgabe', '2024-01-01 00:00:00', 'Alte Anmerkung']];
97
98 $result = $this->call(
99 $rows,
100 ['poll_population_singular' => 'Eine Stimmabgabe'],
101 self::SHIPPED,
102 ['poll_population_singular' => 'Neue Anmerkung']
103 );
104
105 $this->assertSame(
106 ['poll_population_singular' => ['Eine Stimmabgabe', '2024-01-01 00:00:00', 'Neue Anmerkung']],
107 $result
108 );
109 }
110
112 {
113 $rows = [
114 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
115 'poll_population [1]' => ['%s Stimmabgaben', null, 'Alte Anmerkung'],
116 ];
117 $final_entries = ['poll_population [0]' => 'Eine Stimmabgabe', 'poll_population [1]' => '%s Stimmabgaben'];
118
119 $result = $this->call($rows, $final_entries, self::SHIPPED, ['poll_population' => 'Neue Anmerkung']);
120
121 $this->assertSame('Neue Anmerkung', $result['poll_population'][2]);
122 }
123
128 {
129 $rows = ['poll_population_singular' => ['Eine Stimmabgabe', null, 'Eigene Anmerkung']];
130
131 $result = $this->call($rows, ['poll_population_singular' => 'Eine Stimmabgabe'], self::SHIPPED, []);
132
133 $this->assertSame('Eigene Anmerkung', $result['poll_population_singular'][2]);
134 }
135
142 {
143 $rows = [
144 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
145 'poll_population [1]' => ['%s Stimmabgaben', '2024-01-01 00:00:00', 'lokal geändert'],
146 ];
147 // identical to self::SHIPPED - the message did not actually change
148 $final_entries = ['poll_population [0]' => 'Eine Stimmabgabe', 'poll_population [1]' => '%s Stimmabgaben'];
149
150 $result = $this->call($rows, $final_entries, self::SHIPPED);
151
152 $this->assertSame(
153 ['poll_population' => ['%s Stimmabgaben', null, 'lokal geändert']],
154 $result
155 );
156 }
157
163 {
164 $rows = [
165 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
166 'poll_population [1]' => ['%s NEUE Stimmabgaben', '2024-01-01 00:00:00', 'lokal geändert'],
167 ];
168 $final_entries = ['poll_population [0]' => 'Eine Stimmabgabe', 'poll_population [1]' => '%s NEUE Stimmabgaben'];
169
170 $result = $this->call($rows, $final_entries, self::SHIPPED);
171
172 $this->assertSame(
173 ['poll_population' => ['%s NEUE Stimmabgaben', '2024-01-01 00:00:00', 'lokal geändert']],
174 $result
175 );
176 }
177
182 {
183 $rows = [
184 'poll_population [1]' => ['%s NEUE Stimmabgaben', '2024-01-01 00:00:00', 'lokal geändert'],
185 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
186 ];
187 $final_entries = ['poll_population [0]' => 'Eine Stimmabgabe', 'poll_population [1]' => '%s NEUE Stimmabgaben'];
188
189 $result = $this->call($rows, $final_entries, self::SHIPPED);
190
191 $this->assertSame(
192 ['poll_population' => ['%s NEUE Stimmabgaben', '2024-01-01 00:00:00', 'lokal geändert']],
193 $result
194 );
195 }
196
201 {
202 $rows = [
203 'poll_population [0]' => ['Eine Stimmabgabe', null, null],
204 'poll_population [1]' => ['%s Stimmabgaben', null, null],
205 'poll_population_singular' => ['Eine Stimmabgabe', null, null],
206 ];
207 // final content no longer mentions "poll_population" at all
208 $final_entries = ['poll_population_singular' => 'Eine Stimmabgabe'];
209
210 $result = $this->call($rows, $final_entries, self::SHIPPED);
211
212 $this->assertArrayNotHasKey('poll_population', $result);
213 $this->assertSame(['poll_population_singular' => ['Eine Stimmabgabe', null, null]], $result);
214 }
215
220 {
221 $shipped = ['poll_population [0]' => 'ある投票'];
222 $rows = ['poll_population [0]' => ['ある投票NEU', null, null]];
223 $final_entries = ['poll_population [0]' => 'ある投票NEU'];
224
225 $result = $this->call($rows, $final_entries, $shipped);
226
227 $this->assertSame(['poll_population' => ['ある投票NEU', null, null]], $result);
228 }
229}
trait RestoresProcessState
Whatever a test does to the process (locale, LANGUAGE/LC_*, LOCPATH, the static state of the runtime ...
Write access to the language installation: installing, flushing and registering languages in the data...
Covers the private static databaseRowsOfMigratedModule(): it folds the buffered per-form lng_data row...
call(array $rows, array $final_entries, array $shipped_entries, array $remarks=[])
testAPlainRowOfAnUnrelatedIdentifierIsKeptUnchanged()
A plain row of an identifier that is not a plural message of the shipped state (here the separately s...
testASingleFormLanguageStillFoldsIntoOneRow()
A single-form language (nplurals=1) still folds into one row keyed by its identifier.
testTwoFormRowsFoldIntoOneRowWithTheDefaultFormsValue()
Two buffered form rows fold into one row under the plain identifier, with the default form's (msgstr[...
testRemarksParameterOverridesTheRowsOwnRemarkForAPlainIdentifier()
$remarks (from migratedModuleRemarks()) overrides the remark of the buffered rows,...
testLocalChangeIsNullWhenTheMergedDefaultFormValueMatchesTheShippedOne()
local_change depends on the merged default-form VALUE differing from the shipped default,...
testTheFirstNonNullLocalChangeAndRemarksOfTheFormRowsAreKeptWhenTheValueActuallyChanged()
The first non-null local_change/remarks among the form rows wins once the merged value differs; a lat...
testFormRowsWithNoValueInTheFinalContentAreDroppedEntirely()
A form row whose message has no value in the final content is dropped instead of written with a bogus...
testAnEarlierNonNullLocalChangeSurvivesALaterRowsNullOnesWhenTheValueActuallyChanged()
Same, with the local_change-carrying row processed first.
testAnIdentifierNotInRemarksKeepsTheRowsOwnRemark()
An identifier not named in $remarks keeps the rows' own remark.