From ef30f0fa408dcb12e0a4dbd774a756f3753505fc Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 17 Mar 2016 14:19:35 +0900 Subject: [PATCH] Update and expand unit tests for Lang class --- tests/unit/framework/LangTest.php | 42 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tests/unit/framework/LangTest.php b/tests/unit/framework/LangTest.php index 2ca57cb61..094cb9843 100644 --- a/tests/unit/framework/LangTest.php +++ b/tests/unit/framework/LangTest.php @@ -4,30 +4,50 @@ class LangTest extends \Codeception\TestCase\Test { public function testLang() { + // Test separation of languages. $ko = Rhymix\Framework\Lang::getInstance('ko'); $en = Rhymix\Framework\Lang::getInstance('en'); $this->assertTrue($ko instanceof Rhymix\Framework\Lang); $this->assertTrue($en instanceof Rhymix\Framework\Lang); $this->assertFalse($ko === $en); + // Test backward compatible language code for Japanese. $ja = Rhymix\Framework\Lang::getInstance('ja'); $jp = Rhymix\Framework\Lang::getInstance('jp'); $this->assertTrue($ja === $jp); - $this->assertEquals('도움말', $ko->get('common.help')); - $this->assertEquals('Help', $en->get('common.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')); - + // Test loading new plugins. + $this->assertNotEquals('ヘルプ', $ja->help); $ja->loadPlugin('common'); $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님 안녕하세요?'; $this->assertEquals('Travis님 안녕하세요?', $ko->foobartestlang('Travis')); $en->foobartestlang = 'Hello, %s!';