ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncFindModulesWithOverlayTest.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
24use PHPUnit\Framework\Attributes\DataProvider;
25
28{
29 private function touch(string $relative): void
30 {
31 $file = $this->client_data_dir . '/lang/' . $relative;
32 if (!is_dir(dirname($file))) {
33 mkdir(dirname($file), 0775, true);
34 }
35 file_put_contents($file, 'x');
36 }
37
41 public static function overlayMarkers(): array
42 {
43 return [
44 'current' => ['current', true],
45 'po' => ['zmod_de.po', true],
46 'only the lock' => ['zmod_de.lock', false],
47 'only the mo' => ['zmod_de.mo', false],
48 ];
49 }
50
51 #[DataProvider('overlayMarkers')]
52 public function testOnlyCurrentOrAPoMakesAnOverlay(string $file, bool $is_overlay): void
53 {
54 $this->touch('zmod/de/' . $file);
55
56 $this->assertSame($is_overlay ? ['zmod'] : [], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
57 }
58
60 {
61 $this->touch('zmod/de/current');
62 $this->touch('amod/de/amod_de.po');
63 $this->touch('fmod/fr/current');
64
65 $this->assertSame(['amod', 'zmod'], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
66 $this->assertSame(['fmod'], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'fr'));
67 }
68
71 {
72 MigratedLanguageFileSync::markLocalChangesTakenOver($this->client_data_dir, 'de', ['zmod']);
73 $this->touch('.locks/de/current');
74 $this->touch('.locks/de/x.po');
75
76 $this->assertFileExists(MigratedLanguageFilePaths::takenOverFile($this->client_data_dir, 'de'));
77 $this->assertSame([], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
78 }
79
80 public function testSymbolicLinksAreNotFollowed(): void
81 {
82 $outside = sys_get_temp_dir() . '/ilias_find_overlay_outside_' . bin2hex(random_bytes(4));
83 mkdir($outside . '/de', 0775, true);
84 file_put_contents($outside . '/de/current', 'x');
85 try {
86 mkdir($this->client_data_dir . '/lang/linkedmod', 0775, true);
87 symlink($outside . '/de', $this->client_data_dir . '/lang/linkedmod/de');
88 symlink($outside, $this->client_data_dir . '/lang/linkedmodule');
89 mkdir($this->client_data_dir . '/lang/linkedcurrent/de', 0775, true);
90 symlink($outside . '/missing', $this->client_data_dir . '/lang/linkedcurrent/de/current');
91
92 $this->assertSame(['linkedcurrent'], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
93 } finally {
95 }
96 }
97
99 {
100 $this->touch('zmod/de/current');
101
102 $this->assertSame([], MigratedLanguageFileSync::findModulesWithOverlay(null, 'de'));
103 $this->assertSame([], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, '../de'));
104 $this->assertSame([], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir . '/missing', 'de'));
105 }
106
109 {
110 $this->touch('amod/de/current');
111 mkdir($this->client_data_dir . '/lang/zmod/de', 0775, true);
112 chmod($this->client_data_dir . '/lang/zmod/de', 0000);
113 try {
114 if (is_readable($this->client_data_dir . '/lang/zmod/de')) {
115 $this->markTestSkipped('permissions are not enforced (root)');
116 }
117 $this->assertSame(['amod', 'zmod'], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
118
119 chmod($this->client_data_dir . '/lang', 0000);
120 $this->assertSame([], MigratedLanguageFileSync::findModulesWithOverlay($this->client_data_dir, 'de'));
121 } finally {
122 chmod($this->client_data_dir . '/lang', 0775);
123 chmod($this->client_data_dir . '/lang/zmod/de', 0775);
124 }
125 }
126}
The single place that knows where the files of a module migrated to PO/MO live:
Reads the shipped .po of a migrated module and maintains its per-installation overlay: the ....
findModulesWithOverlay(): only current or a .po in lang/<module>/<lang>/ counts, nothing else below l...
testLocksAndTheTakenOverRecordAreNoModules()
The lock directory and the record sit next to the module directories and are no modules.
testUnreadableDirectoriesCountAsOverlayOrFindNothing()
An unreadable module directory counts as overlay, an unreadable overlay root finds nothing.
Fixtures of the MigratedLanguageFileSync tests.
static removeDirectory(string $directory)