Expanded the middleware test
This commit is contained in:
parent
e9ac014bf4
commit
b56f3a8671
2 changed files with 18 additions and 3 deletions
|
@ -48,7 +48,7 @@ class LanguageMiddleware
|
|||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$this->app->setLocale($request->user()->language ?? $this->config->get('app.locale'));
|
||||
$this->app->setLocale($request->user()->language ?? $this->config->get('app.locale', 'en'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use Mockery as m;
|
|||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Pterodactyl\Http\Middleware\LanguageMiddleware;
|
||||
use Pterodactyl\Models\User;
|
||||
|
||||
class LanguageMiddlewareTest extends MiddlewareTestCase
|
||||
{
|
||||
|
@ -31,16 +32,30 @@ class LanguageMiddlewareTest extends MiddlewareTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that a language is defined via the middleware.
|
||||
* Test that a language is defined via the middleware for guests.
|
||||
*/
|
||||
public function testLanguageIsSet()
|
||||
public function testLanguageIsSetForGuest()
|
||||
{
|
||||
$this->request->shouldReceive('user')->withNoArgs()->andReturnNull();
|
||||
|
||||
$this->config->shouldReceive('get')->with('app.locale', 'en')->once()->andReturn('en');
|
||||
$this->appMock->shouldReceive('setLocale')->with('en')->once()->andReturnNull();
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a language is defined via the middleware for a user.
|
||||
*/
|
||||
public function testLanguageIsSetWithAuthenticatedUser() {
|
||||
$user = factory(User::class)->make(['language' => 'de']);
|
||||
|
||||
$this->request->shouldReceive('user')->withNoArgs()->andReturn($user);
|
||||
$this->appMock->shouldReceive('setLocale')->with('de')->once()->andReturnNull();
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the middleware using mocked dependencies.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue