コード例 #1
0
ファイル: UtilTest.php プロジェクト: aiddroid/utilphp
 public function test_seems_utf8()
 {
     // Test a valid UTF-8 sequence: "ÜTF-8 Fµñ".
     $validUTF8 = "ÜTF-8 Fµñ";
     $this->assertTrue(util::seems_utf8($validUTF8));
     $this->assertTrue(util::seems_utf8("� this has �� some invalid utf8 �"));
     // Test invalid UTF-8 sequences
     $invalidUTF8 = "� this has � some invalid utf8 �";
     $this->assertFalse(util::seems_utf8($invalidUTF8));
     // And test some plain ASCII
     $this->assertTrue(util::seems_utf8('The quick brown fox jumps over the lazy dog'));
     // Test an invalid non-UTF-8 string.
     if (function_exists('mb_convert_encoding')) {
         mb_internal_encoding('UTF-8');
         // Converts the 'ç' UTF-8 character to UCS-2LE
         $utf8Char = pack('n', 50087);
         $ucsChar = mb_convert_encoding($utf8Char, 'UCS-2LE', 'UTF-8');
         // Ensure that PHP's internal encoding system isn't malconfigured.
         $this->assertEquals($utf8Char, 'ç', 'This PHP system\'s internal character set is not properly set as UTF-8.');
         $this->assertEquals($utf8Char, pack('n', 50087), 'Something is wrong with your ICU unicode library.');
         // Test for not UTF-8.
         $this->assertFalse(util::seems_utf8($ucsChar));
         // Test the worker method.
         $method = self::getMethod('seemsUtf8Regex');
         $this->assertFalse($method->invoke(null, $invalidUTF8), 'utilphp\\util::seemsUtf8Regex did not properly detect invalid UTF-8.');
         $this->assertTrue($method->invoke(null, $validUTF8), 'utilphp\\util::seemsUtf8Regex did not properly detect valid UTF-8.');
     }
 }