From 64c9ba23f2048d6cbf215caf16286f337d540bb0 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Fri, 17 Jan 2025 13:54:42 +1100 Subject: [PATCH] MDL-84233 core_user: fix unit test --- lib/tests/user_menu_test.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/tests/user_menu_test.php b/lib/tests/user_menu_test.php index 6b7fc8ca22f42..2167c37317f8b 100644 --- a/lib/tests/user_menu_test.php +++ b/lib/tests/user_menu_test.php @@ -92,14 +92,27 @@ public function test_custom_user_menu($data, $entrycount, $dividercount): void { $PAGE->reset_theme_and_output(); $PAGE->initialise_theme_and_output(); + // Empty the custom user menu items. + // This should only contain default items and items added by extend_user_menu. + set_config('customusermenuitems', ''); + + // Default menu items. + $defaultmenu = $OUTPUT->user_menu($USER); + + // Count the number of entries and dividers in the default menu. + preg_match_all('/]+role="menuitem"[^>]+>/', $defaultmenu, $results); + $defaultentrycount = count($results[0]); + preg_match_all('//', $defaultmenu, $results); + $defaultdividercount = count($results[0]); + // Set the configuration. set_config('customusermenuitems', $data); // We always add two dividers as standard. - $dividercount += 2; + $dividercount += $defaultdividercount; // The basic entry count will additionally include the wrapper menu, Preferences, Logout and switch roles link. - $entrycount += 3; + $entrycount += $defaultentrycount; $output = $OUTPUT->user_menu($USER); preg_match_all('/]+role="menuitem"[^>]+>/', $output, $results);