mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-26 22:59:57 +09:00
Update and expand unit tests for Lang class
This commit is contained in:
parent
014e7f13a4
commit
ef30f0fa40
1 changed files with 31 additions and 11 deletions
|
|
@ -4,30 +4,50 @@ class LangTest extends \Codeception\TestCase\Test
|
||||||
{
|
{
|
||||||
public function testLang()
|
public function testLang()
|
||||||
{
|
{
|
||||||
|
// Test separation of languages.
|
||||||
$ko = Rhymix\Framework\Lang::getInstance('ko');
|
$ko = Rhymix\Framework\Lang::getInstance('ko');
|
||||||
$en = Rhymix\Framework\Lang::getInstance('en');
|
$en = Rhymix\Framework\Lang::getInstance('en');
|
||||||
$this->assertTrue($ko instanceof Rhymix\Framework\Lang);
|
$this->assertTrue($ko instanceof Rhymix\Framework\Lang);
|
||||||
$this->assertTrue($en instanceof Rhymix\Framework\Lang);
|
$this->assertTrue($en instanceof Rhymix\Framework\Lang);
|
||||||
$this->assertFalse($ko === $en);
|
$this->assertFalse($ko === $en);
|
||||||
|
|
||||||
|
// Test backward compatible language code for Japanese.
|
||||||
$ja = Rhymix\Framework\Lang::getInstance('ja');
|
$ja = Rhymix\Framework\Lang::getInstance('ja');
|
||||||
$jp = Rhymix\Framework\Lang::getInstance('jp');
|
$jp = Rhymix\Framework\Lang::getInstance('jp');
|
||||||
$this->assertTrue($ja === $jp);
|
$this->assertTrue($ja === $jp);
|
||||||
|
|
||||||
$this->assertEquals('도움말', $ko->get('common.help'));
|
// Test loading new plugins.
|
||||||
$this->assertEquals('Help', $en->get('common.help'));
|
$this->assertNotEquals('ヘルプ', $ja->help);
|
||||||
$this->assertEquals('도움말', $ko->help);
|
|
||||||
$this->assertEquals('Help', $en->help);
|
|
||||||
|
|
||||||
$this->assertEquals('common.nonexistent', $ko->get('common.nonexistent'));
|
|
||||||
$this->assertEquals('common.nonexistent', $ko->get('common.nonexistent', 'foo', 'bar'));
|
|
||||||
|
|
||||||
$this->assertEquals('admin.help', $ko->get('admin.help'));
|
|
||||||
$this->assertEquals('admin.help', $en->get('admin.help'));
|
|
||||||
|
|
||||||
$ja->loadPlugin('common');
|
$ja->loadPlugin('common');
|
||||||
$this->assertEquals('ヘルプ', $ja->help);
|
$this->assertEquals('ヘルプ', $ja->help);
|
||||||
|
|
||||||
|
// Test simple translations with namespacing.
|
||||||
|
$this->assertEquals('도움말', $ko->get('common.help'));
|
||||||
|
$this->assertEquals('Help', $en->get('common.help'));
|
||||||
|
|
||||||
|
// Test simple translations without namespacing.
|
||||||
|
$this->assertEquals('도움말', $ko->help);
|
||||||
|
$this->assertEquals('Help', $en->help);
|
||||||
|
|
||||||
|
// Test complex translations with multidimensional arrays.
|
||||||
|
$this->assertEquals('%d분 전', $ko->get('common.time_gap.min'));
|
||||||
|
$this->assertEquals('10분 전', $ko->get('common.time_gap.min', 10));
|
||||||
|
$this->assertTrue($ko->get('common.time_gap') instanceof \ArrayObject);
|
||||||
|
$this->assertEquals('%d분 전', $ko->get('common.time_gap')->min);
|
||||||
|
|
||||||
|
// Test nonexistent keys.
|
||||||
|
$this->assertEquals('common.nonexistent', $ko->get('common.nonexistent'));
|
||||||
|
$this->assertEquals('common.nonexistent', $ko->get('common.nonexistent', 'foo', 'bar'));
|
||||||
|
$this->assertEquals('admin.help', $ko->get('admin.help'));
|
||||||
|
$this->assertEquals('admin.help', $en->get('admin.help'));
|
||||||
|
|
||||||
|
// Test fallback to English.
|
||||||
|
$en->only_in_english = 'Hello world';
|
||||||
|
$this->assertEquals('Hello world', $ko->only_in_english);
|
||||||
|
$this->assertEquals('Hello world', $en->only_in_english);
|
||||||
|
$this->assertEquals('Hello world', $ja->only_in_english);
|
||||||
|
|
||||||
|
// Test string interpolation.
|
||||||
$ko->foobartestlang = '%s님 안녕하세요?';
|
$ko->foobartestlang = '%s님 안녕하세요?';
|
||||||
$this->assertEquals('Travis님 안녕하세요?', $ko->foobartestlang('Travis'));
|
$this->assertEquals('Travis님 안녕하세요?', $ko->foobartestlang('Travis'));
|
||||||
$en->foobartestlang = 'Hello, %s!';
|
$en->foobartestlang = 'Hello, %s!';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue