From 6ea3b1410fecbd8f22c5e75dce3919add2980437 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 3 Mar 2026 16:36:16 +0100 Subject: [PATCH] MDL-88003 course: Skip plugins without FEATURE_CAN_DISPLAY in navigation --- .../route/controller/course_navigation.php | 4 +- .../controller/course_navigation_test.php | 70 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/public/course/classes/route/controller/course_navigation.php b/public/course/classes/route/controller/course_navigation.php index 16c761a639a..aad3c47809f 100644 --- a/public/course/classes/route/controller/course_navigation.php +++ b/public/course/classes/route/controller/course_navigation.php @@ -144,7 +144,9 @@ class course_navigation { // Skip modules that don't have a URL (like labels). !empty($cm->get_url()) // Skip modules that are not visible to the user. - && $cm->is_visible_on_course_page(); + && $cm->is_visible_on_course_page() + // Skip modules that are not displayable. + && modinfo::is_mod_type_visible_on_course($cm->modname); } /** diff --git a/public/course/tests/route/controller/course_navigation_test.php b/public/course/tests/route/controller/course_navigation_test.php index 8671c45124a..ed59c2a872b 100644 --- a/public/course/tests/route/controller/course_navigation_test.php +++ b/public/course/tests/route/controller/course_navigation_test.php @@ -285,6 +285,41 @@ final class course_navigation_test extends route_testcase { 'id' => '2', ], ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (student)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm1', + 'expected' => [ + 'id' => 'cm3', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (teacher)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm1', + 'expected' => [ + 'id' => 'cm3', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + 'role' => 'teacher', + ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (editingteacher)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm1', + 'expected' => [ + 'id' => 'cm3', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + 'role' => 'editingteacher', + ]; } /** @@ -526,6 +561,41 @@ final class course_navigation_test extends route_testcase { 'role' => 'editingteacher', 'hiddensections' => [2], ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (student)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm3', + 'expected' => [ + 'id' => 'cm1', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (teacher)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm3', + 'expected' => [ + 'id' => 'cm1', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + 'role' => 'teacher', + ]; + yield 'With module not supporting FEATURE_CAN_DISPLAY (editingteacher)' => [ + 'cmsdef' => [ + ['name' => 'cm1'], + ['name' => 'cm2', 'type' => 'qbank'], + ['name' => 'cm3'], + ], + 'current' => 'cm3', + 'expected' => [ + 'id' => 'cm1', // The cm2 should be skipped as it does not support FEATURE_CAN_DISPLAY. + ], + 'role' => 'editingteacher', + ]; } /**