Skip to content

Commit

Permalink
Removed dol_json_encode/decode in favor of native json_encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 12, 2024
1 parent e3d8586 commit a391143
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/phpunit/JsonLibTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ public function testJsonEncode()
$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');
*/

// 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 \\ \' "'));
Expand All @@ -119,28 +121,30 @@ public function testJsonEncode()
$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');
*/

$encoded = dol_json_encode(123);
$encoded = json_encode(123);
$this->assertEquals(123, $encoded);
$decoded = dol_json_decode($encoded, true);
$this->assertEquals(123, $decoded, 'test for dol_json_xxx 123');
$decoded = json_decode($encoded, true);
$this->assertEquals(123, $decoded, 'test for json_xxx 123');

$encoded = dol_json_encode('abc');
$encoded = json_encode('abc');
$this->assertEquals('"abc"', $encoded);
$decoded = dol_json_decode($encoded, true);
$this->assertEquals('abc', $decoded, "test for dol_json_xxx 'abc'");
$decoded = json_decode($encoded, true);
$this->assertEquals('abc', $decoded, "test for json_xxx 'abc'");

// Test with object
$now = gmmktime(12, 0, 0, 1, 1, 1970);
$objecttotest = new stdClass();
$objecttotest->property1 = 'abc';
$objecttotest->property2 = 1234;
$objecttotest->property3 = $now;
$encoded = dol_json_encode($objecttotest);
$encoded = json_encode($objecttotest);
$this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}', $encoded);
}
}

0 comments on commit a391143

Please sign in to comment.