ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncDeltaTest Class Reference

sync() computing the delta overlay: creation, admin edit, reconciling write (refresh), replace semantics. More...

+ Inheritance diagram for MigratedLanguageFileSyncDeltaTest:
+ Collaboration diagram for MigratedLanguageFileSyncDeltaTest:

Public Member Functions

 testSyncingOnlyShippedValuesWritesNoOverlay (bool $refresh)
 A module whose values are all shipped ones needs no overlay: neither file, lock nor directory is created, by an admin edit or a reconciling write. More...
 
 testCreatingTheOverlayWithADeviatingValueRecordsShippedOriginalAndALocalChange ()
 
 testCreatingTheOverlayGivesAnEntryWithoutShippedCounterpartNoOriginalButALocalChange ()
 
 testCreatingTheOverlayKeepsShippedFuzzyOnlyForTheUnchangedShippedValue ()
 A shipped "fuzzy" (an unreviewed value, usually the English fallback) must survive the very first sync as long as the value is still the shipped one - and must not be copied onto a value that differs from it. More...
 
 testTheDeltaIsComparedAgainstTheRawShippedValueNotTheMarkupCleanedOne ()
 The delta is compared against the RAW shipped .po value (TranslationCatalog::fromPoFile()), not the markup- cleaned value the build serves: a value with markup TranslationMarkupPolicy disallows is still the shipped value, so writing it back creates no delta. More...
 
 testTheOverlayTakesTheExtractedCommentsOfTheShippedEntry ()
 Extracted comments ("#. ...", context for translators) are part of the shipped file and are carried into the overlay on creation/refresh. More...
 
 testTheOverlayTakesTheHeadersOfTheShippedPo ()
 
 testAnAdminEditNeverMovesTheOriginal ()
 refresh = false (an ordinary admin edit): the baseline "original" must never move - even when the shipped file changed in the meantime. More...
 
 testAnAdminEditRemovesFuzzyOnlyFromTheValuesItActuallyChanges ()
 
 testWritingTheOriginalValueBackClearsTheLocalChange ()
 
 testTheLocalChangeTimestampOfAnUntouchedEntrySurvivesAnUnrelatedWrite ()
 A full-replace write re-sends every value; an entry whose value did not change must keep its existing local_change timestamp (seeded with a fixed, old value - no sleep()/clock needed). More...
 
 testALegacyEntryWithTheModuleAsMsgctxtIsMigratedToNoContextPreservingItsBookkeeping (bool $refresh)
 An overlay of an earlier version carried the module as msgctxt on every entry (see seedOverlay()); the next write must migrate it to the msgctxt-less shape (TranslationEntry::withContext(null)) while preserving translation, comments, flags, "local_change" and "original". More...
 
 testALegacyFullOverlayShrinksToTheDeltaOnTheNextReconcilingWrite ()
 An overlay written by the pre-delta design carried EVERY entry of the module. More...
 
 testRefreshMovesTheOriginalToTheNewShippedValueAndClearsTheLocalChangeOfAnUnmodifiedEntry ()
 
 testRefreshMovesTheOriginalButKeepsALocalCustomizationFlagged ()
 
 testRefreshKeepsTheOriginalOfAnEntryTheShippedPoNoLongerContains ()
 An entry the shipped .po no longer contains (kept by the caller as a real local change, see LanguageInstallationManager::resolveMigratedModule()) keeps its last "original" and its local_change date - so a later update can still tell it from an unchanged entry. More...
 
 testRefreshRecomputesFuzzyFromTheShippedEntry (array $shipped, array $overlay, string $value, ?bool $expected_fuzzy)
 On refresh fuzzy is recomputed from the shipped file: set exactly when the value is the shipped value and the shipped entry is fuzzy. More...
 
 testReplaceSemanticsRemoveEveryEntryThatIsNotPassed ()
 
 testSyncingNoEntriesRemovesTheOverlayButKeepsTheShippedFile ()
 An empty delta removes the overlay files - the shipped file and the lock file are kept. More...
 
 testEntriesOfAnotherContextInTheOldOverlayAreNotCarriedOver ()
 Entries of a different context (another module) are never taken over into this module's overlay: the overlay holds exactly $entries. More...
 
 testEntriesAreWrittenSortedByIdentifier ()
 Sorted byte-wise by identifier, independent of the order of $entries - keeps the file diff-stable. More...
 

