mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-15 22:11:36 +01:00
Add phpunit on utf8_check and utf8_valid
This commit is contained in:
@@ -9313,10 +9313,10 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a string is in UTF8
|
* Check if a string is in UTF8. Seems similar to utf8_valid() but in pure PHP.
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @return boolean True if string is UTF8 or ISO compatible with UTF8, False if not (ISO with special char or Binary)
|
* @return boolean True if string is UTF8 or ISO compatible with UTF8, False if not (ISO with special non utf8 char or Binary)
|
||||||
* @see utf8_valid()
|
* @see utf8_valid()
|
||||||
*/
|
*/
|
||||||
function utf8_check($str)
|
function utf8_check($str)
|
||||||
@@ -9324,7 +9324,7 @@ function utf8_check($str)
|
|||||||
$str = (string) $str; // Sometimes string is an int.
|
$str = (string) $str; // Sometimes string is an int.
|
||||||
|
|
||||||
// We must use here a binary strlen function (so not dol_strlen)
|
// We must use here a binary strlen function (so not dol_strlen)
|
||||||
$strLength = dol_strlen($str);
|
$strLength = strlen($str);
|
||||||
for ($i = 0; $i < $strLength; $i++) {
|
for ($i = 0; $i < $strLength; $i++) {
|
||||||
if (ord($str[$i]) < 0x80) {
|
if (ord($str[$i]) < 0x80) {
|
||||||
continue; // 0bbbbbbb
|
continue; // 0bbbbbbb
|
||||||
@@ -9351,7 +9351,7 @@ function utf8_check($str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a string is in UTF8
|
* Check if a string is in UTF8. Seems similar to utf8_check().
|
||||||
*
|
*
|
||||||
* @param string $str String to check
|
* @param string $str String to check
|
||||||
* @return boolean True if string is valid UTF8 string, false if corrupted
|
* @return boolean True if string is valid UTF8 string, false if corrupted
|
||||||
|
|||||||
@@ -1675,6 +1675,45 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testUtf8Check
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function testUtf8Check()
|
||||||
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
|
$chaine = 'This is an UTF8 string with a é.';
|
||||||
|
$result = utf8_check($chaine);
|
||||||
|
$this->assertEquals(true, $result);
|
||||||
|
|
||||||
|
$chaine = mb_convert_encoding('This is an UTF8 with a é.', 'ISO-8859-1', 'UTF-8');
|
||||||
|
$result = utf8_check($chaine);
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testUtf8Valid
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function testUtf8Valid()
|
||||||
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
|
$chaine = 'This is an UTF8 string with a é.';
|
||||||
|
$result = utf8_valid($chaine);
|
||||||
|
$this->assertEquals(true, $result);
|
||||||
|
|
||||||
|
$chaine = mb_convert_encoding('This is an UTF8 with a é.', 'ISO-8859-1', 'UTF-8');
|
||||||
|
$result = utf8_valid($chaine);
|
||||||
|
$this->assertEquals(false, $result);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testGetUserRemoteIP
|
* testGetUserRemoteIP
|
||||||
|
|||||||
Reference in New Issue
Block a user