Expanded the middleware test

This commit is contained in:
stanjg 2018-06-01 16:22:06 +02:00
parent e9ac014bf4
commit b56f3a8671
No known key found for this signature in database
GPG key ID: 27D9DF9D28935303
2 changed files with 18 additions and 3 deletions

View file

@ -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);
}

View file

@ -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.
*