alltube/tests/LocaleMiddlewareTest.php

117 lines
2.6 KiB
PHP
Raw Normal View History

2017-05-29 21:11:59 +02:00
<?php
/**
* LocaleMiddlewareTest class.
*/
namespace Alltube\Test;
2017-05-30 23:41:26 +02:00
use Alltube\LocaleManager;
2017-05-29 21:11:59 +02:00
use Alltube\LocaleMiddleware;
2017-10-26 10:46:22 +02:00
use PHPUnit\Framework\TestCase;
2017-05-30 23:41:26 +02:00
use Slim\Container;
2017-05-29 21:11:59 +02:00
use Slim\Http\Environment;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* Unit tests for the FrontController class.
*/
2017-10-26 10:46:22 +02:00
class LocaleMiddlewareTest extends TestCase
2017-05-29 21:11:59 +02:00
{
2017-05-30 23:49:38 +02:00
/**
* LocaleMiddleware instance.
*
* @var LocaleMiddleware
*/
private $middleware;
2017-05-29 22:00:30 +02:00
2017-05-29 21:11:59 +02:00
/**
* Prepare tests.
*/
protected function setUp()
{
2017-05-30 23:41:26 +02:00
$container = new Container();
$container['locale'] = new LocaleManager();
$this->middleware = new LocaleMiddleware($container);
2017-05-29 21:11:59 +02:00
}
/**
* Test the testLocale() function.
*
* @return void
*/
public function testTestLocale()
{
2017-08-21 20:50:44 +02:00
$this->markTestSkipped('For some reason, this test fails on Travis even if the fr_FR locale is installed.');
2017-05-29 21:11:59 +02:00
$locale = [
2017-10-29 23:21:13 +01:00
'language' => 'fr',
'region' => 'FR',
2017-05-29 21:11:59 +02:00
];
$this->assertEquals('fr_FR', $this->middleware->testLocale($locale));
}
/**
* Test the testLocale() function with an unsupported locale.
*
* @return void
*/
public function testLocaleWithWrongLocale()
{
$locale = [
2017-10-29 23:21:13 +01:00
'language' => 'foo',
'region' => 'BAR',
2017-05-29 21:11:59 +02:00
];
$this->assertNull($this->middleware->testLocale($locale));
$this->assertNull($this->middleware->testLocale([]));
}
/**
* Mock function that does nothing.
*
* @return void
*/
public function nothing()
{
}
2017-05-29 21:11:59 +02:00
/**
* Test the __invoke() function.
*
* @return void
*/
public function testInvoke()
{
$request = Request::createFromEnvironment(Environment::mock());
$this->middleware->__invoke(
$request->withHeader('Accept-Language', 'fr-FR'),
new Response(),
[$this, 'nothing']
2017-05-29 21:11:59 +02:00
);
}
2017-05-30 23:41:26 +02:00
/**
* Test the __invoke() function withot the Accept-Language header.
*
* @return void
*/
public function testInvokeWithoutHeader()
{
$request = Request::createFromEnvironment(Environment::mock());
$this->middleware->__invoke(
$request->withoutHeader('Accept-Language'),
new Response(),
[$this, 'nothing']
2017-05-30 23:41:26 +02:00
);
}
/**
* Test that the environment is correctly set up.
*
* @return void
*/
public function testEnv()
{
$this->markTestIncomplete('We need to find a way to reliably test LC_ALL and LANG values');
2017-05-30 23:41:26 +02:00
}
2017-05-29 21:11:59 +02:00
}