From e244d50c69047ef713a1a6e1e7d6505e1d0bd6a7 Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Sat, 20 Apr 2024 20:20:40 +0530 Subject: [PATCH] Improve: Make sure smart menu "locations" is filled with value, resolves #404 --- classes/form/smartmenu_edit_form.php | 6 ++++++ ...smartmenusettings_menus_management.feature | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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 5c95c6a61ce..a93f52c660f 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menus_management.feature @@ -59,6 +59,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" @@ -112,17 +113,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" @@ -130,3 +134,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 location field required + 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" + And I should see "Required" in the "#fitem_id_location" "css_element" + Then I set the field "Menu location(s)" to "Main" + And I click on "Save and return" "button" + And 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"