diff --git a/classes/smartmenu.php b/classes/smartmenu.php index 69b68b4b7d7..9fc0ce9d893 100644 --- a/classes/smartmenu.php +++ b/classes/smartmenu.php @@ -687,6 +687,13 @@ public function build($resetcache=false) { $nodescache->menuitems = $menuitems; $this->cache->set($cachekey, $nodescache); } + + // 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. + 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 6ed50db0641..fc69d143732 100644 --- a/tests/behat/behat_theme_boost_union_base_smartmenus.php +++ b/tests/behat/behat_theme_boost_union_base_smartmenus.php @@ -72,6 +72,55 @@ public function i_create_smartmenu_with_the_following_fields_to_these_values(Tab $this->execute('behat_general::i_click_on', ['Save and return', 'button']); } + /** + * Populate a smart menu and its item using the provided form field/value data. + * + * @Given /^I create smart menu and 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) { + $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']); + $this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$data]); + $this->execute('behat_general::i_click_on', ['Save and configure items', 'button']); + + // Default item for the menu. + $items = new TableNode([ + ['Title', 'Info'], + ['Menu item type', 'Heading'], + ]); + + $this->execute('behat_general::i_click_on', ['Add menu item', 'button']); + $this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$items]); + $this->execute('behat_general::i_click_on', ['Save changes', 'button']); + $this->execute('behat_general::i_click_on_in_the', ['Smart menus', 'link', '.breadcrumb', "css_element"]); + } + + /** + * Creates a static menu for the currently opened menu. + * + * @Given /^I configure smart menu static 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) { + + $items = new TableNode([ + ['Title', $item], + ['Menu item type', 'Static'], + ['URL', $url], + ]); + + $this->execute('behat_general::i_click_on', ['Save and configure items', 'button']); + $this->execute('behat_general::i_click_on', ['Add menu item', 'button']); + $this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$items]); + $this->execute('behat_general::i_click_on', ['Save changes', 'button']); + $this->execute('behat_general::i_click_on_in_the', ['Smart menus', 'link', '.breadcrumb', "css_element"]); + } + /** * Fills a smart menu item form with field/value data. * diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature index 8403de96d02..8e1a6f14836 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature @@ -128,6 +128,10 @@ 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. + And I set "List menu" smart menu items with the following fields to these values: + | Title | Info | + | Menu item type | Heading | And I navigate to smart menu "List menu" items And I click on ".action-edit" "css_element" in the "Dynamic courses" "table_row" And I set the field "Dynamic courses: Enrolment role" to "" @@ -298,3 +302,29 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | 6 | CCC Course | BBB Course | AAA Course | # Option: Course ID number descending | 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" + And I navigate to smart menus + Then 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 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 in as "" + 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 | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature index 746c56fe8f3..29ac2551b77 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_management.feature @@ -138,6 +138,11 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man 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" 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 9bec724035e..932bb172a04 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_presentation.feature @@ -349,3 +349,23 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And ".dropdown-divider" "css_element" should exist in the ".bottom-navigation" "css_element" # Divider in menubar. 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" + And I create smart menu with the following fields to these values: + | Title | Links | + | Menu location(s) | Main, Menu, User, Bottom | + | Menu mode | | + And I should see "Links" in the "smartmenus" "table" + And I should not see smart menu "" in location "Main, Menu, User, Bottom" + And I set "Links" smart menu items with the following fields to these values: + | Title | Smartmenu Resource | + | Menu item type | Static | + | URL | http://moodle.org | + And I should see smart menu "" in location "Main, Menu, User, Bottom" + + Examples: + | menumode | menutitle | + | Submenu | Links | + | Inline | Smartmenu Resource | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature index 7dab82b6642..7b94079699b 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature @@ -36,6 +36,9 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app | Title | Resources | | Menu item type | Static | | URL | https://moodle.org | + And I set "Quick links" smart menu items with the following fields to these values: + | Title | Info | + | Menu item type | Heading | And the following "language packs" exist: | language | | de | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_application.feature index 1c9358dc197..ad2a004b6a0 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 click on "Save and return" "button" + And I configure smart menu static 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,12 +49,9 @@ 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 navigate to smart menus - And I click on "Create menu" "button" - And I set the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Links | | Menu location(s) | Main | - And I click on "Save and return" "button" Then I should see "Main" in the "Links" "table_row" And I should see smart menu "Links" in location "Main" And I click on "Create menu" "button" @@ -76,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 click on "Save and return" "button" + And I configure smart menu static 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" @@ -84,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 click on "Save and return" "button" + And I configure smart menu static 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 5c95c6a61ce..2d6c639dd51 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature @@ -31,6 +31,9 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man | Links | Main | And I should see "Links" in the "smartmenus" "table" And ".smartmenu-actions" "css_element" should exist in the "smartmenus" "table" + And I set "Links" smart menu items with the following fields to these values: + | Title | Info | + | Menu item type | Heading | And I should see smart menu "Links" in location "Main" @javascript @@ -74,12 +77,9 @@ 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 navigate to smart menus - And I click on "Create menu" "button" - And I set the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Links | | Menu location(s) | Main | - And I click on "Save and return" "button" And I should see "Links" in the "smartmenus" "table" And ".action-copy" "css_element" should exist in the "Links" "table_row" And I click on ".action-copy" "css_element" in the "Links" "table_row" @@ -94,12 +94,9 @@ 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 navigate to smart menus - And I click on "Create menu" "button" - And I set the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Links | | Menu location(s) | Main, Menu, User, Bottom | - And I click on "Save and return" "button" And I should see "Links" in the "smartmenus" "table" And ".action-hide" "css_element" should exist in the "Links" "table_row" And ".action-show" "css_element" should not exist in the "Links" "table_row" diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_presentation.feature index 19bcf9cb0ff..46ccf401ef3 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 click on "Save and return" "button" + And I configure smart menu static 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 with the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Test quick demo links 01 | | Menu location(s) | Main, Menu | - And I create smart menu with the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Test quick demo links 02 | | Menu location(s) | Main, Menu | - And I create smart menu with the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Test quick demo links 03 | | Menu location(s) | Main, Menu | - And I create smart menu with the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Test quick demo links 04 | | Menu location(s) | Main, Menu | - And I create smart menu with the following fields to these values: + And I create smart menu and item with the following fields to these values: | Title | Test quick demo links 05 | | Menu location(s) | Main, Menu | - And I create smart menu with the following fields to these values: + And I create smart menu and 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 with the following fields to these values: + And I create smart menu and 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 with the following fields to these values: + And I create smart menu and 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" diff --git a/version.php b/version.php index 6733e27bbeb..1eee1787b57 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_union'; -$plugin->version = 2023102033; +$plugin->version = 2023102034; $plugin->release = 'v4.3-r11'; $plugin->requires = 2023100900; $plugin->supported = [403, 403];