From 63886769ddffff78841f0dfff1c93ae9ff1b487d Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 22 Aug 2023 13:20:53 +0200 Subject: [PATCH] MDL-79093 completion: Default activity completion order Default completion settings page should order activities alphabetically by display name (instead of internal name). --- completion/classes/manager.php | 6 ++++++ completion/tests/behat/default_activity_completion.feature | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/completion/classes/manager.php b/completion/classes/manager.php index 3e3cc7964b9..29ee34a6aba 100644 --- a/completion/classes/manager.php +++ b/completion/classes/manager.php @@ -234,6 +234,12 @@ class manager { $module->completionstatus = $this->get_completion_detail($defaults); } } + // Order modules by displayed name. + $modules = (array) $data->modules; + usort($modules, function($a, $b) { + return strcmp($a->formattedname, $b->formattedname); + }); + $data->modules = $modules; return $data; } diff --git a/completion/tests/behat/default_activity_completion.feature b/completion/tests/behat/default_activity_completion.feature index 3b25858783c..0c51dfe41ed 100644 --- a/completion/tests/behat/default_activity_completion.feature +++ b/completion/tests/behat/default_activity_completion.feature @@ -207,3 +207,9 @@ Feature: Allow teachers to edit the default activity completion rules in a cours And I click on "Save changes" "button" in the "[data-region='activitycompletion-assign']" "css_element" Then I should see "When you select automatic completion, you must also enable at least one requirement (below)." And I should not see "Changes saved" + + Scenario: Activities in Default activity completion are ordered alphabetically + Given I am on the "Course 1" course page logged in as teacher1 + When I navigate to "Course completion" in current page administration + And I set the field "Course completion tertiary navigation" to "Default activity completion" + Then "Survey" "text" should appear before "Text and media area" "text"