From 4cc7838a0dda8b4a4ac3da6a6c9744c2402b6296 Mon Sep 17 00:00:00 2001 From: gloas <gloas@git-test.afi-sa.fr> Date: Tue, 14 Jan 2014 13:38:32 +0000 Subject: [PATCH] Boite login: ajout champ select profil: permet de rediriger les actions de mon compte ou de login sur un profil choisi --- .gitignore | 2 +- .../admin/controllers/AccueilController.php | 5 ++ .../views/scripts/modules/auth_form.phtml | 7 ++ .../opac/controllers/AuthController.php | 1 - .../opac/views/scripts/auth/ajax-login.phtml | 2 +- .../opac/views/scripts/auth/boite-login.phtml | 47 +++++------ library/Class/Notice.php | 1 - .../Class/Systeme/ModulesAccueil/Login.php | 3 +- library/ZendAfi/Form/Album.php | 1 - .../Form/Decorator/CochesSuggestion.php | 1 - .../controllers/AccueilControllerTest.php | 29 +++++-- .../opac/controllers/AuthControllerTest.php | 78 ++++++++++++++++++- .../library/Class/Systeme/ModulesMenuTest.php | 1 - 13 files changed, 142 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index e659caa9a52..87e1ddd7895 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ userfiles/image/* userfiles/js/* userfiles/photoBib/* userfiles/photobib/* -userfiles/web_thumbnails/* \ No newline at end of file +userfiles/web_thumbnails/* diff --git a/application/modules/admin/controllers/AccueilController.php b/application/modules/admin/controllers/AccueilController.php index 09e3a9c5551..65a6b015780 100644 --- a/application/modules/admin/controllers/AccueilController.php +++ b/application/modules/admin/controllers/AccueilController.php @@ -141,6 +141,11 @@ class Admin_AccueilController extends Zend_Controller_Action { public function loginAction() { + $this->view->getHelper('ComboProfils') + ->setTagId('profil_redirect') + ->setTagName('profil_redirect') + ->addEmptyOption(); + $this->_simpleAction(); } diff --git a/application/modules/admin/views/scripts/modules/auth_form.phtml b/application/modules/admin/views/scripts/modules/auth_form.phtml index f61f52738e7..4b8f12f734f 100644 --- a/application/modules/admin/views/scripts/modules/auth_form.phtml +++ b/application/modules/admin/views/scripts/modules/auth_form.phtml @@ -72,3 +72,10 @@ <td class="gauche"><input type="text" name="lien_creer_compte" size="50" value="<?php print($this->preferences["lien_creer_compte"]); ?>"></td> </tr> +<tr> + <td class="droite">Basculer automatiquement sur le profil: </td> + <td class="gauche"> + <?php echo $this->ComboProfils('ALL', 'ALL', $this->preferences['profil_redirect']); + ?> + </td> +</tr> diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index 392303edd3a..2e01b25c91b 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -125,7 +125,6 @@ class AuthController extends ZendAfi_Controller_Action { function boiteLoginAction() { $this->view->preferences = Class_Profil::getCurrentProfil()->getModuleAccueilPreferencesByType('auth'); - $strategy = Auth_Strategy_Abstract::strategyForController($this); $strategy->setDefaultUrl($this->_request->getServer('HTTP_REFERER')); $strategy->processLogin(); diff --git a/application/modules/opac/views/scripts/auth/ajax-login.phtml b/application/modules/opac/views/scripts/auth/ajax-login.phtml index 4ffe141ddaa..1f4b42be829 100644 --- a/application/modules/opac/views/scripts/auth/ajax-login.phtml +++ b/application/modules/opac/views/scripts/auth/ajax-login.phtml @@ -22,7 +22,7 @@ function submit() { <?php if($user = Class_Users::getLoader()->getIdentity()) { echo sprintf("<div class='welcome'>%s %s </div>", $this->_($this->preferences['message_connecte']), $user->getNomAff()); - echo sprintf('<a href="%s/abonne/fiche" target="_parent">» %s</a>', $this->url(['controller'=>'abonne','action'=>'fiche']), $this->_($this->preferences['lien_compte'])); + echo sprintf('<a href="%s/abonne/fiche" target="_parent">» %s</a>', $this->url(['controller'=>'abonne','action'=>'fiche'],null,true), $this->_($this->preferences['lien_compte'])); if ($user->hasIdabon()) echo $this->ficheAbonneLinks($user->getNbEmprunts(), $user->getNbEmpruntsRetard(), $user->getNbReservations()); echo sprintf('<a href="%s" target="_parent">» %s</a>', $this->url(['controller'=>'auth','action'=>'logout']), $this->_($this->preferences['lien_deconnection'])); diff --git a/application/modules/opac/views/scripts/auth/boite-login.phtml b/application/modules/opac/views/scripts/auth/boite-login.phtml index 968a5642fc6..90872411e2b 100644 --- a/application/modules/opac/views/scripts/auth/boite-login.phtml +++ b/application/modules/opac/views/scripts/auth/boite-login.phtml @@ -1,23 +1,26 @@ <div class="form"> -<?php -if($user = Class_Users::getLoader()->getIdentity()) { - echo sprintf("<div class='welcome'>%s %s </div>", $this->_($this->preferences['message_connecte']), $user->getNomAff()); - echo sprintf('<a href="%s" target="_parent">%s</a>', $this->url(['controller'=>'abonne', - 'action'=>'fiche']), $this->_($this->preferences['lien_compte'])); - if ($user->hasIdabon()) - echo $this->ficheAbonneLinks($user->getNbEmprunts(), $user->getNbEmpruntsRetard(), $user->getNbReservations()); - echo sprintf('<a href="%s" target="_parent">%s</a>', $this->url(['controller'=>'auth', - 'action'=>'logout']), $this->_($this->preferences['lien_deconnection'])); -} else { - $form = ZendAfi_Form_Login::newWithOptions(['data' => array_merge( - $this->preferences, - ['redirect_url' => $this->redirect, - 'service' => $this->service, - 'id_notice' => $this->id_notice]), - 'action' => $this->url(['controller' => 'auth', - 'action' => 'boite-login', - 'id_module' => $this->id_module])]); - echo $this->renderForm($form); -} -?> -</div> \ No newline at end of file + <?php + if($user = Class_Users::getLoader()->getIdentity()) { + echo sprintf("<div class='welcome'>%s %s </div>", $this->_($this->preferences['message_connecte']), $user->getNomAff()); + + echo sprintf('<a href="%s" target="_parent">%s</a>', $this->url(['controller'=>'abonne', + 'action'=>'fiche', + 'id_profil'=>$this->preferences['profil_redirect'] > 0 ? $this->preferences['profil_redirect'] : Class_Profil::getCurrentProfil()->getId()],null,true), $this->_($this->preferences['lien_compte'])); + if ($user->hasIdabon()) + echo $this->ficheAbonneLinks($user->getNbEmprunts(), $user->getNbEmpruntsRetard(), $user->getNbReservations()); + echo sprintf('<a href="%s" target="_parent">%s</a>', $this->url(['controller'=>'auth', + 'action'=>'logout', + 'id_profil'=>$this->preferences['profil_redirect'] > 0 ? $this->preferences['profil_redirect'] : Class_Profil::getCurrentProfil()->getId()],null,true), $this->_($this->preferences['lien_deconnection'])); + } else { + $form = ZendAfi_Form_Login::newWithOptions(['data' => array_merge( + $this->preferences, + ['redirect_url' => $this->redirect, + 'service' => $this->service, + 'id_notice' => $this->id_notice]), + 'action' => $this->url(['controller' => 'auth', + 'action' => 'boite-login', + 'id_module' => $this->id_module])]); + echo $this->renderForm($form); + } + ?> +</div> diff --git a/library/Class/Notice.php b/library/Class/Notice.php index bdf58185944..5f4ce5342e6 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -1780,7 +1780,6 @@ class Class_Notice extends Storm_Model_Abstract { public function getPaniersLibelles() { - xdebug_break(); $list_panier = $this->getPaniers(); if(($nb_paniers = count($list_panier)) < 1) return ''; diff --git a/library/Class/Systeme/ModulesAccueil/Login.php b/library/Class/Systeme/ModulesAccueil/Login.php index 80126d766bd..5a91f2973f4 100644 --- a/library/Class/Systeme/ModulesAccueil/Login.php +++ b/library/Class/Systeme/ModulesAccueil/Login.php @@ -54,7 +54,8 @@ class Class_Systeme_ModulesAccueil_Login extends Class_Systeme_ModulesAccueil_Nu 'message_connecte' => 'Bienvenue', 'lien_compte' => '» Mon compte', 'lien_deconnection' => '» Se déconnecter', - 'autocomplete_off' => 1 // si == 1, rajoute autocomplete="off" au formulaire + 'autocomplete_off' => 1 ,// si == 1, rajoute autocomplete="off" au formulaire + 'profil_redirect' => '0' ]; } ?> \ No newline at end of file diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php index 9f05a8053b1..2a3b9dc2cd8 100644 --- a/library/ZendAfi/Form/Album.php +++ b/library/ZendAfi/Form/Album.php @@ -204,7 +204,6 @@ class ZendAfi_Form_Album extends ZendAfi_Form { } public function addAffichageFor($album) { - xdebug_break(); return $this ->addElement('cochesSuggestion', 'bibliotheques', ['label' => 'Bibliotheques', diff --git a/library/ZendAfi/Form/Decorator/CochesSuggestion.php b/library/ZendAfi/Form/Decorator/CochesSuggestion.php index c84dde73fd0..ca6a7693ed6 100644 --- a/library/ZendAfi/Form/Decorator/CochesSuggestion.php +++ b/library/ZendAfi/Form/Decorator/CochesSuggestion.php @@ -25,7 +25,6 @@ class ZendAfi_Form_Decorator_CochesSuggestion extends Zend_Form_Decorator_Abstra */ public function render($content) { $helper = $this->_element->getView()->getHelper('tagListeCoches'); - xdebug_break(); $helper->setSelectedAllMeansNothing($this->_element->getSelectedAllMeansNothing()); return $content .$this->_element->getView()->tagListeCoches( diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index 8626d6bcbd5..c400ef6ec62 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -472,15 +472,22 @@ class AccueilControllerConfigBoiteLoginTest extends Admin_AbstractControllerTest public function setUp() { parent::setUp(); Class_Profil::getCurrentProfil() - ->updateModuleConfigAccueil(25, - array('type_module' => 'LOGIN', - 'division' => 4, - 'id_module' => 32, - 'preferences' => array())); + ->updateModuleConfigAccueil(32, + ['type_module' => 'LOGIN', + 'division' => 4, + 'id_module' => 32, + 'preferences' => ['profil_redirect'=>'1', + 'mot_de_pass_exemple' => 'dd/mm/aaaa']]); $this->dispatch('/admin/accueil/login?config=accueil&type_module=LOGIN&id_module=32', true); } + /** @test */ + public function selectProfilRedirectShouldContainsProfil1() { + $this->assertXPathContentContains('//select[@id="profil_redirect"][@name="profil_redirect"]/optgroup/option[@value="1"][@selected="selected"]', 'portail: Accueil', $this->_response->getBody()); + } + + /** @test */ public function inputTitreShouldBeSeConnecter() { $this->assertXPath('//input[@name="titre"][@value="Se connecter"]'); @@ -533,6 +540,18 @@ class AccueilControllerConfigBoiteLoginTest extends Admin_AbstractControllerTest public function profilShouldBeValid() { $this->assertTrue(Class_Profil::getCurrentProfil()->isValid()); } + + + /** @test **/ + public function configShouldContainsSelectProfil() { + $this->assertXPath('//td/select[@name="profil_redirect"][@id="profil_redirect"]'); + } + + + /** @test **/ + public function selectProfilShloudBeEmptyValue() { + $this->assertXPath('//td/select[@id="profil_redirect"]/option'); + } } diff --git a/tests/application/modules/opac/controllers/AuthControllerTest.php b/tests/application/modules/opac/controllers/AuthControllerTest.php index cb40bc44f8e..9ef2957ade1 100644 --- a/tests/application/modules/opac/controllers/AuthControllerTest.php +++ b/tests/application/modules/opac/controllers/AuthControllerTest.php @@ -38,7 +38,8 @@ abstract class PortailWithOneLoginModuleTestCase extends AbstractControllerTestC 'mot_de_passe_exemple' => '1983', 'titre_connecte' => 'Vous êtes connecté(e)', 'lien_connexion' => 'please, log me', - 'lien_mot_de_passe_oublie' => 'me rappelle plus']]], + 'lien_mot_de_passe_oublie' => 'me rappelle plus', + 'profil_redirect' => 1]]], 'options' => []]; Class_Profil::getCurrentProfil() @@ -113,6 +114,13 @@ class AuthControllerAbonneSIGBLoggedTest extends PortailWithOneLoginModuleTestCa } + + /** @test */ + public function redirectProfilShouldBeProfil1(){ + $this->assertXPath('//a[contains(@href,"abonne/fiche/id_profil/1")]',$this->_response->getBody()); + } + + /** @test */ public function linkPretsShouldBePresent() { $this->assertXPathContentContains('//div[@id="boite_login"]//a[contains(@href, "prets")]', '3'); @@ -228,6 +236,7 @@ class AuthControllerNobodyLoggedAndRegistrationAllowedBoiteLoginTest extends Aut $this->assertXPathContentContains('//h1','Se connecter'); } + public function testLinkSeConnecter() { $this->assertXPath('//div[@id="boite_login"]//a[contains(@onclick,"submit")]'); $this->assertXPathContentContains('//div[@id="boite_login"]//a[contains(@onclick, "submit")]', @@ -954,4 +963,71 @@ class AuthControllerNobodyLoggedAndRegistrationAllowedRegisterTest extends AuthC } } + + +class portailWithOneLoginModuleTestAndLoggedUserCase extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_IntBib') + ->whenCalled('findAllBy') + ->answers([]); + + $cfg_accueil = ['modules' => [4 => ['division' => '4', + 'id_module' => 4, + 'type_module' => 'LOGIN', + 'preferences' => [ + 'identifiant' => 'Numéro de carte', + 'mot_de_passe'=> 'Année de naissance', + 'identifiant_exemple' => 'jj-mm-aaaa', + 'mot_de_passe_exemple' => '1983', + 'titre_connecte' => 'Vous êtes connecté(e)', + 'lien_connexion' => 'please, log me', + 'lien_mot_de_passe_oublie' => 'me rappelle plus', + 'profil_redirect' => 0]]], + 'options' => []]; + + Class_Profil::getCurrentProfil() + ->setBrowser('opac') + ->setCfgAccueil(ZendAfi_Filters_Serialize::serialize($cfg_accueil)); + + + ZendAfi_Auth::getInstance()->logUser( + Class_Users::newInstanceWithId(5, + ['login' => 'Pioup', + 'idabon' => 48, + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'id_site' => 1, + 'fiche_sigb' => []])); + + + + $this->dispatch('/opac/'); + } + + + /** @test */ + public function redirectProfilForLoginShouldBeProfil2(){ + $this->assertXPath('//a[contains(@href,"abonne/fiche/id_profil/2")]',$this->_response->getBody()); + } + + + /** @test */ + public function redirectProfilForLoginShouldNotBeProfil0(){ + $this->assertNotXPath('//a[contains(@href,"abonne/fiche/id_profil/0")]',$this->_response->getBody()); + } + + + /** @test */ + public function redirectProfilForLogoutShouldNotBeProfil2(){ + $this->assertXPath('//a[contains(@href,"auth/logout/id_profil/2")]',$this->_response->getBody()); + } + + + /** @test */ + public function redirectProfilForLogoutShouldNotBeProfil0(){ + $this->assertNotXPath('//a[contains(@href,"abonne/logout/id_profil/0")]',$this->_response->getBody()); + } + +} ?> \ No newline at end of file diff --git a/tests/library/Class/Systeme/ModulesMenuTest.php b/tests/library/Class/Systeme/ModulesMenuTest.php index b2820bb9521..aa8e97c2390 100644 --- a/tests/library/Class/Systeme/ModulesMenuTest.php +++ b/tests/library/Class/Systeme/ModulesMenuTest.php @@ -168,7 +168,6 @@ class ModulesMenuTest extends Storm_Test_ModelTestCase { public function vodeclicUrlWithAbonnementInvalidShouldBeJSAlertAbonnementInvalid() { $this->_logUserGaston(); $vodeclic= new Class_Systeme_ModulesMenu_Vodeclic(); - xdebug_break(); $url = $vodeclic->getDynamiqueUrl(); $this->assertContains('Votre abonnement est terminé', $vodeclic->getMessage()); -- GitLab