From 6d7a11a483f9d1fe56c737fd917e10b5362459db Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Thu, 18 Oct 2018 16:50:39 +0200 Subject: [PATCH] hotline #80724 fix horizontal sub sub menus administration --- VERSIONS_HOTLINE/80724 | 1 + library/Class/Systeme/Widget/Menu.php | 26 +++- .../ZendAfi/Form/Configuration/Menu/Entry.php | 2 +- .../controllers/WidgetControllerTest.php | 134 ++++++++++++++++++ 4 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 VERSIONS_HOTLINE/80724 diff --git a/VERSIONS_HOTLINE/80724 b/VERSIONS_HOTLINE/80724 new file mode 100644 index 00000000000..170a2f0da8f --- /dev/null +++ b/VERSIONS_HOTLINE/80724 @@ -0,0 +1 @@ + - ticket #80724 : Menu horizontal: correction du paramétrage des éléments dans des sous - sous menus \ No newline at end of file diff --git a/library/Class/Systeme/Widget/Menu.php b/library/Class/Systeme/Widget/Menu.php index 45f0f7d38ff..a4e1aa23bd5 100644 --- a/library/Class/Systeme/Widget/Menu.php +++ b/library/Class/Systeme/Widget/Menu.php @@ -117,7 +117,7 @@ class Class_Systeme_Widget_Menu extends Class_Systeme_Widget_Abstract { if(isset($datas['children'])) $sub_menus = $this->_convertChildren($datas['children']); - if(!$this->hasParent() && $sub_menus) { + if(!$this->hasParent()) { $datas['menus'] = (new Class_Systeme_MenuHorizontal($sub_menus))->asCfgProfil(); return $this->_save($datas); } @@ -150,12 +150,34 @@ class Class_Systeme_Widget_Menu extends Class_Systeme_Widget_Abstract { return $profil->setCfgMenus($cfg_menus)->save(); } - $cfg_menus[$this->getParent()]['menus'][$this->getPosition()]['sous_menus'][$this->getId()] = $datas; + $this->_saveDeepIn($cfg_menus[$this->getParent()]['menus'], + $datas); return $profil->setCfgMenus($cfg_menus)->save(); } + + protected function _saveDeepIn(&$entries, $datas) { + foreach($entries as &$entry) { + if(isset($entry['id_module']) && ($this->getId() == (string)$entry['id_module'])) { + $entry = $datas; + return true; + } + + if (isset($entry['sous_menus']) && $this->_saveDeepIn($entry['sous_menus'], $datas)) + return true; + + if (isset($entry['menus']) && $this->_saveDeepIn($entry['menus'], $datas)) + return true; + } + + return false; + } + + + + public function getResourcesProvider() { if(!parent::getResourcesProvider()) $this->setResourcesProvider(new Class_Systeme_ModulesMenu()); diff --git a/library/ZendAfi/Form/Configuration/Menu/Entry.php b/library/ZendAfi/Form/Configuration/Menu/Entry.php index 9cf01a7d782..9c4ab0ad79f 100644 --- a/library/ZendAfi/Form/Configuration/Menu/Entry.php +++ b/library/ZendAfi/Form/Configuration/Menu/Entry.php @@ -27,7 +27,7 @@ class ZendAfi_Form_Configuration_Menu_Entry extends ZendAfi_Form { $this ->addElement('text', 'libelle', - ['label' => $this->_('Text du lien')]) + ['label' => $this->_('Texte du lien')]) ->addElement('IcoPicker', 'picto', ['label' => $this->_('Icône du lien')]) diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php index 8d1ac248df2..7cb15573ca0 100644 --- a/tests/application/modules/admin/controllers/WidgetControllerTest.php +++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php @@ -2437,3 +2437,137 @@ class WidgetControllerLibraryPostDispatchTest extends WidgetControllerWidgetConf $this->assertEquals(['town' => [1]], $widget->getdefault_filters()); } } + + + + +class WidgetControllerHorizontalMenuChangeLinkTextTest extends Admin_AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $cfg_menus = ['H' => + [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '', + 'libelle' => 'Menu horizontal', + 'picto' => 'vide.gif', + 'action' => '', + 'clef_profil' => '0', + 'children' => '29;', + 'preferences' => [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '', + 'libelle' => 'Menu horizontal', + 'picto' => 'vide.gif', + 'action' => '', + 'clef_profil' => '0', + 'children' => '29;' ], + 'menus' => [ + 0 => + [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '0', + 'libelle' => 'AIDE', + 'picto' => 'vide.gif', + 'action' => '', + 'clef_profil' => '', + 'children' => '1;', + 'preferences' => [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '0', + 'libelle' => 'AIDE', + 'picto' => 'vide.gif', + 'action' => '', + 'clef_profil' => '', + 'children' => '1;' ], + 'sous_menus' => [ + 0 => [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '0', + 'libelle' => 'Menu', + 'picto' => '', + 'action' => '', + 'clef_profil' => '0', + 'children' => 'PROFIL;', + 'preferences' => [ + 'type_module' => 'MENU', + 'type_menu' => 'MENU', + 'id_module' => '2', + 'libelle' => 'Menu', + 'picto' => '', + 'action' => '', + 'clef_profil' => '0', + 'children' => 'PROFIL;', + ], + 'sous_menus' => [ + 1 => [ + 'type_module' => 'PROFIL', + 'type_menu' => 'PROFIL', + 'id_module' => '1', + 'libelle' => 'Lien vers un profil ou une page', + 'picto' => '', + 'action' => '', + 'clef_profil' => '1', + ], + ], + ], + ], + ], + ] + ] + ]; + + $this->fixture('Class_Profil', + ['id' => 34, + 'libelle' => 'Numérique', + 'parent_id' => null, + 'cfg_menus' => $cfg_menus]) + ->beCurrentProfil(); + } + + + /** @test */ + public function renameMenuLinkToProfilLabelToPlayMoviesShouldUpdateCfgMenus() { + $this->postDispatch('/admin/widget/edit-menu/id/2/id_profil/34/parent/H', + ['libelle' => 'play movies', + 'clef_profil' => 1, + 'picto' => '']); + + $menus = Class_Profil::find(34)->getCfgMenusAsArray()['H']; + $this->assertEquals('play movies', + $menus['menus'][0]['sous_menus'][1]['sous_menus'][2]['libelle']); + } + + + /** @test */ + public function removeHorizontalMenuChildenShouldDeleteSubmenus() { + $this->postDispatch('/admin/widget/edit-menu/id/H/id_profil/34', + ['libelle' => 'Menu horizontal', + 'children' => '', + 'picto' => '']); + + $menus = Class_Profil::find(34)->getCfgMenusAsArray()['H']; + $this->assertEmpty($menus['menus']); + } + + + + /** @test */ + public function addEntryUnderMenuAidesShouldNotRemoveItsSubmenus() { + $this->postDispatch('/admin/widget/edit-menu/id/0/id_profil/34/parent/H', + ['libelle' => 'Menu', + 'children' => '1;ACCUEIL', + 'picto' => '']); + + $menus = Class_Profil::find(34)->getCfgMenusAsArray()['H']; + $this->assertCount(2, $menus['menus'][0]['sous_menus']); + } +} -- GitLab