2017-05-30 22:48:50 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* LocaleManagerTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
|
|
|
use Alltube\Locale;
|
|
|
|
use Alltube\LocaleManager;
|
2017-10-26 08:46:22 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-05-30 22:48:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the Config class.
|
|
|
|
*/
|
2017-10-26 08:46:22 +00:00
|
|
|
class LocaleManagerTest extends TestCase
|
2017-05-30 22:48:50 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* LocaleManager class instance.
|
|
|
|
*
|
|
|
|
* @var LocaleManager
|
|
|
|
*/
|
|
|
|
private $localeManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
|
|
|
*/
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->localeManager = new LocaleManager();
|
|
|
|
}
|
|
|
|
|
2017-05-30 22:56:53 +00:00
|
|
|
/**
|
|
|
|
* Test the getSupportedLocales function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConstructorWithCookies()
|
|
|
|
{
|
|
|
|
$_SESSION['Alltube\LocaleManager']['locale'] = 'foo_BAR';
|
|
|
|
$localeManager = new LocaleManager([]);
|
|
|
|
$this->assertEquals('foo_BAR', (string) $localeManager->getLocale());
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
$this->assertNull($this->localeManager->getLocale());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|