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
075bdac1
Commit
075bdac1
authored
Jul 09, 2013
by
Bertrand Gauthier
Browse files
Aide de vue UserCurrent : tests unitaires + légères modifs.
parent
bc72ddd5
Changes
6
Show whitespace changes
Inline
Side-by-side
src/UnicaenAuth/View/Helper/UserCurrent.php
View file @
075bdac1
...
...
@@ -12,10 +12,6 @@ namespace UnicaenAuth\View\Helper;
*/
class
UserCurrent
extends
UserAbstract
{
/**
* @var string
*/
protected
$legende
;
/**
* @var bool
*/
...
...
@@ -24,15 +20,13 @@ class UserCurrent extends UserAbstract
/**
* Point d'entrée.
*
* @param string $legende Légende affichée devant l'identité de l'utilisateur connecté éventuel
* @param boolean $affectationFineSiDispo Indique s'il faut prendre en compte l'affectation
* plus fine (ucbnSousStructure) si elle existe, à la place de l'affectation standard (niveau 2)
* @return
U
se
rCurrent
* @return se
lf
*/
public
function
__invoke
(
$legende
=
null
,
$affectationFineSiDispo
=
false
)
public
function
__invoke
(
$affectationFineSiDispo
=
false
)
{
$this
->
setLegende
(
$legende
?:
_
(
"Utilisateur connecté : "
))
->
setAffectationFineSiDispo
(
$affectationFineSiDispo
);
$this
->
setAffectationFineSiDispo
(
$affectationFineSiDispo
);
return
$this
;
}
...
...
@@ -45,19 +39,38 @@ class UserCurrent extends UserAbstract
{
try
{
$id
=
'user-current-info'
;
$status
=
$this
->
getView
()
->
userStatus
(
false
);
$userStatusHelper
=
$this
->
getView
()
->
plugin
(
'userStatus'
);
/* @var $userStatusHelper \UnicaenAuth\View\Helper\UserStatus */
$status
=
$userStatusHelper
(
false
);
if
(
$this
->
getIdentity
())
{
$content
=
$this
->
getView
()
->
userProfile
()
.
$this
->
getView
()
->
userInfo
(
$this
->
getAffectationFineSiDispo
());
$userProfileHelper
=
$this
->
getView
()
->
plugin
(
'userProfile'
);
/* @var $userProfileHelper \UnicaenAuth\View\Helper\UserProfile */
$userInfoHelper
=
$this
->
getView
()
->
plugin
(
'userInfo'
);
/* @var $userInfoHelper \UnicaenAuth\View\Helper\UserInfo */
$content
=
$userProfileHelper
.
$userInfoHelper
(
$this
->
getAffectationFineSiDispo
());
}
else
{
$content
=
"Aucun"
;
$content
=
_
(
"Aucun"
);
if
(
$this
->
getTranslator
())
{
$content
=
$this
->
getTranslator
()
->
translate
(
$content
,
$this
->
getTranslatorTextDomain
());
}
}
$content
=
preg_replace
(
'/\r\n|\n|\r/'
,
''
,
$content
);
$title
=
_
(
"Utilisateur connecté à l'application"
);
if
(
$this
->
getTranslator
())
{
$title
=
$this
->
getTranslator
()
->
translate
(
$title
,
$this
->
getTranslatorTextDomain
());
}
$out
=
<<<EOS
<a class="navbar-link" id="$id" title="Utilisateur connecté" data-placement="bottom" data-toggle="popover" data-content="$content" href="#">$status</a>
<a class="navbar-link"
id="$id"
title="$title"
data-placement="bottom"
data-toggle="popover"
data-content="$content"
href="#">$status</a>
EOS;
$out
.
=
PHP_EOL
;
$out
.
=
<<<EOS
<script type="text/javascript">
$(function() {
...
...
@@ -65,6 +78,7 @@ EOS;
});
</script>
EOS;
$out
.
=
PHP_EOL
;
}
catch
(
\
Exception
$e
)
{
var_dump
(
$e
);
...
...
@@ -74,28 +88,6 @@ EOS;
return
$out
;
}
/**
* Retourne la légende affichée devant l'identité de l'utilisateur connecté éventuel.
*
* @return string
*/
public
function
getLegende
()
{
return
$this
->
legende
;
}
/**
* Change la légende affichée devant l'identité de l'utilisateur connecté éventuel.
*
* @param string $legende
* @return UserCurrent
*/
public
function
setLegende
(
$legende
=
true
)
{
$this
->
legende
=
$legende
;
return
$this
;
}
/**
* Indique si l'affichage de l'affectation fine éventuelle est activé ou non.
*
...
...
@@ -110,12 +102,11 @@ EOS;
* Active ou non l'affichage de l'affectation fine éventuelle.
*
* @param bool $affectationFineSiDispo
* @return
U
se
rCurrent
* @return se
lf
*/
public
function
setAffectationFineSiDispo
(
$affectationFineSiDispo
=
true
)
{
$this
->
affectationFineSiDispo
=
$affectationFineSiDispo
;
return
$this
;
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserCurrentTest.php
0 → 100644
View file @
075bdac1
<?php
namespace
UnicaenAuthTest\View\Helper
;
use
UnicaenAppTest\View\Helper\TestAsset\ArrayTranslatorLoader
;
use
UnicaenAuth\View\Helper\UserCurrent
;
use
Zend\I18n\Translator\Translator
;
/**
* Description of AppConnectionTest
*
* @property UserCurrent $helper Description
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserCurrentTest
extends
AbstractTest
{
protected
$helperClass
=
'UnicaenAuth\View\Helper\UserCurrent'
;
protected
$renderer
;
protected
$authService
;
protected
$userStatusHelper
;
protected
$userProfileHelper
;
protected
$userInfoHelper
;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
userStatusHelper
=
$userStatusHelper
=
$this
->
getMock
(
'UnicaenAuth\View\Helper\UserStatus'
,
array
(
'__invoke'
));
$this
->
userProfileHelper
=
$userProfileHelper
=
$this
->
getMock
(
'UnicaenAuth\View\Helper\UserProfile'
,
array
(
'__toString'
));
$this
->
userInfoHelper
=
$userInfoHelper
=
$this
->
getMock
(
'UnicaenAuth\View\Helper\UserInfo'
,
array
(
'__invoke'
));
$this
->
userStatusHelper
->
expects
(
$this
->
any
())
->
method
(
'__invoke'
)
->
will
(
$this
->
returnValue
(
'User Status Helper Markup'
));
$this
->
userProfileHelper
->
expects
(
$this
->
any
())
->
method
(
'__toString'
)
->
will
(
$this
->
returnValue
(
'User Profile Helper Markup'
));
$this
->
userInfoHelper
->
expects
(
$this
->
any
())
->
method
(
'__invoke'
)
->
will
(
$this
->
returnValue
(
'User Info Helper Markup'
));
$this
->
renderer
=
$this
->
getMock
(
'Zend\View\Renderer\PhpRenderer'
,
array
(
'plugin'
));
$this
->
renderer
->
expects
(
$this
->
any
())
->
method
(
'plugin'
)
->
will
(
$this
->
returnCallback
(
function
(
$helper
)
use
(
$userStatusHelper
,
$userProfileHelper
,
$userInfoHelper
)
{
if
(
'userstatus'
===
strtolower
(
$helper
))
{
return
$userStatusHelper
;
}
if
(
'userprofile'
===
strtolower
(
$helper
))
{
return
$userProfileHelper
;
}
if
(
'userinfo'
===
strtolower
(
$helper
))
{
return
$userInfoHelper
;
}
return
null
;
}));
$this
->
authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
(
'hasIdentity'
,
'getIdentity'
));
$this
->
helper
->
setAuthService
(
$this
->
authService
)
->
setView
(
$this
->
renderer
)
->
setTranslator
(
new
Translator
());
}
public
function
testCanConstructWithAuthService
()
{
$helper
=
new
UserCurrent
(
$this
->
authService
);
$this
->
assertSame
(
$this
->
authService
,
$helper
->
getAuthService
());
}
public
function
testEntryPointReturnsSelfInstance
()
{
$this
->
assertSame
(
$this
->
helper
,
$this
->
helper
->
__invoke
());
}
public
function
testEntryPointCanSetArgs
()
{
$this
->
helper
->
__invoke
(
$flag
=
true
);
$this
->
assertSame
(
$flag
,
$this
->
helper
->
getAffectationFineSiDispo
());
}
public
function
testCanRenderIfNoIdentityAvailable
()
{
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
false
));
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
'user_current/logged-out.phtml'
),
$markup
);
// traduction
$this
->
helper
->
setTranslator
(
$this
->
_getTranslator
());
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
'user_current/logged-out-translated.phtml'
),
$markup
);
}
public
function
testCanRenderLogoutLinkIfIdentityAvailable
()
{
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'getIdentity'
)
->
will
(
$this
->
returnValue
(
$identity
=
'Auth Service Identity'
));
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
'user_current/logged-in.phtml'
),
$markup
);
// traduction
$this
->
helper
->
setTranslator
(
$this
->
_getTranslator
());
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
'user_current/logged-in-translated.phtml'
),
$markup
);
}
/**
* Returns translator
*
* @return Translator
*/
protected
function
_getTranslator
()
{
$loader
=
new
ArrayTranslatorLoader
();
$loader
->
translations
=
array
(
"Utilisateur connecté à l'application"
=>
"Auth user"
,
"Aucun"
=>
"None"
,
);
$translator
=
new
Translator
();
$translator
->
getPluginManager
()
->
setService
(
'default'
,
$loader
);
$translator
->
addTranslationFile
(
'default'
,
null
);
return
$translator
;
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in-translated.phtml
0 → 100644
View file @
075bdac1
<a
class=
"navbar-link"
id=
"user-current-info"
title=
"Auth user"
data-placement=
"bottom"
data-toggle=
"popover"
data-content=
"User Profile Helper MarkupUser Info Helper Markup"
href=
"#"
>
User Status Helper Markup
</a>
<script
type=
"text/javascript"
>
$
(
function
()
{
$
(
"
#user-current-info
"
).
popover
({
html
:
true
,
container
:
'
#navbar
'
});
});
</script>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-in.phtml
0 → 100644
View file @
075bdac1
<a
class=
"navbar-link"
id=
"user-current-info"
title=
"Utilisateur connecté à l'application"
data-placement=
"bottom"
data-toggle=
"popover"
data-content=
"User Profile Helper MarkupUser Info Helper Markup"
href=
"#"
>
User Status Helper Markup
</a>
<script
type=
"text/javascript"
>
$
(
function
()
{
$
(
"
#user-current-info
"
).
popover
({
html
:
true
,
container
:
'
#navbar
'
});
});
</script>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out-translated.phtml
0 → 100644
View file @
075bdac1
<a
class=
"navbar-link"
id=
"user-current-info"
title=
"Auth user"
data-placement=
"bottom"
data-toggle=
"popover"
data-content=
"None"
href=
"#"
>
User Status Helper Markup
</a>
<script
type=
"text/javascript"
>
$
(
function
()
{
$
(
"
#user-current-info
"
).
popover
({
html
:
true
,
container
:
'
#navbar
'
});
});
</script>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_current/logged-out.phtml
0 → 100644
View file @
075bdac1
<a
class=
"navbar-link"
id=
"user-current-info"
title=
"Utilisateur connecté à l'application"
data-placement=
"bottom"
data-toggle=
"popover"
data-content=
"Aucun"
href=
"#"
>
User Status Helper Markup
</a>
<script
type=
"text/javascript"
>
$
(
function
()
{
$
(
"
#user-current-info
"
).
popover
({
html
:
true
,
container
:
'
#navbar
'
});
});
</script>
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