diff options
author | Andrey Andreev <narf@devilix.net> | 2014-02-20 16:51:41 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2014-02-20 16:51:41 +0100 |
commit | bb3edf12d0ca82c62f7b7d570108375ec4379749 (patch) | |
tree | 8be304b5b58b42698bfaf37e6dd19a451a19fa96 /tests/codeigniter/core | |
parent | 10e7a32257b26c5609f4a745e3f80bde00da3a05 (diff) |
CI_Utf8-related changes
- Give priority to mb_convert_encoding() over iconv() in clean_string() (partially fixes #261)
- Add more proper unit tests
Diffstat (limited to 'tests/codeigniter/core')
-rw-r--r-- | tests/codeigniter/core/Input_test.php | 2 | ||||
-rw-r--r-- | tests/codeigniter/core/Utf8_test.php | 70 |
2 files changed, 70 insertions, 2 deletions
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 95833fc91..21ff6d81f 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -13,6 +13,8 @@ class Input_test extends CI_TestCase { $this->ci_set_config('csrf_protection', FALSE); $security = new Mock_Core_Security(); + + $this->ci_set_config('charset', 'UTF-8'); $utf8 = new Mock_Core_Utf8(); $this->input = new Mock_Core_Input($security, $utf8); diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index 2cf404841..7e6ffd930 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -4,22 +4,88 @@ class Utf8_test extends CI_TestCase { public function set_up() { + $this->ci_set_config('charset', 'UTF-8'); $this->utf8 = new Mock_Core_Utf8(); + $this->ci_instance_var('utf8', $this->utf8); } // -------------------------------------------------------------------- - public function test_convert_to_utf8() + /** + * __construct() test + * + * @covers CI_Utf8::__construct + */ + public function test___construct() { - $this->assertEquals('ัะตัั', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251')); + if (defined('PREG_BAD_UTF8_ERROR') && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) && strtoupper(config_item('charset')) === 'UTF-8') + { + $this->assertTrue(UTF8_ENABLED); + } + else + { + $this->assertFalse(UTF8_ENABLED); + } } // -------------------------------------------------------------------- + /** + * is_ascii() test + * + * Note: DO NOT move this below test_clean_string() + */ public function test_is_ascii() { $this->assertTrue($this->utf8->is_ascii('foo bar')); $this->assertFalse($this->utf8->is_ascii('ัะตัั')); } + // -------------------------------------------------------------------- + + /** + * clean_string() test + * + * @depends test_is_ascii + * @covers CI_Utf8::clean_string + */ + public function test_clean_string() + { + $this->assertEquals('foo bar', $this->utf8->clean_string('foo bar')); + + $illegal_utf8 = "\xc0ัะตัั"; + if (MB_ENABLED) + { + $this->assertEquals('ัะตัั', $this->utf8->clean_string($illegal_utf8)); + } + elseif (ICONV_ENABLED) + { + // This is a known issue, iconv doesn't always work with //IGNORE + $this->assertTrue(in_array($this->utf8->clean_string($illegal_utf8), array('ัะตัั', ''), TRUE)); + } + else + { + $this->assertEquals($illegal_utf8, $this->utf8->clean_string($illegal_utf8)); + } + } + + // -------------------------------------------------------------------- + + /** + * convert_to_utf8() test + * + * @covers CI_Utf8::convert_to_utf8 + */ + public function test_convert_to_utf8() + { + if (MB_ENABLED OR ICONV_ENABLED) + { + $this->assertEquals('ัะตัั', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251')); + } + else + { + $this->assertFalse($this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251')); + } + } + }
\ No newline at end of file |