3 * @version $Id: utf8_validation.test.php,v 1.6 2006/02/26 13:39:37 harryf Exp $
8 //--------------------------------------------------------------------
14 require_once(dirname(__FILE__).'/../config.php');
15 require_once UTF8 . '/utils/validation.php';
17 //--------------------------------------------------------------------
22 class test_utf8_is_valid extends UnitTestCase {
24 function test_utf8_is_valid() {
25 $this->UnitTestCase('utf8_is_valid()');
28 function testValidUtf8() {
29 $str = 'Iñtërnâtiônàlizætiøn';
30 $this->assertTrue(utf8_is_valid($str));
33 function testValidUtf8Ascii() {
35 $this->assertTrue(utf8_is_valid($str));
38 function testInvalidUtf8() {
39 $str = "Iñtërnâtiôn\xe9àlizætiøn";
40 $this->assertFalse(utf8_is_valid($str));
43 function testInvalidUtf8Ascii() {
44 $str = "this is an invalid char '\xe9' here";
45 $this->assertFalse(utf8_is_valid($str));
48 function testEmptyString() {
50 $this->assertTrue(utf8_is_valid($str));
53 function testValidTwoOctetId() {
55 $this->assertTrue(utf8_is_valid($str));
58 function testInvalidTwoOctetSequence() {
59 $str = "Iñtërnâtiônàlizætiøn \xc3\x28 Iñtërnâtiônàlizætiøn";
60 $this->assertFalse(utf8_is_valid($str));
63 function testInvalidIdBetweenTwoAndThree() {
64 $str = "Iñtërnâtiônàlizætiøn\xa0\xa1Iñtërnâtiônàlizætiøn";
65 $this->assertFalse(utf8_is_valid($str));
68 function testValidThreeOctetId() {
69 $str = "Iñtërnâtiônàlizætiøn\xe2\x82\xa1Iñtërnâtiônàlizætiøn";
70 $this->assertTrue(utf8_is_valid($str));
73 function testInvalidThreeOctetSequenceSecond() {
74 $str = "Iñtërnâtiônàlizætiøn\xe2\x28\xa1Iñtërnâtiônàlizætiøn";
75 $this->assertFalse(utf8_is_valid($str));
78 function testInvalidThreeOctetSequenceThird() {
79 $str = "Iñtërnâtiônàlizætiøn\xe2\x82\x28Iñtërnâtiônàlizætiøn";
80 $this->assertFalse(utf8_is_valid($str));
83 function testValidFourOctetId() {
84 $str = "Iñtërnâtiônàlizætiøn\xf0\x90\x8c\xbcIñtërnâtiônàlizætiøn";
85 $this->assertTrue(utf8_is_valid($str));
88 function testInvalidFourOctetSequence() {
89 $str = "Iñtërnâtiônàlizætiøn\xf0\x28\x8c\xbcIñtërnâtiônàlizætiøn";
90 $this->assertFalse(utf8_is_valid($str));
93 function testInvalidFiveOctetSequence() {
94 $str = "Iñtërnâtiônàlizætiøn\xf8\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
95 $this->assertFalse(utf8_is_valid($str));
98 function testInvalidSixOctetSequence() {
99 $str = "Iñtërnâtiônàlizætiøn\xfc\xa1\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
100 $this->assertFalse(utf8_is_valid($str));
105 //--------------------------------------------------------------------
110 class test_utf8_compliant extends UnitTestCase {
112 function test_utf8_compliant() {
113 $this->UnitTestCase('utf8_compliant()');
116 function testValidUtf8() {
117 $str = 'Iñtërnâtiônàlizætiøn';
118 $this->assertTrue(utf8_compliant($str));
121 function testValidUtf8Ascii() {
123 $this->assertTrue(utf8_compliant($str));
126 function testInvalidUtf8() {
127 $str = "Iñtërnâtiôn\xe9àlizætiøn";
128 $this->assertFalse(utf8_compliant($str));
131 function testInvalidUtf8Ascii() {
132 $str = "this is an invalid char '\xe9' here";
133 $this->assertFalse(utf8_compliant($str));
136 function testEmptyString() {
138 $this->assertTrue(utf8_compliant($str));
141 function testValidTwoOctetId() {
143 $this->assertTrue(utf8_compliant($str));
146 function testInvalidTwoOctetSequence() {
147 $str = "Iñtërnâtiônàlizætiøn \xc3\x28 Iñtërnâtiônàlizætiøn";
148 $this->assertFalse(utf8_compliant($str));
151 function testInvalidIdBetweenTwoAndThree() {
152 $str = "Iñtërnâtiônàlizætiøn\xa0\xa1Iñtërnâtiônàlizætiøn";
153 $this->assertFalse(utf8_compliant($str));
156 function testValidThreeOctetId() {
157 $str = "Iñtërnâtiônàlizætiøn\xe2\x82\xa1Iñtërnâtiônàlizætiøn";
158 $this->assertTrue(utf8_compliant($str));
161 function testInvalidThreeOctetSequenceSecond() {
162 $str = "Iñtërnâtiônàlizætiøn\xe2\x28\xa1Iñtërnâtiônàlizætiøn";
163 $this->assertFalse(utf8_compliant($str));
166 function testInvalidThreeOctetSequenceThird() {
167 $str = "Iñtërnâtiônàlizætiøn\xe2\x82\x28Iñtërnâtiônàlizætiøn";
168 $this->assertFalse(utf8_compliant($str));
171 function testValidFourOctetId() {
172 $str = "Iñtërnâtiônàlizætiøn\xf0\x90\x8c\xbcIñtërnâtiônàlizætiøn";
173 $this->assertTrue(utf8_compliant($str));
176 function testInvalidFourOctetSequence() {
177 $str = "Iñtërnâtiônàlizætiøn\xf0\x28\x8c\xbcIñtërnâtiônàlizætiøn";
178 $this->assertFalse(utf8_compliant($str));
181 function testInvalidFiveOctetSequence() {
182 $str = "Iñtërnâtiônàlizætiøn\xf8\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
183 $this->assertTrue(utf8_compliant($str));
186 function testInvalidSixOctetSequence() {
187 $str = "Iñtërnâtiônàlizætiøn\xfc\xa1\xa1\xa1\xa1\xa1Iñtërnâtiônàlizætiøn";
188 $this->assertTrue(utf8_compliant($str));
193 //--------------------------------------------------------------------
198 if (!defined('TEST_RUNNING')) {
199 define('TEST_RUNNING', true);
200 $test = &new GroupTest('utf8_validation');
201 $test->addTestCase(new test_utf8_is_valid());
202 $test->addTestCase(new test_utf8_compliant());
203 $reporter = & getTestReporter();
204 $test->run($reporter);