Skip to content

Commit

Permalink
Merge pull request #5 from Laravel-Lang/1.x
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
andrey-helldar authored Jun 9, 2024
2 parents 65443f2 + 0417143 commit c041415
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 110 deletions.
17 changes: 8 additions & 9 deletions tests/Concerns/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,39 @@ public function setUpRoutes(): void
->group(function () {
app('router')
->middleware(ParameterLocale::class)
->get('path/{time}/{locale?}', $this->jsonResponse())
->get('path/{foo}/{locale?}', $this->jsonResponse())
->name('via.parameter');

app('router')
->middleware(ParameterRedirectLocale::class)
->get('redirect/{time}/{locale?}', $this->jsonResponse())
->get('redirect/{foo}/{locale?}', $this->jsonResponse())
->name('via.parameter.redirect');

app('router')
->middleware(ParameterRedirectLocale::class)
->get('not-named/redirect/{time}/{locale?}', $this->jsonResponse());
->get('not-named/redirect/{foo}/{locale?}', $this->jsonResponse());

app('router')
->middleware(HeaderLocale::class)
->get('header/{time}', $this->jsonResponse())
->get('header/{foo}', $this->jsonResponse())
->name('via.header');

app('router')
->middleware(CookiesLocale::class)
->get('cookie/{time}', $this->jsonResponse())
->get('cookie/{foo}', $this->jsonResponse())
->name('via.cookie');

app('router')
->middleware(SessionLocale::class)
->get('session/{time}', $this->jsonResponse())
->get('session/{foo}', $this->jsonResponse())
->name('via.session');
});
}

