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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
df08d838
Commit
df08d838
authored
12 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
More robust phpunit tests
parent
e352e4a5
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/user/class/user.class.php
+5
-1
5 additions, 1 deletion
htdocs/user/class/user.class.php
test/phpunit/UserTest.php
+60
-3
60 additions, 3 deletions
test/phpunit/UserTest.php
with
65 additions
and
4 deletions
htdocs/user/class/user.class.php
+
5
−
1
View file @
df08d838
...
...
@@ -1969,6 +1969,8 @@ class User extends CommonObject
$this
->
admin
=
0
;
$this
->
login
=
'dolibspec'
;
$this
->
pass
=
'dolibspec'
;
//$this->pass_indatabase='dolibspec'; Set after a fetch
//$this->pass_indatabase_crypted='e80ca5a88c892b0aaaf7e154853bccab'; Set after a fetch
$this
->
datec
=
time
();
$this
->
datem
=
time
();
$this
->
webcal_login
=
'dolibspec'
;
...
...
@@ -1977,7 +1979,9 @@ class User extends CommonObject
$this
->
datepreviouslogin
=
time
();
$this
->
statut
=
1
;
$this
->
societe_id
=
1
;
//$this->societe_id = 1; For external users
//$this->contact_id = 1; For external users
$this
->
entity
=
1
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
test/phpunit/UserTest.php
+
60
−
3
View file @
df08d838
...
...
@@ -176,11 +176,18 @@ class UserTest extends PHPUnit_Framework_TestCase
$langs
=
$this
->
savlangs
;
$db
=
$this
->
savdb
;
$
localobject
->
note
=
'New note after update'
;
$
this
->
changeProperties
(
$localobject
)
;
$result
=
$localobject
->
update
(
$user
);
print
__METHOD__
.
" id="
.
$localobject
->
id
.
" result="
.
$result
.
"
\n
"
;
$this
->
assertLessThan
(
$result
,
0
);
// Test everything are still same than specimen
$newlocalobject
=
new
User
(
$this
->
savdb
);
$newlocalobject
->
initAsSpecimen
();
$this
->
changeProperties
(
$newlocalobject
);
$this
->
assertEquals
(
$this
->
objCompare
(
$localobject
,
$newlocalobject
,
true
,
array
(
'id'
,
'ref'
,
'pass_indatabase'
,
'pass_indatabase_crypted'
,
'date_creation'
,
'datelastlogin'
,
'datepreviouslogin'
)),
array
());
// Actual, Expected
return
$localobject
;
}
...
...
@@ -204,6 +211,7 @@ class UserTest extends PHPUnit_Framework_TestCase
print
__METHOD__
.
" id="
.
$localobject
->
id
.
" result="
.
$result
.
"
\n
"
;
$this
->
assertLessThan
(
$result
,
0
);
return
$localobject
;
}
...
...
@@ -260,5 +268,54 @@ class UserTest extends PHPUnit_Framework_TestCase
return
$result
;
}
/**
* Edit an object to test updates
*
* @param mixed &$localobject Object Facture
* @return void
*/
public
function
changeProperties
(
&
$localobject
)
{
$localobject
->
note
=
'New note after update'
;
}
/**
* Compare all public properties values of 2 objects
*
* @param Object $oA Object operand 1
* @param Object $oB Object operand 2
* @param boolean $ignoretype False will not report diff if type of value differs
* @param array $fieldstoignorearray Array of fields to ignore in diff
* @return array Array with differences
*/
public
function
objCompare
(
$oA
,
$oB
,
$ignoretype
=
true
,
$fieldstoignorearray
=
array
(
'id'
))
{
$retAr
=
array
();
if
(
get_class
(
$oA
)
!==
get_class
(
$oB
))
{
$retAr
[]
=
"Supplied objects are not of same class."
;
}
else
{
$oVarsA
=
get_object_vars
(
$oA
);
$oVarsB
=
get_object_vars
(
$oB
);
$aKeys
=
array_keys
(
$oVarsA
);
foreach
(
$aKeys
as
$sKey
)
{
if
(
in_array
(
$sKey
,
$fieldstoignorearray
))
continue
;
if
(
!
$ignoretype
&&
$oVarsA
[
$sKey
]
!==
$oVarsB
[
$sKey
])
{
$retAr
[]
=
$sKey
.
' : '
.
(
is_object
(
$oVarsA
[
$sKey
])
?
get_class
(
$oVarsA
[
$sKey
])
:
$oVarsA
[
$sKey
])
.
' <> '
.
(
is_object
(
$oVarsB
[
$sKey
])
?
get_class
(
$oVarsB
[
$sKey
])
:
$oVarsB
[
$sKey
]);
}
if
(
$ignoretype
&&
$oVarsA
[
$sKey
]
!=
$oVarsB
[
$sKey
])
{
$retAr
[]
=
$sKey
.
' : '
.
(
is_object
(
$oVarsA
[
$sKey
])
?
get_class
(
$oVarsA
[
$sKey
])
:
$oVarsA
[
$sKey
])
.
' <> '
.
(
is_object
(
$oVarsB
[
$sKey
])
?
get_class
(
$oVarsB
[
$sKey
])
:
$oVarsB
[
$sKey
]);
}
}
}
return
$retAr
;
}
}
?>
\ No newline at end of file
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