mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-03 12:55:41 -05:00
initial language pack support
This commit is contained in:
@@ -6,22 +6,38 @@ namespace Pterodactyl\Tests\Pest\Unit\Http\Middleware\LanguageMiddlewareTest;
|
||||
|
||||
use Pterodactyl\Http\Middleware\LanguageMiddleware;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Services\Translations\LanguageRegistry;
|
||||
|
||||
uses(\Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase::class);
|
||||
test('only the core english translations are installed', function () {
|
||||
expect(app(LanguageRegistry::class)->available())->toBe(['en' => 'English']);
|
||||
});
|
||||
test('language is set for guest', function () {
|
||||
$this->setRequestUserModel(null);
|
||||
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
expect($this->app->getLocale())->toBe('en');
|
||||
});
|
||||
test('language is set with authenticated user', function () {
|
||||
$user = User::factory()->make(['language' => 'de']);
|
||||
$this->setRequestUserModel($user);
|
||||
$this->setRequestUserModel(User::factory()->make(['language' => 'en']));
|
||||
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
expect($this->app->getLocale())->toBe('de');
|
||||
expect($this->app->getLocale())->toBe('en');
|
||||
});
|
||||
test('a user without a language follows the panel default', function () {
|
||||
$this->setRequestUserModel(User::factory()->make(['language' => null]));
|
||||
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
expect($this->app->getLocale())->toBe('en');
|
||||
});
|
||||
test('a language no pack provides falls back to the panel default', function () {
|
||||
$this->setRequestUserModel(User::factory()->make(['language' => 'de']));
|
||||
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
expect($this->app->getLocale())->toBe('en');
|
||||
});
|
||||
test('a panel default no pack provides falls back to english', function () {
|
||||
config(['app.locale' => 'de']);
|
||||
$this->setRequestUserModel(null);
|
||||
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
expect($this->app->getLocale())->toBe('en');
|
||||
});
|
||||
/**
|
||||
* Return an instance of the middleware using the real application.
|
||||
*/
|
||||
function getMiddleware(): LanguageMiddleware
|
||||
{
|
||||
return app(LanguageMiddleware::class);
|
||||
|
||||
Reference in New Issue
Block a user