Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
auth
Commits
6100facd
Commit
6100facd
authored
Oct 02, 2013
by
Bertrand Gauthier
Browse files
Tests unitaires et améliorations/refactorisations.
parent
9b578467
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/View/Helper/UserAbstract.php
View file @
6100facd
...
...
@@ -53,6 +53,20 @@ abstract class UserAbstract extends \Zend\I18n\View\Helper\AbstractTranslatorHel
return
null
;
}
return
$this
->
getAuthService
()
->
getIdentity
();
$identity
=
$this
->
getAuthService
()
->
getIdentity
();
if
(
is_array
(
$identity
))
{
if
(
isset
(
$identity
[
'db'
]))
{
$identity
=
$identity
[
'db'
];
}
elseif
(
isset
(
$identity
[
'ldap'
]))
{
$identity
=
$identity
[
'ldap'
];
}
else
{
throw
new
\
InvalidArgumentException
(
"Données d'identité invalides."
);
}
}
return
$identity
;
}
}
src/UnicaenAuth/View/Helper/UserStatus.php
View file @
6100facd
...
...
@@ -60,18 +60,6 @@ class UserStatus extends UserAbstract
protected
function
createStatusContainer
()
{
if
((
$identity
=
$this
->
getIdentity
()))
{
if
(
is_array
(
$identity
))
{
if
(
isset
(
$identity
[
'db'
]))
{
$identity
=
$identity
[
'db'
];
}
elseif
(
isset
(
$identity
[
'ldap'
]))
{
$identity
=
$identity
[
'ldap'
];
}
else
{
throw
new
\
InvalidArgumentException
(
"Données d'identité invalides."
);
}
}
if
(
method_exists
(
$identity
,
'__toString'
))
{
$name
=
(
string
)
$identity
;
}
...
...
tests/UnicaenAuthTest/Provider/Role/DbTest.php
0 → 100644
View file @
6100facd
<?php
namespace
UnicaenAuthTest\Provider\Role
;
use
PHPUnit_Framework_TestCase
;
use
UnicaenAuth\Provider\Role\Db
;
use
BjyAuthorize\Provider\Role\ObjectRepositoryProvider
;
/**
* Description of DbTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
DbTest
extends
PHPUnit_Framework_TestCase
{
protected
$provider
;
protected
$objectRepository
;
protected
function
setUp
()
{
$this
->
objectRepository
=
$this
->
getMock
(
'Doctrine\Common\Persistence\ObjectRepository'
,
array
());
$this
->
provider
=
new
Db
(
$this
->
objectRepository
);
}
public
function
testGettingRolesReturnsParentClassRoles
()
{
ObjectRepositoryProvider
::
$throwException
=
false
;
$this
->
assertEquals
(
array
(
'Role 1'
,
'Role 2'
),
$this
->
provider
->
getRoles
());
}
public
function
testException
()
{
ObjectRepositoryProvider
::
$throwException
=
true
;
$this
->
assertEquals
(
array
(),
$this
->
provider
->
getRoles
());
}
}
namespace
BjyAuthorize\Provider\Role
;
use
Doctrine\Common\Persistence\ObjectRepository
;
class
ObjectRepositoryProvider
implements
ProviderInterface
{
public
static
$throwException
=
false
;
public
function
__construct
(
ObjectRepository
$objectRepository
)
{
}
public
function
getRoles
()
{
if
(
self
::
$throwException
)
{
throw
new
\
PDOException
(
"No db connection!"
);
}
else
{
return
array
(
'Role 1'
,
'Role 2'
);
}
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserAbstractTest.php
View file @
6100facd
...
...
@@ -57,4 +57,53 @@ class UserAbstractTest extends PHPUnit_Framework_TestCase
->
will
(
$this
->
returnValue
(
$identity
=
'Auth Service Identity'
));
$this
->
assertEquals
(
$identity
,
$this
->
helper
->
getIdentity
());
}
public
function
provideValidArrayIdentity
()
{
return
array
(
array
(
array
(
'db'
=>
'Db Identity'
),
'Db Identity'
),
array
(
array
(
'ldap'
=>
'Ldap Identity'
),
'Ldap Identity'
),
array
(
array
(
'db'
=>
'Db Identity'
,
'ldap'
=>
'Ldap Identity'
),
'Db Identity'
),
);
}
/**
* @dataProvider provideValidArrayIdentity
* @param array $identity
* @param string $expected
*/
public
function
testGettingIdentityReturnsAuthServiceIdentityFromValidArrayIdentity
(
$identity
,
$expected
)
{
$this
->
authService
->
expects
(
$this
->
once
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
authService
->
expects
(
$this
->
once
())
->
method
(
'getIdentity'
)
->
will
(
$this
->
returnValue
(
$identity
));
$this
->
assertEquals
(
$expected
,
$this
->
helper
->
getIdentity
());
}
public
function
provideInvalidArrayIdentity
()
{
return
array
(
array
(
array
()),
array
(
array
(
'other'
=>
'Other Identity'
)),
);
}
/**
* @dataProvider provideInvalidArrayIdentity
* @expectedException \InvalidArgumentException
* @param array $identity
*/
public
function
testGettingIdentityThrowsExceptionFromInvalidArrayIdentity
(
$identity
)
{
$this
->
authService
->
expects
(
$this
->
once
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
authService
->
expects
(
$this
->
once
())
->
method
(
'getIdentity'
)
->
will
(
$this
->
returnValue
(
$identity
));
$this
->
helper
->
getIdentity
();
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserStatusTest.php
View file @
6100facd
...
...
@@ -169,7 +169,7 @@ class UserStatusTest extends AbstractTest
{
$loader
=
new
ArrayTranslatorLoader
();
$loader
->
translations
=
array
(
"
Aucun
"
=>
"None"
,
"
Vous n'êtes pas connecté(e)
"
=>
"None"
,
);
$translator
=
new
Translator
();
...
...
tests/UnicaenAuthTest/View/Helper/_files/expected/user_status/no-identity-with-link.phtml
View file @
6100facd
<strong>
Aucun
</strong>
| UserConnection Helper Markup
\ No newline at end of file
<strong>
Vous n'êtes pas connecté(e)
</strong>
| UserConnection Helper Markup
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/_files/expected/user_status/no-identity-without-link.phtml
View file @
6100facd
<strong>
Aucun
</strong>
\ No newline at end of file
<strong>
Vous n'êtes pas connecté(e)
</strong>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment