ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
MigratedLanguageFileSyncTestCase.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
36abstract class MigratedLanguageFileSyncTestCase extends TestCase
37{
39
40 protected const string MODULE = 'stest';
41
42 protected string $fixture_directory;
43 protected string $client_data_dir;
44 protected string $ilias_root;
47
48 protected function setUp(): void
49 {
50 // never the build of the installation, see MigratedPoFixture::resetRuntime()
53
54 $this->ilias_root = (string) realpath(__DIR__ . '/../../../../../');
55
56 $this->fixture_directory = __DIR__ . '/tmp-sync-fixtures-' . bin2hex(random_bytes(4));
57 mkdir($this->fixture_directory, 0775, true);
58 $this->client_data_dir = sys_get_temp_dir() . '/ilias_mlfs_test_' . bin2hex(random_bytes(4));
59 mkdir($this->client_data_dir, 0775, true);
60
61 $this->directory = MigratedPoFixture::directory(
62 self::MODULE,
63 'components/ILIAS/Language/tests/ComponentTranslation/' . basename($this->fixture_directory) . '/'
64 );
65 $this->manager = new LanguageFileDirectoryManager(new CustomizingLanguageFileDirectory(), $this->directory);
66 }
67
68 protected function tearDown(): void
69 {
70 MigratedPoFixture::removeDirectory($this->fixture_directory);
71 MigratedPoFixture::removeDirectory($this->client_data_dir);
73
75 }
76
80 protected function seedShipped(array $entries, string $lang_key = 'de', string $module = self::MODULE): void
81 {
83 }
84
88 protected function seedOverlay(array $entries, string $lang_key = 'de'): void
89 {
90 MigratedPoFixture::writePair($this->overlayBase($lang_key), MigratedPoFixture::catalog(self::MODULE, $entries));
91 }
92
93 protected function shippedPo(string $lang_key = 'de', string $module = self::MODULE): string
94 {
95 return $this->fixture_directory . '/' . $module . '_' . $lang_key . '.po';
96 }
97
98 protected function overlayBase(string $lang_key = 'de'): string
99 {
100 return MigratedPoFixture::overlayBase($this->client_data_dir, $this->directory, $lang_key);
101 }
102
103 protected function overlayPo(): TranslationCatalog
104 {
105 return MigratedPoFixture::readPo($this->overlayBase() . '.po');
106 }
107
111 protected function sync(array $entries, bool $refresh = false, ?string $client_data_dir = 'default'): void
112 {
113 MigratedLanguageFileSync::sync(
114 $this->manager,
115 $this->ilias_root,
116 'de',
117 self::MODULE,
118 $entries,
119 $client_data_dir === 'default' ? $this->client_data_dir : $client_data_dir,
120 $refresh
121 );
122 }
123
127 protected function overlayIdentifiers(): array
128 {
129 return array_map(static fn($entry): string => $entry->getId(), $this->overlayPo()->getEntries());
130 }
131
132 protected function overlayDirectory(): string
133 {
134 return dirname($this->overlayBase());
135 }
136
141 protected function findUnwritable(array $lang_keys = ['de'], ?string $client_data_dir = 'default', ?LanguageFileDirectoryManager $manager = null): array
142 {
143 return MigratedLanguageFileSync::findUnwritableOverlayDirectories(
144 $manager ?? $this->manager,
145 $this->ilias_root,
146 $lang_keys,
147 $client_data_dir === 'default' ? $this->client_data_dir : $client_data_dir
148 );
149 }
150
151
155 public static function refreshFlags(): array
156 {
157 return ['admin edit (refresh = false)' => [false], 'reconciling write (refresh = true)' => [true]];
158 }
159}
trait RestoresProcessState
Whatever a test does to the process (locale, LANGUAGE/LC_*, LOCPATH, the static state of the runtime ...
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.
sync(array $entries, bool $refresh=false, ?string $client_data_dir='default')
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)
findUnwritable(array $lang_keys=['de'], ?string $client_data_dir='default', ?LanguageFileDirectoryManager $manager=null)
static writePair(string $base_path, TranslationCatalog $catalog)
Writes "<base>.po" and, like MigratedLanguageFileSync::sync(), its compiled revision named by current...
static directory(string $prefix, string $path, bool $local=false)
static catalog(string $module, array $entries)
static writePo(string $file, TranslationCatalog $catalog)
static removeDirectory(string $directory)
static readPo(string $file)
static overlayBase(string $client_data_dir, LanguageFileDirectory $directory, string $lang_key)
The overlay of $directory's module for $lang_key without the .po extension.
static resetRuntime(?string $artifact_directory=null)
Forgets the static state of the runtime read path and points build and runtime at $artifact_directory...
if(!isset($arguments[0])) if(count( $arguments) > 3) if(! $remove_from_lang &&isset($arguments[2]) &&!is_dir($arguments[2])) $module
A directory of language files with a path and a prefix for them.