forked from Wavyzz/dolibarr
Fix php 7.2
This commit is contained in:
@@ -49,12 +49,15 @@ function dol_json_encode($elements)
|
|||||||
{
|
{
|
||||||
dol_syslog('dol_json_encode() is deprecated. Please update your code to use native json_encode().', LOG_WARNING);
|
dol_syslog('dol_json_encode() is deprecated. Please update your code to use native json_encode().', LOG_WARNING);
|
||||||
|
|
||||||
$num=count($elements);
|
$num=0;
|
||||||
if (is_object($elements)) // Count number of properties for an object
|
if (is_object($elements)) // Count number of properties for an object
|
||||||
{
|
{
|
||||||
$num=0;
|
|
||||||
foreach($elements as $key => $value) $num++;
|
foreach($elements as $key => $value) $num++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$num=count($elements);
|
||||||
|
}
|
||||||
//var_dump($num);
|
//var_dump($num);
|
||||||
|
|
||||||
// determine type
|
// determine type
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
|
|||||||
// Do a test with an array starting with 0
|
// Do a test with an array starting with 0
|
||||||
$arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
|
$arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
|
||||||
$arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]';
|
$arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]';
|
||||||
|
|
||||||
$encoded=json_encode($arraytotest);
|
$encoded=json_encode($arraytotest);
|
||||||
$this->assertEquals($arrayencodedexpected,$encoded);
|
$this->assertEquals($arrayencodedexpected,$encoded);
|
||||||
$decoded=json_decode($encoded,true);
|
$decoded=json_decode($encoded,true);
|
||||||
@@ -148,7 +148,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
|
|||||||
// Same test but array start with 2 instead of 0
|
// Same test but array start with 2 instead of 0
|
||||||
$arraytotest=array(2=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
|
$arraytotest=array(2=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "'));
|
||||||
$arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}';
|
$arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}';
|
||||||
|
|
||||||
$encoded=json_encode($arraytotest);
|
$encoded=json_encode($arraytotest);
|
||||||
$this->assertEquals($arrayencodedexpected,$encoded);
|
$this->assertEquals($arrayencodedexpected,$encoded);
|
||||||
$decoded=json_decode($encoded,true);
|
$decoded=json_decode($encoded,true);
|
||||||
@@ -158,7 +158,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($arrayencodedexpected,$encoded);
|
$this->assertEquals($arrayencodedexpected,$encoded);
|
||||||
$decoded=dol_json_decode($encoded,true);
|
$decoded=dol_json_decode($encoded,true);
|
||||||
$this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx');
|
$this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx');
|
||||||
|
|
||||||
// Test with object
|
// Test with object
|
||||||
$now=gmmktime(12,0,0,1,1,1970);
|
$now=gmmktime(12,0,0,1,1,1970);
|
||||||
$objecttotest=new stdClass();
|
$objecttotest=new stdClass();
|
||||||
@@ -167,7 +167,5 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
|
|||||||
$objecttotest->property3=$now;
|
$objecttotest->property3=$now;
|
||||||
$encoded=dol_json_encode($objecttotest);
|
$encoded=dol_json_encode($objecttotest);
|
||||||
$this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}',$encoded);
|
$this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}',$encoded);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user