Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed May 11, 2024
1 parent 3c409f1 commit baecd8f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion classes/smartmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions tests/behat/behat_theme_boost_union_base_smartmenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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<itemname>(?:[^"]|\\")*)" "(?P<url>(?:[^"]|\\")*)"$/
* @Given /^I add a smart menu static item item "(?P<itemname>(?:[^"]|\\")*)" "(?P<url>(?:[^"]|\\")*)"$/
* @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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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 "<menumode>"
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 "<role>"
And I set the field "Menu item mode" to "<menumode>"
And I press "Save changes"
Then I log out
And I log out
And I log in as "<user>"
Then I <course1> see smart menu "<menutitle>" in location "Main, Menu, User, Bottom"
Then I <shouldornot> see smart menu "<menutitle>" 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 |
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <menumode> |
And I should see "Links" in the "smartmenus" "table"
Expand All @@ -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 "<menutitle>" in location "Main, Menu, User, Bottom"
Then I should see smart menu "<menutitle>" in location "Main, Menu, User, Bottom"

Examples:
| menumode | menutitle |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -73,14 +73,14 @@ 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"
And I click on "Create menu" "button"
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"
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <span lang="en" class="multilang">Lorem ipsum</span><span lang="de" class="multilang">Dolor sit amet</span> |
| 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)‎"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit baecd8f

Please sign in to comment.