From e05ee8965dbb86e6d94382aa2b1d9289cf5aa9ea Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode <123783602+HolgerHatGarKeineNode@users.noreply.github.com> Date: Sun, 24 May 2026 22:09:26 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20**Add=20tests=20for=20LangCountry?= =?UTF-8?q?=20data=20resolution=20and=20Latvian=20overrides**=20-=20?= =?UTF-8?q?=E2=9E=95=20Introduced=20`LangCountryDataAvailabilityTest`=20to?= =?UTF-8?q?=20validate=20data=20file=20availability=20and=20integrity=20fo?= =?UTF-8?q?r=20allowed=20`lang-country`=20codes.=20-=20=F0=9F=9B=A0?= =?UTF-8?q?=EF=B8=8F=20Added=20Latvian=20(`lv-LV`)=20override=20JSON=20fil?= =?UTF-8?q?e=20with=20localized=20settings=20and=20validation.=20-=20?= =?UTF-8?q?=F0=9F=A7=AA=20Verified=20graceful=20switching=20between=20`lan?= =?UTF-8?q?g-country`=20sessions=20in=20tests.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/lang-country-overrides/lv-LV.json | 19 +++++ .../LangCountryDataAvailabilityTest.php | 76 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 lang/lang-country-overrides/lv-LV.json create mode 100644 tests/Feature/LangCountryDataAvailabilityTest.php diff --git a/lang/lang-country-overrides/lv-LV.json b/lang/lang-country-overrides/lv-LV.json new file mode 100644 index 0000000..2552de0 --- /dev/null +++ b/lang/lang-country-overrides/lv-LV.json @@ -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" +} diff --git a/tests/Feature/LangCountryDataAvailabilityTest.php b/tests/Feature/LangCountryDataAvailabilityTest.php new file mode 100644 index 0000000..fa0a107 --- /dev/null +++ b/tests/Feature/LangCountryDataAvailabilityTest.php @@ -0,0 +1,76 @@ +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'); +});