Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php
7461 views
1
<?php
2
3
namespace Pterodactyl\Tests\Unit\Http\Middleware;
4
5
use Mockery as m;
6
use Mockery\MockInterface;
7
use Pterodactyl\Models\User;
8
use Illuminate\Foundation\Application;
9
use Pterodactyl\Http\Middleware\LanguageMiddleware;
10
11
class LanguageMiddlewareTest extends MiddlewareTestCase
12
{
13
private MockInterface $appMock;
14
15
/**
16
* Setup tests.
17
*/
18
public function setUp(): void
19
{
20
parent::setUp();
21
22
$this->appMock = m::mock(Application::class);
23
}
24
25
/**
26
* Test that a language is defined via the middleware for guests.
27
*/
28
public function testLanguageIsSetForGuest()
29
{
30
$this->request->shouldReceive('user')->withNoArgs()->andReturnNull();
31
$this->appMock->shouldReceive('setLocale')->with('en')->once()->andReturnNull();
32
33
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
34
}
35
36
/**
37
* Test that a language is defined via the middleware for a user.
38
*/
39
public function testLanguageIsSetWithAuthenticatedUser()
40
{
41
$user = User::factory()->make(['language' => 'de']);
42
43
$this->request->shouldReceive('user')->withNoArgs()->andReturn($user);
44
$this->appMock->shouldReceive('setLocale')->with('de')->once()->andReturnNull();
45
46
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
47
}
48
49
/**
50
* Return an instance of the middleware using mocked dependencies.
51
*/
52
private function getMiddleware(): LanguageMiddleware
53
{
54
return new LanguageMiddleware($this->appMock);
55
}
56
}
57
58