Path: blob/1.0-develop/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php
7461 views
<?php12namespace Pterodactyl\Tests\Unit\Http\Middleware;34use Mockery as m;5use Mockery\MockInterface;6use Pterodactyl\Models\User;7use Illuminate\Foundation\Application;8use Pterodactyl\Http\Middleware\LanguageMiddleware;910class LanguageMiddlewareTest extends MiddlewareTestCase11{12private MockInterface $appMock;1314/**15* Setup tests.16*/17public function setUp(): void18{19parent::setUp();2021$this->appMock = m::mock(Application::class);22}2324/**25* Test that a language is defined via the middleware for guests.26*/27public function testLanguageIsSetForGuest()28{29$this->request->shouldReceive('user')->withNoArgs()->andReturnNull();30$this->appMock->shouldReceive('setLocale')->with('en')->once()->andReturnNull();3132$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());33}3435/**36* Test that a language is defined via the middleware for a user.37*/38public function testLanguageIsSetWithAuthenticatedUser()39{40$user = User::factory()->make(['language' => 'de']);4142$this->request->shouldReceive('user')->withNoArgs()->andReturn($user);43$this->appMock->shouldReceive('setLocale')->with('de')->once()->andReturnNull();4445$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());46}4748/**49* Return an instance of the middleware using mocked dependencies.50*/51private function getMiddleware(): LanguageMiddleware52{53return new LanguageMiddleware($this->appMock);54}55}565758