diff --git a/VERSIONS_HOTLINE/140058 b/VERSIONS_HOTLINE/140058 new file mode 100644 index 0000000000000000000000000000000000000000..147783370b7b371a6d0afe3d2b3a69c909c17fa0 --- /dev/null +++ b/VERSIONS_HOTLINE/140058 @@ -0,0 +1 @@ + - ticket #140058 : Magasin de thèmes : Correction du fonctionnement des menus avec des sous menu. \ No newline at end of file diff --git a/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.html b/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.html new file mode 100644 index 0000000000000000000000000000000000000000..d975845567028833f5e04e653e3128abeddc05f8 --- /dev/null +++ b/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<!-- +/** + * Copyright (c) 2012-2021, 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 + */ + --> + +<html> +<head> + <meta charset="utf-8"> + <title>QUnit tests</title> + <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css"> + <link rel="stylesheet" href="../../css/bootstrap.min.css"> + <link rel="stylesheet" href="../../../../css/intonation.css"> + <link rel="stylesheet" href="../../../../../../../../public/opac/css/core.css"> + <script type="text/javascript" src="../../../../../../../../public/admin/js/jquery-3.2.1.min.js"></script> + <script type="text/javascript" src="../../../../../../../../public/admin/js/jquery-ui-1.12.1/jquery-ui.min.js"></script> + <script type="text/javascript" src="../../../popper.min.js"></script> + <script type="text/javascript" src="../bootstrap.min.js"></script> + <script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script> + <script src="dropdown_tests.js"></script> +</head> +<body> + <div id="qunit"></div> + <div id="qunit-fixture"></div> + <div> + <div class="boite"> + <ul class="nav navbar-nav list-unstyled"> + <li class="nav-item"> + <a href="/" class="nav-link active_item active">Home</a> + </li> + <li class="nav-item dropdown"> + <a href="#" id="6126059b06918" onclick="return false;" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Information</a> + <ul class="dropdown-menu list-unstyled" aria-labelledby="6126059b06918"> + <li class="nav-item"> + <a href="" class="nav-link">News</a> + </li> + <li class="nav-item dropdown"> + <a href="#" id="6126059b11326" onclick="return false;" class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Libraries</a> + <ul class="dropdown-menu list-unstyled" aria-labelledby="6126059b11326"> + <li class="nav-item"> + <a href="" class="nav-link">Valleiry</a> + </li> + </ul> + </li> + </ul> + </li> + </ul> + </div> + </div> + <script src="../bootstrap_dropdown.js"></script> +</body> +</html> diff --git a/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.js b/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.js new file mode 100644 index 0000000000000000000000000000000000000000..1d4a9c73adaa42e8f107fdeb6f6b0b25181176c7 --- /dev/null +++ b/library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.js @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2012-2021, 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 + */ + + +QUnit.module('dropdown_with_submenu'); + + +test('Click on Information should display News', function() { + $('#6126059b06918').trigger('click'); + deepEqual($('[aria-labelledby="6126059b06918"].show').length, 1, $('body')); +}); + + +test('Click on Libraries should display Valleiry', function() { + $('#6126059b06918').trigger('click'); + $('#6126059b11326').trigger('click'); + deepEqual($('.has-child-dropdown-show [aria-labelledby="6126059b11326"].show').length, 1, $('body')); +}); diff --git a/library/templates/Intonation/Library/View/Wrapper/MenuEntry.php b/library/templates/Intonation/Library/View/Wrapper/MenuEntry.php index 7f887ab0db78fd68fa656202ff947bcf9a990b0d..63e1398a5fb7c0465dbef4da42b8475aa2c028ff 100644 --- a/library/templates/Intonation/Library/View/Wrapper/MenuEntry.php +++ b/library/templates/Intonation/Library/View/Wrapper/MenuEntry.php @@ -26,6 +26,12 @@ class Intonation_Library_View_Wrapper_MenuEntry extends Intonation_Library_View_ return $this->_model->getLabel(); } + + public function isMenu() { + return $this->_model->isMenu(); + } + + public function getMainLink() { return ''; } diff --git a/library/templates/Intonation/View/Menu/Abstract.php b/library/templates/Intonation/View/Menu/Abstract.php index 6b38f3bca2f31e1516f98de3da222b3d1f9ba5cb..bb220276830755265987ac52cc572e0b669a3f52 100644 --- a/library/templates/Intonation/View/Menu/Abstract.php +++ b/library/templates/Intonation/View/Menu/Abstract.php @@ -38,7 +38,9 @@ abstract class Intonation_View_Menu_Abstract extends ZendAfi_View_Helper_BaseHel $html = ''; foreach ( $collection as $menu) - $html .= $this->_tag('li', $callback($menu), ['class' => 'nav-item']); + $html .= $this->_tag('li', $callback($menu), ['class' => 'nav-item'. (($menu->isMenu()) + ? ' dropdown' + : '')]); return $this->_renderMenu($this->_navbarHeader() . $this->_navbarEntries($html), ['class' => implode(' ', diff --git a/library/templates/Intonation/View/RenderMenuEntry.php b/library/templates/Intonation/View/RenderMenuEntry.php index a70ab34d66679013a1d3ccada529b5d5b2869e60..778e6c1d1aa608c5e71752b5f7841d11db31a8e8 100644 --- a/library/templates/Intonation/View/RenderMenuEntry.php +++ b/library/templates/Intonation/View/RenderMenuEntry.php @@ -37,10 +37,6 @@ class Intonation_View_RenderMenuEntry extends ZendAfi_View_Helper_BaseHelper { $entry .= $this->_renderChildren($menu_entry, $id, $use_menu_layout); - if ($menu_entry->getChildren()) - $entry = $this->_div(['class' => 'dropdown'], - $entry); - return $use_menu_layout ? $entry : $this->_div(['class' => 'menu_entry'], @@ -80,7 +76,9 @@ class Intonation_View_RenderMenuEntry extends ZendAfi_View_Helper_BaseHelper { $html[] = $this->_tag('li', $this->_renderMenuEntry($menu_entry_child, $use_menu_layout), - ['class' => 'nav-item']); + ['class' => 'nav-item' . (($menu_entry_child->isMenu()) + ? ' dropdown' + : '')]); } return $this->_tag('ul', diff --git a/tests/js/BootstrapDropdownTest.php b/tests/js/BootstrapDropdownTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c6dcbc175911c541a5cfa9dde95bff94be36f82e --- /dev/null +++ b/tests/js/BootstrapDropdownTest.php @@ -0,0 +1,25 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 BootstrapDropdownTest extends PhantomJsTest { + protected $_test_path = ['library/templates/Intonation/Assets/Bootstrap/bootstrap-4.3.1-dist/js/tests/dropdown_tests.html']; +} diff --git a/tests/scenarios/Templates/TemplatesMenuTest.php b/tests/scenarios/Templates/TemplatesMenuTest.php index b2e4e0e3c4a52cb7e0ba76acb4a771caf9273d07..140243d823372b1756e0e1a0dd5025abacd0b34b 100644 --- a/tests/scenarios/Templates/TemplatesMenuTest.php +++ b/tests/scenarios/Templates/TemplatesMenuTest.php @@ -135,7 +135,13 @@ class TemplatesMenuDispatchIndexTest extends TemplatesIntonationTestCase { /** @test */ public function navDropdownAnchorShouldHaveOnclichReturnFalse() { - $this->assertXPath('//li[@class="nav-item"]//div[@class="dropdown"]/a[@onclick="return false;"]'); + $this->assertXPath('//li[@class="nav-item dropdown"]/a[@onclick="return false;"]'); + } + + + /** @test */ + public function allNavItemShouldNotHaveDropdownClass() { + $this->assertXPath('//li[@class="nav-item"]'); } } @@ -493,4 +499,34 @@ class TemplatesMenuNavWithLayoutTest extends TemplatesMenuTestCase { public function homeShouldBeRenderInANavTag() { $this->assertXPathContentContains('//footer//nav', 'Home'); } +} + + + + +class TemplatesMenuWithSubmenuTest extends TemplatesMenuTestCase { + + public function setUp() { + parent::setUp(); + $profile_patcher = (new Class_Template_ProfilePatcher(Class_Template::current())) + ->setProfile(Class_Profil::find(7)) + ->addWidget(Intonation_Library_Widget_Nav_Definition::CODE, + Class_Profil::DIV_FOOTER, + ['layout' => 'vertical', + 'menu' => '7-' . $this->_menu_id]); + + $this->dispatch('/index'); + } + + + /** @test */ + public function liShouldHaveClassNavItemDropdown() { + $this->assertXPath('//li[@class="nav-item dropdown"]/a[@onclick="return false;"]'); + } + + + /** @test */ + public function allNavItemShouldNotHaveDropdownClass() { + $this->assertXPath('//li[@class="nav-item dropdown"]//li[@class="nav-item"]/a'); + } } \ No newline at end of file