diff --git a/tests/Concerns/Routes.php b/tests/Concerns/Routes.php index 64ed88e..a388b4e 100644 --- a/tests/Concerns/Routes.php +++ b/tests/Concerns/Routes.php @@ -21,23 +21,37 @@ trait Routes public function setUpRoutes(): void { app('router') - ->middleware(ParameterLocale::class) - ->get('path/{locale?}', $this->jsonResponse()) - ->name('via.parameter'); + ->middleware('web') + ->group(function () { + app('router') + ->middleware(ParameterLocale::class) + ->get('path/{locale?}', $this->jsonResponse()) + ->name('via.parameter'); - app('router') - ->middleware(ParameterRedirectLocale::class) - ->get('redirect/{locale?}', $this->jsonResponse()) - ->name('via.parameter.redirect'); + app('router') + ->middleware(ParameterRedirectLocale::class) + ->get('redirect/{locale?}', $this->jsonResponse()) + ->name('via.parameter.redirect'); - app('router') - ->middleware(ParameterRedirectLocale::class) - ->get('not-named/redirect/{locale?}', $this->jsonResponse()); + app('router') + ->middleware(ParameterRedirectLocale::class) + ->get('not-named/redirect/{locale?}', $this->jsonResponse()); - app('router') - ->middleware(HeaderLocale::class) - ->get('header', $this->jsonResponse()) - ->name('via.header'); + app('router') + ->middleware(HeaderLocale::class) + ->get('header', $this->jsonResponse()) + ->name('via.header'); + + app('router') + ->middleware(CookiesLocale::class) + ->get('cookie', $this->jsonResponse()) + ->name('via.cookie'); + + app('router') + ->middleware(SessionLocale::class) + ->get('session', $this->jsonResponse()) + ->name('via.session'); + }); } protected function jsonResponse(): Closure diff --git a/tests/Feature/CookieTest.php b/tests/Feature/CookieTest.php new file mode 100644 index 0000000..71167a5 --- /dev/null +++ b/tests/Feature/CookieTest.php @@ -0,0 +1,29 @@ +routes->names->cookie, $locale) + ->getJson(route('via.cookie')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationFrench); +})->with('main-locales'); + +test('aliased locale', function (string $locale) { + withCookie(Config::shared()->routes->names->cookie, $locale) + ->getJson(route('via.cookie')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationGerman); +})->with('aliased-locales'); + +test('empty locale', function (int|string|null $locale) { + withCookie(Config::shared()->routes->names->cookie, $locale) + ->getJson(route('via.cookie')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationFrench); +})->with('empty-locales'); diff --git a/tests/Feature/SessionTest.php b/tests/Feature/SessionTest.php new file mode 100644 index 0000000..7cfe365 --- /dev/null +++ b/tests/Feature/SessionTest.php @@ -0,0 +1,29 @@ +routes->names->session => $locale]) + ->getJson(route('via.session')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationFrench); +})->with('main-locales'); + +test('aliased locale', function (string $locale) { + withSession([Config::shared()->routes->names->session => $locale]) + ->getJson(route('via.session')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationGerman); +})->with('aliased-locales'); + +test('empty locale', function (int|string|null $locale) { + withSession([Config::shared()->routes->names->session => $locale]) + ->getJson(route('via.session')) + ->assertSuccessful() + ->assertJsonPath('message', LocaleValue::TranslationFrench); +})->with('empty-locales');