protected function jsonResponse(): Closure
{
return fn (int $time) => response()->json([
'message' => __(LocaleValue::TranslationKey),
'time' => $time,
return fn (string $foo) => response()->json([
$foo => __(LocaleValue::TranslationKey),
]);
}
}
35 changes: 15 additions & 20 deletions tests/Feature/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,51 @@
use function Pest\Laravel\withCredentials;

test('main locale', function (string $locale) {
$time = time();
$foo = 'test';

withCredentials()
->withCookie(Config::shared()->routes->names->cookie, $locale)
->getJson(route('via.cookie', compact('time')))
->getJson(route('via.cookie', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('main-locales');

test('aliased locale', function (string $locale) {
$time = time();
$foo = 'test';

withCredentials()
->withCookie(Config::shared()->routes->names->cookie, $locale)
->getJson(route('via.cookie', compact('time')))
->getJson(route('via.cookie', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationGerman)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationGerman);
})->with('aliased-locales');

test('empty locale', function (int|string|null $locale) {
$time = time();
$foo = 'test';

withCredentials()
->withCookie(Config::shared()->routes->names->cookie, (string) $locale)
->getJson(route('via.cookie', compact('time')))
->getJson(route('via.cookie', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('empty-locales');

test('uninstalled locale', function (string $locale) {
$time = time();
$foo = 'test';

withCredentials()
->withCookie(Config::shared()->routes->names->cookie, $locale)
->getJson(route('via.cookie', compact('time')))
->getJson(route('via.cookie', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('uninstalled-locales');

test('unknown locale', function (int|string $locale) {
$time = time();
$foo = 'test';

withCredentials()
->withCookie(Config::shared()->routes->names->cookie, (string) $locale)
->getJson(route('via.cookie', compact('time')))
->getJson(route('via.cookie', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('unknown-locales');
35 changes: 15 additions & 20 deletions tests/Feature/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,51 @@
use function Pest\Laravel\getJson;

test('main locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.header', compact('time')), [
getJson(route('via.header', compact('foo')), [
Config::shared()->routes->names->header => $locale,
])
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('main-locales');

test('aliased locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.header', compact('time')), [
getJson(route('via.header', compact('foo')), [
Config::shared()->routes->names->header => $locale,
])
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationGerman)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationGerman);
})->with('aliased-locales');

test('empty locale', function (int|string|null $locale) {
$time = time();
$foo = 'test';

getJson(route('via.header', compact('time')), [
getJson(route('via.header', compact('foo')), [
Config::shared()->routes->names->header => $locale,
])
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('empty-locales');

test('uninstalled locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.header', compact('time')), [
getJson(route('via.header', compact('foo')), [
Config::shared()->routes->names->header => $locale,
])
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('uninstalled-locales');

test('unknown locale', function (int|string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.header', compact('time')), [
getJson(route('via.header', compact('foo')), [
Config::shared()->routes->names->header => $locale,
])
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('unknown-locales');
39 changes: 18 additions & 21 deletions tests/Feature/ParameterRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,55 @@
use function Pest\Laravel\getJson;

test('main locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter.redirect', compact('time', 'locale')))
getJson(route('via.parameter.redirect', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('main-locales');

test('aliased locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter.redirect', compact('time', 'locale')))
getJson(route('via.parameter.redirect', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationGerman)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationGerman);
})->with('aliased-locales');

test('empty locale', function (int|string|null $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter.redirect', compact('time', 'locale')))
getJson(route('via.parameter.redirect', compact('foo', 'locale')))
->assertRedirectToRoute('via.parameter.redirect', [
'locale' => LocaleValue::LocaleMain,
'time' => $time,
'foo' => $foo,
]);
})->with('empty-locales');

test('uninstalled locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter.redirect', compact('time', 'locale')))
getJson(route('via.parameter.redirect', compact('foo', 'locale')))
->assertRedirectToRoute('via.parameter.redirect', [
'locale' => LocaleValue::LocaleMain,
'time' => $time,
'foo' => $foo,
]);
})->with('uninstalled-locales');

test('unknown locale', function (int|string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter.redirect', compact('time', 'locale')))
getJson(route('via.parameter.redirect', compact('foo', 'locale')))
->assertRedirectToRoute('via.parameter.redirect', [
'locale' => LocaleValue::LocaleMain,
'time' => $time,
'foo' => $foo,
]);
})->with('unknown-locales');

test('not named', function (int|string|null $locale) {
$time = time();
$foo = 'test';

getJson(url('not-named/redirect/' . $time . '/' . $locale))
getJson(url('not-named/redirect/' . $foo . '/' . $locale))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('empty-locales');
35 changes: 15 additions & 20 deletions tests/Feature/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,41 @@
use function Pest\Laravel\getJson;

test('main locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter', compact('time', 'locale')))
getJson(route('via.parameter', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('main-locales');

test('aliased locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter', compact('time', 'locale')))
getJson(route('via.parameter', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationGerman)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationGerman);
})->with('aliased-locales');

test('empty locale', function (int|string|null $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter', compact('time', 'locale')))
getJson(route('via.parameter', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('empty-locales');

test('uninstalled locale', function (string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter', compact('time', 'locale')))
getJson(route('via.parameter', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('uninstalled-locales');

test('unknown locale', function (int|string $locale) {
$time = time();
$foo = 'test';

getJson(route('via.parameter', compact('time', 'locale')))
getJson(route('via.parameter', compact('foo', 'locale')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('unknown-locales');
35 changes: 15 additions & 20 deletions tests/Feature/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,46 @@
use function Pest\Laravel\withSession;

test('main locale', function (string $locale) {
$time = time();
$foo = 'test';

withSession([Config::shared()->routes->names->session => $locale])
->getJson(route('via.session', compact('time')))
->getJson(route('via.session', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('main-locales');

test('aliased locale', function (string $locale) {
$time = time();
$foo = 'test';

withSession([Config::shared()->routes->names->session => $locale])
->getJson(route('via.session', compact('time')))
->getJson(route('via.session', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationGerman)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationGerman);
})->with('aliased-locales');

test('empty locale', function (int|string|null $locale) {
$time = time();
$foo = 'test';

withSession([Config::shared()->routes->names->session => $locale])
->getJson(route('via.session', compact('time')))
->getJson(route('via.session', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('empty-locales');

test('uninstalled locale', function (string $locale) {
$time = time();
$foo = 'test';

withSession([Config::shared()->routes->names->session => $locale])
->getJson(route('via.session', compact('time')))
->getJson(route('via.session', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('uninstalled-locales');

test('unknown locale', function (int|string $locale) {
$time = time();
$foo = 'test';

withSession([Config::shared()->routes->names->session => $locale])
->getJson(route('via.session', compact('time')))
->getJson(route('via.session', compact('foo')))
->assertSuccessful()
->assertJsonPath('message', LocaleValue::TranslationFrench)
->assertJsonPath('time', $time);
->assertJsonPath($foo, LocaleValue::TranslationFrench);
})->with('unknown-locales');

0 comments on commit c041415

Please sign in to comment.