ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncEditableTest.php
Go to the documentation of this file.
1<?php
2
20declare(strict_types=1);
21
23use PHPUnit\Framework\Attributes\DataProvider;
24
30{
34 private function editable(?string $client_data_dir = 'default', string $module = self::MODULE, string $lang_key = 'de', bool $for_writing = false): ?array
35 {
36 $content = MigratedLanguageFileSync::loadEditableModuleTranslations(
37 $this->manager,
38 $lang_key,
39 $module,
40 $client_data_dir === 'default' ? $this->client_data_dir : $client_data_dir,
41 $this->ilias_root,
42 $for_writing
43 );
44
45 return $content === null ? null : array_map(static fn(array $entry): string => $entry['value'], $content);
46 }
47
49 {
50 $this->seedShipped(['greeting' => 'Hallo', 'farewell' => 'Tschüss']);
51 $this->seedOverlay(['greeting' => 'Moin']);
52
53 $this->assertSame(['greeting' => 'Moin', 'farewell' => 'Tschüss'], $this->editable());
54 }
55
57 {
58 $this->seedShipped(['greeting' => 'Hallo']);
59 $this->seedOverlay(['greeting' => 'Moin']);
60 file_put_contents($this->overlayBase() . '.po', "msgid \"kaputt\n");
61
62 $this->expectOutputRegex('/The local changes of module "stest" for "de" cannot be read, the shipped values are used/');
63 $this->assertSame(['greeting' => 'Hallo'], $this->editable());
64 }
65
68 {
69 $this->seedShipped(['greeting' => 'Hallo']);
70 $this->seedOverlay(['greeting' => 'Moin']);
71 file_put_contents($this->overlayBase() . '.po', "msgid \"kaputt\n");
72
73 $this->expectException(\RuntimeException::class);
74 $this->editable('default', self::MODULE, 'de', true);
75 }
76
78 {
79 $this->seedShipped(['greeting' => 'Hallo', 'farewell' => 'Tschüss']);
80 $this->seedOverlay(['greeting' => 'Moin']);
81
82 $this->assertSame(['greeting' => 'Moin', 'farewell' => 'Tschüss'], $this->editable('default', self::MODULE, 'de', true));
83 }
84
86 {
87 $this->seedShipped(['greeting' => 'Hallo']);
88
89 $this->assertSame(['greeting' => 'Hallo'], $this->editable(null));
90 $this->expectOutputString('');
91 }
92
93 public function testAnUnreadableShippedPoThrows(): void
94 {
95 file_put_contents($this->shippedPo(), "msgid \"kaputt\n");
96
97 $this->expectOutputRegex('/cannot be read/');
98 $this->expectException(\RuntimeException::class);
99 $this->editable();
100 }
101
105 public static function nothingToEdit(): array
106 {
107 return [
108 'module of no directory' => ['unknown', 'de'],
109 'no shipped po for the language' => ['stest', 'fr'],
110 'invalid language key' => ['stest', '../de'],
111 ];
112 }
113
114 #[DataProvider('nothingToEdit')]
115 public function testWithoutDirectoryShippedPoOrValidKeyThereIsNothingToEdit(string $module, string $lang_key): void
116 {
117 $this->seedShipped(['greeting' => 'Hallo']);
118
119 $this->assertNull($this->editable('default', $module, $lang_key));
120 }
121}
Reads the shipped .po of a migrated module and maintains its per-installation overlay: the ....
MigratedLanguageFileSync::loadEditableModuleTranslations(): the content the administration edits,...
testAnUnreadableOverlayThrowsForWritingAndIsNotReportedAsUsable()
For writing, the shipped values alone would drop the other local changes of the overlay: it throws in...
editable(?string $client_data_dir='default', string $module=self::MODULE, string $lang_key='de', bool $for_writing=false)
testWithoutDirectoryShippedPoOrValidKeyThereIsNothingToEdit(string $module, string $lang_key)
Fixtures of the MigratedLanguageFileSync tests.
seedOverlay(array $entries, string $lang_key='de')
seedShipped(array $entries, string $lang_key='de', string $module=self::MODULE)
shippedPo(string $lang_key='de', string $module=self::MODULE)
if(!isset($arguments[0])) if(count( $arguments) > 3) if(! $remove_from_lang &&isset($arguments[2]) &&!is_dir($arguments[2])) $module