From 120574bdf461098e4e8600d6c70885221529bbfb Mon Sep 17 00:00:00 2001 From: prasanna-lmsace <57126778+prasanna-lmsace@users.noreply.github.com> Date: Sat, 11 May 2024 21:46:38 +0530 Subject: [PATCH] Improvement: Make sure smart menu "locations" is filled with value, resolves #404 (#636) --- CHANGES.md | 1 + classes/form/smartmenu_edit_form.php | 6 ++++++ ...smartmenusettings_menus_management.feature | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6afb8fa1167..48e51421096 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2024-05-11 - Improvement: Smart menu "locations" must be filled with a value, resolves #404 * 2024-05-10 - Bugfix: Do not show empty smart menus to users, resolves #405 * 2024-05-09 - Bugfix: Smart menu menubar overlaid course index, resolves #607 * 2024-04-27 - Improvement: Add navigation to policy overview page, resolves #633 diff --git a/classes/form/smartmenu_edit_form.php b/classes/form/smartmenu_edit_form.php index 58cc884a133..becdd8de8c2 100644 --- a/classes/form/smartmenu_edit_form.php +++ b/classes/form/smartmenu_edit_form.php @@ -77,6 +77,7 @@ public function definition() { $locationtypes); $mform->addHelpButton('location', 'smartmenusmenulocation', 'theme_boost_union'); $location->setMultiple(true); + $mform->addRule('location', get_string('required'), 'required'); // Add mode as select element. $modeoptions = [ @@ -320,6 +321,11 @@ public function validation($data, $files) { } } + // Validate the smart menu location is filled. + if (empty($data['location'])) { + $errors['location'] = get_string('required'); + } + // Return errors. return $errors; } diff --git a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature index aa5ab40e4da..f9f212e602c 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature @@ -62,6 +62,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man And I click on "Create menu" "button" 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 should see "Links" in the "smartmenus" "table" And ".action-delete" "css_element" should exist in the "smartmenus" "table" @@ -109,17 +110,20 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man And I click on ".action-show" "css_element" in the "Links" "table_row" Then I should see smart menu "Links" in location "Main, Menu, User, Bottom" + @javascript Scenario: Smartmenus: Menus: Management - Move an existing smart menu up and down 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: | Title | Enrolled courses | + | Menu location(s) | Main | And I click on "Save and return" "button" And I should see "Enrolled courses" in the "smartmenus" "table" And I click on "Create menu" "button" And I set the following fields to these values: | Title | Completed courses | + | Menu location(s) | Main | And I click on "Save and return" "button" And I should see "Completed courses" in the "smartmenus" "table" And "Enrolled courses" "table_row" should appear before "Completed courses" "table_row" @@ -127,3 +131,20 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, man Then "Enrolled courses" "table_row" should appear after "Completed courses" "table_row" And I click on ".sort-smartmenus-up-action" "css_element" in the "Enrolled courses" "table_row" And "Enrolled courses" "table_row" should appear before "Completed courses" "table_row" + + @javascript + Scenario: Smartmenus: Menus: Management - Make sure that location field is filled + 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: + | Title | Links | + And I click on "Save and return" "button" + Then I should see "Required" in the "#fitem_id_location" "css_element" + And I set the field "Menu location(s)" to "Main" + And I click on "Save and return" "button" + Then I should see "Links" in the "smartmenus" "table" + And I set "Links" smart menu items with the following fields to these values: + | Title | Info | + | Menu item type | Heading | + Then I should see smart menu "Links" in location "Main"