Static Public Member Functions

static refreshFlags ()
 
static refreshFuzzyCases ()
 
static refreshFlags ()
 

Additional Inherited Members

- Protected Member Functions inherited from MigratedLanguageFileSyncTestCase
 setUp ()
 
 tearDown ()
 
 seedShipped (array $entries, string $lang_key='de', string $module=self::MODULE)
 
 seedOverlay (array $entries, string $lang_key='de')
 
 shippedPo (string $lang_key='de', string $module=self::MODULE)
 
 overlayBase (string $lang_key='de')
 
 overlayPo ()
 
 sync (array $entries, bool $refresh=false, ?string $client_data_dir='default')
 
 overlayIdentifiers ()
 
 overlayDirectory ()
 
 findUnwritable (array $lang_keys=['de'], ?string $client_data_dir='default', ?LanguageFileDirectoryManager $manager=null)
 
- Protected Attributes inherited from MigratedLanguageFileSyncTestCase
const string MODULE = 'stest'
 
string $fixture_directory
 
string $client_data_dir
 
string $ilias_root
 
LanguageFileDirectory $directory
 
LanguageFileDirectoryManager $manager
 

Detailed Description

sync() computing the delta overlay: creation, admin edit, reconciling write (refresh), replace semantics.

Definition at line 34 of file MigratedLanguageFileSyncDeltaTest.php.

Member Function Documentation

◆ refreshFlags()

static MigratedLanguageFileSyncDeltaTest::refreshFlags ( )
static
Returns
array<string, array{0: bool}>

Reimplemented from MigratedLanguageFileSyncTestCase.

Definition at line 55 of file MigratedLanguageFileSyncDeltaTest.php.

55 : array
56 {
57 return ['admin edit (refresh = false)' => [false], 'reconciling write (refresh = true)' => [true]];
58 }

◆ refreshFuzzyCases()

static MigratedLanguageFileSyncDeltaTest::refreshFuzzyCases ( )
static
Returns
array<string, array<int, mixed>>

Definition at line 368 of file MigratedLanguageFileSyncDeltaTest.php.

368 : array
369 {
370 return [
371 'shipped fuzzy, value is shipped' => [
372 ['value' => 'Hello', 'fuzzy' => true], ['value' => 'Hello', 'original' => 'Hello'], 'Hello', null,
373 ],
374 'shipped fuzzy, value differs' => [
375 ['value' => 'Hello', 'fuzzy' => true], ['value' => 'Hallo', 'original' => 'Hello', 'fuzzy' => true], 'Hallo', false,
376 ],
377 'shipped reviewed now, overlay still fuzzy' => [
378 ['value' => 'Hallo'], ['value' => 'Hallo', 'original' => 'Hello', 'fuzzy' => true], 'Hallo', null,
379 ],
380 ];
381 }

◆ testALegacyEntryWithTheModuleAsMsgctxtIsMigratedToNoContextPreservingItsBookkeeping()

MigratedLanguageFileSyncDeltaTest::testALegacyEntryWithTheModuleAsMsgctxtIsMigratedToNoContextPreservingItsBookkeeping ( bool  $refresh)

An overlay of an earlier version carried the module as msgctxt on every entry (see seedOverlay()); the next write must migrate it to the msgctxt-less shape (TranslationEntry::withContext(null)) while preserving translation, comments, flags, "local_change" and "original".

Definition at line 236 of file MigratedLanguageFileSyncDeltaTest.php.

