**Add tests for LangCountry data resolution and Latvian overrides**

-  Introduced `LangCountryDataAvailabilityTest` to validate data file availability and integrity for allowed `lang-country` codes.
- 🛠️ Added Latvian (`lv-LV`) override JSON file with localized settings and validation.
- 🧪 Verified graceful switching between `lang-country` sessions in tests.
This commit is contained in:
HolgerHatGarKeineNode
2026-05-24 22:09:26 +02:00
parent e244c14f55
commit e05ee8965d
2 changed files with 95 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
{
"country": "LV",
"country_name": "Latvia",
"country_name_local": "Latvija",
"lang": "lv",
"name": "Latviešu",
"date_numbers": "d.m.Y",
"date_numbers_full_capitals": "DD.MM.YYYY",
"date_words_without_day": "Y. \\g\\a\\d\\a j. F",
"date_words_with_day": "l, Y. \\g\\a\\d\\a j. F",
"date_birthday": "j. F",
"time_format": "H:i",
"emoji_flag": "🇱🇻",
"currency_code": "EUR",
"currency_symbol": "€",
"currency_symbol_local": "€",
"currency_name": "Euro",
"currency_name_local": "eiro"
}
@@ -0,0 +1,76 @@
<?php
use Stefro\LaravelLangCountry\LangCountry;
/**
* Resolves a lang-country data file the same way the package does:
* a published override in lang/lang-country-overrides/ takes precedence,
* otherwise the file shipped with the package is used.
*/
function resolveLangCountryFile(string $langCountry): ?string
{
$override = lang_path('lang-country-overrides/'.$langCountry.'.json');
if (file_exists($override)) {
return $override;
}
$packaged = base_path('vendor/stefro/laravel-lang-country/src/LangCountryData/'.$langCountry.'.json');
return file_exists($packaged) ? $packaged : null;
}
dataset('allowed_lang_countries', function () {
$config = require __DIR__.'/../../config/lang-country.php';
return collect($config['allowed'])
->mapWithKeys(fn (string $langCountry) => [$langCountry => [$langCountry]])
->all();
});
it('has a resolvable data file for every allowed lang-country', function (string $langCountry) {
$file = resolveLangCountryFile($langCountry);
expect($file)->not->toBeNull(
"No data file found for allowed lang-country [{$langCountry}]. "
."Add lang/lang-country-overrides/{$langCountry}.json."
);
$data = json_decode(file_get_contents($file), true);
expect($data)->toBeArray()->toHaveKeys([
'country',
'country_name',
'country_name_local',
'lang',
'name',
'date_numbers',
'date_numbers_full_capitals',
'date_words_without_day',
'date_words_with_day',
'date_birthday',
'time_format',
'emoji_flag',
'currency_code',
'currency_symbol',
'currency_symbol_local',
'currency_name',
'currency_name_local',
]);
})->with('allowed_lang_countries');
it('can construct LangCountry for every allowed lang-country without error', function (string $langCountry) {
session(['lang_country' => $langCountry]);
$langCountryInstance = new LangCountry;
expect($langCountryInstance->currentLangCountry())->toBe($langCountry);
})->with('allowed_lang_countries');
it('switches away from a freshly added lang-country without throwing', function () {
session(['lang_country' => 'lv-LV']);
$response = $this->get(config('lang-country.lang_switcher_uri').'/de-DE');
$response->assertRedirect();
expect(session('lang_country'))->toBe('de-DE');
});