Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
eef5df58
Commit
eef5df58
authored
7 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
Fix php 7.2
parent
3717a016
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/core/lib/json.lib.php
+5
-2
5 additions, 2 deletions
htdocs/core/lib/json.lib.php
test/phpunit/JsonLibTest.php
+3
-5
3 additions, 5 deletions
test/phpunit/JsonLibTest.php
with
8 additions
and
7 deletions
htdocs/core/lib/json.lib.php
+
5
−
2
View file @
eef5df58
...
...
@@ -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
);
$num
=
count
(
$elements
)
;
$num
=
0
;
if
(
is_object
(
$elements
))
// Count number of properties for an object
{
$num
=
0
;
foreach
(
$elements
as
$key
=>
$value
)
$num
++
;
}
else
{
$num
=
count
(
$elements
);
}
//var_dump($num);
// determine type
...
...
This diff is collapsed.
Click to expand it.
test/phpunit/JsonLibTest.php
+
3
−
5
View file @
eef5df58
...
...
@@ -134,7 +134,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
// 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
);
$this
->
assertEquals
(
$arrayencodedexpected
,
$encoded
);
$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
$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
);
...
...
@@ -158,7 +158,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
$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
();
...
...
@@ -167,7 +167,5 @@ class JsonLibTest extends PHPUnit_Framework_TestCase
$objecttotest
->
property3
=
$now
;
$encoded
=
dol_json_encode
(
$objecttotest
);
$this
->
assertEquals
(
'{"property1":"abc","property2":1234,"property3":43200}'
,
$encoded
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment