From 1879b2749018ef5c8f861e03adc2593c19cc8f31 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Tue, 17 Nov 2020 10:49:45 +0100 Subject: [PATCH] hotline MT #121345 Chili template: - add custom login widget which can display a choosen profile menu when user is connected - menus patron cards / loans / holds have a custom form for Intonation to display additional informations --- VERSIONS_HOTLINE/121345 | 1 + .../admin/controllers/TemplateController.php | 4 +- .../opac/controllers/AbonneController.php | 18 +- .../opac/controllers/ModulesController.php | 10 + .../opac/views/scripts/abonne/cards.phtml | 82 +------- library/Class/Profil/Promoter.php | 2 +- library/Class/Systeme/ModulesAccueil/Null.php | 5 + library/Class/Systeme/ModulesMenu.php | 99 ++++++---- library/Class/Systeme/Widget/Menu.php | 5 + library/Class/Template.php | 14 ++ library/ZendAfi/Controller/Action.php | 10 - .../ZendAfi/Controller/Action/Helper/View.php | 6 + .../Form/Configuration/Widget/Login.php | 2 + .../Helper/Abonne/ConfigurationsBoard.php | 131 ++++++++++++ .../Chili/Library/FormCustomizer/Login.php | 41 ++++ .../Chili/Library/ProfilePatcher.php | 2 + .../Chili/Library/Widget/Login/Definition.php | 28 +++ .../Chili/Library/Widget/Login/View.php | 53 +++++ library/templates/Chili/Template.php | 16 ++ .../Library/Menu/AbonneCards/Definition.php | 38 ++++ .../Library/Menu/AbonnePrets/Definition.php | 35 ++++ .../Menu/AbonneReservations/Definition.php | 35 ++++ .../Library/Menu/Form/AbonneCards.php | 31 +++ .../Library/Menu/Form/WithCounter.php | 31 +++ .../Intonation/Library/Widget/Nav/View.php | 5 + library/templates/Intonation/Template.php | 7 + .../modules/AbstractControllerTestCase.php | 19 +- tests/scenarios/Templates/ChiliLoginTest.php | 187 ++++++++++++++++++ tests/scenarios/Templates/ChiliTest.php | 32 +-- .../Templates/TemplatesAbonneTest.php | 16 ++ .../scenarios/Templates/TemplatesRssTest.php | 11 +- .../scenarios/Templates/TemplatesTryTest.php | 29 +++ 32 files changed, 821 insertions(+), 184 deletions(-) create mode 100644 VERSIONS_HOTLINE/121345 create mode 100644 library/ZendAfi/View/Helper/Abonne/ConfigurationsBoard.php create mode 100644 library/templates/Chili/Library/FormCustomizer/Login.php create mode 100644 library/templates/Chili/Library/Widget/Login/Definition.php create mode 100644 library/templates/Chili/Library/Widget/Login/View.php create mode 100644 library/templates/Intonation/Library/Menu/AbonneCards/Definition.php create mode 100644 library/templates/Intonation/Library/Menu/AbonnePrets/Definition.php create mode 100644 library/templates/Intonation/Library/Menu/AbonneReservations/Definition.php create mode 100644 library/templates/Intonation/Library/Menu/Form/AbonneCards.php create mode 100644 library/templates/Intonation/Library/Menu/Form/WithCounter.php create mode 100644 tests/scenarios/Templates/ChiliLoginTest.php diff --git a/VERSIONS_HOTLINE/121345 b/VERSIONS_HOTLINE/121345 new file mode 100644 index 00000000000..34a58aae830 --- /dev/null +++ b/VERSIONS_HOTLINE/121345 @@ -0,0 +1 @@ + - ticket #121345 : Magasin de thèmes : amélioration de la boite de connexion dans le thème Chili. Il est maintenant possible d'utiliser un menu dans la boite login en mode formulaire à bascule pour gérer les liens qui seront affichés une fois connecté. \ No newline at end of file diff --git a/application/modules/admin/controllers/TemplateController.php b/application/modules/admin/controllers/TemplateController.php index 0553812a909..b99e4adbc6c 100644 --- a/application/modules/admin/controllers/TemplateController.php +++ b/application/modules/admin/controllers/TemplateController.php @@ -59,7 +59,9 @@ class Admin_TemplateController extends ZendAfi_Controller_Action { if ($this->view->profile = Class_Profil::findFirstBy(['commentaire' => $control_key])) return; - $this->_forward('try'); + $this->view->titre = $this->_('Génération du profil qui sera utilisé pour tester le thème %s', + $this->view->template->getTitle()); + return $this->_popupJavascriptRedirectTo($this->view->url(['action' => 'try'])); } diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 11bb9d0a38e..e647c7e75dc 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -1255,13 +1255,6 @@ class AbonneController extends ZendAfi_Controller_Action { } - public function cardsAction() { - $this->view->titre = $this->_('Mes cartes'); - $this->view->child_cards = new Class_User_Cards($this->_user); - $this->view->parent_cards = $this->_user->getParentCards(); - } - - public function associatedProvidersAction() { $this->view->titre = $this->_('Mes comptes associés'); $this->view->identities = Class_User_Identity::findIdentitiesForActiveProviders($this->_user); @@ -1824,16 +1817,13 @@ class AbonneController extends ZendAfi_Controller_Action { } - public function mesAvisAction() { - } + public function mesAvisAction() { } + public function cardsAction() { } - public function configurationsAction() { - } - + public function configurationsAction() { } - public function agendaAction() { - } + public function agendaAction() { } public function donnerDesAvisAction() { diff --git a/application/modules/opac/controllers/ModulesController.php b/application/modules/opac/controllers/ModulesController.php index 9999ee9f3ae..d69b2381942 100644 --- a/application/modules/opac/controllers/ModulesController.php +++ b/application/modules/opac/controllers/ModulesController.php @@ -91,4 +91,14 @@ class ModulesController extends ZendAfi_Controller_Action { $this->willRedirectToMe($link) ->checkNotifyMessage($link, $link->getDynamiqueUrl()); } + + + protected function checkNotifyMessage($ressource_link, $url) { + if ('' == $url) { + $this->_helper->notify($ressource_link->getMessage()); + return $this->_redirect($this->_request->getServer('HTTP_REFERER')); + } + + $this->_javascriptRedirectTo($url); + } } diff --git a/application/modules/opac/views/scripts/abonne/cards.phtml b/application/modules/opac/views/scripts/abonne/cards.phtml index 4575b9d3ea2..ae3c486b897 100644 --- a/application/modules/opac/views/scripts/abonne/cards.phtml +++ b/application/modules/opac/views/scripts/abonne/cards.phtml @@ -1,82 +1,2 @@ <?php -$this->openBoite($this->titre); -?> -<section> - <?php - echo $this->tag('h2', $this->_('J\'utilise les cartes suivantes')); - - echo $this->child_cards->isEmpty() - ? $this->tag('p', $this->_('Vous n\'avez ajouté aucune carte')) - : $this->tagModelTable( - $this->child_cards, - - [$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom'), $this->_('Expire le')], - - ['login', - 'nom', - 'prenom', - 'subscription_end'], - - [ function($user) { - if ($user->getId() == Class_Users::getIdentity()->getId()) - return ''; - return $this->tagAnchor(['action' => 'unlink-card', 'id' => $user->getId()], - $this->boutonIco('type=del')); - } ], - - 'child_cards', - - null, - - ['login' => function($user) { - return $user->getId() == Class_Users::getIdentity()->getId() - ? $this->_('%s (ma carte)', $user->getLogin()) - : $user->getLogin(); - }, - - 'subscription_end' => function($user) { - return Class_Date::humanDate($user->getDateFin(), 'dd MMMM yyyy'); - } - ]); - - - echo $this->tagAnchor(['action' => 'add-card'], - $this->_('Ajouter une carte'), - ['data-popup' => 'true', - 'class' => 'bouton']); - ?> -</section> - -<?php -if ($this->parent_cards) { -?> - <section> - <?php - echo $this->tag('h2', $this->_('Les utilisateurs suivants ont ma carte')); - - echo $this->tagModelTable($this->parent_cards, - - [$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom')], - - ['login', - 'nom', - 'prenom', - ], - - [ function($user) { - return $this->tagAnchor(['action' => 'unlink-parent-card', 'id' => $user->getId()], - $this->boutonIco('type=del')); - } ], - - 'parent_cards', - - null); - - ?> - </section> -<?php } ?> - -<?php -$this->closeBoite(); -echo $this->abonne_RetourFiche(); -?> +echo $this->abonne_ConfigurationsBoard($this->user); diff --git a/library/Class/Profil/Promoter.php b/library/Class/Profil/Promoter.php index 5a08e2945a0..d98121f3fba 100644 --- a/library/Class/Profil/Promoter.php +++ b/library/Class/Profil/Promoter.php @@ -97,7 +97,7 @@ class Class_Profil_Promoter { if ( is_array($value)) $new_cfg = $this->_upgradeCfg($new_cfg, $key, $value, $old_id); - if ( ( 'menu' === $key ) || ( 'use_profil' === $key ) ) + if (in_array($key, ['menu', 'use_profil', 'authenticated_menu'])) $new_cfg [$key] = str_replace($old_id, Class_Profil::DEFAULT_PROFIL, $value); } diff --git a/library/Class/Systeme/ModulesAccueil/Null.php b/library/Class/Systeme/ModulesAccueil/Null.php index 2dc167fe996..aa00b872ef3 100644 --- a/library/Class/Systeme/ModulesAccueil/Null.php +++ b/library/Class/Systeme/ModulesAccueil/Null.php @@ -209,4 +209,9 @@ class Class_Systeme_ModulesAccueil_Null { public function getViewHelper() { return $this->_view_helper; } + + + public function getTag($params) { + return ''; + } } \ No newline at end of file diff --git a/library/Class/Systeme/ModulesMenu.php b/library/Class/Systeme/ModulesMenu.php index f82a92521e7..127846901b3 100644 --- a/library/Class/Systeme/ModulesMenu.php +++ b/library/Class/Systeme/ModulesMenu.php @@ -34,6 +34,48 @@ class Class_Systeme_ModulesMenu extends Class_Systeme_ModulesAbstract { const MODULE_ACCUEIL_PREFIX = 'MODULE_ACCUEIL_'; + const MODULES_CLASS_DEFINITION = ['vide' => Class_Systeme_ModulesMenu_Null::class, + 'MENU' => Class_Systeme_ModulesMenu_Menu::class, + 'ACCUEIL' => Class_Systeme_ModulesMenu_Accueil::class, + 'CONNECT' => Class_Systeme_ModulesMenu_Connect::class, + 'DISCONNECT' => Class_Systeme_ModulesMenu_Disconnect::class, + 'AVIS' => Class_Systeme_ModulesMenu_Avis::class, + 'LAST_NEWS' => Class_Systeme_ModulesMenu_LastNews::class, + 'NEWS' => Class_Systeme_ModulesMenu_News::class, + 'SITO' => Class_Systeme_ModulesMenu_Sitotheque::class, + 'RSS' => Class_Systeme_ModulesMenu_Rss::class, + 'URL' => Class_Systeme_ModulesMenu_Url::class, + 'PROFIL' => Class_Systeme_ModulesMenu_Profil::class, + 'BIBNUM' => Class_Systeme_ModulesMenu_BibliothequeNumerique::class, + 'RECH_SIMPLE' => Class_Systeme_ModulesMenu_RechercheSimple::class, + 'RECH_AVANCEE' => Class_Systeme_ModulesMenu_RechercheAvancee::class, + 'RECH_GUIDEE' => Class_Systeme_ModulesMenu_RechercheGuidee::class, + 'RECH_GEO' => Class_Systeme_ModulesMenu_RechercheGeographique::class, + 'RECH_OAI' => Class_Systeme_ModulesMenu_RechercheOai::class, + 'CATALOGUE' => Class_Systeme_ModulesMenu_Catalogue::class, + 'PANIER' => Class_Systeme_ModulesMenu_Paniers::class, + 'REGISTER' => Class_Systeme_ModulesMenu_Register::class, + 'PREREGISTRATION' => Class_Systeme_ModulesMenu_PreRegistration::class, + 'ABON_AVIS' => Class_Systeme_ModulesMenu_AbonneAvis::class, + 'ABON_FICHE' => Class_Systeme_ModulesMenu_AbonneFiche::class, + 'ABON_MODIF_FICHE' => Class_Systeme_ModulesMenu_AbonneModificationFiche::class, + 'ABON_PRETS' => Class_Systeme_ModulesMenu_AbonnePrets::class, + 'ABON_CARDS' => Class_Systeme_ModulesMenu_AbonneCards::class, + 'ABON_RESAS' => Class_Systeme_ModulesMenu_AbonneReservations::class, + 'ABON_ACTIVITIES' => Class_Systeme_ModulesMenu_AbonneActivities::class, + 'FORM_CONTACT' => Class_Systeme_ModulesMenu_FormulaireContact::class, + 'VODECLIC' => Class_Systeme_ModulesMenu_Vodeclic::class, + 'NUMILOG' => Class_Systeme_ModulesMenu_Numilog::class, + 'ARTEVOD' => Class_Systeme_ModulesMenu_ArteVOD::class, + 'MYCOW' => Class_Systeme_ModulesMenu_MyCow::class, + 'PLANETNEMO' => Class_Systeme_ModulesMenu_PlanetNemo::class, + 'KIDLILANGUES' => Class_Systeme_ModulesMenu_Kidilangues::class, + 'LESOCIAL' => Class_Systeme_ModulesMenu_LeSocial::class, + 'RESERVER_POSTE' => Class_Systeme_ModulesMenu_ReserverPoste::class, + 'SUGGESTION_ACHAT' => Class_Systeme_ModulesMenu_SuggestionAchat::class, + 'WEBKIOSK_RESERVATION' => Class_Systeme_ModulesMenu_WebkioskReservation::class, + 'CITE_DE_LA_MUSIQUE' => Class_Systeme_ModulesMenu_CiteDeLaMusique::class]; + protected static $_modules; private $fonctions; @@ -87,48 +129,11 @@ class Class_Systeme_ModulesMenu extends Class_Systeme_ModulesAbstract { if (isset(static::$_modules)) return static::$_modules; - static::$_modules = array_merge( - ["vide" => new Class_Systeme_ModulesMenu_Null(), - "MENU" => new Class_Systeme_ModulesMenu_Menu(), - "ACCUEIL" => new Class_Systeme_ModulesMenu_Accueil(), - "CONNECT" => new Class_Systeme_ModulesMenu_Connect(), - "DISCONNECT" => new Class_Systeme_ModulesMenu_Disconnect(), - "AVIS" => new Class_Systeme_ModulesMenu_Avis(), - "LAST_NEWS" => new Class_Systeme_ModulesMenu_LastNews(), - "NEWS" => new Class_Systeme_ModulesMenu_News(), - "SITO" => new Class_Systeme_ModulesMenu_Sitotheque(), - "RSS" => new Class_Systeme_ModulesMenu_Rss(), - "URL" => new Class_Systeme_ModulesMenu_Url(), - "PROFIL" => new Class_Systeme_ModulesMenu_Profil(), - "BIBNUM" => new Class_Systeme_ModulesMenu_BibliothequeNumerique(), - "RECH_SIMPLE" => new Class_Systeme_ModulesMenu_RechercheSimple(), - "RECH_AVANCEE" => new Class_Systeme_ModulesMenu_RechercheAvancee(), - "RECH_GUIDEE" => new Class_Systeme_ModulesMenu_RechercheGuidee(), - "RECH_GEO" => new Class_Systeme_ModulesMenu_RechercheGeographique(), - "RECH_OAI" => new Class_Systeme_ModulesMenu_RechercheOai(), - "CATALOGUE" => new Class_Systeme_ModulesMenu_Catalogue(), - "PANIER" => new Class_Systeme_ModulesMenu_Paniers(), - "REGISTER" => new Class_Systeme_ModulesMenu_Register(), - "PREREGISTRATION" => new Class_Systeme_ModulesMenu_PreRegistration(), - "ABON_AVIS" => new Class_Systeme_ModulesMenu_AbonneAvis(), - "ABON_FICHE" => new Class_Systeme_ModulesMenu_AbonneFiche(), - "ABON_MODIF_FICHE" => new Class_Systeme_ModulesMenu_AbonneModificationFiche(), - "ABON_PRETS" => new Class_Systeme_ModulesMenu_AbonnePrets(), - "ABON_CARDS" => new Class_Systeme_ModulesMenu_AbonneCards(), - "ABON_RESAS" => new Class_Systeme_ModulesMenu_AbonneReservations(), - "ABON_ACTIVITIES" => new Class_Systeme_ModulesMenu_AbonneActivities(), - "FORM_CONTACT" => new Class_Systeme_ModulesMenu_FormulaireContact(), - "VODECLIC" => new Class_Systeme_ModulesMenu_Vodeclic(), - "NUMILOG" => new Class_Systeme_ModulesMenu_Numilog(), - "ARTEVOD" => new Class_Systeme_ModulesMenu_ArteVOD(), - "MYCOW" => new Class_Systeme_ModulesMenu_MyCow(), - "PLANETNEMO" => new Class_Systeme_ModulesMenu_PlanetNemo(), - "KIDLILANGUES" => new Class_Systeme_ModulesMenu_Kidilangues(), - "LESOCIAL" => new Class_Systeme_ModulesMenu_LeSocial(), - "RESERVER_POSTE" => new Class_Systeme_ModulesMenu_ReserverPoste(), - 'SUGGESTION_ACHAT' => new Class_Systeme_ModulesMenu_SuggestionAchat(), - 'WEBKIOSK_RESERVATION' => new Class_Systeme_ModulesMenu_WebkioskReservation(), - 'CITE_DE_LA_MUSIQUE' => new Class_Systeme_ModulesMenu_CiteDeLaMusique()], + static::$_modules = []; + + $modules_definition = $this->_buildModulesMenuInstances(); + + static::$_modules = array_merge($modules_definition, Class_DigitalResource::getInstance()->getModulesMenu()); if (!Class_AdminVar::isMenuBoiteEnabled()) @@ -143,6 +148,16 @@ class Class_Systeme_ModulesMenu extends Class_Systeme_ModulesAbstract { } + protected function _buildModulesMenuInstances() { + $modules_definition = static::MODULES_CLASS_DEFINITION; + Class_Template::current()->updateModulesMenuClassDefinition($modules_definition); + foreach($modules_definition as $identifier => $class_name) + $modules[$identifier] = new $class_name(); + + return $modules; + } + + public function getValeursParDefaut($type) { $values = $this->getFonction($type)->getDefaultValues(); if(false !== strpos($type, static::MODULE_ACCUEIL_PREFIX)) diff --git a/library/Class/Systeme/Widget/Menu.php b/library/Class/Systeme/Widget/Menu.php index 1329a4f890f..8ff69d6f801 100644 --- a/library/Class/Systeme/Widget/Menu.php +++ b/library/Class/Systeme/Widget/Menu.php @@ -203,4 +203,9 @@ class Class_Systeme_Widget_Menu extends Class_Systeme_Widget_Abstract { public function hasParent() { return '' != (String) $this->getParent(); } + + + public function getTag() { + return $this->_getWidgetResources()->getTag($this->getLocalSettings()); + } } diff --git a/library/Class/Template.php b/library/Class/Template.php index 99ec5bc1dfb..0ff8e0c76b6 100644 --- a/library/Class/Template.php +++ b/library/Class/Template.php @@ -315,6 +315,11 @@ class Class_Template { } + public function customLoginForm($form) { + return $form; + } + + public function customUserSettingsForm($form) { return $form; } @@ -593,4 +598,13 @@ class Class_Template { public function providesSearchByWork() { return false; } + + + /** + * Each template can register other classes for menus + * Default values : Class_Systeme_ModulesMenu::MODULES_CLASS_DEFINITION + * @see Class_Systeme_ModulesMenu::initModules + */ + public function updateModulesMenuClassDefinition(&$modules_definition) { + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index ffb803b6019..85c4b5e3cb3 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -270,16 +270,6 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function checkNotifyMessage($ressource_link, $url) { - if ('' == $url) { - $this->_helper->notify($ressource_link->getMessage()); - return $this->_redirect($this->_request->getServer('HTTP_REFERER')); - } - - $this->_javascriptRedirectTo($url); - } - - protected function _javascriptRedirectTo($url, $message = null) { if($message) $this->_helper->notify($message); diff --git a/library/ZendAfi/Controller/Action/Helper/View.php b/library/ZendAfi/Controller/Action/Helper/View.php index 7dc10c86e1b..9b0351fefcc 100644 --- a/library/ZendAfi/Controller/Action/Helper/View.php +++ b/library/ZendAfi/Controller/Action/Helper/View.php @@ -177,6 +177,7 @@ class ZendAfi_Controller_Action_Helper_View extends Zend_View { print($this->openBoiteContent($titre)); } + //------------------------------------------------------------------------------------------------------ // Fermeture d'une boite //------------------------------------------------------------------------------------------------------ @@ -192,6 +193,11 @@ class ZendAfi_Controller_Action_Helper_View extends Zend_View { } + public function openCloseBoite($titre, $content) { + return $this->openBoiteContent($titre) . $content . $this->closeBoiteContent(); + } + + // Génère le titre de la page public function getTitre() { if (!$this->_titles[0]) diff --git a/library/ZendAfi/Form/Configuration/Widget/Login.php b/library/ZendAfi/Form/Configuration/Widget/Login.php index aefab50e2e3..ab04037c298 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Login.php +++ b/library/ZendAfi/Form/Configuration/Widget/Login.php @@ -101,6 +101,8 @@ class ZendAfi_Form_Configuration_Widget_Login extends ZendAfi_Form_Configuration 'lien_compte', 'lien_creer_compte', 'pre_registration']); + + Class_Template::current()->customLoginForm($this); } diff --git a/library/ZendAfi/View/Helper/Abonne/ConfigurationsBoard.php b/library/ZendAfi/View/Helper/Abonne/ConfigurationsBoard.php new file mode 100644 index 00000000000..79b0c4bb630 --- /dev/null +++ b/library/ZendAfi/View/Helper/Abonne/ConfigurationsBoard.php @@ -0,0 +1,131 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_View_Helper_Abonne_ConfigurationsBoard extends ZendAfi_View_Helper_BaseHelper { + public function abonne_ConfigurationsBoard($user) { + $this->view->titre = $this->_('Mes cartes'); + $this->_user = $user; + $this->_child_cards = new Class_User_Cards($this->_user); + $this->_parent_cards = $this->_user->getParentCards(); + return + $this->view->openCloseBoite($this->view->titre, + $this->_renderCards()) + . + $this->view->abonne_RetourFiche(); + } + + + protected function _renderCards() { + return + $this->_section($this->_renderMyCards()) + . + $this->_section($this->_renderUsersOfMyCard()); + } + + + protected function _section($content) { + return $content + ? $this->_tag('section', $content) + : ''; + } + + + protected function _renderMyCards() { + $html = $this->_tag('h2', + $this->_('J\'utilise les cartes suivantes')); + + $html .= $this->_child_cards->isEmpty() + ? $this->_tag('p', $this->_('Vous n\'avez ajouté aucune carte')) + : $this->_renderChildCardsTable(); + + + $html .= $this->view->tagAnchor(['action' => 'add-card'], + $this->_('Ajouter une carte'), + ['data-popup' => 'true', + 'class' => 'bouton']); + return $html; + } + + + protected function _renderChildCardsTable() { + return $this->view + ->tagModelTable( + $this->_child_cards, + + [$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom'), $this->_('Expire le')], + + ['login', + 'nom', + 'prenom', + 'subscription_end'], + + [ function($user) { + if ($user->getId() == Class_Users::getIdentity()->getId()) + return ''; + return $this->view->tagAnchor(['action' => 'unlink-card', 'id' => $user->getId()], + $this->view->boutonIco('type=del')); + } ], + + 'child_cards', + + null, + + ['login' => function($user) { + return $user->getId() == Class_Users::getIdentity()->getId() + ? $this->_('%s (ma carte)', $user->getLogin()) + : $user->getLogin(); + }, + + 'subscription_end' => function($user) { + return Class_Date::humanDate($user->getDateFin(), 'dd MMMM yyyy'); + } + ]); + } + + + protected function _renderUsersOfMyCard() { + if (!$this->_parent_cards) + return ''; + + $html = $this->_tag('h2', $this->_('Les utilisateurs suivants ont ma carte')); + + return $html + . + $this->view->tagModelTable($this->_parent_cards, + + [$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom')], + + ['login', + 'nom', + 'prenom', + ], + + [ function($user) { + return $this->view->tagAnchor(['action' => 'unlink-parent-card', 'id' => $user->getId()], + $this->view->boutonIco('type=del')); + } ], + + 'parent_cards', + + null); + } +} diff --git a/library/templates/Chili/Library/FormCustomizer/Login.php b/library/templates/Chili/Library/FormCustomizer/Login.php new file mode 100644 index 00000000000..96e67548b95 --- /dev/null +++ b/library/templates/Chili/Library/FormCustomizer/Login.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Chili_Library_FormCustomizer_Login extends Intonation_Library_FormCustomizer_Abstract { + + public function getForm() { + Class_ScriptLoader::getInstance() + ->addJQueryReady('radioToggleVisibilityForElement("input[name=\'' . Class_Template::current()->withNameSpace('form_style') . '\']", $("#authenticated_menu").closest("tr"), ["toggle"]);'); + + $this->_form + ->addElement('select', + 'authenticated_menu', + ['label' => $this->_('Menu à afficher en étant connecté'), + 'registerInArrayValidator' => false, + 'multiOptions' => (new Class_Systeme_ModulesAccueil_MenuVertical())->getMenus()]) + + ->addToDisplayGroup(['authenticated_menu'], + Class_Template::current()->withNameSpace('group')); + + return $this; + } +} diff --git a/library/templates/Chili/Library/ProfilePatcher.php b/library/templates/Chili/Library/ProfilePatcher.php index be5aa31f18b..c9ca8e5f69d 100644 --- a/library/templates/Chili/Library/ProfilePatcher.php +++ b/library/templates/Chili/Library/ProfilePatcher.php @@ -146,6 +146,7 @@ class Chili_Library_ProfilePatcher extends Intonation_Library_ProfilePatcher { ] ]); + $this->_search_menu = $this->_profile ->addMenu(['libelle' => $this->_('Menu de recherche en scroll'), 'picto' => '', @@ -320,6 +321,7 @@ class Chili_Library_ProfilePatcher extends Intonation_Library_ProfilePatcher { 'lien_compte' => $this->_('SE CONNECTER'), 'lien_creer_compte' => '', 'pre_registration' => $this->_('Je n\'ai pas encore de compte'), + 'authenticated_menu' => $this->_profile_id . '-' . $this->_login_menu, $this->_template->withNameSpace('form_style') => 'toggle', $this->_template->withNameSpace('width_xsmall') => 2, $this->_template->withNameSpace('show_header') => 0, diff --git a/library/templates/Chili/Library/Widget/Login/Definition.php b/library/templates/Chili/Library/Widget/Login/Definition.php new file mode 100644 index 00000000000..cc2277a8fea --- /dev/null +++ b/library/templates/Chili/Library/Widget/Login/Definition.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Chili_Library_Widget_Login_Definition extends Intonation_Library_Widget_Login_Definition { + public function __construct() { + parent::__construct(); + $this->_view_helper = Chili_Library_Widget_Login_View::class; + } +} diff --git a/library/templates/Chili/Library/Widget/Login/View.php b/library/templates/Chili/Library/Widget/Login/View.php new file mode 100644 index 00000000000..d175e7a4040 --- /dev/null +++ b/library/templates/Chili/Library/Widget/Login/View.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Chili_Library_Widget_Login_View extends Intonation_Library_Widget_Login_View { + protected function _getRenderStrategy() { + if ('toggle' == $this->_settings->getFormStyle()) + return new ChililLoginRenderToggle($this->view, $this->_settings, $this->_user); + + return parent::_getRenderStrategy(); + } +} + + + + +class ChililLoginRenderToggle extends IntonationLoginRenderToggle { + public function renderLogged() { + $id_menu = $this->_settings->getAuthenticatedMenu(); + + $helper = new Intonation_Library_Widget_Menu_View(1, ['type_module' => 'MENU', + 'preferences' => ['menu' => $id_menu]]); + $helper->setView($this->_view); + + return $this->_view->renderDropdown($this->_view->tag('h1', + $this->_user->getNomAff(), + ['class' => 'widget-header']) + . + $helper->getContent(), + + $this->_view->abonne_Name($this->_user), + '', + 'dropdown-menu-right'); + } +} diff --git a/library/templates/Chili/Template.php b/library/templates/Chili/Template.php index 67b906a629d..674b341d997 100644 --- a/library/templates/Chili/Template.php +++ b/library/templates/Chili/Template.php @@ -89,4 +89,20 @@ class Chili_Template extends Intonation_Template { return [Chili_Library_Widget_Carousel_Definition::TOP_HIGHLIGHT_CAROUSEL => $this->_('Carousel avec mise en avant au dessus'), Chili_Library_Widget_Carousel_Definition::LEFT_HIGHLIGHT_CAROUSEL => $this->_('Carousel avec mise en avant à gauche')]; } + + + public function customLoginForm($form) { + return (new Chili_Library_FormCustomizer_Login($this, $form))->getForm(); + } + + + public function getWidgets() { + if ($this->_widgets_cache) + return $this->_widgets_cache; + + parent::getWidgets(); + + $this->_widgets_cache[Intonation_Library_Widget_Login_Definition::CODE] = new Chili_Library_Widget_Login_Definition; + return $this->_widgets_cache; + } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/Menu/AbonneCards/Definition.php b/library/templates/Intonation/Library/Menu/AbonneCards/Definition.php new file mode 100644 index 00000000000..2f80fccf8e1 --- /dev/null +++ b/library/templates/Intonation/Library/Menu/AbonneCards/Definition.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Menu_AbonneCards_Definition extends Class_Systeme_ModulesMenu_AbonneCards { + protected $_form = Intonation_Library_Menu_Form_AbonneCards::class; + + + public function getTag($params) { + if (!$params['display_end_validity']) + return ''; + + if (!$current_user = Class_Users::getIdentity()) + return ''; + + return ($date_fin = $current_user->getDateFin()) + ? (new DateTime($date_fin))->format($this->_('d/m/Y')) + : ''; + } +} diff --git a/library/templates/Intonation/Library/Menu/AbonnePrets/Definition.php b/library/templates/Intonation/Library/Menu/AbonnePrets/Definition.php new file mode 100644 index 00000000000..8c75f4eb82d --- /dev/null +++ b/library/templates/Intonation/Library/Menu/AbonnePrets/Definition.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Menu_AbonnePrets_Definition extends Class_Systeme_ModulesMenu_AbonnePrets { + protected + $_form = Intonation_Library_Menu_Form_WithCounter::class, + $_defaultValues = ['display_counter' => false]; + + public function getTag($params) { + if (!$params['display_counter']) + return ''; + + $cards = new Class_User_Cards(Class_Users::getIdentity()); + return $cards->getLoansCount(); + } +} diff --git a/library/templates/Intonation/Library/Menu/AbonneReservations/Definition.php b/library/templates/Intonation/Library/Menu/AbonneReservations/Definition.php new file mode 100644 index 00000000000..8ede78706ec --- /dev/null +++ b/library/templates/Intonation/Library/Menu/AbonneReservations/Definition.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Menu_AbonneReservations_Definition extends Class_Systeme_ModulesMenu_AbonneReservations { + protected + $_form = Intonation_Library_Menu_Form_WithCounter::class, + $_defaultValues = ['display_counter' => false]; + + public function getTag($params) { + if (!$params['display_counter']) + return ''; + + $cards = new Class_User_Cards(Class_Users::getIdentity()); + return $cards->getHoldsCount(); + } +} diff --git a/library/templates/Intonation/Library/Menu/Form/AbonneCards.php b/library/templates/Intonation/Library/Menu/Form/AbonneCards.php new file mode 100644 index 00000000000..1cc2df1132c --- /dev/null +++ b/library/templates/Intonation/Library/Menu/Form/AbonneCards.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Menu_Form_AbonneCards extends ZendAfi_Form_Configuration_Menu_Entry { + public function init() { + parent::init(); + $this->addElement('checkbox', + 'display_end_validity', + ['label' => $this->_('Afficher la date de fin d\'abonnement')]) + ->addToStyleGroup(['display_end_validity']); + } +} diff --git a/library/templates/Intonation/Library/Menu/Form/WithCounter.php b/library/templates/Intonation/Library/Menu/Form/WithCounter.php new file mode 100644 index 00000000000..6354d1631d6 --- /dev/null +++ b/library/templates/Intonation/Library/Menu/Form/WithCounter.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_Library_Menu_Form_WithCounter extends ZendAfi_Form_Configuration_Menu_Entry { + public function init() { + parent::init(); + $this->addElement('checkbox', + 'display_counter', + ['label' => $this->_('Afficher le compteur')]) + ->addToStyleGroup(['display_counter']); + } +} diff --git a/library/templates/Intonation/Library/Widget/Nav/View.php b/library/templates/Intonation/Library/Widget/Nav/View.php index 51ef44d806d..22a333f7610 100644 --- a/library/templates/Intonation/Library/Widget/Nav/View.php +++ b/library/templates/Intonation/Library/Widget/Nav/View.php @@ -199,6 +199,11 @@ class Intonation_Library_Widget_Nav_View extends Zendafi_View_Helper_Accueil_Bas $child->getLabel(), ['class' => 'button_text d-sm-inline text-left']); + if ('' !== ($tag = (string)$child->getTag())) + $label .= $this->view->tag('span', + $tag, + ['class' => 'badge_tag']); + $html = $this->_getHtml($child, $label); return $html diff --git a/library/templates/Intonation/Template.php b/library/templates/Intonation/Template.php index e8ab5e8d7bd..ccf50abef82 100644 --- a/library/templates/Intonation/Template.php +++ b/library/templates/Intonation/Template.php @@ -398,4 +398,11 @@ class Intonation_Template extends Class_Template { public function providesSearchByWork() { return Class_AdminVar::isSearchByWorkEnabled(); } + + + public function updateModulesMenuClassDefinition(&$modules_definition) { + $modules_definition['ABON_CARDS'] = Intonation_Library_Menu_AbonneCards_Definition::class; + $modules_definition['ABON_PRETS'] = Intonation_Library_Menu_AbonnePrets_Definition::class; + $modules_definition['ABON_RESAS'] = Intonation_Library_Menu_AbonneReservations_Definition::class; + } } diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index 98675bab9ab..f02ed674888 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -202,26 +202,15 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe protected function _buildTemplateProfil($attributes) { Class_AdminVar::set('FEATURES_TRACKING_ENABLE', 0); - $disk = $this - ->mock() - ->whenCalled('filesAt') - ->answers([]) - ->whenCalled('directoryAt') - ->answers(null) - - ->whenCalled('fileAt') - ->answers(null); - - Class_FileManager::setFileSystem($disk); - - Class_Systeme_ModulesAccueil::reset(); Class_AdminVar::set('TEMPLATING', 1); $profile = $this->fixture('Class_Profil', - $attributes); + array_merge(['template' => 'INTONATION', + 'parent_id' => null], + $attributes)); + $profile->beCurrentProfil(); - (new Intonation_Template)->applyOn($profile); return $profile; } diff --git a/tests/scenarios/Templates/ChiliLoginTest.php b/tests/scenarios/Templates/ChiliLoginTest.php new file mode 100644 index 00000000000..538f4056d54 --- /dev/null +++ b/tests/scenarios/Templates/ChiliLoginTest.php @@ -0,0 +1,187 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +abstract class ChiliLoginWidgetTestCase extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 4, + 'template' => 'CHILI']); + $id_menu = $profile + ->addMenu(['libelle' => 'Authenticated menu', + 'picto' => '', + 'type_menu' => 'MENU', + 'menus' => [0 => ['type_menu' => 'ACCUEIL', + 'libelle' => 'Home'], + + 1 => ['type_menu' => 'URL', + 'libelle' => 'Contact us', + 'url' => '/contactus'], + + 2 => ['type_menu' => 'ABON_PRETS', + 'libelle' => 'My loans', + 'display_counter' => '1'], + + 3 => ['type_menu' => 'ABON_RESAS', + 'libelle' => 'My holds', + 'display_counter' => '1'], + + 4 => ['type_menu' => 'ABON_CARDS', + 'libelle' => 'My account', + 'display_end_validity' => '1'], + + 5 => ['type_menu' => 'ABON_RESAS', + 'libelle' => 'My holds without tag', + 'display_counter' => '0'] + ]]); + + (new Class_Template_ProfilePatcher(null)) + ->setProfile($profile) + ->addWidget(Intonation_Library_Widget_Login_Definition::CODE, + Class_Profil::DIV_MAIN, + ['authenticated_menu' => '4-' . $id_menu, + 'Chili_form_style' => 'toggle']); + + $profile->assertSave(); + } +} + + + + +class ChiliLoginWidgetAdminFormsTest extends ChiliLoginWidgetTestCase { + /** @test */ + public function pageShouldContainsFormWithAuthenticatedMenuSelectorWithHomeSubmenu() { + $this->dispatch('/admin/widget/edit-widget/id/1/id_profil/4'); + $this->assertXPath('//form//select[@name="authenticated_menu"]//option[@label="Authenticated menu"][@selected]'); + } + + + /** @test */ + public function editMenuMyLoansWithIdTwoShouldContainsCheckboxDisplayCounter() { + $this->dispatch('/admin/widget/edit-menu/id/2/id_profil/4/parent/0'); + $this->assertXPath('//form//input[@type="checkbox"][@name="display_counter"][@checked]'); + } + + + /** @test */ + public function editMenuMyHoldsWithIdThreeShouldContainsCheckboxDisplayCounter() { + $this->dispatch('/admin/widget/edit-menu/id/3/id_profil/4/parent/0'); + $this->assertXPath('//form//input[@type="checkbox"][@name="display_counter"][@checked]'); + } + + + /** @test */ + public function editMenuMyCardsWithIdFourShouldContainsCheckboxDisplayEndValidity() { + $this->dispatch('/admin/widget/edit-menu/id/4/id_profil/4/parent/0'); + $this->assertXPath('//form//input[@type="checkbox"][@name="display_end_validity"][@checked]'); + } +} + + + + +class ChiliLoginWidgetFrontTest extends ChiliLoginWidgetTestCase { + public function setUp() { + parent::setUp(); + + $emprunteur = new Class_WebService_SIGB_Emprunteur('123', 'Anne-Laure'); + $emprunteur + ->empruntsAddAll([Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() + ->setDateRetour('23/12/2056'), + + Class_WebService_SIGB_Emprunt::newInstanceWithEmptyExemplaire() + ->setDateRetour('23/1/1999')]) + ->reservationsAddAll([Class_WebService_SIGB_Reservation::newInstanceWithEmptyExemplaire()]); + + + + Class_Users::getIdentity() + ->setPseudo('Anne-Laure') + ->setDateFin('2021/12/14') + ->beAbonneSIGB() + ->setBib(Class_Bib::newInstanceWithIdAssertSave(1, + ['libelle' => 'Annecy'])) + ->setFicheSIGB(['fiche' => $emprunteur]) ; + + $this->dispatch('/index/index/id_profil/4'); + } + + + /** @test */ + public function loginWidgetShouldContainsContactUsLink() { + $this->assertXPathContentContains('//div[contains(@class, "dropdown-menu-right")]//a[@href="/contactus"]', 'Contact us'); + } + + + /** @test */ + public function dropdownMenuShouldContainsH1WithAnneLaure() { + $this->assertXPathContentContains('//div[contains(@class, "dropdown-menu-right")]//h1[contains(@class, "widget-header")]', + 'Anne-Laure'); + } + + + /** @test */ + public function menuShouldLinkToMyLoansWithCounterTwo() { + $this->assertXPathContentContains('//a[contains(@class, "nav-link")][contains(@href, "/abonne/prets")]//span[contains(@class, "badge_tag")]', '2'); + } + + + /** @test */ + public function menuShouldLinkToMyHoldsWithCounterOne() { + $this->assertXPathContentContains('//a[contains(@class, "nav-link")][contains(@href, "/abonne/reservations")]//span[contains(@class, "badge_tag")]', '1'); + } + + + /** @test */ + public function menuHoldsWithoutDisplayCounterShouldNotDisplayBadge() { + $this->assertXPathCount('//a[contains(@class, "nav-link")][contains(@href, "/abonne/reservations")]//span[contains(@class, "badge_tag")]', 1); + } + + + /** @test */ + public function withoutHoldsShouldMenuHoldsTagShouldContainsZero() { + Class_Users::getIdentity()->setFicheSIGB(['fiche' => new Class_WebService_SIGB_Emprunteur('123', 'Anne-Laure')]); + $this->_response->setBody(''); + $this->dispatch('/index/index/id_profil/4'); + + $this->assertXPath('//a[contains(@class, "nav-link")][contains(@href, "/abonne/reservations")]//span[contains(@class, "badge_tag")][text()="0"]'); + } + + + /** @test */ + public function menuCardsShouldDisplayBadgeEndValidity14122021() { + $this->assertXPathContentContains('//a[contains(@class, "nav-link")][contains(@href, "/abonne/cards")]//span[contains(@class, "badge_tag")]','14/12/2021'); + } + + + /** @test */ + public function withoutEndValidityBadgeShouldNotBePresent() { + Class_Users::getIdentity()->setDateFin(''); + $this->_response->setBody(''); + $this->dispatch('/index/index/id_profil/4'); + + $this->assertNotXPath('//a[contains(@class, "nav-link")][contains(@href, "/abonne/cards")]//span[contains(@class, "badge_tag")]'); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/ChiliTest.php b/tests/scenarios/Templates/ChiliTest.php index 4a145574654..26e308b0243 100644 --- a/tests/scenarios/Templates/ChiliTest.php +++ b/tests/scenarios/Templates/ChiliTest.php @@ -161,6 +161,12 @@ class ChiliTemplateOpacIndexWithUserAgentTest extends ChiliTemplateTestCase { } + /** @test */ + public function loginWidgetShouldContainsAuthenticatedMenuWithHoldsLinkAndBadge() { + $this->assertXPath('//div[contains(@class, "boite login")]//a[contains(@class, "nav-link")][contains(@href, "/abonne/reservations")]//span[contains(@class, "badge_tag")]'); + } + + /** @test */ public function pageShouldBeHtml5Valid() { $this->assertHTML5(); @@ -360,7 +366,7 @@ class ChiliTemplateAdminNewPageTest extends ChiliTemplateTestCase { /** @test */ public function shouldRedirectToProfile26() { - $this->assertRedirectTo('/admin/profil/accueil/id_profil/26'); + $this->assertRedirectTo('/admin/profil/accueil/id_profil/26'); } @@ -452,9 +458,9 @@ class ChiliTemplateSearchResultWithDomainBrowserTest extends ChiliTemplateTestCa $profile = Class_Profil::getPortail()->updateModuleConfigAccueil(78, - ['type_module' => 'DOMAIN_BROWSER', - 'division' => 2, - 'preferences' => $preferences]); + ['type_module' => 'DOMAIN_BROWSER', + 'division' => 2, + 'preferences' => $preferences]); $profile->save(); @@ -519,17 +525,17 @@ class ChiliTemplateNotLoggedTest extends ChiliTemplateTestCase { class ChiliEditWidgetLibraryTest extends ChiliTemplateTestCase { - protected $_storm_default_to_volatile = true; + protected $_storm_default_to_volatile = true; - public function setUp() { - parent::setUp(); - $this->dispatch('admin/widget/edit-widget/id/8/id_profil/1'); - } + public function setUp() { + parent::setUp(); + $this->dispatch('admin/widget/edit-widget/id/8/id_profil/1'); + } - /** @test */ - public function layoutSelectorShouldContainsLeftHighlightCarousel() { - $this->assertXPath('//form//select[@name="layout"]/option[@value="left_highlight_carousel"]'); - } + /** @test */ + public function layoutSelectorShouldContainsLeftHighlightCarousel() { + $this->assertXPath('//form//select[@name="layout"]/option[@value="left_highlight_carousel"]'); + } } \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesAbonneTest.php b/tests/scenarios/Templates/TemplatesAbonneTest.php index 7681f5b405d..9c260ca146d 100644 --- a/tests/scenarios/Templates/TemplatesAbonneTest.php +++ b/tests/scenarios/Templates/TemplatesAbonneTest.php @@ -1000,3 +1000,19 @@ class TemplatesDispatchAbonneClearHistoryTest extends TemplatesIntonationAccount $this->assertRedirect(); } } + + + + +class TemplatesDispatchAbonneCardsTest extends TemplatesIntonationAccountTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/abonne/cards/id_profil/72'); + } + + + /** @test */ + public function shouldForwardToConfigurationsAction() { + $this->assertXPathContentContains('//div//h2[contains(@class, "jumbotron_section_title")]', 'Mes configurations'); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesRssTest.php b/tests/scenarios/Templates/TemplatesRssTest.php index 1ef4d95fd77..3fc694d82fd 100644 --- a/tests/scenarios/Templates/TemplatesRssTest.php +++ b/tests/scenarios/Templates/TemplatesRssTest.php @@ -27,15 +27,12 @@ class TemplatesRssWidgetWithDescriptionLengthTest extends AbstractControllerTest public function setUp() { parent::setUp(); - Class_AdminVar::set('TEMPLATING', 1); - ZendAfi_Auth::getInstance()->clearIdentity(); - $profile = $this->fixture('Class_Profil', - ['id' => 34, - 'template' => 'MUSCLE' - ]); + ZendAfi_Auth::getInstance()->clearIdentity(); - $profile->beCurrentProfil(); + $profile = $this->_buildTemplateProfil(['id' => 34, + 'template' => 'MUSCLE' + ]); $profile_patcher = (new Class_Template_ProfilePatcher(null)) ->setProfile($profile); diff --git a/tests/scenarios/Templates/TemplatesTryTest.php b/tests/scenarios/Templates/TemplatesTryTest.php index 261cdb8177e..f7b9e09eb96 100644 --- a/tests/scenarios/Templates/TemplatesTryTest.php +++ b/tests/scenarios/Templates/TemplatesTryTest.php @@ -170,3 +170,32 @@ class TemplatesTryActionsErrorsTest $this->assertFlashMessengerContentContains('Une erreur s\'est produite. Vous ne pouvez pas tester le thème'); } } + + + + +class TemplatesTryCheckBeforeTryIntonationWithNoTestProfileTest + extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + Class_AdminVar::set('TEMPLATING', 1); + + $this->dispatch('admin/template/check-before-try/template/INTONATION/on/1'); + } + + + /** @test */ + public function shouldRedirectToTryActionWithScript() { + $this->assertXPathContentContains('//script[contains(text(), "location.href =")]', 'admin/template/try/template/INTONATION/on/1'); + } + + + /** @test */ + public function shouldContainsGenerateProfileForTestTitle() { + $this->assertXPathContentContains('//div//h1', 'Génération du profil qui sera utilisé pour tester le thème Intonation'); + } +} \ No newline at end of file -- GitLab