2
0
forked from Wavyzz/dolibarr

Fix: json

This commit is contained in:
Laurent Destailleur
2013-10-11 18:33:21 +02:00
parent 56730741bc
commit de97cd1812
2 changed files with 28 additions and 13 deletions

View File

@@ -130,22 +130,35 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
$this->savlangs=$langs;
$this->savdb=$db;
// Do a test with an array starting with 0
$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 \\\\ \' \""}]';
$encoded=json_encode($arraytotest);
//var_dump($encoded);
$this->assertEquals('[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]',$encoded);
$this->assertEquals($arrayencodedexpected,$encoded);
$decoded=json_decode($encoded,true);
//var_dump($decoded);
$this->assertEquals($arraytotest,$decoded);
$this->assertEquals($arraytotest,$decoded,'test for json_xxx');
$encoded=dol_json_encode($arraytotest);
//var_dump($encoded);
$this->assertEquals('[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]',$encoded);
$this->assertEquals($arrayencodedexpected,$encoded);
$decoded=dol_json_decode($encoded,true);
//var_dump($decoded);
$this->assertEquals($arraytotest,$decoded);
$this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx');
// 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 \\ \' "'));
$arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}';
$encoded=json_encode($arraytotest);
$this->assertEquals($arrayencodedexpected,$encoded);
$decoded=json_decode($encoded,true);
$this->assertEquals($arraytotest,$decoded,'test for json_xxx');
$encoded=dol_json_encode($arraytotest);
$this->assertEquals($arrayencodedexpected,$encoded);
$decoded=dol_json_decode($encoded,true);
$this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx');
// Test with object
$now=gmmktime(12,0,0,1,1,1970);
$objecttotest=new stdClass();
$objecttotest->property1='abc';