summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/core/Lang.php2
-rw-r--r--tests/codeigniter/core/Lang_test.php60
2 files changed, 57 insertions, 5 deletions
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 94342133a..ae0a4d642 100644
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -168,7 +168,7 @@ class CI_Lang {
*/
public function line($line, $log_errors = TRUE)
{
- $value = ($line === '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
+ $value = isset($this->language[$line]) ? $this->language[$line] : FALSE;
// Because killer robots like unicorns!
if ($value === FALSE && $log_errors === TRUE)
diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php
index 3364362e0..c437779e1 100644
--- a/tests/codeigniter/core/Lang_test.php
+++ b/tests/codeigniter/core/Lang_test.php
@@ -8,7 +8,6 @@ class Lang_test extends CI_TestCase {
{
$loader_cls = $this->ci_core_class('load');
$this->ci_instance_var('load', new $loader_cls);
-
$cls = $this->ci_core_class('lang');
$this->lang = new $cls;
}
@@ -17,18 +16,71 @@ class Lang_test extends CI_TestCase {
public function test_load()
{
+ // Regular usage
$this->ci_vfs_clone('system/language/english/profiler_lang.php');
$this->assertTrue($this->lang->load('profiler', 'english'));
- $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
+ $this->assertEquals('URI STRING', $this->lang->language['profiler_uri_string']);
+
+ // Already loaded file
+ $this->assertNull($this->lang->load('profiler', 'english'));
+
+ // Unspecified language (defaults to english)
+ $this->ci_vfs_clone('system/language/english/date_lang.php');
+ $this->assertTrue($this->lang->load('date'));
+ $this->assertEquals('Year', $this->lang->language['date_year']);
+
+ // Non-alpha idiom (should act the same as unspecified language)
+ $this->ci_vfs_clone('system/language/english/number_lang.php');
+ $this->assertTrue($this->lang->load('number'));
+ $this->assertEquals('Bytes', $this->lang->language['bytes']);
+
+ // Non-existent file
+ $this->setExpectedException(
+ 'RuntimeException',
+ 'CI Error: Unable to load the requested language file: language/english/nonexistent_lang.php'
+ );
+ $this->lang->load('nonexistent');
+
+ // File with no language content
+ $this->ci_vfs_create('foo_lang.php', '<?php $foo = 0;', $this->ci_app_root, 'language/english');
+ $this->assertNull($this->lang->load('foo'));
+
+ // Non-array $lang
+ $this->ci_vfs_create('bar_lang.php', '<?php $lang = FALSE;', $this->ci_app_root, 'language/english');
+ $this->assertNull($this->lang->load('bar'));
+
+ // Non-array / no content, with return = TRUE
+ $this->assertEquals(array(), $this->lang->load('bar'));
+
+ // With an alt_path, return = TRUE & suffix included
+ $this->ci_vfs_mkdir('fubar/language/english', $this->ci_app_root);
+ $this->ci_vfs_create('fubar_lang.php', '<?php $lang = array(\'fubar_test\' => \'Test\');', $this->ci_app_root.'/fubar/language/english');
+ $this->assertEquals(
+ array('fubar_test' => 'Test'),
+ $this->lang->load('fubar_lang', 'english', TRUE, TRUE, $this->ci_app_root.'fubar')
+ );
+ $this->assertEquals(
+ array('fubar_test' => 'Test'),
+ $this->lang->load('fubar_lang', 'english', TRUE, FALSE, $this->ci_app_root.'fubar')
+ );
+ $this->assertEquals(
+ array('fubar_test' => 'Test'),
+ $this->lang->load('fubar_lang.php', 'english', TRUE, FALSE, $this->ci_app_root.'fubar')
+ );
}
// --------------------------------------------------------------------
- public function test_load_with_unspecified_language()
+ /**
+ * @depends test_load
+ */
+ public function test_line()
{
$this->ci_vfs_clone('system/language/english/profiler_lang.php');
- $this->assertTrue($this->lang->load('profiler'));
+ $this->lang->load('profiler', 'english');
$this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string'));
+ $this->assertFalse($this->lang->line('nonexistent_string'));
+ $this->assertFalse($this->lang->line(NULL));
}
} \ No newline at end of file