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

61 lines
1.6 KiB
PHP
Raw Normal View History

2017-11-03 23:16:49 +00:00
<?php
namespace Tests\Unit\Http\Middleware;
use Mockery as m;
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
{
/**
* @var \Illuminate\Foundation\Application|\Mockery\Mock
*/
private $appMock;
/**
* Setup tests.
*/
public function setUp()
{
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()
{
2018-06-01 14:22:06 +00:00
$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());
}
2017-11-03 23:16:49 +00:00
/**
* Return an instance of the middleware using mocked dependencies.
*
* @return \Pterodactyl\Http\Middleware\LanguageMiddleware
*/
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
}
}