236 : void
237 {
238 $this->seedShipped(['greeting' => 'Hallo']);
239 $legacy_overlay = MigratedPoFixture::catalog(self::MODULE, [
240 'greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z'],
241 ]);
242 $legacy_overlay->find(self::MODULE, 'greeting')->addExtractedComment('shown on the login page');
243 MigratedPoFixture::writePair($this->overlayBase(), $legacy_overlay);
244 $this->assertNotNull($this->overlayPo()->find(self::MODULE, 'greeting'), 'precondition: seeded with the module as msgctxt');
245
246 // a genuine local change is kept alive by re-sending the exact same value
247 $this->sync(['greeting' => 'Servus'], $refresh);
248
249 $this->assertNull($this->overlayPo()->find(self::MODULE, 'greeting'), 'no longer stored under the module context');
250 $migrated = $this->overlayPo()->find(null, 'greeting');
251 $this->assertNotNull($migrated);
252 $this->assertSame('Servus', $migrated->getTranslation());
253 $this->assertSame('Hallo', LocalChangeComments::getOriginal($migrated));
254 $this->assertSame('2020-01-01T00:00:00Z', LocalChangeComments::getLocalChange($migrated));
255 if (!$refresh) {
256 // refresh=true re-baselines extracted comments from the shipped entry (which has none
257 // here) - only an ordinary admin edit (refresh=false) keeps the overlay's own comment
258 $this->assertSame(['shown on the login page'], $migrated->getExtractedComments());
259 }
260 }
sync(array $entries, bool $refresh=false, ?string $client_data_dir='default')
seedShipped(array $entries, string $lang_key='de', string $module=self::MODULE)
static writePair(string $base_path, TranslationCatalog $catalog)
Writes "<base>.po" and, like MigratedLanguageFileSync::sync(), its compiled revision named by current...
static catalog(string $module, array $entries)

References MigratedPoFixture\catalog(), MigratedLanguageFileSyncTestCase\overlayBase(), MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedShipped(), MigratedLanguageFileSyncTestCase\sync(), and MigratedPoFixture\writePair().

+ Here is the call graph for this function:

◆ testALegacyFullOverlayShrinksToTheDeltaOnTheNextReconcilingWrite()

MigratedLanguageFileSyncDeltaTest::testALegacyFullOverlayShrinksToTheDeltaOnTheNextReconcilingWrite ( )

An overlay written by the pre-delta design carried EVERY entry of the module.

The next reconciling write (Setup update) must shrink it to the true delta in one sync(): entries equal to the shipped value without local_change are dropped, a genuine local change survives - no dedicated migration step.

Definition at line 267 of file MigratedLanguageFileSyncDeltaTest.php.

267 : void
268 {
269 $this->seedShipped(['unchanged_one' => 'A', 'unchanged_two' => 'B', 'changed' => 'C']);
270 // A full overlay as an old version would have written it: every entry present, most of them
271 // carrying exactly the shipped value with no local_change at all.
272 $this->seedOverlay([
273 'unchanged_one' => ['value' => 'A', 'original' => 'A'],
274 'unchanged_two' => ['value' => 'B', 'original' => 'B'],
275 'changed' => ['value' => 'C, lokal', 'original' => 'C', 'local_change' => '2020-01-01T00:00:00Z'],
276 ]);
277
278 $this->sync(['unchanged_one' => 'A', 'unchanged_two' => 'B', 'changed' => 'C, lokal'], true);
279
280 $this->assertSame(['changed'], $this->overlayIdentifiers());
281 $this->assertSame(
282 '2020-01-01T00:00:00Z',
283 LocalChangeComments::getLocalChange($this->overlayPo()->find(null, 'changed'))
284 );
285 }
seedOverlay(array $entries, string $lang_key='de')

References MigratedLanguageFileSyncTestCase\overlayIdentifiers(), MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testAnAdminEditNeverMovesTheOriginal()

MigratedLanguageFileSyncDeltaTest::testAnAdminEditNeverMovesTheOriginal ( )

refresh = false (an ordinary admin edit): the baseline "original" must never move - even when the shipped file changed in the meantime.

Definition at line 157 of file MigratedLanguageFileSyncDeltaTest.php.

