ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
LanguageInstallationManagerDuplicateIdentifiersTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
30 {
31 $this->expectManagerWarning();
32 $this->writeLang('lang/ilias_de.lang', ['common#:#yes#:#Ja']);
33 $this->writeLang('lang/customizing/ilias_de.lang.local', ['common#:#yes#:#Jawohl', 'common#:#dup#:#Eigen']);
34 $this->duplicate_rows = [['module' => 'other', 'identifier' => 'dup']];
35
36 $manager = $this->manager();
37 $unwritten = $manager->insertLanguageForInstallation('de');
38
39 $this->assertSame([], $unwritten, 'a skipped entry is no unwritten overlay');
40 $this->assertSame('Jawohl', $this->lngModules()['common']['yes']);
41 $this->assertArrayNotHasKey('dup', $this->lngModules()['common'], 'the entry is not applied');
42 $this->assertSame(['de' => ['common#:#dup' => ['other: dup']]], $manager->getSkippedDuplicateEntries());
43 $this->assertStringContainsString('common#:#dup', $this->loggedWarnings());
44 }
45
47 {
48 $this->expectManagerWarning();
49 $this->writeLang('lang/ilias_de.lang', ['common#:#yes#:#Ja']);
50 $this->writeLang('lang/customizing/ilias_de.lang.local', ['common#:#dup#:#Eigen']);
51 $this->duplicate_rows = [['module' => 'other', 'identifier' => 'dup']];
52 $manager = $this->manager();
53 $manager->insertLanguageForInstallation('de');
54 $this->assertNotSame([], $manager->getSkippedDuplicateEntries(), 'precondition');
55
56 $this->duplicate_rows = [];
57 $manager->insertLanguageForInstallation('de');
58
59 $this->assertSame([], $manager->getSkippedDuplicateEntries());
60 $this->assertSame('Eigen', $this->lngModules()['common']['dup']);
61 }
62
65 {
66 $this->writeLang('lang/ilias_de.lang', ['common#:#dup#:#Shipped']);
67 $this->writeLang('lang/customizing/ilias_de.lang.local', ['common#:#dup#:#Eigen']);
68 $this->duplicate_rows = [['module' => 'other', 'identifier' => 'dup'], ['module' => 'common', 'identifier' => 'dup']];
69
70 $manager = $this->manager();
71 $manager->insertLanguageForInstallation('de');
72
73 $this->assertSame([], $manager->getSkippedDuplicateEntries());
74 $this->assertSame('Eigen', $this->lngModules()['common']['dup']);
75 }
76
84 #[\PHPUnit\Framework\Attributes\DataProvider('entriesOfTheSameRun')]
85 public function testEntriesOfTheSameRunCountAsExisting(array $shipped_lang_lines, ?array $shipped_po, string $expected_duplicate): void
86 {
87 $this->expectManagerWarning();
88 $this->writeLang('lang/ilias_de.lang', $shipped_lang_lines);
89 if ($shipped_po !== null) {
90 $this->shipPo($shipped_po);
91 }
92 $this->writeLang('lang/customizing/ilias_de.lang.local', ['common#:#dup#:#Eigen']);
93
94 $manager = $this->manager();
95 $manager->insertLanguageForInstallation('de');
96
97 $this->assertSame(['de' => ['common#:#dup' => [$expected_duplicate]]], $manager->getSkippedDuplicateEntries());
98 $this->assertArrayNotHasKey('dup', $this->lngModules()['common'] ?? []);
99 }
100
102 public static function entriesOfTheSameRun(): array
103 {
104 return [
105 'a line of the shipped language file' => [['other#:#dup#:#Shipped'], null, 'other: dup'],
106 'another spelling in the shipped language file' => [['other#:#DUP#:#Shipped'], null, 'other: DUP'],
107 'an entry of a shipped .po' => [['common#:#yes#:#Ja'], ['dup' => 'Aus der PO'], 'pilot: dup'],
108 ];
109 }
110
112 {
113 $this->expectManagerWarning();
114 $this->shipPo(['greeting' => 'Hallo']);
115 $this->shipSecondModule(['farewell' => 'Tschüss']);
116 $this->writeLang('lang/customizing/ilias_de.lang.local', ['pilot#:#extra#:#Eigen']);
117 $this->duplicate_rows = [['module' => 'other', 'identifier' => 'extra']];
118 $manager = $this->manager();
119
120 $manager->insertLanguageForInstallation('de');
121
122 $this->assertSame(['pilot2'], $this->takenOver());
123 $this->assertArrayHasKey('pilot#:#extra', $manager->getSkippedDuplicateEntries()['de'] ?? []);
124
125 $this->duplicate_rows = [];
126 $manager->insertLanguageForInstallation('de');
127
128 $this->assertSame([self::MODULE, 'pilot2'], $this->takenOver());
129 }
130
132 private function takenOver(): array
133 {
134 return MigratedLanguageFileSync::modulesWithLocalChangesTakenOver($this->root . '/client-data', 'de');
135 }
136}
Reads the shipped .po of a migrated module and maintains its per-installation overlay: the ....
A line of the customizing file whose identifier exists in another module or in another spelling is le...
testEntriesOfTheSameRunCountAsExisting(array $shipped_lang_lines, ?array $shipped_po, string $expected_duplicate)
lng_data is emptied before an installation, so what this run writes besides counts as existing: the l...
testAnOldCollisionOfTheOwnModuleIsApplied()
An old collision stays editable: the own module holds the identifier in this very spelling.
Fixtures of the LanguageInstallationManager tests for modules migrated to PO/MO ("pilot").
shipSecondModule(array $entries)
A second migrated module "pilot2" next to "pilot".
manager(?\Closure $client_data_dir_resolver=null, ?\Closure $language_cache_invalidator=null, bool $with_resolver=true, bool $with_logger=true, ?LoggerInterface $logger=null)