ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncUnwritableTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28use PHPUnit\Framework\Attributes\DataProvider;
29use PHPUnit\Framework\TestCase;
30
35{
38 {
39 $this->seedShipped(['greeting' => 'Hallo']);
40 mkdir(dirname($this->overlayDirectory()), 0775, true);
41 file_put_contents($this->overlayDirectory(), 'not a directory');
42
43 $this->assertSame([$this->overlayDirectory()], $this->findUnwritable());
44 }
45
48 {
49 $this->seedShipped(['greeting' => 'Hallo']);
50 file_put_contents($this->client_data_dir . '/lang', 'not a directory');
51
52 $this->assertSame([$this->overlayDirectory()], $this->findUnwritable());
53 }
54
59 #[DataProvider('danglingSymlinkPositions')]
60 public function testADanglingSymlinkInTheOverlayPathIsReported(\Closure $link_path): void
61 {
62 $this->seedShipped(['greeting' => 'Hallo']);
63 $link = $link_path($this);
64 if (!is_dir(dirname($link))) {
65 mkdir(dirname($link), 0775, true);
66 }
67 symlink($this->client_data_dir . '/does-not-exist', $link);
68
69 $this->assertSame([$this->overlayDirectory()], $this->findUnwritable());
70 }
71
75 public static function danglingSymlinkPositions(): array
76 {
77 return [
78 'the overlay directory' => [static fn(self $test): string => $test->overlayDirectory()],
79 'a parent ("lang")' => [static fn(self $test): string => $test->client_data_dir . '/lang'],
80 ];
81 }
82
85 {
86 $this->seedShipped(['greeting' => 'Hallo']);
87 mkdir($this->client_data_dir . '/elsewhere');
88 symlink($this->client_data_dir . '/elsewhere', $this->client_data_dir . '/lang');
89
90 $this->assertSame([], $this->findUnwritable());
91 }
92
95 {
96 $this->seedShipped(['greeting' => 'Hallo']);
97
98 $this->assertDirectoryDoesNotExist($this->client_data_dir . '/lang');
99 $this->assertSame([], $this->findUnwritable());
100 $this->assertDirectoryDoesNotExist($this->client_data_dir . '/lang', 'the check itself creates nothing');
101 }
102
104 {
105 $this->seedShipped(['greeting' => 'Hallo']);
106
107 $this->assertSame([], $this->findUnwritable(['de'], $this->client_data_dir . '/not-yet-created'));
108 }
109
111 {
112 $this->seedShipped(['greeting' => 'Hallo']);
113 mkdir($this->overlayDirectory(), 0775, true);
114
115 $this->assertSame([], $this->findUnwritable());
116 }
117
119 {
120 $this->seedShipped(['greeting' => 'Hallo']);
121 file_put_contents($this->client_data_dir . '/lang', 'not a directory');
122
123 $this->assertSame([], $this->findUnwritable(['de'], null));
124 }
125
131 {
132 $this->seedShipped(['greeting' => 'Hello'], 'en');
133 file_put_contents($this->client_data_dir . '/lang', 'not a directory');
134
135 $this->assertSame([], $this->findUnwritable(['de']));
136 $this->assertSame([$this->client_data_dir . '/lang/' . self::MODULE . '/en'], $this->findUnwritable(['de', 'en']));
137 }
138
143 {
144 $second = MigratedPoFixture::directory('stwo', 'components/ILIAS/Language/tests/ComponentTranslation/' . basename($this->fixture_directory) . '/sub/');
145 $manager = new LanguageFileDirectoryManager(new CustomizingLanguageFileDirectory(), $this->directory, $second);
146 $this->seedShipped(['greeting' => 'Hallo'], 'de');
147 $this->seedShipped(['greeting' => 'Hello'], 'en');
149 $this->fixture_directory . '/sub/stwo_de.po',
150 MigratedPoFixture::catalog('stwo', ['x' => 'y'])
151 );
152 file_put_contents($this->client_data_dir . '/lang', 'not a directory');
153
154 $this->assertSame(
155 [
156 $this->client_data_dir . '/lang/' . self::MODULE . '/de',
157 $this->client_data_dir . '/lang/stwo/de',
158 $this->client_data_dir . '/lang/' . self::MODULE . '/en',
159 ],
160 $this->findUnwritable(['de', 'en', 'de'], 'default', $manager)
161 );
162 }
163}
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 ....
Fixtures of the MigratedLanguageFileSync tests.
seedShipped(array $entries, string $lang_key='de', string $module=self::MODULE)
findUnwritable(array $lang_keys=['de'], ?string $client_data_dir='default', ?LanguageFileDirectoryManager $manager=null)
MigratedLanguageFileSync::findUnwritableOverlayDirectories().
testASymlinkToAWritableDirectoryIsNotReported()
A symlink to an existing writable directory is fine (e.g.
testAFileInPlaceOfAParentOfTheOverlayDirectoryIsReported()
A file further up (where "<client data dir>/lang" is created) blocks the path just as well.
testAFileInPlaceOfTheOverlayDirectoryIsReported()
Root-proof: a regular file in place of the overlay directory - no user can create it,...
testADanglingSymlinkInTheOverlayPathIsReported(\Closure $link_path)
A dangling symlink does not "exist" for file_exists(), but mkdir() cannot create anything in its plac...
testAModuleThatIsNotMigratedForTheLanguageIsIgnored()
Only modules migrated for a given language count: without a shipped .po no overlay is written,...
testEachUnwritableOverlayDirectoryIsReportedOnceAcrossLanguagesAndModules()
Each module has an overlay directory per language (lang/<module>/<lang>); each blocked one is reporte...
testAMissingButCreatableOverlayDirectoryIsNotReported()
A missing directory is fine if the closest existing parent is writable: sync() creates it.
static directory(string $prefix, string $path, bool $local=false)
static catalog(string $module, array $entries)
static writePo(string $file, TranslationCatalog $catalog)
A directory of language files with a path and a prefix for them.