From fe3aa58be7c86c5b7ca978f41b1f5b034d55c9a8 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Fri, 22 Nov 2024 09:28:58 +0000 Subject: [PATCH] Optimise Smart menu behat features for dynamic courses and rules (#765). This performs several optimisations to make these tests a lot faster. Creation of smart menus and menu item has been changed to use generators, rather than filling the forms each time. Manual navigation has been replaced with `I am on the 'identifier' 'type' page` as much as possible. The assertions being made have been optimised. Previously, every assertion of what was in a menu was opening each menu location and checking for each item. Given that there's no option to display different items when a menu is in different location, a lot of this is redunant, and actually opening each menu takes time. I have optimised this so that one scenario does a check that the menu opens and the items are actually visible. Then each scenario tests than an expected item exists in each menu (without opening the menu) and checks for subsequent items just check existance in a single menu. This balances coverage of the different functionality with speed and conciseness of tests. --- classes/form/smartmenu_edit_form.php | 8 +- classes/form/smartmenu_item_edit_form.php | 8 +- ...usettings_menuitems_dynamiccourses.feature | 371 ++++++++------- ..._smartmenusettings_menuitems_rules.feature | 431 ++++++++---------- .../behat_theme_boost_union_generator.php | 13 + tests/generator/lib.php | 98 +--- 6 files changed, 412 insertions(+), 517 deletions(-) diff --git a/classes/form/smartmenu_edit_form.php b/classes/form/smartmenu_edit_form.php index fe4731a6946..d5432427a97 100644 --- a/classes/form/smartmenu_edit_form.php +++ b/classes/form/smartmenu_edit_form.php @@ -182,12 +182,8 @@ public function definition() { } // Add restriction as select element. - $rolecontext = [ - smartmenu::BYADMIN_ALL => get_string('smartmenusbyadmin_all', 'theme_boost_union'), - smartmenu::BYADMIN_ADMINS => get_string('smartmenusbyadmin_admins', 'theme_boost_union'), - smartmenu::BYADMIN_NONADMINS => get_string('smartmenusbyadmin_nonadmins', 'theme_boost_union'), - ]; - $mform->addElement('select', 'byadmin', get_string('smartmenusbyadmin', 'theme_boost_union'), $rolecontext); + $byadminoptions = smartmenu::get_byadmin_options(); + $mform->addElement('select', 'byadmin', get_string('smartmenusbyadmin', 'theme_boost_union'), $byadminoptions); $mform->setDefault('byadmin', smartmenu::BYADMIN_ALL); $mform->setType('byadmin', PARAM_INT); $mform->addHelpButton('byadmin', 'smartmenusbyadmin', 'theme_boost_union'); diff --git a/classes/form/smartmenu_item_edit_form.php b/classes/form/smartmenu_item_edit_form.php index 8b8695a32ed..c8bd55082c9 100644 --- a/classes/form/smartmenu_item_edit_form.php +++ b/classes/form/smartmenu_item_edit_form.php @@ -329,12 +329,8 @@ public function definition() { } // Add restriction as select element. - $rolecontext = [ - smartmenu::BYADMIN_ALL => get_string('smartmenusbyadmin_all', 'theme_boost_union'), - smartmenu::BYADMIN_ADMINS => get_string('smartmenusbyadmin_admins', 'theme_boost_union'), - smartmenu::BYADMIN_NONADMINS => get_string('smartmenusbyadmin_nonadmins', 'theme_boost_union'), - ]; - $mform->addElement('select', 'byadmin', get_string('smartmenusbyadmin', 'theme_boost_union'), $rolecontext); + $byadminoptions = smartmenu::get_byadmin_options(); + $mform->addElement('select', 'byadmin', get_string('smartmenusbyadmin', 'theme_boost_union'), $byadminoptions); $mform->setDefault('byadmin', smartmenu::BYADMIN_ALL); $mform->setType('byadmin', PARAM_INT); $mform->addHelpButton('byadmin', 'smartmenusbyadmin', 'theme_boost_union'); diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature index be3253953b7..eae56aa4002 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature @@ -37,23 +37,19 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | student1 | C2 | student | | student1 | C3 | student | | student1 | C4 | student | - And I log in as "admin" - And I create smart menu with the following fields to these values: - | Title | List menu | - | Menu location(s) | Main, Menu, User, Bottom | - | CSS class | dynamiccoursetest | - And I set "List menu" smart menu items with the following fields to these values: - | Title | Dynamic courses | - | Menu item type | Dynamic courses | + And the following "theme_boost_union > smart menu" exists: + | title | List menu | + | location | Main navigation, Menu bar, User menu, Bottom bar | + | cssclass | dynamiccoursetest | @javascript Scenario: Smartmenus: Menu items: Dynamic courses - Check the smart menu item settings fields which are shown conditionally for dynamic courses - When I log in as "admin" - And I navigate to smart menus - And I should see "List menu" in the "smartmenus" "table" - And I click on ".action-list-items" "css_element" in the "List menu" "table_row" - Then I should see "Dynamic courses" - And I click on ".action-edit" "css_element" in the "Dynamic courses" "table_row" + Given the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + And I am logged in as "admin" + When I am on the "List menu > Dynamic courses" "theme_boost_union > smart menu item" page And I should see "Dynamic courses: Course category" And I should see "Dynamic courses: Enrolment role" And I should see "Dynamic courses: Completion status" @@ -61,34 +57,44 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi @javascript Scenario: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on all existing courses (without any condition) - When I log in as "student1" - Then I should see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I should see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I should see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I should see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" - And I should see smart menu "List menu" item "Course 05" in location "Main, Menu, User, Bottom" - And I should see smart menu "List menu" item "Course 06" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + When I am logged in as "student1" + Then "Course 01" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 02" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 03" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 05" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 06" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And I should see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a category condition - When I log in as "admin" - 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: Course category" to "" - And I press "Save changes" - And I log out - And I log in as "" - Then I see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 05" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 06" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | categories | | + When I am logged in as "student1" + Then "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 02" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 03" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 05" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 06" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: - | category | user | course1 | course2 | course3 | course4 | course5 | course6 | - | Category 01 | student1 | should | should | should | should not | should not | should not | - | Category 02 | student1 | should not | should not | should not | should | should | should not | + | category | course1 | course2 | course3 | course4 | course5 | course6 | + | CAT1 | should | should | should | should not | should not | should not | + | CAT2 | should not | should not | should not | should | should | should not | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a category condition (with or without subcategories) @@ -107,18 +113,20 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | student1 | C1a | student | | student1 | C1b | student | | student1 | C1aa | student | - When I log in as "admin" - 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: Course category" to "Category 01" - And I set the field "Include subcategories" to "" - And I press "Save changes" - And I log out - And I log in as "student1" - Then I should see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 01a" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 01b" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 01aa" in location "Main, Menu, User, Bottom" + And the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | categories | CAT1 | + | category_subcats | | + When I log in as "student1" + Then "Course 01" "theme_boost_union > Smart menu item" should exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01a" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01a" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01a" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01a" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 01b" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01aa" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: | subcat | shouldornot | @@ -127,56 +135,50 @@ 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 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 | - 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 "" - And I press "Save changes" - And I log out - And I log in as "" - Then I see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 05" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 06" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu items" exist: + | menu | title | itemtype | enrolmentrole | + | List menu | Info | Heading | | + | List menu | Dynamic courses | Dynamic courses | | + When I log in as "" + Then "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 02" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 03" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 05" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 06" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: - | role | user | course1 | course2 | course3 | course4 | course5 | course6 | - | Non-editing teacher, Teacher | student1 | should not | should not | should not | should not | should not | should not | - | Non-editing teacher, Teacher | teacher | should | should not | should not | should not | should | should | - | Student | student1 | should | should | should | should | should not | should not | - | Student | teacher | should not | should not | should not | should not | should not | should not | + | role | user | course1 | course2 | course3 | course4 | course5 | course6 | + | teacher, editingteacher | student1 | should not | should not | should not | should not | should not | should not | + | teacher, editingteacher | teacher | should | should not | should not | should not | should | should | + | student | student1 | should | should | should | should | should not | should not | + | student | teacher | should not | should not | should not | should not | should not | should not | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a completion status condition - When I log in as "admin" - 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: Completion status" to "" - And I press "Save changes" - And I am on "Course 01" course homepage with editing mode on - And I navigate to "Course completion" in current page administration - And I click on "Condition: Activity completion" "link" + Given the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | completionstatus | | + And I am on the "Course 01" "theme_boost_union > Course completion" page logged in as "admin" + And I expand all fieldsets And I set the following fields to these values: | Assignment - Test assignment name1 | 1 | | Assignment - Test assignment name2 | 1 | And I press "Save changes" - And I am on "Course 02" course homepage with editing mode on - And I navigate to "Course completion" in current page administration - And I click on "Condition: Activity completion" "link" + And I am on the "Course 02" "theme_boost_union > Course completion" page + And I expand all fieldsets And I set the following fields to these values: | Assignment - Test assignment name3 | 1 | | Assignment - Test assignment name4 | 1 | And I press "Save changes" - And I log out - And I log in as "" - And I am on "Course 01" course homepage + And I am on the "Course 01" "course" page logged in as "student1" And the manual completion button of "Test assignment name1" is displayed as "Mark as done" And I toggle the manual completion state of "Test assignment name1" And the manual completion button of "Test assignment name2" is displayed as "Mark as done" @@ -185,82 +187,73 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi And the manual completion button of "Test assignment name3" is displayed as "Mark as done" And I toggle the manual completion state of "Test assignment name3" And I follow "Dashboard" - Then I see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 05" in location "Main, Menu, User, Bottom" + Then "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 02" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 03" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 05" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: - | completionstatus | user | course1 | course2 | course3 | course4 | course5 | - | Enrolled, In progress, Completed | student1 | should | should | should | should | should not | - | In progress, Completed | student1 | should | should | should not | should not | should not | - | Enrolled | student1 | should not | should not | should | should | should not | - | Completed | student1 | should | should not | should not | should not | should not | - | In progress | student1 | should not | should | should not | should not | should not | + | completionstatus | course1 | course2 | course3 | course4 | course5 | + | Enrolled, In progress, Completed | should | should | should | should | should not | + | In progress, Completed | should | should | should not | should not | should not | + | Enrolled | should not | should not | should | should | should not | + | Completed | should | should not | should not | should not | should not | + | In progress | should not | should | should not | should not | should not | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a date range condition - When I log in as "admin" - 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: Date range" to "" - And I press "Save changes" - And I log out - And I log in as "" - Then I see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | daterange | | + When I log in as "student1" + Then "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 01" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 02" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 03" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 05" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: - | daterange | user | course1 | course2 | course3 | course4 | course5 | - | Past, Present, Future | student1 | should | should | should | should | should | - | Future | student1 | should not | should not | should | should not | should not | - | Present | student1 | should | should not | should not | should | should | - | Past | student1 | should not | should | should not | should not | should not | + | daterange | course1 | course2 | course3 | course4 | course5 | + | Past, Present, Future | should | should | should | should | should | + | Future | should not | should not | should | should not | should not | + | Present | should | should not | should not | should | should | + | Past | should not | should | should not | should not | should not | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Compose the dynamic course list based on a course field condition Given the following "custom field categories" exist: | name | component | area | itemid | | Others | core_course | course | 0 | - And I log in as "admin" - And I navigate to "Courses > Course custom fields" in site administration - And I click on "Add a new custom field" "link" - And I click on "Short text" "link" - And I set the following fields to these values: - | Name | Test field | - | Short name | testfield | - And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue" - And I follow "Dashboard" - And I am on "Course 01" course homepage - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Test field | value1 | - And I click on "Save and display" "button" - And I am on "Course 02" course homepage - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Test field | value1 | - And I click on "Save and display" "button" - And I am on "Course 03" course homepage - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Test field | value2 | - And I click on "Save and display" "button" - When I log in as "admin" - 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 should see "Test field" - And I set the field "Test field" to "" - And I press "Save changes" - And I log out - And I log in as "" - Then I see smart menu "List menu" item "Course 01" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 02" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 03" in location "Main, Menu, User, Bottom" - And I see smart menu "List menu" item "Course 04" in location "Main, Menu, User, Bottom" + And the following "custom fields" exist: + | name | category | type | shortname | + | Test field | Others | text | testfield | + And the following "courses" exist: + | fullname | shortname | customfield_testfield | + | Course 07 | C7 | value1 | + | Course 08 | C8 | value1 | + | Course 09 | C9 | value2 | + And the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | customfields | Test field: | + When I log in as "" + Then "Course 07" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 07" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Menu bar smart menu" + And "Course 07" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > User menu smart menu" + And "Course 07" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Bottom bar smart menu" + And "Course 08" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 09" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" + And "Course 04" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu smart menu" Examples: | value | user | course1 | course2 | course3 | course4 | @@ -274,58 +267,52 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | AAA Course | BBB | CAT1 | CCC | | BBB Course | AAA | CAT1 | BBB | | CCC Course | CCC | CAT1 | AAA | - When I log in as "admin" - 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: Course list sorting" to "" - And I press "Save changes" - And I log out + And the following "theme_boost_union > smart menu item" exists: + | menu | List menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | listsort | | When I log in as "student1" - And I click on ".dynamiccoursetest" "css_element" + And I click on "List menu" "theme_boost_union > Smart menu" Then "" "text" should appear before "" "text" in the ".dynamiccoursetest .dropdown-menu" "css_element" And "" "text" should appear before "" "text" in the ".dynamiccoursetest .dropdown-menu" "css_element" Examples: - | sorting | thisbeforethat1 | thisbeforethat2 | thisbeforethat3 | - # Option: Course fullname ascending - | 0 | AAA Course | BBB Course | CCC Course | - # Option: Course fullname descending - | 1 | CCC Course | BBB Course | AAA Course | - # Option: Course shortname ascending - | 2 | BBB Course | AAA Course | CCC Course | - # Option: Course shortname descending - | 3 | CCC Course | AAA Course | BBB Course | - # Option: Course ID ascending - | 4 | AAA Course | BBB Course | CCC Course | - # Option: Course ID descending - | 5 | CCC Course | BBB Course | AAA Course | - # Option: Course ID number ascending - | 6 | CCC Course | BBB Course | AAA Course | - # Option: Course ID number descending - | 7 | AAA Course | BBB Course | CCC Course | + | sorting | thisbeforethat1 | thisbeforethat2 | thisbeforethat3 | + | Course fullname ascending | AAA Course | BBB Course | CCC Course | + | Course fullname descending | CCC Course | BBB Course | AAA Course | + | Course shortname ascending | BBB Course | AAA Course | CCC Course | + | Course shortname descending | CCC Course | AAA Course | BBB Course | + | Course ID ascending | AAA Course | BBB Course | CCC Course | + | Course ID descending | CCC Course | BBB Course | AAA Course | + | Course ID number ascending | CCC Course | BBB Course | AAA Course | + | Course ID number descending | AAA Course | BBB Course | CCC Course | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Hide empty menus - When I log in as "admin" - And I navigate to smart menus - 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" - 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" - And I log out - And I log in as "" - Then I see smart menu "" in location "Main, Menu, User, Bottom" + And the following "theme_boost_union > smart menu" exists: + | title | Mode menu | + | location | Main navigation, Menu bar, User menu, Bottom bar | + | mode | | + And the following "theme_boost_union > smart menu item" exists: + | menu | Mode menu | + | title | Dynamic courses | + | itemtype | Dynamic courses | + | itemmode | | + | enrolmentrole | | + When I log in as "" + Then "" "theme_boost_union > Main menu " exist + And "" "theme_boost_union > Menu bar " exist + And "" "theme_boost_union > User menu " exist + And "" "theme_boost_union > Bottom bar " exist Examples: - | 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 | + | role | user | shouldornot | menutitle | menumode | locator | + | teacher, editingteacher | student1 | should not | Mode menu | Submenu | smart menu | + | teacher, editingteacher | teacher | should | Mode menu | Submenu | smart menu | + | student | student1 | should | Mode menu | Submenu | smart menu | + | student | teacher | should not | Mode menu | Submenu | smart menu | + | teacher, editingteacher | student1 | should not | Course 01 | Inline | smart menu item | + | teacher, editingteacher | teacher | should | Course 01 | Inline | smart menu item | + | student | student1 | should | Course 01 | Inline | smart menu item | + | student | teacher | should not | Course 01 | Inline | smart menu item | diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature index bbf14b159d5..2280eefb6ae 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_rules.feature @@ -29,22 +29,15 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app | student2 | CH1 | | student2 | CH2 | | teacher | CH2 | - And I create smart menu with the following fields to these values: - | Title | Quick links | - | Menu location(s) | Main, Menu, User, Bottom | - And I set "Quick links" smart menu items with the following fields to these values: - | Title | Resources | - | Menu item type | Static | - | URL | https://moodle.org | + And the following "theme_boost_union > smart menu" exists: + | title | Quick links | + | location | Main navigation, Menu bar, User menu, Bottom bar | # 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 | - And the following "language packs" exist: - | language | - | de | - | fr | + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Info | + | itemtype | Heading | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on the user roles @@ -61,265 +54,227 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app And the following "roles" exist: | name | shortname | description | | Visitor | visitor | My visitor role | + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | roles | | + | rolecontext | | + Given I am logged in as "admin" And I navigate to "Users > Permissions > User policies" in site administration And I set the field "Role for visitors" to "Visitor (visitor)" And I press "Save changes" - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By role" to "" - And I set the field "Context" to "" - And I click on "Save changes" "button" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "coursemanager" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student1" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "teacher" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "systemmanager" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log in as "guest" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, Bottom" - And I log out - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, Bottom" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "coursemanager" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I am logged in as "teacher" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I am logged in as "systemmanager" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I am logged in as "guest" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I log out + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" Examples: - | byrole | context | student1shouldorshouldnot | teachershouldorshouldnot | managershouldorshouldnot | guestshouldorshouldnot | adminshouldorshouldnot | systemshouldorshouldnot | visitorshouldorshouldnot | - | Manager | Any | should not | should not | should | should not | should not | should | should not | - | Manager, Student | Any | should | should not | should | should not | should not | should | should not | - | Manager, Student, Teacher | Any | should | should | should | should not | should not | should | should not | - | Manager, Student, Teacher | System | should not | should not | should not | should not | should not | should | should not | - | Authenticated user | Any | should | should | should | should not | should | should | should not | - | Guest | Any | should not | should not | should not | should | should not | should not | should not | - | Visitor | Any | should not | should not | should not | should not | should not | should not | should | + | byrole | context | student1shouldorshouldnot | teachershouldorshouldnot | managershouldorshouldnot | guestshouldorshouldnot | adminshouldorshouldnot | systemshouldorshouldnot | visitorshouldorshouldnot | + | Manager | Any | should not | should not | should | should not | should not | should | should not | + | Manager, Student | Any | should | should not | should | should not | should not | should | should not | + | Manager, Student, editingteacher | Any | should | should | should | should not | should not | should | should not | + | Manager, Student, editingteacher | System | should not | should not | should not | should not | should not | should | should not | + | user | Any | should | should | should | should not | should | should | should not | + | Guest | Any | should not | should not | should not | should | should not | should not | should not | + | Visitor | Any | should not | should not | should not | should not | should not | should not | should | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on being site admin - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "Show to" to "" - And I click on "Save changes" "button" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student1" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | byadmin | | + When I am logged in as "admin" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student1" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" Examples: - | byadmin | adminshouldorshouldnot | student1shouldorshouldnot | - | 0 | should | should | - | 1 | should | should not | - | 2 | should not | should | + | byadmin | adminshouldorshouldnot | student1shouldorshouldnot | + | All users | should | should | + | Site admins only | should | should not | + | Non-admins only | should not | should | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on the user assignment in single cohorts - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By cohort" to "" - And I click on "Save changes" "button" - And I should not see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student1" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student2" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "teacher" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | cohorts | | + When I am logged in as "admin" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student2" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "teacher" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" Examples: | bycohort | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | - | Cohort 1 | should | should | should not | - | Cohort 2 | should not | should | should | + | CH1 | should | should | should not | + | CH2 | should not | should | should | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on the user assignment in multiple cohorts - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By cohort" to "" - And I set the field "Operator" to "" - And I click on "Save changes" "button" - And I should not see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student1" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student2" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "teacher" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | cohorts | | + | operator | | + When I am logged in as "admin" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" should not exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student2" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "teacher" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" Examples: - | bycohorts | operator | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | - | Cohort 1, Cohort 2 | Any | should | should | should | - | Cohort 1, Cohort 2 | All | should not | should | should not | + | bycohorts | operator | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | + | CH1, CH2 | Any | should | should | should | + | CH1, CH2 | All | should not | should | should not | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on the user's prefered language - When I log in as "teacher" - And I follow "Preferences" in the user menu - And I click on "Preferred language" "link" - And I set the field "Preferred language" to "Deutsch ‎(de)‎" - And I press "Save changes" - And I log out - And I log in as "student1" - 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)‎" - And I press "Save changes" - And I log out - And I log in as "student2" - And I follow "Preferences" in the user menu - And I click on "Preferred language" "link" - And I set the field "Preferred language" to "Français ‎(fr)‎" - And I press "Save changes" - And I log out - When I log in as "admin" - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By language" to "" - And I click on "Save changes" "button" - And I log out - And I log in as "student1" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student2" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "teacher" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + Given the following "language packs" exist: + | language | + | de | + | fr | + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | languages | | + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student2" + And I follow "Language" in the user menu + And I click on "Français" "link" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "teacher" + And I follow "Language" in the user menu + And I click on "Deutsch" "link" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" Examples: - | bylanguage | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | - | English | should | should not | should not | - | English, Deutsch | should | should not | should | + | bylanguage | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | + | en | should | should not | should not | + | en, de | should | should not | should | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on the custom date range - When I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the following fields to these values: - | id_start_date_enabled | | - | id_end_date_enabled | | - | id_start_date_day | | - | id_start_date_month | | - | id_start_date_year | | - | id_end_date_day | | - | id_end_date_month | | - | id_end_date_year | | - And I click on "Save changes" "button" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - Then I log out - And I log in as "student1" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - When I log in as "teacher" - And I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + Given the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | start_date | | + | end_date | | + When I am logged in as "admin" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + When I am logged in as "teacher" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" Examples: - | startenabled |endenabled | start_day | start_month | start_year | end_day | end_month | end_year | menushouldorshouldnot | - | 1 | 1 | 1 | January | 2023 | 1 | January | 2050 | should | - | 1 | 1 | 1 | January | 2049 | 1 | January | 2050 | should not | - | 1 | 1 | 1 | January | 2023 | 1 | December | 2023 | should not | - | 1 | 0 | 1 | January | 2023 | 1 | 1 | 2023 | should | - | 1 | 0 | 1 | January | 2049 | 1 | 1 | 2023 | should not | - | 0 | 1 | 1 | January | 2023 | 1 | December | 2050 | should | - | 0 | 1 | 1 | January | 2023 | 1 | December | 2023 | should not | + | start_date | end_date | menushouldorshouldnot | + | ## 1 January 2023 ## | ## 1 January 2050 ## | should | + | ## 1 January 2049 ## | ## 1 January 2050 ## | should not | + | ## 1 January 2023 ## | ## 1 December 2023 ## | should not | + | ## 1 January 2023 ## | | should | + | ## 1 January 2049 ## | | should not | + | | ## 1 December 2050 ## | should | + | | ## 1 December 2023 ## | should not | @javascript Scenario Outline: Smartmenu: Menu items: Rules - Show smart menu item based on multiple conditions - When I log in as "teacher" - And I follow "Preferences" in the user menu - And I click on "Preferred language" "link" - And I set the field "Preferred language" to "Deutsch ‎(de)‎" - And I press "Save changes" - And I log out - And I log in as "student1" - 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)‎" - And I press "Save changes" - And I log out - And I log in as "student2" - And I follow "Preferences" in the user menu - And I click on "Preferred language" "link" - And I set the field "Preferred language" to "Français ‎(fr)‎" - And I press "Save changes" - And I log out - When I log in as "admin" - And I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I should see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By role" to "" - And I set the field "By cohort" to "" - And I set the field "By language" to "" - And I click on "Save changes" "button" - And I log out - And I log in as "student1" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "student2" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" - And I log out - And I log in as "teacher" - Then I see smart menu "Quick links" item "Resources" in location "Main, Menu, User, Bottom" + Given the following "language packs" exist: + | language | + | de | + | fr | + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | roles | | + | cohorts | | + | languages | | + When I am logged in as "student1" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Main menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Menu bar smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > User menu smart menu" + And "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "student2" + And I follow "Language" in the user menu + And I click on "Français" "link" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" + When I am logged in as "teacher" + And I follow "Language" in the user menu + And I click on "Deutsch" "link" + Then "Resources" "theme_boost_union > Smart menu item" exist in the "Quick links" "theme_boost_union > Bottom bar smart menu" Examples: - | byrole | bycohort | bylanguage | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | - | Manager, Student | Cohort 1 | English | should | should not | should not | - | Manager, Student, Teacher | Cohort 1, Cohort 2 | English, Deutsch | should | should not | should | + | byrole | bycohort | bylanguage | student1shouldorshouldnot | student2shouldorshouldnot | teachershouldorshouldnot | + | Manager, Student | CH1 | en | should | should not | should not | + | Manager, Student, editingteacher | CH1, CH2 | en, de | should | should not | should | @javascript Scenario: Smartmenu: Menu items: Rules - Deleting a cohort used for a rule removes it from the rule - Given I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By cohort" to "Cohort 1, Cohort 2" - And I set the field "Operator" to "Any" - And I click on "Save changes" "button" + Given the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | cohorts | CH1, CH2 | + And I am on the "Quick links" "theme_boost_union > Smart menu > Items" page logged in as "admin" And I should see "Cohort 1" in the "Resources" "table_row" And I should see "Cohort 2" in the "Resources" "table_row" When I navigate to "Users > Cohorts" in site administration And I open the action menu in "Cohort 1" "table_row" And I choose "Delete" in the open action menu And I press "Continue" - And I navigate to smart menus - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I should not see "Cohort 1" in the "Resources" "table_row" + And I am on the "Quick links" "theme_boost_union > Smart menu > Items" page + Then I should not see "Cohort 1" in the "Resources" "table_row" And I should see "Cohort 2" in the "Resources" "table_row" @javascript @@ -328,20 +283,18 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, app | shortname | name | | test1 | Test role 1 | | test2 | Test role 2 | - And I navigate to smart menus - And I should see "Quick links" in the "smartmenus" "table" - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I click on ".action-edit" "css_element" in the "Resources" "table_row" - And I expand all fieldsets - And I set the field "By role" to "Test role 1, Test role 2" - And I set the field "Operator" to "Any" - And I click on "Save changes" "button" + And the following "theme_boost_union > smart menu item" exists: + | menu | Quick links | + | title | Resources | + | itemtype | Static | + | url | https://moodle.org | + | roles | test1, test2 | + And I am on the "Quick links" "theme_boost_union > Smart menu > Items" page logged in as "admin" And I should see "Test role 1" in the "Resources" "table_row" And I should see "Test role 2" in the "Resources" "table_row" When I navigate to "Users > Define roles" in site administration And I click on "Delete" "link" in the "Test role 1" "table_row" And I press "Yes" - And I navigate to smart menus - And I click on ".action-list-items" "css_element" in the "Quick links" "table_row" - And I should not see "Test role 1" in the "Resources" "table_row" + And I am on the "Quick links" "theme_boost_union > Smart menu > Items" page + Then I should not see "Test role 1" in the "Resources" "table_row" And I should see "Test role 2" in the "Resources" "table_row" diff --git a/tests/generator/behat_theme_boost_union_generator.php b/tests/generator/behat_theme_boost_union_generator.php index 0f95c2236df..faba43f59ba 100644 --- a/tests/generator/behat_theme_boost_union_generator.php +++ b/tests/generator/behat_theme_boost_union_generator.php @@ -66,6 +66,7 @@ protected function get_creatable_entities(): array { 'cohorts' => 'cohorts', 'operator' => 'operator', 'languages' => 'languages', + 'byadmin' => 'byadmin', ], ], @@ -92,6 +93,7 @@ protected function get_creatable_entities(): array { 'cohorts' => 'cohorts', 'operator' => 'operator', 'languages' => 'languages', + 'byadmin' => 'byadmin', ], ], ]; @@ -277,6 +279,17 @@ protected function get_operator_id(string $operator): int { return $this->option_id('operator', $operator, smartmenu::get_operator_options()); } + /** + * Return the ID for the given byadmin setting. + * + * @param string $byadmin + * @return int + * @throws Exception + */ + protected function get_byadmin_id(string $byadmin): int { + return $this->option_id('byadmin', $byadmin, smartmenu::get_byadmin_options()); + } + /** * Given a comma-separated list of language short codes, return an array of each trimmed value. * diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 7fef482f2d2..e1e33051551 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -41,46 +41,26 @@ public function create_smartmenu(array $data): \stdClass { if (empty($location)) { throw new Exception('A Smart menu location must be specified.'); } - $validlocations = [ - smartmenu::LOCATION_MAIN, - smartmenu::LOCATION_MENU, - smartmenu::LOCATION_BOTTOM, - smartmenu::LOCATION_USER, - ]; + $validlocations = array_keys(smartmenu::get_locations()); if (!empty(array_diff($validlocations, $location))) { throw new Exception('Invalid Smart menu location.'); } - $validdescriptions = [ - smartmenu::DESC_NEVER, - smartmenu::DESC_ABOVE, - smartmenu::DESC_BELOW, - smartmenu::DESC_HELP, - ]; + $validdescriptions = array_keys(smartmenu::get_showdescription_options()); $showdescription = $data['showdescription'] ?? smartmenu::DESC_NEVER; if (!in_array($showdescription, $validdescriptions)) { throw new Exception('Invalid showdescription.'); } - $validtypes = [ - smartmenu::TYPE_LIST, - smartmenu::TYPE_CARD, - ]; + $validtypes = array_keys(smartmenu::get_types()); $type = $data['type'] ?? smartmenu::TYPE_LIST; if (!in_array($type, $validtypes)) { throw new Exception('Invalid showdescription.'); } - $validmodes = [ - smartmenu::MODE_SUBMENU, - smartmenu::MODE_INLINE, - ]; + $validmodes = array_keys(smartmenu::get_mode_options()); $mode = $data['mode'] ?? smartmenu::MODE_SUBMENU; if (!in_array($mode, $validmodes)) { throw new Exception('Invalid mode.'); } - $validbehaviours = [ - smartmenu::MOREMENU_DONOTCHANGE, - smartmenu::MOREMENU_INTO, - smartmenu::MOREMENU_OUTSIDE, - ]; + $validbehaviours = array_keys(smartmenu::get_moremenu_options()); $moremenubehaviour = $data['moremenubehaviour'] ?? smartmenu::MOREMENU_DONOTCHANGE; if (!in_array($moremenubehaviour, $validbehaviours)) { throw new Exception('Invalid moremenubehaviour.'); @@ -90,30 +70,17 @@ public function create_smartmenu(array $data): \stdClass { $cardform = null; $cardoverflowbehaviour = null; if ($type === smartmenu::TYPE_CARD) { - $validcardsizes = [ - smartmenu::CARDSIZE_TINY, - smartmenu::CARDSIZE_SMALL, - smartmenu::CARDSIZE_MEDIUM, - smartmenu::CARDSIZE_LARGE, - ]; + $validcardsizes = array_keys(smartmenu::get_cardsize_options()); $cardsize = $data['cardsize'] ?? smartmenu::CARDSIZE_SMALL; if (!in_array($cardsize, $validcardsizes)) { throw new Exception('Invalid cardsize.'); } - $validcardforms = [ - smartmenu::CARDFORM_SQUARE, - smartmenu::CARDFORM_PORTRAIT, - smartmenu::CARDFORM_LANDSCAPE, - smartmenu::CARDFORM_FULLWIDTH, - ]; + $validcardforms = array_keys(smartmenu::get_cardform_options()); $cardform = $data['cardform'] ?? smartmenu::CARDFORM_SQUARE; if (!in_array($cardform, $validcardforms)) { throw new Exception('Invalid cardform.'); } - $validbehaviours = [ - smartmenu::CARDOVERFLOWBEHAVIOUR_NOWRAP, - smartmenu::CARDOVERFLOWBEHAVIOUR_WRAP, - ]; + $validbehaviours = array_keys(smartmenu::get_cardoverflowbehaviour_options()); $cardoverflowbehaviour = strtolower($data['cardoverflowbehaviour']) ?? smartmenu::CARDOVERFLOWBEHAVIOUR_NOWRAP; if (!in_array($cardoverflowbehaviour, $validbehaviours)) { throw new Exception('Invalid cardoverflowbehaviour.'); @@ -124,6 +91,7 @@ public function create_smartmenu(array $data): \stdClass { $rolecontext, $cohorts, $operator, + $byadmin, $languages, $startdate, $enddate, @@ -148,6 +116,7 @@ public function create_smartmenu(array $data): \stdClass { 'rolecontext' => $rolecontext, 'cohorts' => $cohorts, 'operator' => $operator, + 'byadmin' => $byadmin, 'languages' => $languages, 'start_date' => $startdate, 'end_date' => $enddate, @@ -174,11 +143,7 @@ public function create_smartmenu_item(array $data): \stdClass { $sortorder = $data['sortorder'] ?? $DB->count_records('theme_boost_union_menus') + 1; - $validtypes = [ - smartmenu_item::TYPESTATIC, - smartmenu_item::TYPEHEADING, - smartmenu_item::TYPEDYNAMIC, - ]; + $validtypes = array_keys(smartmenu_item::get_types()); $type = $data['type'] ?? smartmenu_item::TYPESTATIC; if (!in_array($type, $validtypes)) { throw new Exception('Invalid type.'); @@ -202,24 +167,12 @@ public function create_smartmenu_item(array $data): \stdClass { $displayfield = null; $textcount = null; if ($type == smartmenu_item::TYPEDYNAMIC) { - $validsorts = [ - smartmenu_item::LISTSORT_FULLNAME_ASC, - smartmenu_item::LISTSORT_FULLNAME_DESC, - smartmenu_item::LISTSORT_SHORTNAME_ASC, - smartmenu_item::LISTSORT_SHORTNAME_DESC, - smartmenu_item::LISTSORT_COURSEID_ASC, - smartmenu_item::LISTSORT_COURSEID_DESC, - smartmenu_item::LISTSORT_COURSEIDNUMBER_ASC, - smartmenu_item::LISTSORT_COURSEIDNUMBER_DESC, - ]; + $validsorts = array_keys(smartmenu_item::get_listsort_options()); $listsort = $data['listsort'] ?? smartmenu_item::LISTSORT_FULLNAME_ASC; if (!in_array($listsort, $validsorts)) { throw new Exception('Invalid listsort.'); } - $validdisplayfields = [ - smartmenu_item::FIELD_FULLNAME, - smartmenu_item::FIELD_SHORTNAME, - ]; + $validdisplayfields = array_keys(smartmenu_item::get_displayfield_options()); $displayfield = $data['displayfield'] ?? smartmenu_item::FIELD_FULLNAME; if (!in_array($displayfield, $validdisplayfields)) { throw new Exception('Invalid displayfield.'); @@ -236,30 +189,19 @@ public function create_smartmenu_item(array $data): \stdClass { throw new Exception('Invalid mode.'); } - $validdisplays = [ - smartmenu_item::DISPLAY_SHOWTITLEICON, - smartmenu_item::DISPLAY_HIDETITLE, - smartmenu_item::DISPLAY_HIDETITLEMOBILE, - ]; + $validdisplays = array_keys(smartmenu_item::get_display_options()); $display = $data['display'] ?? smartmenu_item::DISPLAY_SHOWTITLEICON; if (!in_array($display, $validdisplays)) { throw new Exception('Invalid display.'); } - $validtargets = [ - smartmenu_item::TARGET_SAME, - smartmenu_item::TARGET_NEW, - ]; + $validtargets = array_keys(smartmenu_item::get_target_options()); $target = $data['target'] ?? smartmenu_item::TARGET_SAME; if (!in_array($target, $validtargets)) { throw new Exception('Invalid target.'); } - $validtextpositions = [ - smartmenu_item::POSITION_BELOW, - smartmenu_item::POSITION_OVERLAYTOP, - smartmenu_item::POSITION_OVERLAYBOTTOM, - ]; + $validtextpositions = array_keys(smartmenu_item::get_textposition_options()); $textposition = $data['textposition'] ?? smartmenu_item::POSITION_BELOW; if (!in_array($textposition, $validtextpositions)) { throw new Exception('Invalid text position.'); @@ -270,6 +212,7 @@ public function create_smartmenu_item(array $data): \stdClass { $rolecontext, $cohorts, $operator, + $byadmin, $languages, $startdate, $enddate, @@ -304,6 +247,7 @@ public function create_smartmenu_item(array $data): \stdClass { 'mobile' => $data['mobile'] ?? 0, 'roles' => $roles, 'rolecontext' => $rolecontext, + 'byadmin' => $byadmin, 'cohorts' => $cohorts, 'operator' => $operator, 'languages' => $languages, @@ -341,6 +285,11 @@ protected function parse_restrictions(array $data): array { throw new Exception('Invalid operator.'); } } + $validbyadmins = array_keys(smartmenu::get_byadmin_options()); + $byadmin = $data['byadmin'] ?? smartmenu::BYADMIN_ALL; + if (!in_array($byadmin, $validbyadmins)) { + throw new Exception('Invalid byadmin.'); + } $languages = $data['languages'] ?? []; $startdate = $data['start_date'] ?? 0; $enddate = $data['end_date'] ?? 0; @@ -349,6 +298,7 @@ protected function parse_restrictions(array $data): array { $rolecontext, json_encode($cohorts), $operator, + $byadmin, json_encode($languages), $startdate, $enddate,