From 8a2b5e3377f9f0d4e2a533c14962ad629c677bb9 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 8 Sep 2021 16:09:15 +0200 Subject: [PATCH] hotline MT #140106 fix menu entry articles selection --- VERSIONS_HOTLINE/140106 | 1 + .../opac/controllers/WidgetController.php | 8 +- library/Class/Systeme/Widget/Abstract.php | 20 +- .../Library/Menu/Articles/Definition.php | 4 +- ..._profile_with_menu_with_articles_list.json | 399 ++++++++++++++++++ tests/scenarios/Templates/ChiliLoginTest.php | 6 +- .../scenarios/Templates/TemplatesMenuTest.php | 40 +- 7 files changed, 452 insertions(+), 26 deletions(-) create mode 100644 VERSIONS_HOTLINE/140106 create mode 100644 tests/scenarios/Templates/140106_profile_with_menu_with_articles_list.json diff --git a/VERSIONS_HOTLINE/140106 b/VERSIONS_HOTLINE/140106 new file mode 100644 index 00000000000..92719302b7f --- /dev/null +++ b/VERSIONS_HOTLINE/140106 @@ -0,0 +1 @@ + - ticket #140106 : Magasin de thèmes : Correction des entrées de menu lien vers une sélection d'articles. \ No newline at end of file diff --git a/application/modules/opac/controllers/WidgetController.php b/application/modules/opac/controllers/WidgetController.php index 6aaa0b4eec2..817dbe16192 100644 --- a/application/modules/opac/controllers/WidgetController.php +++ b/application/modules/opac/controllers/WidgetController.php @@ -115,10 +115,10 @@ class WidgetController extends ZendAfi_Controller_Action { public function renderMenuEntryAction() { - if (null === ($id_menu = $this->_getParam('id_menu', null))) + if (null === ($parent = $this->_getParam('parent', null))) return ''; - if (null === ($id_submenu = $this->_getParam('id_submenu', null))) + if (null === ($menu = $this->_getParam('menu', null))) return ''; if (!$profile_id = $this->_getParam('menu_profil')) @@ -129,9 +129,9 @@ class WidgetController extends ZendAfi_Controller_Action { $child = new Class_Systeme_Widget_Menu; if ($this->view->widget = $child - ->setId($id_submenu) + ->setId($menu) ->setProfileId($profile_id) - ->setParent($id_menu) + ->setParent($parent) ->load()) return; diff --git a/library/Class/Systeme/Widget/Abstract.php b/library/Class/Systeme/Widget/Abstract.php index d0b4d8df856..9d95ce834ee 100644 --- a/library/Class/Systeme/Widget/Abstract.php +++ b/library/Class/Systeme/Widget/Abstract.php @@ -45,11 +45,8 @@ abstract class Class_Systeme_Widget_Abstract extends Class_Entity { public function load() { $cache_key = $this->_getCacheKey(); - if (isset(static::$_loaded_instances[$cache_key])) { - $cached_instance = static::$_loaded_instances[$cache_key]; - $cached_instance->updateWidgetContext(); - return $cached_instance; - } + if (isset(static::$_loaded_instances[$cache_key])) + return static::$_loaded_instances[$cache_key]; if (!$this->init()) return; @@ -177,16 +174,11 @@ abstract class Class_Systeme_Widget_Abstract extends Class_Entity { protected function _getWidgetResources() { - if ( isset($this->_resources_definition)) - return $this->_resources_definition; - - return $this->_resources_definition = - $this->getResourcesDefinition()->setWidgetContext($this); - } - + $ressources_definition = isset($this->_resources_definition) + ? $this->_resources_definition + : $this->getResourcesDefinition(); - public function updateWidgetContext() { - return $this->_getWidgetResources()->setWidgetContext($this); + return $this->_resources_definition = $ressources_definition->setWidgetContext($this); } diff --git a/library/templates/Intonation/Library/Menu/Articles/Definition.php b/library/templates/Intonation/Library/Menu/Articles/Definition.php index d0ea7e70d5b..ad2ec72f6f7 100644 --- a/library/templates/Intonation/Library/Menu/Articles/Definition.php +++ b/library/templates/Intonation/Library/Menu/Articles/Definition.php @@ -38,9 +38,9 @@ class Intonation_Library_Menu_Articles_Definition extends Class_Systeme_ModulesM return Class_Url::relative(['module' => 'opac', 'controller' => 'widget', 'action' => 'render-menu-entry', - 'id_menu' => $widget_context->getParent(), + 'parent' => $widget_context->getParent(), 'menu_profil' => $widget_context->getProfileId(), - 'id_submenu' => $widget_context->getId(), + 'menu' => $widget_context->getId(), 'id_profil' => $use_profil], null, true); } diff --git a/tests/scenarios/Templates/140106_profile_with_menu_with_articles_list.json b/tests/scenarios/Templates/140106_profile_with_menu_with_articles_list.json new file mode 100644 index 00000000000..402ffdeb104 --- /dev/null +++ b/tests/scenarios/Templates/140106_profile_with_menu_with_articles_list.json @@ -0,0 +1,399 @@ +{ + "id": 146, + "id_profil": 146, + "parent_id": null, + "browser": "opac", + "id_site": 0, + "libelle": "Biblioth\u00e8ques municipales de Chamb\u00e9ry", + "commentaire": "Le bouquet des m\u00e9diath\u00e8ques : M\u00e9diath\u00e8que de Chamb\u00e9ry,", + "titre_site": "Biblioth\u00e8ques municipales de Chamb\u00e9ry", + "ref_description": "", + "cfg_accueil": { + "modules": { + "17": { + "division": "2", + "type_module": "MENU", + "preferences": { + "titre": "Facebook et blogs", + "menu": "146-9", + "layout": "horizontal", + "boite": [ + "justify-content-center", + "no_border", + "no_border_radius", + "no_shadow" + ], + "id_module": "17", + "profile_id": "146", + "PolygoneExpandBreakpoint": "sm", + "PolygoneWidthXsmall": "12", + "PolygoneWidthMedium": "4", + "PolygoneVisibilityIndex": "1", + "PolygoneVisibilityRecherche": "1", + "PolygoneVisibilityAbonne": "1", + "PolygoneVisibilityCms": "1", + "PolygoneVisibilityBlog": "1", + "PolygoneVisibilityAuth": "1" + } + }, + + "24": { + "type_module": "MENU", + "preferences": { + "titre": "Boite menu", + "menu": "146-11", + "layout": "horizontal", + "boite": [ + "BOUQUET_boite-menu-retour-reseau", + "justify-content-center", + "no_border", + "no_border_radius", + "no_shadow" + ], + "profile_id": "146", + "all_rendering": "card-description", + "all_layout": "carousel", + "description_length": "20", + "PolygoneVisibilityIndex": "1", + "PolygoneVisibilityRecherche": "1", + "PolygoneVisibilityAbonne": "1", + "PolygoneVisibilityCms": "1", + "PolygoneVisibilityBlog": "1", + "PolygoneVisibilityAuth": "1" + }, + "division": "2", + "id_module": "24", + "profile_id": "146" + }, + + "20": { + "division": "4", + "type_module": "MENU", + "preferences": { + "titre": "Boite menu", + "menu": "146-10", + "layout": "horizontal", + "boite": [ + "BOUQUET_boite-menu-retour-reseau", + "justify-content-center", + "no_border", + "no_border_radius", + "no_shadow" + ], + "id_module": "20", + "profile_id": "146", + "PolygoneWidthXsmall": "12", + "PolygoneWidthMedium": "4", + "PolygoneVisibilityIndex": "1", + "PolygoneVisibilityRecherche": "1", + "PolygoneVisibilityAbonne": "1", + "PolygoneVisibilityCms": "1", + "PolygoneVisibilityBlog": "1", + "PolygoneVisibilityAuth": "1", + "all_rendering": "card-description", + "all_layout": "carousel", + "description_length": "20" + } + }, + + "16": { + "division": "4", + "type_module": "MENU", + "preferences": { + "titre": "Boite menu", + "menu": "146-H", + "layout": "horizontal", + "boite": [ + "BOUQUET_boite-menu-retour-bib", + "justify-content-center", + "no_border", + "no_border_radius", + "no_shadow" + ], + "id_module": "16", + "profile_id": "146", + "PolygoneWidthXsmall": "12", + "PolygoneWidthMedium": "4", + "PolygoneOrderXsmall": "7", + "PolygoneVisibilityIndex": "1", + "PolygoneVisibilityRecherche": "1", + "PolygoneVisibilityAbonne": "1", + "PolygoneVisibilityCms": "1", + "PolygoneVisibilityBlog": "1", + "PolygoneVisibilityAuth": "1", + "all_rendering": "card-description", + "all_layout": "carousel", + "description_length": "20" + } + }, + + "12": { + "division": "4", + "type_module": "MENU", + "preferences": { + "titre": "menu", + "menu": "146-3", + "layout": "horizontal", + "boite": [ + "BOUQUET_boite-menu-principal", + "justify-content-center", + "no_border", + "no_border_radius", + "no_shadow" + ], + "id_module": "12", + "profile_id": "146", + "PolygoneExpandBreakpoint": "sm", + "PolygoneWidthXsmall": "12", + "PolygoneWidthMedium": "8", + "PolygoneOrderXsmall": "8", + "PolygoneVisibilityIndex": "1", + "PolygoneVisibilityRecherche": "1", + "PolygoneVisibilityAbonne": "1", + "PolygoneVisibilityCms": "1", + "PolygoneVisibilityBlog": "1", + "PolygoneVisibilityAuth": "1", + "all_rendering": "card-description", + "all_layout": "carousel", + "description_length": "20" + } + } + } + }, + "cfg_menus": { + "H": { + "type_menu": "MENU", + "libelle": "menu haut", + "preferences": [], + "menus": [ + { + "type_menu": "PROFIL", + "libelle": "Biblioth\u00e8ques municipales de Chamb\u00e9ry", + "preferences": { + "clef_profil": "146" + } + } + ], + "children": "PROFIL;" + }, + "3": { + "type_menu": "MENU", + "libelle": "Menu principal", + "preferences": [], + "menus": { + "0": { + "type_menu": "MENU", + "libelle": "En pratique", + "preferences": [], + "children": "PROFIL;PROFIL;PROFIL;", + "sous_menus": { + "1": { + "type_menu": "PROFIL", + "libelle": "Horaires et acc\u00e8s", + "preferences": { + "clef_profil": "247" + } + }, + "2": { + "type_menu": "PROFIL", + "libelle": "Inscriptions et tarifs", + "preferences": { + "clef_profil": "249" + } + }, + "3": { + "type_menu": "PROFIL", + "libelle": "Espace pro", + "preferences": { + "clef_profil": "250" + } + } + } + }, + "5": { + "type_menu": "NEWS", + "libelle": "M\u00e9diavue et handicap", + "preferences": { + "id_items": "980", + "nb_aff": "5", + "nb_analyse": "10", + "display_order": "DateCreationDesc", + "display_mode": "Submenu", + "summary_content": "FullContent", + "layout": "list", + "rendering": "page", + "size": "20", + "all_layout": "list", + "all_rendering": "card-horizontal", + "description_length": "20", + "titre": "Boite d'articles", + "order": "Selection", + "boite": [], + "use_profil": "146", + "PolygoneShowContent": "1" + } + }, + "6": { + "type_menu": "NEWS", + "libelle": "Atelier multim\u00e9dia", + "preferences": { + "id_items": "57", + "nb_aff": "5", + "nb_analyse": "10", + "display_order": "DateCreationDesc", + "display_mode": "Submenu", + "summary_content": "FullContent", + "use_profil": "146" + } + }, + "7": { + "type_menu": "PROFIL", + "libelle": "Patrimoine", + "preferences": { + "clef_profil": "156" + } + }, + "8": { + "type_menu": "PROFIL", + "libelle": "Action \u00e9ducative et culturelle", + "preferences": { + "clef_profil": "246" + } + }, + "9": { + "type_menu": "MENU", + "libelle": "Autres services", + "preferences": [], + "children": "NEWS;NEWS;", + "sous_menus": { + "10": { + "type_menu": "NEWS", + "libelle": "Pr\u00eat entre biblioth\u00e8ques", + "preferences": { + "id_items": "71", + "nb_aff": "5", + "nb_analyse": "10", + "display_order": "DateCreationDesc", + "display_mode": "Submenu", + "summary_content": "FullContent", + "use_profil": "146" + } + }, + "11": { + "type_menu": "NEWS", + "libelle": "Demande de reproductions", + "preferences": { + "id_items": "72", + "nb_aff": "5", + "nb_analyse": "10", + "display_order": "DateCreationDesc", + "display_mode": "Submenu", + "summary_content": "FullContent", + "use_profil": "146" + } + } + } + }, + "13": { + "type_menu": "NEWS", + "libelle": "Ressources en ligne", + "preferences": { + "id_items": "248", + "nb_aff": "5", + "nb_analyse": "10", + "display_order": "DateCreationDesc", + "display_mode": "Submenu", + "summary_content": "FullContent", + "layout": "list", + "rendering": "page", + "size": "20", + "all_layout": "list", + "all_rendering": "card-horizontal", + "description_length": "20", + "titre": "Boite d'articles", + "order": "Selection", + "boite": [], + "use_profil": "146", + "PolygoneShowContent": "1" + } + } + }, + "children": "MENU;1;2;3;4;5;6;" + }, + "8": { + "libelle": "Mentions l\u00e9gales", + "menus": [ + { + "type_menu": "URL", + "libelle": "Mentions l\u00e9gales" + } + ] + }, + "9": { + "type_menu": "MENU", + "libelle": "Facebook et blogs", + "preferences": [], + "menus": [ + { + "type_menu": "URL", + "libelle": "Facebook des BM de Chamb\u00e9ry", + "picto": "\/userfiles\/image\/entetes\/facebook-logo-png.png", + "preferences": { + "url": "https:\/\/fr-fr.facebook.com\/bibchambery" + } + }, + { + "type_menu": "URL", + "libelle": "Le blog des secteurs jeunesse", + "picto": "\/userfiles\/image\/entetes\/boiteabonbec.png", + "preferences": { + "url": "https:\/\/boiteabonbecs.blogspot.com\/" + } + }, + { + "type_menu": "URL", + "libelle": "Express'Haut", + "picto": "\/userfiles\/image\/entetes\/espresshauts.png", + "preferences": { + "url": "https:\/\/expresshauts73.wordpress.com\/" + } + } + ], + "children": "0;1;2" + }, + "10": { + "type_menu": "MENU", + "libelle": "lien vers page d'accueil", + "preferences": [], + "menus": [ + { + "type_menu": "PROFIL", + "libelle": "Lien vers un profil ou une page", + "picto": "\/userfiles\/image\/banniere\/banniereBouquet2021.png", + "preferences": { + "clef_profil": "1" + } + } + ], + "children": "PROFIL;" + }, + "11": { + "type_menu": "MENU", + "libelle": "pop", + "picto": "\/userfiles\/image\/POP\/POP.jpg", + "preferences": [], + "menus": [ + { + "type_menu": "PROFIL", + "libelle": "Expo POP", + "picto": "\/userfiles\/image\/POP\/POP.jpg", + "preferences": { + "clef_profil": "273" + } + } + ], + "children": "PROFIL;" + } + }, + "template": "POLYGONE" +} diff --git a/tests/scenarios/Templates/ChiliLoginTest.php b/tests/scenarios/Templates/ChiliLoginTest.php index 4d63c7344f5..fce308f9703 100644 --- a/tests/scenarios/Templates/ChiliLoginTest.php +++ b/tests/scenarios/Templates/ChiliLoginTest.php @@ -228,7 +228,7 @@ class ChiliLoginWidgetFrontTest extends ChiliLoginWidgetTestCase { /** @test */ public function loginWidgetShouldContainsLastNewsLink() { - $this->assertXPathContentContains('//div[contains(@class, "dropdown-menu-right")]//li[@class= "nav-item menu_entry_NEWS_0_6"]//a[@href="/widget/render-menu-entry/id_menu/0/menu_profil/4/id_submenu/6"]', 'Latest news'); + $this->assertXPathContentContains('//div[contains(@class, "dropdown-menu-right")]//li[@class= "nav-item menu_entry_NEWS_0_6"]//a[@href="/widget/render-menu-entry/parent/0/menu_profil/4/menu/6"]', 'Latest news'); } } @@ -263,7 +263,7 @@ class ChiliLoginDispatchMenuArticlesTest extends ChiliLoginWidgetTestCase { 'titre' => 'New article', 'contenu' => '<i>A new article is readeable.</i>']); - $this->dispatch('/widget/render-menu-entry/id_menu/0/menu_profil/4/id_submenu/6'); + $this->dispatch('/widget/render-menu-entry/parent/0/menu_profil/4/menu/6'); } @@ -285,7 +285,7 @@ class ChiliLoginDispatchMenuArticlesFailureTest extends ChiliLoginWidgetTestCase 'titre' => 'New article', 'contenu' => '<i>A new article is readeable.</i>']); - $this->dispatch('/widget/render-menu-entry/id_menu/3434/menu_profil/34/id_submenu/08906'); + $this->dispatch('/widget/render-menu-entry/parent/3434/menu_profil/34/menu/08906'); } diff --git a/tests/scenarios/Templates/TemplatesMenuTest.php b/tests/scenarios/Templates/TemplatesMenuTest.php index 55d8f66a142..a22adfc48fa 100644 --- a/tests/scenarios/Templates/TemplatesMenuTest.php +++ b/tests/scenarios/Templates/TemplatesMenuTest.php @@ -215,12 +215,12 @@ class TemplatesMenuDisplayTwoTimesTest extends Admin_AbstractControllerTestCase /** @test */ public function linkToRenderMenuEntryIWantToSubscribeShouldBeParentMenu6SubMenu3MenuProfil1() { - $this->assertXPathContentContains('//a[@href="/widget/render-menu-entry/id_menu/6/menu_profil/1/id_submenu/3/id_profil/55"]', 'Je veux m\'inscrire'); + $this->assertXPathContentContains('//a[@href="/widget/render-menu-entry/parent/6/menu_profil/1/menu/3/id_profil/55"]', 'Je veux m\'inscrire'); } /** @test */ public function linkToRenderMenuEntryIWantToSubscribeShouldBePresentTwoTime() { - $this->assertXPathCount('//a[@href="/widget/render-menu-entry/id_menu/6/menu_profil/1/id_submenu/3/id_profil/55"]', 2); + $this->assertXPathCount('//a[@href="/widget/render-menu-entry/parent/6/menu_profil/1/menu/3/id_profil/55"]', 2); } } @@ -325,7 +325,7 @@ class TemplatesMenuDefaultSettingsTest extends Admin_AbstractControllerTestCase (new Class_Profil_Import($profile)) ->import(__DIR__ . '/137985_profile_with_menu_with_widget_with_menu.json'); - $this->dispatch('/widget/render-menu-entry/id_menu/6/menu_profil/1/id_submenu/3'); + $this->dispatch('/widget/render-menu-entry/parent/6/menu_profil/1/menu/3'); } @@ -530,3 +530,37 @@ class TemplatesMenuWithSubmenuTest extends TemplatesMenuTestCase { $this->assertXPath('//li[@class="nav-item menu_entry_MENU_0_1 dropdown"]//li[@class="nav-item menu_entry_URL_0_2"]/a'); } } + + + + +class TemplatesMenuDisplayWithArticlesListTest extends Admin_AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $profile = $this->_buildTemplateProfil(['id' => 1, + 'template' => 'POLYGONE']); + + (new Class_Profil_Import($profile)) + ->import(__DIR__ . '/140106_profile_with_menu_with_articles_list.json'); + + + $this->dispatch('/index'); + } + + + /** @test */ + public function linkToRenderMenuEntryMediavueEtHandicapShouldContainsParent3AndMenu5() { + $this->assertXPathContentContains('//a[@href="/widget/render-menu-entry/parent/3/menu_profil/1/menu/5/id_profil/146"]', 'Médiavue et handicap', $this->_response->getBody()); + } + + + /** @test */ + public function linkToRenderMenuEntryRessourcesEnLigneShouldContainsParent3AndMenu13() { + $this->assertXPathContentContains('//a[@href="/widget/render-menu-entry/parent/3/menu_profil/1/menu/13/id_profil/146"]', 'Ressources en ligne'); + } +} -- GitLab