2017-11-03 18:16:49 -05:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Pest\Unit\Http\Middleware\LanguageMiddlewareTest;
|
2017-11-03 18:16:49 -05:00
|
|
|
|
|
|
|
|
use Pterodactyl\Http\Middleware\LanguageMiddleware;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Pterodactyl\Models\User;
|
2026-10-27 11:42:22 +00:00
|
|
|
use Pterodactyl\Services\Translations\LanguageRegistry;
|
2017-11-03 18:16:49 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
uses(\Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase::class);
|
2026-10-27 11:42:22 +00:00
|
|
|
test('only the core english translations are installed', function () {
|
|
|
|
|
expect(app(LanguageRegistry::class)->available())->toBe(['en' => 'English']);
|
|
|
|
|
});
|
2026-10-05 18:10:18 -04:00
|
|
|
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 () {
|
2026-10-27 11:42:22 +00:00
|
|
|
$this->setRequestUserModel(User::factory()->make(['language' => 'en']));
|
|
|
|
|
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
|
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);
|
2026-10-05 18:10:18 -04:00
|
|
|
getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
2026-10-27 11:42:22 +00:00
|
|
|
expect($this->app->getLocale())->toBe('en');
|
2026-10-05 18:10:18 -04:00
|
|
|
});
|
|
|
|
|
function getMiddleware(): LanguageMiddleware
|
2017-11-03 18:16:49 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return app(LanguageMiddleware::class);
|
2017-11-03 18:16:49 -05:00
|
|
|
}
|