misc_pterodactyl-panel/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php

57 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2017-11-03 23:16:49 +00:00
<?php
namespace Pterodactyl\Tests\Unit\Http\Middleware;
2017-11-03 23:16:49 +00:00
use Mockery as m;
use Mockery\MockInterface;
2018-09-03 22:17:53 +00:00
use Pterodactyl\Models\User;
2017-11-03 23:16:49 +00:00
use Illuminate\Foundation\Application;
use Pterodactyl\Http\Middleware\LanguageMiddleware;
class LanguageMiddlewareTest extends MiddlewareTestCase
{
private MockInterface $appMock;
2017-11-03 23:16:49 +00:00
/**
* Setup tests.
*/
public function setUp(): void
2017-11-03 23:16:49 +00:00
{
parent::setUp();
$this->appMock = m::mock(Application::class);
}
/**
2018-06-01 14:22:06 +00:00
* Test that a language is defined via the middleware for guests.
2017-11-03 23:16:49 +00:00
*/
2018-06-01 14:22:06 +00:00
public function testLanguageIsSetForGuest()
2017-11-03 23:16:49 +00:00
{
2018-06-01 14:22:06 +00:00
$this->request->shouldReceive('user')->withNoArgs()->andReturnNull();
2017-11-03 23:16:49 +00:00
$this->appMock->shouldReceive('setLocale')->with('en')->once()->andReturnNull();
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
2018-06-01 14:22:06 +00:00
/**
* Test that a language is defined via the middleware for a user.
*/
2018-09-03 22:17:53 +00:00
public function testLanguageIsSetWithAuthenticatedUser()
{
$user = User::factory()->make(['language' => 'de']);
2018-06-01 14:22:06 +00:00
$this->request->shouldReceive('user')->withNoArgs()->andReturn($user);
$this->appMock->shouldReceive('setLocale')->with('de')->once()->andReturnNull();
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
2017-11-03 23:16:49 +00:00
/**
* Return an instance of the middleware using mocked dependencies.
*/
private function getMiddleware(): LanguageMiddleware
{
2018-09-03 22:17:53 +00:00
return new LanguageMiddleware($this->appMock);
2017-11-03 23:16:49 +00:00
}
}