diff --git a/CHANGES.md b/CHANGES.md index b90671326cb..5d2f286e762 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2024-05-10 - Bugfix: Do not show empty smart menus to users, resolves #405 * 2024-04-27 - Improvement: Add navigation to policy overview page, resolves #633 ### v4.3-r12 diff --git a/classes/smartmenu.php b/classes/smartmenu.php index 9fc0ce9d893..c39478a96a0 100644 --- a/classes/smartmenu.php +++ b/classes/smartmenu.php @@ -690,10 +690,11 @@ public function build($resetcache=false) { // If the current menu doesn't contain any nodes, hide the menu from users. // Verify after storing the cache to prevent rebuilding the menu items. - // This helps to verify the cached menus too. + // This helps to verify the cached menus, too. if (!isset($builditems) || empty($builditems)) { return false; } + // Remove the menu items list from nodes. it doesn't need to build the smartmenus. if (isset($nodes->menuitems)) { // Remove the menu items list from nodes, it doesn't need anymore. diff --git a/tests/behat/behat_theme_boost_union_base_smartmenus.php b/tests/behat/behat_theme_boost_union_base_smartmenus.php index fc69d143732..7172fdba768 100644 --- a/tests/behat/behat_theme_boost_union_base_smartmenus.php +++ b/tests/behat/behat_theme_boost_union_base_smartmenus.php @@ -73,13 +73,14 @@ public function i_create_smartmenu_with_the_following_fields_to_these_values(Tab } /** - * Populate a smart menu and its item using the provided form field/value data. + * Populate a smart menu using the provided form field/value data and add a default item to the menu + * (to make sure that it is not hidden as empty menu). * - * @Given /^I create smart menu and item with the following fields to these values:$/ + * @Given /^I create smart menu with a default item with the following fields to these values:$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param TableNode $data */ - public function i_create_smartmenu_and_item_with_the_following_fields_to_these_values(TableNode $data) { + public function i_create_smartmenu_with_default_item_with_the_following_fields_to_these_values(TableNode $data) { $this->execute('behat_navigation::i_navigate_to_in_site_administration', ['Appearance > Boost Union > Smart menus']); $this->execute('behat_general::i_click_on', ['Create menu', 'button']); @@ -99,14 +100,14 @@ public function i_create_smartmenu_and_item_with_the_following_fields_to_these_v } /** - * Creates a static menu for the currently opened menu. + * Adds a static menu item to the currently opened menu. * - * @Given /^I configure smart menu static item "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)"$/ + * @Given /^I add a smart menu static item item "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)"$/ * @throws ElementNotFoundException Thrown by behat_base::find * @param string $item Item title. * @param string $url URL of the static item. */ - public function i_configure_menu_static_item($item, $url) { + public function i_add_menu_static_item($item, $url) { $items = new TableNode([ ['Title', $item], diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature index 8e1a6f14836..be3253953b7 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature @@ -128,7 +128,8 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a enrolment role condition When I log in as "admin" - # Empty menus are hidden from view. To prevent menu display issues, a sample item is created. + # Empty menus are hidden from view. To prevent that the whole menu is missing and the test fails, + # a sample item is created. And I set "List menu" smart menu items with the following fields to these values: | Title | Info | | Menu item type | Heading | @@ -304,27 +305,27 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | 7 | AAA Course | BBB Course | CCC Course | @javascript - Scenario Outline: Smartmenus: Menu items: Dynamic courses - Hide the empty menus - Given I log in as "admin" + Scenario Outline: Smartmenus: Menu items: Dynamic courses - Hide empty menus + When I log in as "admin" And I navigate to smart menus - Then I click on ".action-edit" "css_element" in the "List menu" "table_row" + And I click on ".action-edit" "css_element" in the "List menu" "table_row" And I set the field "Menu mode" to "" And I click on "Save and configure items" "button" - Then I click on ".action-edit" "css_element" in the "Dynamic courses" "table_row" + And I click on ".action-edit" "css_element" in the "Dynamic courses" "table_row" And I set the field "Dynamic courses: Enrolment role" to "" And I set the field "Menu item mode" to "" And I press "Save changes" - Then I log out + And I log out And I log in as "" - Then I see smart menu "" in location "Main, Menu, User, Bottom" + Then I see smart menu "" in location "Main, Menu, User, Bottom" Examples: - | role | user | course1 | menutitle | menumode | - | Non-editing teacher, Teacher | student1 | should not | List menu | Submenu | - | Non-editing teacher, Teacher | teacher | should | List menu | Submenu | - | Student | student1 | should | List menu | Submenu | - | Student | teacher | should not | List menu | Submenu | - | Non-editing teacher, Teacher | student1 | should not | Course 01 | Inline | - | Non-editing teacher, Teacher | teacher | should | Course 01 | Inline | - | Student | student1 | should | Course 01 | Inline | - | Student | teacher | should not | Course 01 | Inline | + | role | user | shouldornot | menutitle | menumode | + | Non-editing teacher, Teacher | student1 | should not | List menu | Submenu | + | Non-editing teacher, Teacher | teacher | should | List menu | Submenu | + | Student | student1 | should | List menu | Submenu | + | Student | teacher | should not | List menu | Submenu | + | Non-editing teacher, Teacher | student1 | should not | Course 01 | Inline | + | Non-editing teacher, Teacher | teacher | should | Course 01 | Inline | + | Student | student1 | should | Course 01 | Inline | + | Student | teacher | should not | Course 01 | Inline | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature index 29ac2551b77..466c2d5fb20 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature @@ -137,12 +137,12 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man | Info | And ".action-hide" "css_element" should exist in the "Info" "table_row" And ".action-show" "css_element" should not exist in the "Info" "table_row" - Then I should see smart menu "Quick links" item "Info" in location "Main, Menu, User, Bottom" And I click on "Add menu item" "button" And I set the following fields to these values: | Title | Demo item | | Menu item type | Heading | And I click on "Save changes" "button" + Then I should see smart menu "Quick links" item "Info" in location "Main, Menu, User, Bottom" And I click on ".action-hide" "css_element" in the "Info" "table_row" Then I should not see smart menu "Quick links" item "Info" in location "Main, Menu, User, Bottom" And ".action-hide" "css_element" should not exist in the "Info" "table_row" diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature index 932bb172a04..7f801658ff9 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature @@ -351,10 +351,10 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And ".dropdown-divider" "css_element" should exist in the "nav.menubar" "css_element" @javascript - Scenario Outline: Smartmenus: Menu items: Hide the empty menus - Given I log in as "admin" + Scenario Outline: Smartmenus: Menu items: Hide empty menus + When I log in as "admin" And I create smart menu with the following fields to these values: - | Title | Links | + | Title | Links | | Menu location(s) | Main, Menu, User, Bottom | | Menu mode | | And I should see "Links" in the "smartmenus" "table" @@ -363,7 +363,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app | Title | Smartmenu Resource | | Menu item type | Static | | URL | http://moodle.org | - And I should see smart menu "" in location "Main, Menu, User, Bottom" + Then I should see smart menu "" in location "Main, Menu, User, Bottom" Examples: | menumode | menutitle | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature index 7b94079699b..ee2c62576c7 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature @@ -36,6 +36,8 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app | Title | Resources | | Menu item type | Static | | URL | https://moodle.org | + # Empty menus are hidden from view. To prevent that the whole menu is missing and the test fails, + # a sample item is created. And I set "Quick links" smart menu items with the following fields to these values: | Title | Info | | Menu item type | Heading | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature index ad2a004b6a0..41a7159290c 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature @@ -17,7 +17,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And I set the following fields to these values: | Title | Links | | Menu location(s) | Main | - And I configure smart menu static item "Info" "https://moodle.org" + And I add a smart menu static item item "Info" "https://moodle.org" Then I should see smart menu "Links" in location "Main" And I log out And I log in as "user1" @@ -49,7 +49,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app @javascript Scenario: Smartmenu: Menus: Application - Show a smart menu in different locations When I log in as "admin" - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Links | | Menu location(s) | Main | Then I should see "Main" in the "Links" "table_row" @@ -73,7 +73,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And I set the following fields to these values: | Title | Certificates | | Menu location(s) | User | - And I configure smart menu static item "Course completions" "https://moodle.org" + And I add a smart menu static item item "Course completions" "https://moodle.org" Then I should see "User" in the "Certificates" "table_row" And I should not see "Main" in the "Certificates" "table_row" And I should see smart menu "Certificates" in location "User" @@ -81,6 +81,6 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And I set the following fields to these values: | Title | SmartMenu Policy | | Menu location(s) | Bottom | - And I configure smart menu static item "Privacy" "https://moodle.org/privacy" + And I add a smart menu static item item "Privacy" "https://moodle.org/privacy" Then I should see "Bottom" in the "SmartMenu Policy" "table_row" And I should see smart menu "SmartMenu Policy" in location "Bottom" diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature index 2d6c639dd51..13a4e5c473c 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature @@ -77,7 +77,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man @javascript Scenario: Smartmenus: Menus: Management - Duplicate an existing smart menu When I log in as "admin" - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Links | | Menu location(s) | Main | And I should see "Links" in the "smartmenus" "table" @@ -94,7 +94,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man @javascript Scenario: Smartmenus: Menus: Management - Modify the visibility of an existing smart menu When I log in as "admin" - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Links | | Menu location(s) | Main, Menu, User, Bottom | And I should see "Links" in the "smartmenus" "table" diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature index 46ccf401ef3..c6684101338 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature @@ -188,7 +188,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And I set the following fields to these values: | Title | Lorem ipsumDolor sit amet | | Menu location(s) | Main, Menu, User, Bottom | - And I configure smart menu static item "Multilang" "https://moodle.org" + And I add a smart menu static item item "Multilang" "https://moodle.org" And I follow "Preferences" in the user menu And I click on "Preferred language" "link" And I set the field "Preferred language" to "English ‎(en)‎" @@ -221,28 +221,28 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app Then I should see smart menu "Quick links" in location "Main" And I click on "More" "link" in the ".boost-union-menubar" "css_element" Then I should see smart menu "Quick links" in location "Menu" - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 01 | | Menu location(s) | Main, Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 02 | | Menu location(s) | Main, Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 03 | | Menu location(s) | Main, Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 04 | | Menu location(s) | Main, Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 05 | | Menu location(s) | Main, Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links long title 01 | | Menu location(s) | Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links long title 02 | | Menu location(s) | Menu | - And I create smart menu and item with the following fields to these values: + And I create smart menu with a default item with the following fields to these values: | Title | Test quick demo links 06 | | Menu location(s) | Main, Menu | Then I change the viewport size to "1600x495"