From c261fca22a1715d7faa9528dcc7fb40d55bdccfc Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Tue, 3 Sep 2024 17:05:41 +0200 Subject: [PATCH] MDL-82983 course: prevent subsection default completion --- completion/classes/manager.php | 3 ++ mod/subsection/lib.php | 1 + .../behat/subsection_no_completion.feature | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 mod/subsection/tests/behat/subsection_no_completion.feature diff --git a/completion/classes/manager.php b/completion/classes/manager.php index 4c9fc29fbde..f77a543d0f3 100644 --- a/completion/classes/manager.php +++ b/completion/classes/manager.php @@ -244,6 +244,9 @@ class manager { if (!file_exists($libfile)) { continue; } + if (!plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) { + continue; + } $module->icon = $OUTPUT->image_url('monologo', $module->name)->out(); $module->formattedname = format_string(get_string('modulename', 'mod_' . $module->name), true, ['context' => $context]); diff --git a/mod/subsection/lib.php b/mod/subsection/lib.php index 0ec8838b564..580a7d34cac 100644 --- a/mod/subsection/lib.php +++ b/mod/subsection/lib.php @@ -43,6 +43,7 @@ function subsection_supports($feature) { FEATURE_BACKUP_MOODLE2 => true, FEATURE_SHOW_DESCRIPTION => false, FEATURE_MOD_PURPOSE => MOD_PURPOSE_CONTENT, + FEATURE_MODEDIT_DEFAULT_COMPLETION => false, default => null, }; } diff --git a/mod/subsection/tests/behat/subsection_no_completion.feature b/mod/subsection/tests/behat/subsection_no_completion.feature new file mode 100644 index 00000000000..d0efef7dcb8 --- /dev/null +++ b/mod/subsection/tests/behat/subsection_no_completion.feature @@ -0,0 +1,37 @@ +@mod @mod_subsection +Feature: Subsection does not have completion. + In order to use subsections as normal sections + As an teacher + I need to use subsection activity without completion + + Background: + Given I enable "subsection" "mod" plugin + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | numsections | initsections | enablecompletion | + | Course 1 | C1 | 0 | 1 | 1 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | course | idnumber | section | + | subsection | Subsection 1 | C1 | subsection1 | 1 | + | page | Page in Subsection 1 | C1 | page1 | 2 | + + Scenario: Subsection does not appear in the site default completion form + Given I log in as "admin" + When I navigate to "Courses > Default settings > Default activity completion" in site administration + And I should see "Default activity completion" + Then I should see "Forum" in the "region-main" "region" + And I should not see "Subsection" in the "region-main" "region" + + @javascript + Scenario: Subsection does not appear in the course default completion form + Given I am on the "C1" "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" + And I should see "Default activity completion" + Then I should see "Forum" in the "region-main" "region" + And I should not see "Subsection" in the "region-main" "region"