Skip to content

Commit

Permalink
MDL-84233 core_user: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Jan 17, 2025
1 parent a2653cc commit f3d1d9b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/tests/user_menu_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 fillers in the default menu.
preg_match_all('/<a [^>]+role="menuitem"[^>]+>/', $defaultmenu, $results);
$defaultentrycount = count($results[0]);
preg_match_all('/<span class="filler">/', $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('/<a [^>]+role="menuitem"[^>]+>/', $output, $results);
Expand Down

0 comments on commit f3d1d9b

Please sign in to comment.