Merge branch 'develop' of ssh://git@github.com/Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
e6efef9e5c
@ -23,6 +23,19 @@
|
||||
* \ingroup core
|
||||
*/
|
||||
|
||||
if (! function_exists('json_encode'))
|
||||
{
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
*
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function json_encode($elements)
|
||||
{
|
||||
return dol_json_encode($elements);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement json_encode for PHP that does not support it
|
||||
@ -30,7 +43,7 @@
|
||||
* @param mixed $elements PHP Object to json encode
|
||||
* @return string Json encoded string
|
||||
*/
|
||||
function json_encode($elements)
|
||||
function dol_json_encode($elements)
|
||||
{
|
||||
$num = count($elements);
|
||||
|
||||
@ -174,6 +187,20 @@ function _val($val)
|
||||
else return 'null';
|
||||
}
|
||||
|
||||
if (! function_exists('json_decode'))
|
||||
{
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
*
|
||||
* @param string $json Json encoded to PHP Object or Array
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function json_decode($json, $assoc=false)
|
||||
{
|
||||
return dol_json_decode($json, $assoc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement json_decode for PHP that does not support it
|
||||
@ -182,7 +209,7 @@ function _val($val)
|
||||
* @param bool $assoc False return an object, true return an array
|
||||
* @return mixed Object or Array
|
||||
*/
|
||||
function json_decode($json, $assoc=false)
|
||||
function dol_json_decode($json, $assoc=false)
|
||||
{
|
||||
$comment = false;
|
||||
|
||||
@ -226,7 +253,6 @@ function json_decode($json, $assoc=false)
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return text according to type
|
||||
*
|
||||
@ -245,7 +271,6 @@ function _unval($val)
|
||||
return $val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-16 char to one UTF-8 char
|
||||
*
|
||||
@ -289,7 +314,6 @@ function utf162utf8($utf16)
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-8 char to one UTF-16 char
|
||||
*
|
||||
|
||||
@ -28,6 +28,7 @@ global $conf,$user,$langs,$db;
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/core/lib/json.lib.php';
|
||||
|
||||
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
||||
if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
|
||||
@ -378,12 +379,20 @@ class FunctionsTest extends PHPUnit_Framework_TestCase
|
||||
$this->savdb=$db;
|
||||
|
||||
$arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
|
||||
|
||||
$encoded=json_encode($arraytotest);
|
||||
//var_dump($encoded);
|
||||
$this->assertEquals('[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]',$encoded);
|
||||
$decoded=json_decode($encoded,true);
|
||||
//var_dump($decoded);
|
||||
$this->assertEquals($arraytotest,$decoded);
|
||||
|
||||
$encoded=dol_json_encode($arraytotest);
|
||||
//var_dump($encoded);
|
||||
$this->assertEquals('[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]',$encoded);
|
||||
$decoded=dol_json_decode($encoded,true);
|
||||
//var_dump($decoded);
|
||||
$this->assertEquals($arraytotest,$decoded);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user