Fix unit tests, and auto-load default lang if not loaded

This commit is contained in:
Kijin Sung 2016-02-18 08:49:57 +09:00
parent c67dbbc659
commit 1a3c500c76
2 changed files with 19 additions and 24 deletions

View file

@ -859,7 +859,7 @@ class Context
* Load language file according to language type
*
* @param string $path Path of the language file
* @return bool
* @return void
*/
public static function loadLang($path)
{
@ -872,15 +872,13 @@ class Context
$plugin_name = null;
}
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{
return $GLOBALS['lang']->loadDirectory($path, $plugin_name);
return true;
}
else
{
return false;
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
return $GLOBALS['lang']->loadDirectory($path, $plugin_name);
}
/**
@ -923,14 +921,13 @@ class Context
*/
public static function getLang($code)
{
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{
return $GLOBALS['lang']->get($code);
}
else
{
return $code;
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
return $GLOBALS['lang']->get($code);
}
/**
@ -938,19 +935,17 @@ class Context
*
* @param string $code Language variable name
* @param string $val `$code`s value
* @return bool
* @return void
*/
public static function setLang($code, $val)
{
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
{
$GLOBALS['lang']->set($code, $val);
return true;
}
else
{
return false;
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
}
$GLOBALS['lang']->set($code, $val);
}
/**

View file

@ -77,8 +77,8 @@ class DateTimeTest extends \Codeception\TestCase\Test
public function testGetTimeGap()
{
Context::getInstance()->lang = Rhymix\Framework\Lang::getInstance('en');
Context::getInstance()->lang->loadPlugin('common');
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance('en');
$GLOBALS['lang']->loadPlugin('common');
// Test getTimeGap() when the internal time zone is different from the default time zone.
Rhymix\Framework\Config::set('locale.internal_timezone', 10800);