blob: 7762132045a48bc099d7841cfa15062063cbe799 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<?php
/**
* @runTestsInSeparateProcesses
*/
class Utf8_test extends CI_TestCase {
public function test___constructUTF8_ENABLED()
{
if ( ! defined('PREG_BAD_UTF8_ERROR') OR (ICONV_ENABLED === FALSE && MB_ENABLED === FALSE))
{
return $this->markTestSkipped('PCRE_UTF8 and/or both ext/mbstring & ext/iconv are unavailable');
}
new CI_Utf8('UTF-8');
$this->assertTrue(UTF8_ENABLED);
}
// --------------------------------------------------------------------
public function test__constructUTF8_DISABLED()
{
new CI_Utf8('WINDOWS-1251');
$this->assertFalse(UTF8_ENABLED);
}
// --------------------------------------------------------------------
/**
* is_ascii() test
*
* Note: DO NOT move this below test_clean_string()
*/
public function test_is_ascii()
{
$utf8 = new CI_Utf8('UTF-8');
$this->assertTrue($utf8->is_ascii('foo bar'));
$this->assertFalse($utf8->is_ascii('тест'));
}
// --------------------------------------------------------------------
/**
* clean_string() test
*
* @depends test_is_ascii
* @covers CI_Utf8::clean_string
*/
public function test_clean_string()
{
$utf8 = new CI_Utf8('UTF-8');
$this->assertEquals('foo bar', $utf8->clean_string('foo bar'));
$illegal_utf8 = "\xc0тест";
if (MB_ENABLED)
{
$this->assertEquals('тест', $utf8->clean_string($illegal_utf8));
}
elseif (ICONV_ENABLED)
{
// This is a known issue, iconv doesn't always work with //IGNORE
$this->assertContains($this->utf8->clean_string($illegal_utf8), array('тест', ''));
}
else
{
$this->assertEquals($illegal_utf8, $utf8->clean_string($illegal_utf8));
}
}
// --------------------------------------------------------------------
/**
* convert_to_utf8() test
*
* @covers CI_Utf8::convert_to_utf8
*/
public function test_convert_to_utf8()
{
$utf8 = new CI_Utf8('UTF-8');
if (MB_ENABLED OR ICONV_ENABLED)
{
$this->assertEquals('тест', $utf8->convert_to_utf8('', 'WINDOWS-1251'));
}
else
{
$this->assertFalse($utf8->convert_to_utf8('', 'WINDOWS-1251'));
}
}
}
|