diff --git a/CHANGES.md b/CHANGES.md index a090e8474a0..ceac0b196d6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2024-12-06 - Tests: Add several Behat optimisations to bring down the test suite run time, resolves #765. * 2024-12-06 - Upstream change: Adopt changes from MDL-83759 ('System notification navbar popover is misplaced in Moodle 4.4 and 4.5') * 2024-12-06 - Upstream change: Adopt changes from MDL-75610 ('Quiz activity name no longer being displayed in quiz landing page when using Safe Exam Browser'), resolves #766. * 2024-11-19 - Bugfix: Port the activity icon sizes in the nav drawer back to stable versions, resolves #755. diff --git a/classes/smartmenu.php b/classes/smartmenu.php index 66d039ce41a..a482d2f5a0d 100644 --- a/classes/smartmenu.php +++ b/classes/smartmenu.php @@ -594,11 +594,18 @@ public function build($resetcache=false) { return false; } + // Add marker class to make clear that this is a Boost Union smart menu. $this->menu->classes[] = 'boost-union-smartmenu'; + + // Add custom CSS class. + $this->menu->classes[] = $this->menu->cssclass; + + // Add CSS classes for card menus. $this->menu->classes[] = $this->get_cardform(); // Html class for the card form size, Potrait, Square, landscape. $this->menu->classes[] = $this->get_cardsize(); // HTML class for the card Size, tiny, small, medium, large. $this->menu->classes[] = $this->get_cardwrap(); // HtML class for the card overflow behaviour. - $this->menu->classes[] = $this->menu->cssclass;// Custom class selector for menu. + + // Add CSS classes for more behaviour. $this->menu->classes[] = ($this->menu->moremenubehavior == self::MOREMENU_OUTSIDE) ? "force-menu-out" : ''; // Card type menus doesn't supports inline menus. diff --git a/classes/smartmenu_item.php b/classes/smartmenu_item.php index 7f05ae49c06..634bb7c45bc 100644 --- a/classes/smartmenu_item.php +++ b/classes/smartmenu_item.php @@ -1042,9 +1042,12 @@ public function build() { return false; } - // Add custom css class. - $class[] = 'boost-union-smartitem'; + // Add marker class to make clear that this is a Boost Union smart menu item. + $class[] = 'boost-union-smartmenuitem'; + + // Add custom CSS class. $class[] = $this->item->cssclass; + // Add classes for hide items in specific viewport. $class[] = $this->item->desktop ? 'd-lg-none' : 'd-lg-inline-flex'; $class[] = $this->item->tablet ? 'd-md-none' : 'd-md-inline-flex'; @@ -1052,11 +1055,14 @@ public function build() { // Add classes for item title placement on card. $class[] = $this->get_textposition_class(); - // Menu item class. + + // Add menu item class. $types = [self::TYPESTATIC => 'static', self::TYPEDYNAMIC => 'dynamic', self::TYPEHEADING => 'heading']; $class[] = 'menu-item-'.($types[$this->item->type] ?? ''); + // Add classes to item data. $this->item->classes = $class; + // Load the location of menu, used to collect menus for locations in menu inline mode. $this->item->location = $this->menu->location; @@ -1330,20 +1336,17 @@ public static function get_types(?int $type = null) { } /** - * Returns the display options for the menu items. + * Return the options for the display setting. * - * @param int|null $option The display option to retrieve. If null, returns all display options. - * @return array|string The array of display options if $option is null, or the display option string if $option is set. - * @throws coding_exception if $option is set but invalid. + * @return array + * @throws \coding_exception */ - public static function get_display_options(?int $option = null) { - $displayoptions = [ + public static function get_display_options() { + return [ self::DISPLAY_SHOWTITLEICON => get_string('smartmenusmenuitemdisplayoptionsshowtitleicon', 'theme_boost_union'), self::DISPLAY_HIDETITLE => get_string('smartmenusmenuitemdisplayoptionshidetitle', 'theme_boost_union'), self::DISPLAY_HIDETITLEMOBILE => get_string('smartmenusmenuitemdisplayoptionshidetitlemobile', 'theme_boost_union'), ]; - - return ($option !== null && isset($displayoptions[$option])) ? $displayoptions[$option] : $displayoptions; } /** diff --git a/tests/behat/behat_theme_boost_union.php b/tests/behat/behat_theme_boost_union.php index 495c8a4145e..5139ec649a4 100644 --- a/tests/behat/behat_theme_boost_union.php +++ b/tests/behat/behat_theme_boost_union.php @@ -15,12 +15,12 @@ // along with Moodle. If not, see . /** - * Standard behat step data providers for theme_boost_union + * Theme Boost Union - Standard behat step data providers. * - * @package theme_boost_union - * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} - * @author Mark Johnson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package theme_boost_union + * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} + * @author Mark Johnson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_theme_boost_union extends behat_base { /** @@ -203,7 +203,7 @@ protected function resolve_page_instance_url(string $type, string $identifier): ); default: - throw new Exception('Unrecognised quiz page type "' . $type . '."'); + throw new Exception('Unrecognised theme_boost_union page type "' . $type . '."'); } } @@ -232,7 +232,7 @@ public static function get_exact_named_selectors(): array { ), new behat_component_named_selector( 'Smart menu item', - [".//a[contains(@class, 'boost-union-smartitem')][contains(text(), %locator%)]"], + [".//a[contains(@class, 'boost-union-smartmenuitem')][contains(text(), %locator%)]"], ), new behat_component_named_selector( 'Main menu smart menu', @@ -245,7 +245,7 @@ public static function get_exact_named_selectors(): array { 'Main menu smart menu item', [ ".//div[contains(@class, 'primary-navigation')]" . - "//a[contains(@class, 'boost-union-smartitem')][contains(text(), %locator%)]", + "//a[contains(@class, 'boost-union-smartmenuitem')][contains(text(), %locator%)]", ], ), new behat_component_named_selector( @@ -259,7 +259,7 @@ public static function get_exact_named_selectors(): array { 'Menu bar smart menu item', [ ".//nav[contains(@class, 'boost-union-menubar')]" . - "//a[contains(@class, 'boost-union-smartitem')][contains(text(), %locator%)]", + "//a[contains(@class, 'boost-union-smartmenuitem')][contains(text(), %locator%)]", ], ), new behat_component_named_selector( @@ -272,7 +272,7 @@ public static function get_exact_named_selectors(): array { 'User menu smart menu item', [ ".//div[@id = 'usermenu-carousel']//div[contains(@class, 'carousel-item')]" . - "//a[contains(@class, 'boost-union-smartitem')][contains(text(), %locator%)]", + "//a[contains(@class, 'boost-union-smartmenuitem')][contains(text(), %locator%)]", ], ), new behat_component_named_selector( @@ -285,7 +285,7 @@ public static function get_exact_named_selectors(): array { 'Bottom bar smart menu item', [ ".//nav[contains(@class, 'boost-union-bottom-menu')]" . - "//a[contains(@class, 'boost-union-smartitem')][contains(text(), %locator%)]", + "//a[contains(@class, 'boost-union-smartmenuitem')][contains(text(), %locator%)]", ], ), ]; diff --git a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature index be3253953b7..e947688648c 100644 --- a/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature +++ b/tests/behat/theme_boost_union_smartmenusettings_menuitems_dynamiccourses.feature @@ -107,6 +107,7 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi | student1 | C1a | student | | student1 | C1b | student | | student1 | C1aa | student | +<<<<<<< HEAD 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" @@ -119,6 +120,22 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi 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 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 01a" "theme_boost_union > Smart menu item" exist in the "List menu" "theme_boost_union > Main menu 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" +>>>>>>> 1c1bd47 (Review changes) Examples: | subcat | shouldornot | @@ -225,47 +242,32 @@ Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, usi 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 "student1" + 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 | - | value1 | student1 | should | should | should not | should not | - | value2 | student1 | should not | should not | should | should not | + | value | course1 | course2 | course3 | course4 | + | value1 | should | should | should not | should not | + | value2 | should not | should not | should | should not | @javascript Scenario Outline: Smartmenus: Menu items: Dynamic courses - Sort the course list based on the given setting diff --git a/tests/generator/behat_theme_boost_union_generator.php b/tests/generator/behat_theme_boost_union_generator.php index 0f95c2236df..b678539ca47 100644 --- a/tests/generator/behat_theme_boost_union_generator.php +++ b/tests/generator/behat_theme_boost_union_generator.php @@ -18,12 +18,12 @@ use theme_boost_union\smartmenu_item; /** - * Behat generator for Boost Union + * Theme Boost Union - Behat generator. * - * @package theme_boost_union - * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} - * @author Mark Johnson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package theme_boost_union + * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} + * @author Mark Johnson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_theme_boost_union_generator extends behat_generator_base { /** diff --git a/tests/generator/lib.php b/tests/generator/lib.php index 7fef482f2d2..2a1201bbf3f 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -18,12 +18,12 @@ use theme_boost_union\smartmenu_item; /** - * Boost Union test data generator + * Theme Boost Union - Test data generator. * - * @package theme_boost_union - * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} - * @author Mark Johnson - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package theme_boost_union + * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net} + * @author Mark Johnson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class theme_boost_union_generator extends component_generator_base { /**