*/ public static function localeProvider(): array { return [ 'de' => ['de'], 'en' => ['en'], 'uk' => ['uk'], 'ru' => ['ru'], ]; } #[Test] public function allFourLocaleFilesLoadAndAreArrays(): void { foreach (self::localeProvider() as [$locale]) { I18n::flushCache(); $data = require __DIR__ . '/../../app/Locales/' . $locale . '.php'; self::assertIsArray($data, "Locale file {$locale}.php must return an array"); self::assertNotEmpty($data, "Locale file {$locale}.php must not be empty"); } } #[Test] public function everyLocaleHasExactlyTheSameKeySet(): void { $keysByLocale = []; foreach (self::localeProvider() as [$locale]) { $keysByLocale[$locale] = array_keys(require __DIR__ . '/../../app/Locales/' . $locale . '.php'); sort($keysByLocale[$locale]); } $reference = $keysByLocale['de']; foreach (['en', 'uk', 'ru'] as $locale) { $missing = array_diff($reference, $keysByLocale[$locale]); $extra = array_diff($keysByLocale[$locale], $reference); self::assertSame( [], $missing, "Locale '{$locale}' is missing keys: " . implode(', ', $missing) ); self::assertSame( [], $extra, "Locale '{$locale}' has extra keys not in DE: " . implode(', ', $extra) ); } } #[Test] public function noTranslationValueIsEmpty(): void { foreach (self::localeProvider() as [$locale]) { $data = require __DIR__ . '/../../app/Locales/' . $locale . '.php'; foreach ($data as $key => $value) { self::assertIsString($value, "{$locale}.{$key} must be a string"); self::assertNotSame('', trim($value), "{$locale}.{$key} must not be empty"); } } } #[Test] #[DataProvider('localeProvider')] public function everyTranslationIsValidUtf8(string $locale): void { $data = require __DIR__ . '/../../app/Locales/' . $locale . '.php'; foreach ($data as $key => $value) { self::assertTrue( mb_check_encoding($value, 'UTF-8'), "{$locale}.{$key} contains invalid UTF-8" ); } } }