From 0c0e318f82e9000ae9a821dd72aa9902f316883a Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 4 May 2022 17:30:13 +0200 Subject: [PATCH] dev #156378 add novelties tab to libraries --- FEATURES/156378 | 10 + VERSIONS_WIP/156378 | 1 + .../opac/controllers/BibController.php | 5 + .../opac/controllers/RssController.php | 66 ++- .../opac/controllers/WidgetController.php | 33 +- .../opac/views/scripts/bib/novelties.phtml | 2 + library/Class/Systeme/ModulesAccueil/Null.php | 2 +- .../Widget/Action/LibraryNovelties.php | 50 +++ library/Class/Systeme/Widget/ActionLoader.php | 3 + library/Class/Template/ProfilePatcher.php | 6 + .../Form/Configuration/Widget/Action/Tabs.php | 2 +- library/ZendAfi/View/Helper/Accueil/Base.php | 7 +- .../ZendAfi/View/Helper/Admin/RenderIcon.php | 2 +- .../Herisson/Library/ProfilePatcher.php | 1 + .../Intonation/Library/ProfilePatcher.php | 2 + .../View/Wrapper/Library/RichContent.php | 20 +- .../Wrapper/Library/RichContent/Novelties.php | 98 +++++ .../View/Wrapper/Record/RichContent/Items.php | 2 +- .../View/Wrapper/RichContent/Abstract.php | 28 +- .../View/Wrapper/RichContent/Section.php | 16 +- .../Carousel/LibraryNovelties/Definition.php | 56 +++ .../Widget/Carousel/LibraryNovelties/Form.php | 53 +++ .../Widget/Carousel/LibraryNovelties/View.php | 72 ++++ .../Widget/Carousel/Record/Definition.php | 1 + .../Library/Widget/Carousel/View.php | 28 +- .../Intonation/View/Library/Novelties.php | 31 ++ public/admin/css/front_nav.css | 4 +- .../Templates/TemplatesArticlesTest.php | 12 +- .../TemplatesLibraryNoveltiesTabTest.php | 395 ++++++++++++++++++ .../Templates/TemplatesWidgetTest.php | 6 +- 30 files changed, 932 insertions(+), 82 deletions(-) create mode 100644 FEATURES/156378 create mode 100644 VERSIONS_WIP/156378 create mode 100644 application/modules/opac/views/scripts/bib/novelties.phtml create mode 100644 library/Class/Systeme/Widget/Action/LibraryNovelties.php create mode 100644 library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Novelties.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Definition.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Form.php create mode 100644 library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/View.php create mode 100644 library/templates/Intonation/View/Library/Novelties.php create mode 100644 tests/scenarios/Templates/TemplatesLibraryNoveltiesTabTest.php diff --git a/FEATURES/156378 b/FEATURES/156378 new file mode 100644 index 00000000000..63507e248cb --- /dev/null +++ b/FEATURES/156378 @@ -0,0 +1,10 @@ + '156378' => + ['Label' => $this->_('Onglet nouveauté dans la fiche bibliothèque'), + 'Desc' => $this->_('Un nouvel onglet "Nouveautés" dans la fiche bibliothèque est disponible. Il vous permet d\'afficher les notices marquées comme nouveauté. Le kiosque de nouveautés profite de toute la configuration d\'une boite de notices.'), + 'Image' => '', + 'Video' => 'https://youtu.be/LSUqlTS5OHY', + 'Category' => $this->_('Mise en page'), + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=Fiche_biblioth%C3%A8que', + 'Test' => '', + 'Date' => '2022-05-04'], \ No newline at end of file diff --git a/VERSIONS_WIP/156378 b/VERSIONS_WIP/156378 new file mode 100644 index 00000000000..994a9e50044 --- /dev/null +++ b/VERSIONS_WIP/156378 @@ -0,0 +1 @@ + - fonctionnalité #156378 : Magasin de thèmes : Ajout de l'onglet nouveauté dans la fiche bibliothèque. \ No newline at end of file diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index 0757f026ca8..1513c5d161d 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.php @@ -346,6 +346,11 @@ class BibController extends ZendAfi_Controller_Action { } + public function noveltiesAction() { + $this->_initLibrary(); + } + + public function avisProAction() { $this->_initProUser(); } diff --git a/application/modules/opac/controllers/RssController.php b/application/modules/opac/controllers/RssController.php index 6cb92161133..bd24b9b1fa4 100644 --- a/application/modules/opac/controllers/RssController.php +++ b/application/modules/opac/controllers/RssController.php @@ -239,6 +239,52 @@ class RssController extends ZendAfi_Controller_Action { } + public function libraryNoveltiesAction() { + if ( ! $profile_id = (int) $this->_getParam('id_profil')) + return $this->_noDataRss(); + + if ( ! $library_id = $this->_getParam('id')) + return $this->_noDataRss(); + + return ($widget = (new Class_Systeme_Widget_Action_LibraryNovelties) + ->setId('bib_novelties_' . $library_id) + ->setProfileId($profile_id) + ->load()) + ? $this->_renderWidgetElementsAsRss($widget) + : $this->_noDataRss(); + } + + + protected function _renderWidgetElementsAsRss(Class_Systeme_Widget_Abstract $widget) : void { + $widget->setSection(new Class_Entity); + $template = Class_Template::current(); + $theme_widget = (new Intonation_System_Widget($template))->setSettings($widget); + + $elements = $theme_widget->findElements($this->view); + + $titre = '<![CDATA[' . $widget->getTitre() . ']]>'; + $rss = ['titre' => $titre, + 'description' => $titre, + 'lien' => $this->view->absoluteUrl(), + 'lastBuildDate' => time(), + 'items' => $this->_recordsForRss($elements)]; + + $this->_helper->rssResponse($this->view->renderRss($rss)); + } + + + protected function _noDataRss() : void { + $rss_array = + ['titre' => $this->_('Aucune donnée'), + 'lien' => $this->view->absoluteUrl(), + 'description' => '', + 'lastBuildDate' => time(), + 'items' => []]; + + $this->_helper->rssResponse($this->view->renderRss($rss_array)); + } + + public function kiosqueAction() { if ($cache_key = $this->_getParam('cache_key')) return $this->_renderRSSFromVolatile($cache_key); @@ -290,22 +336,12 @@ class RssController extends ZendAfi_Controller_Action { protected function _renderRSSFromVolatile($cache_key) { - $volatile_widget = (new Intonation_Library_Widget_Carousel_VolatileLoader)->load($cache_key); - $widget = (new Class_Systeme_Widget_Widget)->loadFromSettings($volatile_widget->getSettings()); - $widget->setSection(new Class_Entity); - $template = Class_Template::current(); - $theme_widget = (new Intonation_System_Widget($template))->setSettings($widget); - - $elements = $theme_widget->findElements($this->view); - - $titre = '<![CDATA[' . $widget->getTitre() . ']]>'; - $rss = ['titre' => $titre, - 'description' => $titre, - 'lien' => $this->view->absoluteUrl(), - 'lastBuildDate' => time(), - 'items' => $this->_recordsForRss($elements)]; + if ( !$volatile_widget = (new Intonation_Library_Widget_Carousel_VolatileLoader)->load($cache_key)) + return $this->_noDataRss(); - return $this->_helper->rssResponse($this->view->renderRss($rss)); + return ($widget = (new Class_Systeme_Widget_Widget)->loadFromSettings($volatile_widget->getSettings())) + ? $this->_renderWidgetElementsAsRss($widget) + : $this->_noDataRss(); } diff --git a/application/modules/opac/controllers/WidgetController.php b/application/modules/opac/controllers/WidgetController.php index f0516fa3341..cd714067cdd 100644 --- a/application/modules/opac/controllers/WidgetController.php +++ b/application/modules/opac/controllers/WidgetController.php @@ -32,19 +32,27 @@ class WidgetController extends ZendAfi_Controller_Action { Class_Template::setCurrentFrom($profile_id); - if ($widget = ((new Class_Systeme_Widget_Widget) - ->setId($id) - ->setProfileId($profile_id) - ->setAnchorTarget($this->_getParam('anchor_target')) - ->load())) { + if ($widget = $this->_findWidgetBy($id, $profile_id)) return Class_Template::current()->renderWidget($widget, $this->view); - } }; return $this->_helper->iframe($callback); } + protected function _findWidgetBy(string $id, string $profile_id) : ?Class_Systeme_Widget_Abstract { + return ((new Class_Systeme_Widget_Widget) + ->setId($id) + ->setProfileId($profile_id) + ->setAnchorTarget($this->_getParam('anchor_target')) + ->load()) + ?? ((new Class_Systeme_Widget_Action_LibraryNovelties) + ->setId($id) + ->setProfileId($profile_id) + ->load()); + } + + public function renderAllAction() { if ( $article = Class_Article::find($this->_getParam('article_id', null))) return $this->view->widget = (new Class_Article_Widget($article, @@ -59,10 +67,7 @@ class WidgetController extends ZendAfi_Controller_Action { Class_Template::setCurrentFrom($profile_id); - if ( !$widget = ((new Class_Systeme_Widget_Widget) - ->setId($id) - ->setProfileId($profile_id) - ->load())) + if ( !$widget = $this->_findWidgetBy($id, $profile_id)) return $this->getResponse()->setHttpResponseCode(404); $this->view->widget = $widget; @@ -133,10 +138,10 @@ class WidgetController extends ZendAfi_Controller_Action { $child = new Class_Systeme_Widget_Menu; if ($this->view->widget = $child - ->setId($menu) - ->setProfileId($profile_id) - ->setParent($parent) - ->load()) + ->setId($menu) + ->setProfileId($profile_id) + ->setParent($parent) + ->load()) return; $this->_helper->notify($this->_('Une erreur c\'est produite. Il est impossible d\'afficher cette page'), ['status' => 'error']); diff --git a/application/modules/opac/views/scripts/bib/novelties.phtml b/application/modules/opac/views/scripts/bib/novelties.phtml new file mode 100644 index 00000000000..3a142e45e32 --- /dev/null +++ b/application/modules/opac/views/scripts/bib/novelties.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->library_Novelties($this->library); diff --git a/library/Class/Systeme/ModulesAccueil/Null.php b/library/Class/Systeme/ModulesAccueil/Null.php index 07c222e568a..8a6f8dc647e 100644 --- a/library/Class/Systeme/ModulesAccueil/Null.php +++ b/library/Class/Systeme/ModulesAccueil/Null.php @@ -234,7 +234,7 @@ class Class_Systeme_ModulesAccueil_Null { public function shouldCacheContent() { return ($widget = ZendAfi_View_Helper_Accueil_Base::getWidget($this->getWidgetContext()->getId(), $this->getWidgetContext()->forForm(), - null)) + new Zend_View)) ? $widget->shouldCacheContent() : true; } diff --git a/library/Class/Systeme/Widget/Action/LibraryNovelties.php b/library/Class/Systeme/Widget/Action/LibraryNovelties.php new file mode 100644 index 00000000000..e5e6a1f575e --- /dev/null +++ b/library/Class/Systeme/Widget/Action/LibraryNovelties.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2012-2022, 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 Class_Systeme_Widget_Action_LibraryNovelties extends Class_Systeme_Widget_Action { + public function getResourcesDefinition() { + return new Intonation_Library_Widget_Carousel_LibraryNovelties_Definition; + } + + + public function _getTitle() { + return $this->_('Configuration des nouveautés de %s', $this->_getLibraryLabel()); + } + + + protected function _getLibraryLabel() : string { + $id_as_array = explode('_', $this->getId()); + + $library_id = array_pop($id_as_array); + + return ($library = Class_Bib::find($library_id)) + ? $library->getLabel() + : ''; + } + + + public function load() : ?Class_Systeme_Widget_Abstract { + return $this->_getLibraryLabel() + ? parent::load() + : null; + } +} \ No newline at end of file diff --git a/library/Class/Systeme/Widget/ActionLoader.php b/library/Class/Systeme/Widget/ActionLoader.php index cf5475b0cc6..3184051ad90 100644 --- a/library/Class/Systeme/Widget/ActionLoader.php +++ b/library/Class/Systeme/Widget/ActionLoader.php @@ -62,6 +62,9 @@ class Class_Systeme_Widget_ActionLoader { foreach (Class_TypeDoc::findAll() as $doc_type) $actions ['recherche_viewnotice_' . $doc_type->getId()] = Class_Systeme_Widget_Action_Record::class; + foreach (Class_Bib::findAll() as $library) + $actions ['bib_novelties_' . $library->getId()] = Class_Systeme_Widget_Action_LibraryNovelties::class; + return $actions; } } diff --git a/library/Class/Template/ProfilePatcher.php b/library/Class/Template/ProfilePatcher.php index 98f95f4a5f9..afa2dab8b39 100644 --- a/library/Class/Template/ProfilePatcher.php +++ b/library/Class/Template/ProfilePatcher.php @@ -191,6 +191,12 @@ class Class_Template_ProfilePatcher extends Class_Template_NullPatcher { } + protected function _enableLibraryNoveltiesTab() : self { + return $this->_setActionSettings('bib', 'en-lire-plus', + [Intonation_Library_View_Wrapper_Library_RichContent_Novelties::class => '1']); + } + + protected function _setNoMediaInNoticeSettings(array $settings) : self { foreach ( [Class_TypeDoc::LIVRE, Class_TypeDoc::PERIODIQUE] as $doc_type_id) diff --git a/library/ZendAfi/Form/Configuration/Widget/Action/Tabs.php b/library/ZendAfi/Form/Configuration/Widget/Action/Tabs.php index 6060370070a..eb0cffea732 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Action/Tabs.php +++ b/library/ZendAfi/Form/Configuration/Widget/Action/Tabs.php @@ -53,7 +53,7 @@ abstract class ZendAfi_Form_Configuration_Widget_Action_Tabs extends ZendAfi_For ->addElement('checkbox', get_class($tab), ['label' => $this->_('Activer l\'affichage de l\'onglet %s', $title), - 'value' => 1]); + 'value' => $tab->getDefaultActivation()]); $group [] = get_class($tab); $group [] = $ico_id; diff --git a/library/ZendAfi/View/Helper/Accueil/Base.php b/library/ZendAfi/View/Helper/Accueil/Base.php index aa911d20293..5ef950f5205 100644 --- a/library/ZendAfi/View/Helper/Accueil/Base.php +++ b/library/ZendAfi/View/Helper/Accueil/Base.php @@ -363,7 +363,12 @@ class ZendAfi_View_Helper_Accueil_Base extends ZendAfi_View_Helper_ModuleAbstrac } - public static function getModuleHelperFromParams($id_module, $module_params, $view) { + public static function getModuleHelperFromParams($id_module, $module_params, Zend_View_Interface $view) { + if ( isset($module_params['ViewHelper']) + && $view_helper = trim($module_params['ViewHelper'])) + return (new $view_helper($id_module, $module_params)) + ->setView($view); + $type_module = isset($module_params["type_module"]) ? $module_params["type_module"] : null; diff --git a/library/ZendAfi/View/Helper/Admin/RenderIcon.php b/library/ZendAfi/View/Helper/Admin/RenderIcon.php index 1b981283d13..af58c6e5a22 100644 --- a/library/ZendAfi/View/Helper/Admin/RenderIcon.php +++ b/library/ZendAfi/View/Helper/Admin/RenderIcon.php @@ -22,7 +22,7 @@ class ZendAfi_View_Helper_Admin_RenderIcon extends ZendAfi_View_Helper_RenderIcon { - public function Admin_RenderIcon(string $name, array $attribs = []) : string { + public function admin_RenderIcon(string $name, array $attribs = []) : string { return parent::renderIcon($name, $attribs); } } diff --git a/library/templates/Herisson/Library/ProfilePatcher.php b/library/templates/Herisson/Library/ProfilePatcher.php index 5e4fee73835..e511ecb95d0 100644 --- a/library/templates/Herisson/Library/ProfilePatcher.php +++ b/library/templates/Herisson/Library/ProfilePatcher.php @@ -853,6 +853,7 @@ class Herisson_Library_ProfilePatcher extends Intonation_Library_ProfilePatcher ->_setNoMapsInBibSettings($no_maps_bib_settings) ->_setNoTeamsInBibSettings($no_teams_bib_settings) ->_setNoMediaInNoticeSettings($no_media_notice_settings) + ->_enableLibraryNoveltiesTab() ->_setActionSettings('cms', 'articleview', $default_action_settings) ->_setActionSettings('recherche', 'avancee', $default_action_settings) ->_setActionSettings('widget', 'render-all', $default_action_settings) diff --git a/library/templates/Intonation/Library/ProfilePatcher.php b/library/templates/Intonation/Library/ProfilePatcher.php index a9f3a8a75eb..a055e626089 100644 --- a/library/templates/Intonation/Library/ProfilePatcher.php +++ b/library/templates/Intonation/Library/ProfilePatcher.php @@ -282,6 +282,8 @@ class Intonation_Library_ProfilePatcher extends Class_Template_ProfilePatcher { 'highlight_search_terms' => '1', 'facets_closed_codes' => implode(array_diff($codes,[Class_TypeDoc::CODE_FACETTE]))]); + $this->_enableLibraryNoveltiesTab(); + return $this; } diff --git a/library/templates/Intonation/Library/View/Wrapper/Library/RichContent.php b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent.php index ac0b5dca1c8..d5a33e99f89 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Library/RichContent.php +++ b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent.php @@ -26,9 +26,10 @@ class Intonation_Library_View_Wrapper_Library_RichContent extends Intonation_Lib HOME = 0, OPENINGS = 1, DETAILS = 2, - MAP = 3, - AGENDA = 4, - TEAM = 5; + NOVELTIES = 3, + MAP = 4, + AGENDA = 5, + TEAM = 6; protected $_navigation; @@ -55,12 +56,13 @@ class Intonation_Library_View_Wrapper_Library_RichContent extends Intonation_Lib protected function _getSectionsMap() { - return [self::HOME => Intonation_Library_View_Wrapper_Library_RichContent_Home::class, - self::OPENINGS => Intonation_Library_View_Wrapper_Library_RichContent_Openings::class, - self::DETAILS => Intonation_Library_View_Wrapper_Library_RichContent_Details::class, - self::MAP => Intonation_Library_View_Wrapper_Library_RichContent_Map::class, - self::AGENDA => Intonation_Library_View_Wrapper_Library_RichContent_Agenda::class, - self::TEAM =>Intonation_Library_View_Wrapper_Library_RichContent_Team::class]; + return [static::HOME => Intonation_Library_View_Wrapper_Library_RichContent_Home::class, + static::OPENINGS => Intonation_Library_View_Wrapper_Library_RichContent_Openings::class, + static::DETAILS => Intonation_Library_View_Wrapper_Library_RichContent_Details::class, + static::NOVELTIES => Intonation_Library_View_Wrapper_Library_RichContent_Novelties::class, + static::MAP => Intonation_Library_View_Wrapper_Library_RichContent_Map::class, + static::AGENDA => Intonation_Library_View_Wrapper_Library_RichContent_Agenda::class, + static::TEAM =>Intonation_Library_View_Wrapper_Library_RichContent_Team::class]; } diff --git a/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Novelties.php b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Novelties.php new file mode 100644 index 00000000000..9486c0e62bc --- /dev/null +++ b/library/templates/Intonation/Library/View/Wrapper/Library/RichContent/Novelties.php @@ -0,0 +1,98 @@ +<?php +/** + * Copyright (c) 2012-2019, 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_View_Wrapper_Library_RichContent_Novelties extends Intonation_Library_View_Wrapper_Library_RichContent_Section { + + public function getTitle() { + return $this->_('Nouveautés'); + } + + + public function getContent() { + return ($widget = $this->_getWidget()) + ? Class_Template::current()->renderWidget($widget, $this->_view) + : ''; + } + + + protected function _getWidget() : ?Class_Systeme_Widget_Action_LibraryNovelties { + return (new Class_Systeme_Widget_Action_LibraryNovelties) + ->setId('bib_novelties_' . $this->_model->getId()) + ->setProfileId(Class_Profil::getCurrentProfil()->getId()) + ->load(); + } + + + public function getClass() { + return 'library_novelties'; + } + + + public function getNavUrl() { + return ['controller' => 'bib', + 'action' => 'novelties']; + } + + + public function getNavIco() { + return 'class fas fa-bullhorn'; + } + + + public function getNavTitle() { + return $this->_('Les nouveautés de la bibliothèque'); + } + + + public function handleSection() { + return true; + } + + + public function getDefaultActivation() : int { + return static::DEACTIVATED_BY_DEFAULT; + } + + + public function renderSettingsAction() : string { + $current_profile = Class_Profil::getCurrentProfil(); + + if ( ! Class_Users::isCurrentUserAllowedToEditProfile($current_profile)) + return ''; + + $label = $this->_('Modifier la configuration de l\'onglet %s', $this->getDBTitle()); + + $url_params = + ['module' => 'admin', + 'controller' => 'widget', + 'action' => 'edit-action', + 'id' => implode('_', [...array_values($this->getNavUrl()), ...[$this->_model->getId()]]), + 'id_profil' => $current_profile->getId()]; + + return $this->_view + ->tagAnchor($this->_view->url($url_params, null, true), + $this->_view->admin_RenderIcon('class fas fa-wrench'), + ['data-popup' => 'true', + 'class' => 'tab_configuration', + 'title' => $label]); + } +} diff --git a/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Items.php b/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Items.php index a94d83b7b77..94384c60d46 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Items.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record/RichContent/Items.php @@ -43,7 +43,7 @@ class Intonation_Library_View_Wrapper_Record_RichContent_Items extends Intonatio } - public function renderSettingsAction() { + public function renderSettingsAction() : string { $current_profile = Class_Profil::getCurrentProfil(); if (!Class_Users::isCurrentUserAllowedToEditProfile($current_profile)) diff --git a/library/templates/Intonation/Library/View/Wrapper/RichContent/Abstract.php b/library/templates/Intonation/Library/View/Wrapper/RichContent/Abstract.php index 208d74fb7bc..e02bdf26769 100644 --- a/library/templates/Intonation/Library/View/Wrapper/RichContent/Abstract.php +++ b/library/templates/Intonation/Library/View/Wrapper/RichContent/Abstract.php @@ -65,32 +65,22 @@ abstract class Intonation_Library_View_Wrapper_RichContent_Abstract { if ($this->_sections) return $this->_sections; - $map = $this->_getSectionsMap(); - $map = $this->_removeDisabledSections($map); - - return $this->_sections = - array_map(function($class) - { - return new $class($this->getWrapperInstance()); - }, - $map); + $instances = array_map(fn(string $section) => new $section($this->getWrapperInstance()), + $this->_getSectionsMap()); + + return $this->_sections = $this->_removeDisabledSections($instances); } - protected function _removeDisabledSections($map) { + protected function _removeDisabledSections(array $sections) : array { if ( ! $settings = $this->_view->_module_settings) - return $map; + return $sections; if ( ! $settings = $settings->getLocalSettings()) - return $map; - - return array_filter($map, function($section) use ($settings) - { - if ( ! isset($settings[$section])) - return true; + return $sections; - return (bool) $settings[$section]; - }); + return array_filter($sections, + fn($section) => $section->isActivatedIn($settings)); } diff --git a/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php b/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php index d0f88613dac..8ac105c32f5 100644 --- a/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php +++ b/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php @@ -24,6 +24,10 @@ abstract class Intonation_Library_View_Wrapper_RichContent_Section { use Trait_Translator, Trait_TemplateAware; + const ACTIVATED_BY_DEFAULT = 1, + DEACTIVATED_BY_DEFAULT = 0; + + protected $_view, $_model, @@ -113,7 +117,7 @@ abstract class Intonation_Library_View_Wrapper_RichContent_Section { } - public function renderSettingsAction() { + public function renderSettingsAction() : string { return ''; } @@ -213,6 +217,16 @@ abstract class Intonation_Library_View_Wrapper_RichContent_Section { } + public function isActivatedIn(array $settings) : bool { + return $settings[get_called_class()] ?? (bool) $this->getDefaultActivation(); + } + + + public function getDefaultActivation() :int { + return static::ACTIVATED_BY_DEFAULT; + } + + abstract public function getTitle(); abstract public function getContent(); abstract public function getClass(); diff --git a/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Definition.php new file mode 100644 index 00000000000..f7ac57d5a6c --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Definition.php @@ -0,0 +1,56 @@ +<?php +/** + * Copyright (c) 2012-2017, 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_Widget_Carousel_LibraryNovelties_Definition extends Intonation_Library_Widget_Carousel_Record_Definition { + + const CODE = 'LIBRARY_NOVELTIES'; + + + public function __construct() { + parent::__construct(); + $this->_libelle = $this->_('Nouveautés de la bibliothèque'); + $this->_form = Intonation_Library_Widget_Carousel_LibraryNovelties_Form::class; + $this->_view_helper = Intonation_Library_Widget_Carousel_LibraryNovelties_View::class; + $this->_defaultValues = + array_merge($this->_defaultValues, + ['titre' => $this->_libelle, + 'layout' => Intonation_Library_Widget_Carousel_Definition::MULTIPLE_CAROUSEL_PLUS, + 'rendering' => Intonation_Library_Widget_Carousel_Definition::CARD_OVERLAY, + 'auto_selection' => 1, + 'size' => 20, + 'cycle' => 4, + 'order' => Class_CriteresRecherche::SORT_NOVELTY_DESC, + 'type_module' => static::CODE, + Class_Template::current()->withNameSpace('show_header') => 0, + Class_Template::current()->withNameSpace('show_content') => 0, + Class_Template::current()->withNameSpace('show_footer') => 0, + Class_Template::current()->withNameSpace('styles_pack') => $this->_getDefaultStylePack()]); + } + + + protected function _getDefaultStylePack() : int { + return ($pack = Class_StylesPack::findFirstBy(['label' => 'Sans bordure, sans arrondi, sans ombre, sans fond', + 'template' => Class_Template::current()->getId()])) + ? $pack->getId() + : 0; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Form.php b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Form.php new file mode 100644 index 00000000000..ba746747c04 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/Form.php @@ -0,0 +1,53 @@ +<?php +/** + * Copyright (c) 2012-2022, 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_Widget_Carousel_LibraryNovelties_Form + extends Intonation_Library_Widget_Carousel_Record_Form { + + + public function init() { + parent::init(); + + Class_ScriptLoader::getInstance() + ->addJQueryReady('checkBoxToggleVisibilityForElement("#auto_selection", $(".data_sources"), false);'); + + $this + ->addElement('checkbox', + 'auto_selection', + ['label' => $this->_('Sélectionner les nouveautés automatiquement'), + 'value' => 1]); + + $template = Class_Template::current(); + + $this->getElement($template->withNameSpace('show_header'))->setValue(0); + $this->getElement($template->withNameSpace('show_content'))->setValue(0); + $this->getElement($template->withNameSpace('show_footer'))->setValue(0); + } + + + public function initDisplayGroups() { + $this->addToSelectionGroup(['auto_selection']); + parent::initDisplayGroups(); + $this->removeDisplayGroupAndElements((Class_Template::current() + ->withNameSpace('visibility_group'))); + } +} diff --git a/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/View.php b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/View.php new file mode 100644 index 00000000000..dd365af24c1 --- /dev/null +++ b/library/templates/Intonation/Library/Widget/Carousel/LibraryNovelties/View.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright (c) 2012-2018, 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_Widget_Carousel_LibraryNovelties_View extends Intonation_Library_Widget_Carousel_Record_View { + + protected function _findRecords($params) { + return $this->_settings->getAutoSelection() + ? $this->_autoSelectedElements($params) + : parent::_findRecords($params); + } + + + protected function _autoSelectedElements(array $params) : array { + $params['bib_select'] = $this->_extractLibraryIdFromSettings(); + $params['tri'] = $params['order']; + + $criteres = (new Class_CriteresRecherche)->setParams($params); + $result = (new Class_MoteurRecherche)->lancerRecherche($criteres); + return Class_Notice::findAllByIds($result->fetchAllRecordsIds(), + $params['limit'], + 1); + } + + + protected function _extractLibraryIdFromSettings() : int { + $id_module_as_array = explode('_', $this->id_module); + return array_pop($id_module_as_array); + } + + + protected function getFonctionAdmin() { + return ''; + } + + + protected function _getLinkToAllAsSearchParams() : array { + return $this->_settings->getAutoSelection() + ? array_merge(parent::_getLinkToAllAsSearchParams(), + ['bib_select' => $this->_extractLibraryIdFromSettings()]) + : parent::_getLinkToAllAsSearchParams(); + } + + + protected function _getRSSUrl() { + $profile = Class_Profil::getCurrentProfil(); + return Class_Url::absolute(['module' => 'opac', + 'controller' => 'rss', + 'action' => 'library-novelties', + 'id' => $this->_extractLibraryIdFromSettings(), + 'language' => $profile->getLocale(), + 'id_profil' => $profile->getId()]); + } +} diff --git a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php index e6ef3556cd2..da30063c2e3 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Record/Definition.php @@ -36,6 +36,7 @@ class Intonation_Library_Widget_Carousel_Record_Definition extends Intonation_Li $this->_view_helper = 'Intonation_Library_Widget_Carousel_Record_View'; $this->_defaultValues = array_merge($this->_defaultValues, ['titre' => $this->_libelle, + 'all_layout' => static::SEARCH, 'order' => Class_CriteresRecherche::SORT_RANDOM]); } } \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/View.php b/library/templates/Intonation/Library/Widget/Carousel/View.php index 07c4e0e651e..575ed3fb4d4 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/View.php @@ -297,20 +297,30 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help return $url; if ($this->_settings->getAllLayout() == Intonation_Library_Widget_Carousel_Record_Definition::SEARCH) - return $this->view->url(array_filter(['module' => 'opac', - 'controller' => 'recherche', - 'action' => 'simple', - 'id_catalogue' => $this->_settings->getIdCatalogue(), - 'id_panier' => $this->_settings->getIdPanier(), - 'tri' => $this->_settings->getOrder(), - 'titre' => str_replace(['/', '%2F'], ' ', $this->_settings->getTitre())]), - null, - true); + return $this->_getLinkToAllAsSearch(); return $this->view->url($this->_getLinkToAllUrlParams(), null, true); } + protected function _getLinkToAllAsSearch() : string { + return + $this->view->url(array_filter($this->_getLinkToAllAsSearchParams()), null, true); + } + + + protected function _getLinkToAllAsSearchParams() : array { + return + ['module' => 'opac', + 'controller' => 'recherche', + 'action' => 'simple', + 'id_catalogue' => $this->_settings->getIdCatalogue(), + 'id_panier' => $this->_settings->getIdPanier(), + 'tri' => $this->_settings->getOrder(), + 'titre' => str_replace(['/', '%2F'], ' ', $this->_settings->getTitre())]; + } + + protected function _getLinkToAllUrlParams() : array { $url_params = ['module' => 'opac', diff --git a/library/templates/Intonation/View/Library/Novelties.php b/library/templates/Intonation/View/Library/Novelties.php new file mode 100644 index 00000000000..ab096be35d0 --- /dev/null +++ b/library/templates/Intonation/View/Library/Novelties.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright (c) 2012-2022, 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_View_Library_Novelties extends Intonation_View_Library { + + protected $_show_current_section = 'library_novelties'; + + + public function library_Novelties($library) { + return $this->_renderSection($library); + } +} diff --git a/public/admin/css/front_nav.css b/public/admin/css/front_nav.css index 59dd5856aa7..3e39d38ece7 100644 --- a/public/admin/css/front_nav.css +++ b/public/admin/css/front_nav.css @@ -233,6 +233,7 @@ body > .menu_admin_front .form select { font-weight: bold; } +#site_web_wrapper a[href*="/admin"].tab_configuration i, a[class*="edit_"]:not(.edit_profil){ position: absolute; } @@ -241,6 +242,7 @@ a[class*="edit_"]:not(.edit_profil){ position: static; } +#site_web_wrapper a[href*="/admin"].tab_configuration, nav > a.edit_menu:focus, nav > a.edit_menu , #menu_horizontal > a.edit_menu:focus, @@ -267,6 +269,7 @@ section .edit_openings { left: 3ex; } +#site_web_wrapper a[href*="/admin"].tab_configuration, article header .edit_article { position:absolute; top: 2ex; @@ -302,7 +305,6 @@ body .warning { color: var(--warning-text); } - #site_web_wrapper div.wrapper_document_items a.section_configuration { left: auto; } diff --git a/tests/scenarios/Templates/TemplatesArticlesTest.php b/tests/scenarios/Templates/TemplatesArticlesTest.php index b48810ec54b..65c8af24ade 100644 --- a/tests/scenarios/Templates/TemplatesArticlesTest.php +++ b/tests/scenarios/Templates/TemplatesArticlesTest.php @@ -940,7 +940,6 @@ class TemplatesArticlesWidgetAjaxRenderingWithOrdersTest extends TemplatesArticl abstract class TemplatesArticlesWithWidgetRenderWallTestCase extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); @@ -953,7 +952,7 @@ abstract class TemplatesArticlesWithWidgetRenderWallTestCase extends AbstractCon ['id' => 55, 'titre' => 'Mes dvds', 'description' => 'Un article avec un kiosque dans du data-code', - 'contenu' => '<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=123&"><img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=124&">']); + 'contenu' => '<img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=123&all_layout=list&"><img class="bokeh_kiosk" data-code="KIOSQUE" data-form="titre=&style_liste=mur&aleatoire=1&tri=1&boite=&rss=1&MybibappShowFooter=1&link_to_all=1&id_panier=124&all_layout=list&">']); $this->_dispatch(); } @@ -1039,6 +1038,7 @@ class TemplatesArticlesWithWidgetRenderWallNotLoggedTest 'MybibappShowFooter' => '1', 'link_to_all' => '1', 'id_panier' => '123', + 'all_layout' => 'list', ], 'style_liste' => 'mur', 'aleatoire' => '1', @@ -1053,13 +1053,13 @@ class TemplatesArticlesWithWidgetRenderWallNotLoggedTest /** @test */ public function enLirePlusShouldBePresentForFirstCarousel() { - $this->assertXPathContentContains('//div//a[contains(@href, "/widget/render-all/profile_id/32/article_id/55/widget_key/e6871b8faf022fd81b4a3e18ad734eb8")]', 'En lire plus'); + $this->assertXPathContentContains('//div//a[contains(@href, "/widget/render-all/profile_id/32/article_id/55/widget_key/8114554cd19c8d3ef808e70f527411b6")]', 'En lire plus'); } /** @test */ public function enLirePlusShouldBePresentForSecondCarousel() { - $this->assertXPathContentContains('//div//a[contains(@href, "/widget/render-all/profile_id/32/article_id/55/widget_key/5d2c8a1b42d7d4e33d4b8a9e7300f3a9")]', 'En lire plus'); + $this->assertXPathContentContains('//div//a[contains(@href, "/widget/render-all/profile_id/32/article_id/55/widget_key/fe3385428fb49a368c0c2a67bebb2cbc")]', 'En lire plus'); } } @@ -1090,7 +1090,7 @@ class TemplatesArticlesRenderAllFromArticleTest 'notices' => 'COMBAT ORDINAIRE;BLACKSAD']) ->addNotice($trolls); - $this->dispatch('/widget/render-all/profile_id/32/article_id/55/widget_key/e6871b8faf022fd81b4a3e18ad734eb8'); + $this->dispatch('/widget/render-all/profile_id/32/article_id/55/widget_key/fe3385428fb49a368c0c2a67bebb2cbc'); $this->assertXPathContentContains('//div[@data-action="widget_render-all"]//div[@class="card-title"]', 'TROLLS DE TROY'); @@ -1114,7 +1114,7 @@ class TemplatesArticlesRenderAllFromArticleTest 'date_maj' => '10/02/2011']) ->addNotice($trolls); - $this->dispatch('/widget/render-all/profile_id/32/article_id/55/widget_key/5d2c8a1b42d7d4e33d4b8a9e7300f3a9'); + $this->dispatch('/widget/render-all/profile_id/32/article_id/55/widget_key/8114554cd19c8d3ef808e70f527411b6'); $this->assertXPathContentContains('//div[@data-action="widget_render-all"]//div[@class="card-title"]', 'TROLLS DE TROY 2'); diff --git a/tests/scenarios/Templates/TemplatesLibraryNoveltiesTabTest.php b/tests/scenarios/Templates/TemplatesLibraryNoveltiesTabTest.php new file mode 100644 index 00000000000..b31fd213258 --- /dev/null +++ b/tests/scenarios/Templates/TemplatesLibraryNoveltiesTabTest.php @@ -0,0 +1,395 @@ +<?php +/** + * Copyright (c) 2012-2022, 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 TemplatesLibraryNoveltiesTabSettingsTest extends Admin_AbstractControllerTestCase { + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 12]); + + $conf = (new Class_Systeme_Widget_Action) + ->setId('bib_en-lire-plus') + ->setProfileId(12) + ->load(); + + $conf + ->setNewDatas(['IntonationLabelLibraryNovelties' => 'Dans les bacs']) + ->updateProfile(); + + $this->dispatch('/admin/widget/edit-action/id/bib_en-lire-plus/id_profil/12'); + } + + + /** @test */ + public function tabNoveltiesShouldBePresent() { + $this->assertXPathContentContains('//form//label', 'Activer l\'affichage de l\'onglet Nouveautés'); + } + + + /** @test */ + public function tabNoveltiesShouldNotBeActivated() { + $this->assertXPath('//form//input[@type="checkbox"][@name="Intonation_Library_View_Wrapper_Library_RichContent_Novelties"][not(@checked)]'); + } +} + + + + +class TemplatesLibraryNoveltiesDefaultTest extends Admin_AbstractControllerTestCase { + + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 12, + 'libelle' => 'accueil']); + + (new Muscle_Template)->tryOn($profile); + $this->dispatch('/admin/widget/edit-action/id/bib_en-lire-plus/id_profil/13'); + } + + + /** @test */ + public function tabNoveltiesShouldBeActivated() { + $this->assertXPath('//form//input[@type="checkbox"][@name="Intonation_Library_View_Wrapper_Library_RichContent_Novelties"][@checked]'); + } +} + + + + +abstract class TemplatesLibraryNoveltiesWithLibraryTestCase extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 21, + 'libelle' => 'accueil']); + + $this->fixture(Class_Bib::class, + ['id' => 1, + 'libelle' => 'Saint Jorioz', + 'visibilite' => Class_Bib::V_NODATA, + 'rewrite_url' => 'saint_jorioz' + ]); + + $profile = $this->_buildTemplateProfil(['id' => 22]); + (new Herisson_Template)->tryOn($profile); + } +} + + + + +class TemplatesLibraryNoveltiesTabIndexDispatchTest extends TemplatesLibraryNoveltiesWithLibraryTestCase { + + + public function setUp() { + parent::setUp(); + $this->dispatch('/bib/en-lire-plus/id/1'); + } + + + /** @test */ + public function noveltiesTabShouldBeDisplay() { + $this->assertXPathContentContains('//div/h2/span', 'Nouveautés'); + } + + + /** @test */ + public function linkToEditNoveltiesShouldBePresent() { + $this->assertXPath('//a[@href="/admin/widget/edit-action/id/bib_novelties_1/id_profil/23"]'); + } +} + + + + +class TemplatesLibraryNoveltiesEditTest extends TemplatesLibraryNoveltiesWithLibraryTestCase { + + + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/widget/edit-action/id/bib_novelties_1/id_profil/23'); + } + + + /** @test */ + public function formShouldContainsLayout() { + $this->assertXPath('//form//select[@name="layout"]'); + } + + + /** @test */ + public function formShouldContainsRendering() { + $this->assertXPath('//form//select[@name="rendering"]'); + } + + + /** @test */ + public function formShouldContainsAutoSelection() { + $this->assertXPath('//form//input[@name="auto_selection"][@type="checkbox"][@checked]'); + } + + + /** @test */ + public function titleShouldContainsSaintJorioz() { + $this->assertXPathContentContains('//div//h1', 'Configuration des nouveautés de Saint Jorioz'); + } + + + /** @test */ + public function formShouldContainsUncheckedShowHeader() { + $this->assertXPath('//form//input[@name="HerissonShowHeader"][not(@checked)]'); + } + + + /** @test */ + public function visibilityTabShouldNotBeDisplay() { + $this->assertNotXPathContentContains('//form', 'Visibilité'); + } + + + /** @test */ + public function defaultStylePackShouldBeAlignCenterNoBorder() { + $this->assertXPathContentContains('//form//select/option[@selected]', + 'Sans bordure, sans arrondi, sans ombre, sans fond'); + } +} + + + + +class TemplatesLibraryNoveltiesPostEditTest extends TemplatesLibraryNoveltiesWithLibraryTestCase { + + + protected $_widget; + + + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/widget/edit-action/id/bib_novelties_1/id_profil/23', + ['layout' => 'list', + 'rendering' => 'card-description']); + + $this->_widget = (new Class_Systeme_Widget_Action_LibraryNovelties) + ->setId('bib_novelties_1') + ->setProfileId(23) + ->load(); + } + + + /** @test */ + public function layoutShouldHaveBeenUpdatedToList() { + $this->assertEquals('list', $this->_widget->getlayout()); + } + + + /** @test */ + public function renderingShouldHaveBeenUpdatedToCardDescription() { + $this->assertEquals('card-description', $this->_widget->getrendering()); + } + + + /** @test */ + public function defaultSelectionShouldBeAutoNoveltiesForSaintJorioz() { + $this->assertEquals('1', $this->_widget->getauto_selection()); + } + + + /** @test */ + public function defaultStylePackShouldBeAlignCenterNoBorder() { + $this->assertEquals('Sans bordure, sans arrondi, sans ombre, sans fond', + Class_StylesPack::find($this->_widget->getHerissonStylesPack())->getLabel()); + } + + + /** @test */ + public function cycleShouldBeFour() { + $this->assertEquals('4', $this->_widget->getcycle()); + } +} + + + + +abstract class TemplatesLibraryNoveltiesTabWithAutoSelectionTestCase extends AbstractControllerTestCase { + + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 23]); + + (new Class_Profil_Preferences()) + ->setModulePref($profile, + (new Class_Profil_ModuleDefinition('bib', + 'en-lire-plus')), + [Intonation_Library_View_Wrapper_Library_RichContent_Novelties::class => '1']); + + $this->fixture(Class_Bib::class, + ['id' => 1, + 'libelle' => 'Saint Jorioz']); + + $this->fixture(Class_Notice::class, + ['id' => 789, + 'titre_principal' => 'Despot\'s Game (Original Game Soundtrack)']); + + $sql = $this + ->mock() + + ->whenCalled('fetchAll') + ->with('select id_notice, facettes from notices Where (MATCH(facettes) AGAINST(\'+(B1)\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="", date_creation desc, alpha_titre asc limit 20', true, false) + ->answers([[789, '']]) + + ->beStrict(); + + Zend_Registry::set('sql', $sql); + $this->_dispatch(); + } + + + abstract protected function _dispatch() : void; +} + + + + +class TemplatesLibraryNoveltiesTabDispatchTest extends TemplatesLibraryNoveltiesTabWithAutoSelectionTestCase { + + + protected function _dispatch() : void { + $this->dispatch('/bib/novelties/id/1'); + } + + + /** @test */ + public function defaultLayoutShoulBeMultipleCarouselPlus() { + $this->assertXPath('//div[@class="carousel slide multiple_carousel"]'); + } + + + /** @test */ + public function defaultRenderingShoulBeMedia() { + $this->assertXPath('//div[@class="card_with_overlay card text-center"]'); + } + + + /** @test */ + public function despotsGameRecordShouldBeDisplay() { + $this->assertXPathContentContains('//div[@class="card-title"]', 'Despot\'s Game'); + } + + + /** @test */ + public function adminActionsShouldNotBePresent() { + $this->assertNotXPath('//div[@id="boite_bib_novelties_1"]//div[@class="section_configuration"]'); + } +} + + + + +class TemplatesLibraryNoveltiesTabWidgetRenderTest extends TemplatesLibraryNoveltiesTabDispatchTest { + + protected function _dispatch() : void { + $this->dispatch('/widget/render/widget_id/bib_novelties_1/profile_id/23/anchor_target/_blank'); + } +} + + + + +class TemplatesLibraryNoveltiesTabWidgetRenderAllTest extends TemplatesLibraryNoveltiesTabDispatchTest { + + protected function _dispatch() : void { + $conf = (new Class_Systeme_Widget_Action) + ->setId('bib_novelties_1') + ->setProfileId(23) + ->load(); + + $conf + ->setNewDatas(['all_rendering' => 'card-overlay', + 'all_layout' => 'multiple_carousel_plus']) + ->updateProfile(); + + + $sql = Zend_Registry::get('sql') + + ->whenCalled('fetchAll') + ->with('select id_notice, facettes from notices Where (MATCH(facettes) AGAINST(\'+(B1)\' IN BOOLEAN MODE)) and type=1 order by url_image="no", url_image="", date_creation desc, alpha_titre asc limit 1000', true, false) + ->answers([[789, '']]); + + $this->dispatch('widget/render-all/profile_id/23/widget_id/bib_novelties_1'); + } +} + + + + +class TemplatesLibraryNoveltiesTabWidgetShowFooterTest extends TemplatesLibraryNoveltiesTabDispatchTest { + + protected function _dispatch() : void { + $conf = (new Class_Systeme_Widget_Action_LibraryNovelties) + ->setId('bib_novelties_1') + ->setProfileId(23) + ->load(); + + $conf + ->setNewDatas(['IntonationShowFooter' => '1', + 'link_to_all' => '1', + 'rss' => '1']) + ->updateProfile(); + + parent::_dispatch(); + } + + + /** @test */ + public function linkToAllShouldBeRechercheSimple() { + $this->assertXPathContentContains('//div//a[@href="/recherche/simple/tri/date_creation+desc%2C+alpha_titre+asc/titre/Nouveaut%C3%A9s+de+la+biblioth%C3%A8que/bib_select/1"]', + 'En lire plus'); + } + + + /** @test */ + public function rssLinkShouldUseCacheKey() { + $this->assertXPath('//div//a[contains(@href, "/rss/library-novelties/id/1/language/fr/id_profil/23")]'); + } +} + + + + +class TemplatesLibraryNoveltiesRSSTest extends TemplatesLibraryNoveltiesTabWithAutoSelectionTestCase { + + + protected function _dispatch() : void { + $this->dispatch('rss/library-novelties/id/1/id_profil/23/language/fr'); + } + + + /** @test */ + public function rssShouldContainsDespotSGame() { + $this->assertXPathContentContains('//rss//title', + '<![CDATA[Despot\'s Game (Original Game Soundtrack), ]]>', + $this->_response->getBody()); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesWidgetTest.php b/tests/scenarios/Templates/TemplatesWidgetTest.php index a45d52b6040..a705a515d3f 100644 --- a/tests/scenarios/Templates/TemplatesWidgetTest.php +++ b/tests/scenarios/Templates/TemplatesWidgetTest.php @@ -911,13 +911,13 @@ class TemplateRecordsWidgetWithOptionsTest extends TemplatesIntonationTestCase { /** @test */ public function shouldContainsShowAllRecords() { - $this->assertXPath('//a[contains(@href, "/widget/render-all")][contains(@title, "Voir tous les documents de la liste")]'); + $this->assertXPath('//a[contains(@href, "/recherche/simple")][contains(@title, "Voir tous les documents de la liste")]'); } /** @test */ - public function shouldContainsLinkToAllWithHrefWidgetRenderAll() { - $this->assertXPath('//a[contains(@href, "/widget/render-all/profile_id/72/widget_id/17")][contains(@title, "Voir tous les documents")]'); + public function shouldContainsLinkToAllWithHrefRechercheSimple() { + $this->assertXPath('//a[contains(@href, "/recherche/simple/tri/alpha_titre+ASC/titre/Boite+de+notices")][contains(@title, "Voir tous les documents")]'); } } -- GitLab