2017-05-30 22:48:50 +00:00
|
|
|
<?php
|
2019-10-03 19:24:12 +00:00
|
|
|
|
2017-05-30 22:48:50 +00:00
|
|
|
/**
|
|
|
|
* LocaleManagerTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2020-10-21 20:47:15 +00:00
|
|
|
use Alltube\Factory\SessionFactory;
|
2017-05-30 22:48:50 +00:00
|
|
|
use Alltube\Locale;
|
|
|
|
use Alltube\LocaleManager;
|
2020-10-21 21:04:29 +00:00
|
|
|
use Slim\Container;
|
2017-05-30 22:48:50 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-20 22:34:12 +00:00
|
|
|
* Unit tests for the LocaleManagerTest class.
|
2017-05-30 22:48:50 +00:00
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class LocaleManagerTest extends BaseTest
|
2017-05-30 22:48:50 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* LocaleManager class instance.
|
|
|
|
*
|
|
|
|
* @var LocaleManager
|
|
|
|
*/
|
|
|
|
private $localeManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
|
|
|
*/
|
2019-11-30 13:08:18 +00:00
|
|
|
protected function setUp(): void
|
2017-05-30 22:48:50 +00:00
|
|
|
{
|
2018-02-05 15:48:58 +00:00
|
|
|
$_SESSION[LocaleManager::class]['locale'] = 'foo_BAR';
|
2020-10-21 21:04:29 +00:00
|
|
|
$this->localeManager = new LocaleManager(SessionFactory::create(new Container()));
|
2017-05-30 22:48:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:56:53 +00:00
|
|
|
/**
|
2019-04-20 10:17:52 +00:00
|
|
|
* Unset locale after each test.
|
2017-05-30 22:56:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-11-30 13:08:18 +00:00
|
|
|
protected function tearDown(): void
|
2017-05-30 22:56:53 +00:00
|
|
|
{
|
2019-04-20 10:17:52 +00:00
|
|
|
$this->localeManager->unsetLocale();
|
2017-05-30 22:56:53 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:48:50 +00:00
|
|
|
/**
|
|
|
|
* Test the getSupportedLocales function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetSupportedLocales()
|
|
|
|
{
|
|
|
|
foreach ($this->localeManager->getSupportedLocales() as $locale) {
|
|
|
|
$this->assertInstanceOf(Locale::class, $locale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the getLocale function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetLocale()
|
|
|
|
{
|
2017-10-26 08:55:29 +00:00
|
|
|
$this->assertEquals(new Locale('foo_BAR'), $this->localeManager->getLocale());
|
2017-05-30 22:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setLocale function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetLocale()
|
|
|
|
{
|
|
|
|
$this->localeManager->setLocale(new Locale('foo_BAR'));
|
|
|
|
$locale = $this->localeManager->getLocale();
|
|
|
|
$this->assertInstanceOf(Locale::class, $locale);
|
|
|
|
$this->assertEquals('foo_BAR', (string) $locale);
|
|
|
|
}
|
2017-11-10 11:18:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the unsetLocale function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testUnsetLocale()
|
|
|
|
{
|
|
|
|
$this->localeManager->unsetLocale();
|
|
|
|
$this->assertNull($this->localeManager->getLocale());
|
|
|
|
}
|
2017-11-11 22:00:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that the environment is correctly set up.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testEnv()
|
|
|
|
{
|
2019-11-27 23:04:05 +00:00
|
|
|
putenv('LANG=foo_BAR');
|
2017-11-11 22:00:53 +00:00
|
|
|
$this->localeManager->setLocale(new Locale('foo_BAR'));
|
|
|
|
$this->assertEquals('foo_BAR', getenv('LANG'));
|
|
|
|
}
|
2017-05-30 22:48:50 +00:00
|
|
|
}
|