157 : void
158 {
159 $this->seedShipped(['greeting' => 'Hallo, neu']);
160 $this->seedOverlay(['greeting' => ['value' => 'Hallo', 'original' => 'Hallo']]);
161
162 $this->sync(['greeting' => 'Servus']);
163
164 $greeting = $this->overlayPo()->find(null, 'greeting');
165 $this->assertSame('Servus', $greeting->getTranslation());
166 $this->assertSame('Hallo', LocalChangeComments::getOriginal($greeting));
167 $this->assertNotNull(LocalChangeComments::getLocalChange($greeting));
168 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testAnAdminEditRemovesFuzzyOnlyFromTheValuesItActuallyChanges()

MigratedLanguageFileSyncDeltaTest::testAnAdminEditRemovesFuzzyOnlyFromTheValuesItActuallyChanges ( )

Definition at line 170 of file MigratedLanguageFileSyncDeltaTest.php.

170 : void
171 {
172 $this->seedShipped([
173 'kept' => ['value' => 'Hello', 'fuzzy' => true],
174 'edited' => ['value' => 'Bye', 'fuzzy' => true],
175 ]);
176 $this->seedOverlay([
177 'kept' => ['value' => 'Hello', 'original' => 'Hello', 'fuzzy' => true],
178 'edited' => ['value' => 'Bye', 'original' => 'Bye', 'fuzzy' => true],
179 ]);
180
181 $this->sync(['kept' => 'Hello', 'edited' => 'Tschüss']);
182
183 // the kept shipped value (fuzzy in the shipped .po) leaves the overlay, the edited one is no longer fuzzy
184 $overlay = $this->overlayPo();
185 $this->assertNull($overlay->find(null, 'kept'));
186 $this->assertFalse($overlay->find(null, 'edited')->hasFlag('fuzzy'));
187 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testCreatingTheOverlayGivesAnEntryWithoutShippedCounterpartNoOriginalButALocalChange()

MigratedLanguageFileSyncDeltaTest::testCreatingTheOverlayGivesAnEntryWithoutShippedCounterpartNoOriginalButALocalChange ( )

Definition at line 75 of file MigratedLanguageFileSyncDeltaTest.php.

75 : void
76 {
77 $this->seedShipped(['greeting' => 'Hallo']);
78
79 $this->sync(['greeting' => 'Hallo', 'custom' => 'Eigener Wert']);
80
81 $custom = $this->overlayPo()->find(null, 'custom');
82 $this->assertSame('Eigener Wert', $custom->getTranslation());
83 $this->assertNull(LocalChangeComments::getOriginal($custom));
84 $this->assertNotNull(LocalChangeComments::getLocalChange($custom));
85 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testCreatingTheOverlayKeepsShippedFuzzyOnlyForTheUnchangedShippedValue()

MigratedLanguageFileSyncDeltaTest::testCreatingTheOverlayKeepsShippedFuzzyOnlyForTheUnchangedShippedValue ( )

A shipped "fuzzy" (an unreviewed value, usually the English fallback) must survive the very first sync as long as the value is still the shipped one - and must not be copied onto a value that differs from it.

Definition at line 92 of file MigratedLanguageFileSyncDeltaTest.php.

92 : void
93 {
94 $this->seedShipped([
95 'unchanged' => ['value' => 'Hello', 'fuzzy' => true],
96 'changed' => ['value' => 'Bye', 'fuzzy' => true],
97 'reviewed' => ['value' => 'Hallo'],
98 ]);
99
100 $this->sync(['unchanged' => 'Hello', 'changed' => 'Tschüss', 'reviewed' => 'Hallo']);
101
102 // the shipped values (and their fuzzy flag) stay in the shipped .po, only the changed value enters the overlay
103 // - never fuzzy
104 $overlay = $this->overlayPo();
105 $this->assertNull($overlay->find(null, 'unchanged'));
106 $this->assertFalse($overlay->find(null, 'changed')->hasFlag('fuzzy'));
107 $this->assertNull($overlay->find(null, 'reviewed'));
108 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testCreatingTheOverlayWithADeviatingValueRecordsShippedOriginalAndALocalChange()

MigratedLanguageFileSyncDeltaTest::testCreatingTheOverlayWithADeviatingValueRecordsShippedOriginalAndALocalChange ( )

Definition at line 60 of file MigratedLanguageFileSyncDeltaTest.php.

60 : void
61 {
62 $this->seedShipped(['greeting' => 'Hallo']);
63
64 $this->sync(['greeting' => 'Servus']);
65
66 $greeting = $this->overlayPo()->find(null, 'greeting');
67 $this->assertSame('Servus', $greeting->getTranslation());
68 $this->assertSame('Hallo', LocalChangeComments::getOriginal($greeting));
69 $this->assertMatchesRegularExpression(
70 '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/',
71 (string) LocalChangeComments::getLocalChange($greeting)
72 );
73 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testEntriesAreWrittenSortedByIdentifier()

MigratedLanguageFileSyncDeltaTest::testEntriesAreWrittenSortedByIdentifier ( )

Sorted byte-wise by identifier, independent of the order of $entries - keeps the file diff-stable.

SORT_STRING: upper case before lower case, "10" before "9".

Definition at line 434 of file MigratedLanguageFileSyncDeltaTest.php.

434 : void
435 {
436 $this->seedShipped(['b' => 'B']);
437
438 $this->sync(['b' => 'B', 'a' => 'A', 'C' => 'C', '9' => 'neun', '10' => 'zehn']);
439
440 // "b" carries the shipped value and is not written
441 $this->assertSame(['10', '9', 'C', 'a'], $this->overlayIdentifiers());
442 }

◆ testEntriesOfAnotherContextInTheOldOverlayAreNotCarriedOver()

MigratedLanguageFileSyncDeltaTest::testEntriesOfAnotherContextInTheOldOverlayAreNotCarriedOver ( )

Entries of a different context (another module) are never taken over into this module's overlay: the overlay holds exactly $entries.

Definition at line 416 of file MigratedLanguageFileSyncDeltaTest.php.

416 : void
417 {
418 $this->seedShipped(['greeting' => 'Hallo']);
419 $this->seedOverlay([
420 'greeting' => ['value' => 'Hallo', 'original' => 'Hallo'],
421 'foreign' => ['value' => 'Fremd', 'context' => 'other_module'],
422 ]);
423
424 // a local change keeps an overlay to look into (delta)
425 $this->sync(['greeting' => 'Servus']);
426
427 $this->assertNull($this->overlayPo()->find('other_module', 'foreign'));
428 }

◆ testRefreshKeepsTheOriginalOfAnEntryTheShippedPoNoLongerContains()

MigratedLanguageFileSyncDeltaTest::testRefreshKeepsTheOriginalOfAnEntryTheShippedPoNoLongerContains ( )

An entry the shipped .po no longer contains (kept by the caller as a real local change, see LanguageInstallationManager::resolveMigratedModule()) keeps its last "original" and its local_change date - so a later update can still tell it from an unchanged entry.

Definition at line 322 of file MigratedLanguageFileSyncDeltaTest.php.

322 : void
323 {
324 $this->seedShipped(['greeting' => 'Hallo']);
325 $this->seedOverlay([
326 'greeting' => ['value' => 'Hallo', 'original' => 'Hallo'],
327 'dropped' => ['value' => 'Neu', 'original' => 'Alt', 'local_change' => '2020-01-01T00:00:00Z'],
328 ]);
329
330 $this->sync(['greeting' => 'Hallo', 'dropped' => 'Neu'], true);
331
332 $dropped = $this->overlayPo()->find(null, 'dropped');
333 $this->assertSame('Alt', LocalChangeComments::getOriginal($dropped));
334 $this->assertSame('2020-01-01T00:00:00Z', LocalChangeComments::getLocalChange($dropped));
335 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testRefreshMovesTheOriginalButKeepsALocalCustomizationFlagged()

MigratedLanguageFileSyncDeltaTest::testRefreshMovesTheOriginalButKeepsALocalCustomizationFlagged ( )

Definition at line 302 of file MigratedLanguageFileSyncDeltaTest.php.

302 : void
303 {
304 $this->seedShipped(['greeting' => 'Hallo, überarbeitet']);
305 $this->seedOverlay([
306 'greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z'],
307 ]);
308
309 $this->sync(['greeting' => 'Servus'], true);
310
311 $greeting = $this->overlayPo()->find(null, 'greeting');
312 $this->assertSame('Servus', $greeting->getTranslation());
313 $this->assertSame('Hallo, überarbeitet', LocalChangeComments::getOriginal($greeting));
314 $this->assertSame('2020-01-01T00:00:00Z', LocalChangeComments::getLocalChange($greeting));
315 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testRefreshMovesTheOriginalToTheNewShippedValueAndClearsTheLocalChangeOfAnUnmodifiedEntry()

MigratedLanguageFileSyncDeltaTest::testRefreshMovesTheOriginalToTheNewShippedValueAndClearsTheLocalChangeOfAnUnmodifiedEntry ( )

Definition at line 287 of file MigratedLanguageFileSyncDeltaTest.php.

287 : void
288 {
289 $this->seedShipped(['greeting' => 'Hallo, überarbeitet']);
290 $this->seedOverlay(['greeting' => ['value' => 'Hallo', 'original' => 'Hallo']]);
291
292 $this->sync(['greeting' => 'Hallo, überarbeitet'], true);
293
294 // the new shipped value is served from the shipped .po, the outdated overlay entry is removed
295 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
296 $this->assertSame(
297 ['value' => 'Hallo, überarbeitet', 'local_change' => false, 'local_change_date' => null, 'original' => 'Hallo, überarbeitet'],
298 MigratedLanguageFileSync::loadModuleTranslations($this->manager, 'de', self::MODULE, $this->client_data_dir)['greeting']
299 );
300 }

References MigratedLanguageFileSyncTestCase\overlayBase(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testRefreshRecomputesFuzzyFromTheShippedEntry()

MigratedLanguageFileSyncDeltaTest::testRefreshRecomputesFuzzyFromTheShippedEntry ( array  $shipped,
array  $overlay,
string  $value,
?bool  $expected_fuzzy 
)

On refresh fuzzy is recomputed from the shipped file: set exactly when the value is the shipped value and the shipped entry is fuzzy.

Parameters
array<string,mixed>$shipped
array<string,mixed>$overlay

Definition at line 345 of file MigratedLanguageFileSyncDeltaTest.php.

350 : void {
351 $this->seedShipped(['greeting' => $shipped]);
352 $this->seedOverlay(['greeting' => $overlay]);
353
354 $this->sync(['greeting' => $value], true);
355
356 // `null`: the value is the shipped one, so the entry (and its fuzzy flag) lives in the shipped .po only and the
357 // overlay is removed
358 if ($expected_fuzzy === null) {
359 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
360 return;
361 }
362 $this->assertSame($expected_fuzzy, $this->overlayPo()->find(null, 'greeting')->hasFlag('fuzzy'));
363 }

◆ testReplaceSemanticsRemoveEveryEntryThatIsNotPassed()

MigratedLanguageFileSyncDeltaTest::testReplaceSemanticsRemoveEveryEntryThatIsNotPassed ( )

Definition at line 383 of file MigratedLanguageFileSyncDeltaTest.php.

383 : void
384 {
385 $this->seedShipped(['greeting' => 'Hallo', 'farewell' => 'Tschüss']);
386 // local changes, since shipped values are never in the overlay
387 $this->seedOverlay([
388 'greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z'],
389 'farewell' => ['value' => 'Pfiat di', 'original' => 'Tschüss', 'local_change' => '2020-01-01T00:00:00Z'],
390 ]);
391
392 $this->sync(['greeting' => 'Servus']);
393
394 $this->assertSame(['greeting'], $this->overlayIdentifiers());
395 $this->assertSame(['greeting' => 'Servus'], MigratedPoFixture::readMo(MigratedPoFixture::overlayMo($this->overlayBase())));
396 }
static readMo(string $file)
static overlayMo(string $base_path)
The compiled catalog of the revision current names; a non-existing path if there is none.

References MigratedPoFixture\overlayMo(), and MigratedPoFixture\readMo().

+ Here is the call graph for this function:

◆ testSyncingNoEntriesRemovesTheOverlayButKeepsTheShippedFile()

MigratedLanguageFileSyncDeltaTest::testSyncingNoEntriesRemovesTheOverlayButKeepsTheShippedFile ( )

An empty delta removes the overlay files - the shipped file and the lock file are kept.

Definition at line 399 of file MigratedLanguageFileSyncDeltaTest.php.

399 : void
400 {
401 $this->seedShipped(['greeting' => 'Hallo']);
402 $this->seedOverlay(['greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z']]);
403
404 $this->sync([]);
405
406 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
407 $this->assertFileDoesNotExist(MigratedPoFixture::overlayMo($this->overlayBase()));
408 $this->assertFileExists(MigratedPoFixture::overlayLock($this->overlayBase()), 'the lock file is only removed on uninstall');
409 $this->assertNotNull(MigratedPoFixture::readPo($this->shippedPo())->find(self::MODULE, 'greeting'));
410 }
shippedPo(string $lang_key='de', string $module=self::MODULE)
static overlayLock(string $base_path)
static readPo(string $file)

References MigratedPoFixture\overlayLock(), MigratedPoFixture\overlayMo(), and MigratedPoFixture\readPo().

+ Here is the call graph for this function:

◆ testSyncingOnlyShippedValuesWritesNoOverlay()

MigratedLanguageFileSyncDeltaTest::testSyncingOnlyShippedValuesWritesNoOverlay ( bool  $refresh)

A module whose values are all shipped ones needs no overlay: neither file, lock nor directory is created, by an admin edit or a reconciling write.

Definition at line 41 of file MigratedLanguageFileSyncDeltaTest.php.

41 : void
42 {
43 $this->seedShipped(['greeting' => 'Hallo', 'farewell' => 'Tschüss']);
44 $shipped_before = file_get_contents($this->shippedPo());
45
46 $this->sync(['greeting' => 'Hallo', 'farewell' => 'Tschüss'], $refresh);
47
48 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
49 $this->assertFileDoesNotExist(MigratedPoFixture::overlayMo($this->overlayBase()));
50 $this->assertFileDoesNotExist(MigratedPoFixture::overlayLock($this->overlayBase()));
51 $this->assertDirectoryDoesNotExist(dirname($this->overlayBase()));
52 $this->assertSame($shipped_before, file_get_contents($this->shippedPo()), 'the shipped .po is never written');
53 }

References MigratedLanguageFileSyncTestCase\overlayBase(), MigratedPoFixture\overlayLock(), MigratedPoFixture\overlayMo(), MigratedLanguageFileSyncTestCase\seedShipped(), MigratedLanguageFileSyncTestCase\shippedPo(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testTheDeltaIsComparedAgainstTheRawShippedValueNotTheMarkupCleanedOne()

MigratedLanguageFileSyncDeltaTest::testTheDeltaIsComparedAgainstTheRawShippedValueNotTheMarkupCleanedOne ( )

The delta is compared against the RAW shipped .po value (TranslationCatalog::fromPoFile()), not the markup- cleaned value the build serves: a value with markup TranslationMarkupPolicy disallows is still the shipped value, so writing it back creates no delta.

Definition at line 115 of file MigratedLanguageFileSyncDeltaTest.php.

115 : void
116 {
117 $this->seedShipped(['greeting' => '<script>alert(1)</script>Hallo']);
118
119 $this->sync(['greeting' => '<script>alert(1)</script>Hallo']);
120
121 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
122 }

References MigratedLanguageFileSyncTestCase\overlayBase(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testTheLocalChangeTimestampOfAnUntouchedEntrySurvivesAnUnrelatedWrite()

MigratedLanguageFileSyncDeltaTest::testTheLocalChangeTimestampOfAnUntouchedEntrySurvivesAnUnrelatedWrite ( )

A full-replace write re-sends every value; an entry whose value did not change must keep its existing local_change timestamp (seeded with a fixed, old value - no sleep()/clock needed).

Definition at line 213 of file MigratedLanguageFileSyncDeltaTest.php.

213 : void
214 {
215 $this->seedShipped(['greeting' => 'Hallo', 'farewell' => 'Tschüss']);
216 $this->seedOverlay([
217 'greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z'],
218 'farewell' => ['value' => 'Tschüss', 'original' => 'Tschüss'],
219 ]);
220
221 $this->sync(['greeting' => 'Servus', 'farewell' => 'Pfiat di']);
222
223 $overlay = $this->overlayPo();
224 $this->assertSame('2020-01-01T00:00:00Z', LocalChangeComments::getLocalChange($overlay->find(null, 'greeting')));
225 $farewell_change = LocalChangeComments::getLocalChange($overlay->find(null, 'farewell'));
226 $this->assertNotNull($farewell_change);
227 $this->assertNotSame('2020-01-01T00:00:00Z', $farewell_change);
228 }

References MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

◆ testTheOverlayTakesTheExtractedCommentsOfTheShippedEntry()

MigratedLanguageFileSyncDeltaTest::testTheOverlayTakesTheExtractedCommentsOfTheShippedEntry ( )

Extracted comments ("#. ...", context for translators) are part of the shipped file and are carried into the overlay on creation/refresh.

Definition at line 128 of file MigratedLanguageFileSyncDeltaTest.php.

128 : void
129 {
130 $catalog = MigratedPoFixture::catalog(self::MODULE, ['greeting' => 'Hallo']);
131 $catalog->find(self::MODULE, 'greeting')->addExtractedComment('shown on the login page');
132 MigratedPoFixture::writePo($this->shippedPo(), $catalog);
133
134 $this->sync(['greeting' => 'Servus']);
135
136 $this->assertSame(['shown on the login page'], $this->overlayPo()->find(null, 'greeting')->getExtractedComments());
137 }
static writePo(string $file, TranslationCatalog $catalog)

References MigratedPoFixture\catalog(), MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\shippedPo(), MigratedLanguageFileSyncTestCase\sync(), and MigratedPoFixture\writePo().

+ Here is the call graph for this function:

◆ testTheOverlayTakesTheHeadersOfTheShippedPo()

MigratedLanguageFileSyncDeltaTest::testTheOverlayTakesTheHeadersOfTheShippedPo ( )

Definition at line 139 of file MigratedLanguageFileSyncDeltaTest.php.

139 : void
140 {
141 $catalog = MigratedPoFixture::catalog(self::MODULE, ['greeting' => 'Hallo']);
142 $catalog->setHeader('Language', 'de');
143 $catalog->setHeader('Plural-Forms', 'nplurals=2; plural=(n != 1);');
144 MigratedPoFixture::writePo($this->shippedPo(), $catalog);
145
146 // a local change - with only shipped values there is no overlay (delta)
147 $this->sync(['greeting' => 'Servus']);
148
149 $this->assertSame('de', $this->overlayPo()->getHeader('Language'));
150 $this->assertSame('nplurals=2; plural=(n != 1);', $this->overlayPo()->getHeader('Plural-Forms'));
151 }

References MigratedPoFixture\catalog(), MigratedLanguageFileSyncTestCase\overlayPo(), MigratedLanguageFileSyncTestCase\shippedPo(), MigratedLanguageFileSyncTestCase\sync(), and MigratedPoFixture\writePo().

+ Here is the call graph for this function:

◆ testWritingTheOriginalValueBackClearsTheLocalChange()

MigratedLanguageFileSyncDeltaTest::testWritingTheOriginalValueBackClearsTheLocalChange ( )

Definition at line 189 of file MigratedLanguageFileSyncDeltaTest.php.

189 : void
190 {
191 $this->seedShipped(['greeting' => 'Hallo']);
192 $this->seedOverlay([
193 'greeting' => ['value' => 'Servus', 'original' => 'Hallo', 'local_change' => '2020-01-01T00:00:00Z'],
194 ]);
195
196 $this->sync(['greeting' => 'Hallo']);
197
198 // the shipped value again is no local change: the entry, and with it the now empty overlay, is removed
199 $this->assertFileDoesNotExist($this->overlayBase() . '.po');
200 $this->assertFileDoesNotExist(MigratedPoFixture::overlayMo($this->overlayBase()));
201 $this->assertFalse(MigratedLanguageFileSync::loadModuleTranslations(
202 $this->manager,
203 'de',
204 self::MODULE,
205 $this->client_data_dir
206 )['greeting']['local_change']);
207 }

References MigratedLanguageFileSyncTestCase\overlayBase(), MigratedPoFixture\overlayMo(), MigratedLanguageFileSyncTestCase\seedOverlay(), MigratedLanguageFileSyncTestCase\seedShipped(), and MigratedLanguageFileSyncTestCase\sync().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: