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
af02bf43
Commit
af02bf43
authored
Jul 10, 2013
by
Bertrand Gauthier
Browse files
Aide de vue UserInfo : améliorations importantes et tests unitaires.
parent
8d1d077d
Changes
18
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/View/Helper/UserInfo.php
View file @
af02bf43
...
...
@@ -47,10 +47,20 @@ class UserInfo extends UserAbstract
return
''
;
}
$libAffAdmin
=
_
(
"Affectations administratives"
);
$libAffRech
=
_
(
"Affectations recherche"
);
$libRespons
=
_
(
"Responsabilités"
);
if
(
$this
->
getTranslator
())
{
$libAffAdmin
=
$this
->
getTranslator
()
->
translate
(
$libAffAdmin
,
$this
->
getTranslatorTextDomain
());
$libAffRech
=
$this
->
getTranslator
()
->
translate
(
$libAffRech
,
$this
->
getTranslatorTextDomain
());
$libRespons
=
$this
->
getTranslator
()
->
translate
(
$libRespons
,
$this
->
getTranslatorTextDomain
());
}
$out
=
''
;
$templateAff
=
'
<strong>
'
.
$
this
->
getView
()
->
translate
(
"Affectations administratives"
)
.
'
:</strong> %s
'
;
$templateAffRech
=
'
<strong>
'
.
$
this
->
getView
()
->
translate
(
"Affectations recherche"
)
.
'
:</strong> %s
'
;
$templateFonctStruct
=
'
<strong>
'
.
$
this
->
getView
()
->
translate
(
"Responsabilités"
)
.
'
:</strong> %s
'
;
$templateAff
=
"
<strong>
"
.
$
libAffAdmin
.
"
:</strong> %s
"
;
$templateAffRech
=
"
<strong>
"
.
$
libAffRech
.
"
:</strong> %s
"
;
$templateFonctStruct
=
"
<strong>
"
.
$
libRespons
.
"
:</strong> %s
"
;
$helperHtmlList
=
new
HtmlList
();
...
...
@@ -58,106 +68,41 @@ class UserInfo extends UserAbstract
// affectations admin
$affectations
=
$authIdentity
->
getAffectationsAdmin
(
$this
->
getMapperStructure
(),
$this
->
getAffectationPrincipale
());
if
(
$affectations
)
{
// $affectations = (array)$this->getMapperStructure()->getMapper()->findChemin(array_keys($affectations));
if
(
empty
(
$affectations
))
$affectations
[]
=
$this
->
getView
()
->
translate
(
"Aucune affectation trouvée."
);
ksort
(
$affectations
);
$affectations
=
$helperHtmlList
(
$affectations
,
$ordered
=
false
,
$attribs
=
false
,
$escape
=
false
);
$out
.
=
sprintf
(
$templateAff
,
$affectations
);
if
(
!
$affectations
)
{
$aucuneAffTrouvee
=
_
(
"Aucune affectation trouvée."
);
if
(
$this
->
getTranslator
())
{
$aucuneAffTrouvee
=
$this
->
getTranslator
()
->
translate
(
$aucuneAffTrouvee
,
$this
->
getTranslatorTextDomain
());
}
$affectations
[]
=
$aucuneAffTrouvee
;
}
ksort
(
$affectations
);
$affectations
=
$helperHtmlList
(
$affectations
,
$ordered
=
false
,
$attribs
=
false
,
$escape
=
false
);
$out
.
=
sprintf
(
$templateAff
,
$affectations
);
// affectations recherche
$affectations
=
$authIdentity
->
getAffectationsRecherche
();
$affectations
=
$authIdentity
->
getAffectationsRecherche
(
$this
->
getMapperStructure
()
);
if
(
$affectations
)
{
$affectations
=
(
array
)
$this
->
getMapperStructure
()
->
findAllPathByCodeStructure
(
array_keys
(
$affectations
));
ksort
(
$affectations
);
$affectations
=
$helperHtmlList
(
$affectations
,
$ordered
=
false
,
$attribs
=
false
,
$escape
=
false
);
$out
.
=
sprintf
(
$templateAffRech
,
$affectations
);
}
// // fonctions structurelles (responsabilités)
// $fss = $authIdentity->getFonctionsStructurelles();
// if ($fss) {
// if (!is_array($fss))
// $fss = array($fss);
// foreach ($fss as $cStructure => $data) {
// if (is_array($data)) {
// $fss[$cStructure] = implode(' ; ', $data);
// }
// }
// ksort($fss);
// $fss = $helperHtmlList($fss, $ordered = false, $attribs = false, $escape = false);
// $out .= sprintf($templateFonctStruct, $fss);
// }
// fonctions structurelles
$fonctions
=
$authIdentity
->
getFonctionsStructurelles
(
$this
->
getMapperStructure
());
if
(
$fonctions
)
{
ksort
(
$fonctions
);
$fonctions
=
$helperHtmlList
(
$fonctions
,
$ordered
=
false
,
$attribs
=
false
,
$escape
=
false
);
$out
.
=
sprintf
(
$templateFonctStruct
,
$fonctions
);
}
}
else
{
$out
.
=
$this
->
getView
()
->
translate
(
"Aucune affectation disponible."
);
$aucuneAffDispo
=
_
(
"Aucune information disponible."
);
if
(
$this
->
getTranslator
())
{
$aucuneAffDispo
=
$this
->
getTranslator
()
->
translate
(
$aucuneAffDispo
,
$this
->
getTranslatorTextDomain
());
}
$out
.
=
$aucuneAffDispo
;
}
// if ($authIdentity instanceof Unicaen_Auth_Identity && $authIdentity->getLdapIdentityData()
// && $authIdentity->getLdapIdentityData() instanceof Unicaen_Model_LdapPeople) {
//
// // affectations admin
// $affectations = $authIdentity->getLdapIdentityData()->getAffectationsAdmin($this->getAffectationPrincipale());
// if ($affectations) {
// $affectations = (array)$this->getMapperStructure()->findChemin(array_keys($affectations));
// if (empty($affectations))
// $affectations[] = "Aucune affectation trouvée.";
// ksort($affectations);
// $affectations = $helperHtmlList($affectations, $ordered = false, $attribs = false, $escape = false);
// $out .= sprintf($templateAff, $affectations);
// }
//
// // affectations recherche
// $affectations = $authIdentity->getLdapIdentityData()->getAffectationsRecherche();
// if ($affectations) {
// $affectations = (array)$this->getMapperStructure()->findChemin(array_keys($affectations));
// ksort($affectations);
// $affectations = $helperHtmlList($affectations, $ordered = false, $attribs = false, $escape = false);
// $out .= sprintf($templateAffRech, $affectations);
// }
//
// // fonctions structurelles (responsabilités)
// $fss = $authIdentity->getLdapIdentityData()->getFonctionsStructurelles();
// if ($fss) {
// if (!is_array($fss))
// $fss = array($fss);
// foreach ($fss as $cStructure => $data) {
// if (is_array($data)) {
// $fss[$cStructure] = implode(' ; ', $data);
// }
// }
// ksort($fss);
// $fss = $helperHtmlList($fss, $ordered = false, $attribs = false, $escape = false);
// $out .= sprintf($templateFonctStruct, $fss);
// }
// /**
// * Problème rencontré en exploitant les rôles génériques: on apprend que NHS est
// * "SECRETAIRE GENERAL" de l'UNIVERSITE DE CAEN, ce qui est faux,
// * comme HBT et ILD. Alors que la base Harpege, elle, indique que NHS est
// * "Directrice Générale Adjointe des Services" de l'UNIVERSITE DE CAEN.
// * J'ai laissé le code pour plus tard...
// */
//// $rolesArray = $authIdentity->getLdapIdentityData()->getRolesToArray(null, true); // format condensé
//// $fss = array();
//// if ($rolesArray) {
//// $facadeLdapStructure = new Unicaen_Model_Facade_Ldap_Structure();
//// foreach ($rolesArray as $code => $roles) {
//// $cs = Unicaen_Model_LdapStructure::extractCodeStrutureHarpege($code);
//// $structure = $facadeLdapStructure->find($cs);
//// foreach ($roles as $r) {
//// $lr = array_key_exists($r, $nomenc=Unicaen_Model_LdapRoleGenerique::$roles) ? $nomenc[$r] : 'Rôle inconnu';
//// $fss[$cs][] = $lr . " ({$structure->lc_structure})";
//// }
//// $fss[$cs] = implode(' ; ', $fss[$cs]);
//// }
//// ksort($fss);
//// $fss = $helperHtmlList->htmlList($fss, $ordered = false, $attribs = false, $escape = false);
//// $out .= sprintf($templateFonctStruct, $fss);
//// }
// }
return
$out
;
}
...
...
tests/UnicaenAuthTest/View/Helper/UserInfoTest.php
0 → 100644
View file @
af02bf43
<?php
namespace
UnicaenAuthTest\View\Helper
;
use
\
UnicaenApp\Entity\Ldap\People
as
LdapPeopleEntity
;
use
\
UnicaenApp\Entity\Ldap\Structure
as
LdapStructureEntity
;
use
UnicaenAppTest\Entity\Ldap\TestAsset\People
as
LdapPeopleTestAsset
;
use
UnicaenAppTest\Entity\Ldap\TestAsset\Structure
as
LdapStructureTestAsset
;
use
UnicaenAppTest\View\Helper\TestAsset\ArrayTranslatorLoader
;
use
UnicaenAuth\View\Helper\UserInfo
;
use
Zend\I18n\Translator\Translator
;
/**
* Description of AppConnectionTest
*
* @property UserInfo $helper Description
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserInfoTest
extends
AbstractTest
{
protected
$helperClass
=
'UnicaenAuth\View\Helper\UserInfo'
;
protected
$renderer
;
protected
$authService
;
protected
$mapperStructure
;
/**
* 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
->
authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
(
'hasIdentity'
,
'getIdentity'
));
$this
->
mapperStructure
=
$this
->
getMock
(
'UnicaenApp\Mapper\Ldap\Structure'
,
array
(
'findOneByDn'
,
'findOnePathByCodeStructure'
,
'findAllPathByCodeStructure'
,
'findOneByCodeEntite'
));
$this
->
helper
->
setMapperStructure
(
$this
->
mapperStructure
)
->
setAuthService
(
$this
->
authService
)
->
setTranslator
(
new
Translator
());
}
public
function
testCanConstructWithAuthService
()
{
$helper
=
new
UserInfo
(
$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
->
getAffectationPrincipale
());
}
public
function
testRenderingReturnsEmptyStringIfNoIdentityAvailable
()
{
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
false
));
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
''
,
$markup
);
}
public
function
testRenderingReturnsInfoMessageIfUnexpectedIdentityAvailable
()
{
$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
(
"Aucune information disponible."
,
$markup
);
// traduction
$this
->
helper
->
setTranslator
(
$this
->
_getTranslator
());
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
"No info available."
,
$markup
);
}
public
function
getInfosAndExpectedScript
()
{
return
array
(
'rien'
=>
array
(
array
(),
array
(),
array
(),
'user_info/rien.phtml'
,
'user_info/rien-translated.phtml'
,
),
'aff-admin-seule'
=>
array
(
array
(
"Chemin > Structure > Affectation"
),
array
(),
array
(),
'user_info/aff-admin-seule.phtml'
,
'user_info/aff-admin-seule-translated.phtml'
,
),
'aff-rech-seule'
=>
array
(
array
(),
array
(
"Chemin > Structure > Recherche"
),
array
(),
'user_info/aff-rech-seule.phtml'
,
'user_info/aff-rech-seule-translated.phtml'
,
),
'fonct-seule'
=>
array
(
array
(),
array
(),
array
(
"Responsable (DSI)"
),
'user_info/fonct-seule.phtml'
,
'user_info/fonct-seule-translated.phtml'
,
),
'pas-fonct'
=>
array
(
array
(
"Chemin > Structure > Affectation"
),
array
(
"Chemin > Structure > Recherche"
),
array
(),
'user_info/pas-fonct.phtml'
,
'user_info/pas-fonct-translated.phtml'
,
),
'pas-aff-admin'
=>
array
(
array
(),
array
(
"Chemin > Structure > Recherche"
),
array
(
"Responsable (DSI)"
),
'user_info/pas-aff-admin.phtml'
,
'user_info/pas-aff-admin-translated.phtml'
,
),
'pas-aff-rech'
=>
array
(
array
(
"Chemin > Structure > Affectation"
),
array
(),
array
(
"Responsable (DSI)"
),
'user_info/pas-aff-rech.phtml'
,
'user_info/pas-aff-rech-translated.phtml'
,
),
'tout'
=>
array
(
array
(
"Chemin > Structure > Affectation"
),
array
(
"Chemin > Structure > Recherche"
),
array
(
"Responsable (DSI)"
),
'user_info/tout.phtml'
,
'user_info/tout-translated.phtml'
,
),
);
}
/**
* @dataProvider getInfosAndExpectedScript
* @param array $affectationsAdmin
* @param array $affectationsRecherche
* @param array $fonctionsStructurelles
* @param string $expectedScript
* @param string $expectedScriptTranslated
*/
public
function
testCanRenderLogoutLinkIfIdentityAvailable
(
$affectationsAdmin
,
$affectationsRecherche
,
$fonctionsStructurelles
,
$expectedScript
,
$expectedScriptTranslated
)
{
$identity
=
$this
->
getMock
(
'UnicaenApp\Entity\Ldap\People'
,
array
(
'getAffectationsAdmin'
,
'getAffectationsRecherche'
,
'getFonctionsStructurelles'
),
array
(),
''
,
false
);
$identity
->
expects
(
$this
->
any
())
->
method
(
'getAffectationsAdmin'
)
->
will
(
$this
->
returnValue
(
$affectationsAdmin
));
$identity
->
expects
(
$this
->
any
())
->
method
(
'getAffectationsRecherche'
)
->
will
(
$this
->
returnValue
(
$affectationsRecherche
));
$identity
->
expects
(
$this
->
any
())
->
method
(
'getFonctionsStructurelles'
)
->
will
(
$this
->
returnValue
(
$fonctionsStructurelles
));
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'hasIdentity'
)
->
will
(
$this
->
returnValue
(
true
));
$this
->
authService
->
expects
(
$this
->
any
())
->
method
(
'getIdentity'
)
->
will
(
$this
->
returnValue
(
$identity
));
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
$expectedScript
),
$markup
);
// traduction
$this
->
helper
->
setTranslator
(
$this
->
_getTranslator
());
$markup
=
(
string
)
$this
->
helper
;
$this
->
assertEquals
(
$this
->
getExpected
(
$expectedScriptTranslated
),
$markup
);
}
/**
* Returns translator
*
* @return Translator
*/
protected
function
_getTranslator
()
{
$loader
=
new
ArrayTranslatorLoader
();
$loader
->
translations
=
array
(
"Aucune information disponible."
=>
"No info available."
,
"Affectations administratives"
=>
"Administrative affectations"
,
"Affectations recherche"
=>
"Research affectations"
,
"Responsabilités"
=>
"Responsabilities"
,
"Aucune affectation trouvée."
=>
"No affectation found."
,
);
$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_info/aff-admin-seule-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/aff-admin-seule.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/aff-rech-seule-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
No affectation found.
</li>
</ul>
<strong>
Research affectations :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/aff-rech-seule.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Aucune affectation trouvée.
</li>
</ul>
<strong>
Affectations recherche :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/fonct-seule-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
No affectation found.
</li>
</ul>
<strong>
Responsabilities :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/fonct-seule.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Aucune affectation trouvée.
</li>
</ul>
<strong>
Responsabilités :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-aff-admin-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
No affectation found.
</li>
</ul>
<strong>
Research affectations :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
<strong>
Responsabilities :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-aff-admin.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Aucune affectation trouvée.
</li>
</ul>
<strong>
Affectations recherche :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
<strong>
Responsabilités :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-aff-rech-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Responsabilities :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-aff-rech.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Responsabilités :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-fonct-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Research affectations :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/pas-fonct.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Affectations recherche :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/rien-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
No affectation found.
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/rien.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Aucune affectation trouvée.
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/tout-translated.phtml
0 → 100644
View file @
af02bf43
<strong>
Administrative affectations :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Research affectations :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
<strong>
Responsabilities :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
tests/UnicaenAuthTest/View/Helper/_files/expected/user_info/tout.phtml
0 → 100644
View file @
af02bf43
<strong>
Affectations administratives :
</strong>
<ul>
<li>
Chemin > Structure > Affectation
</li>
</ul>
<strong>
Affectations recherche :
</strong>
<ul>
<li>
Chemin > Structure > Recherche
</li>
</ul>
<strong>
Responsabilités :
</strong>
<ul>
<li>
Responsable (DSI)
</li>
</ul>
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