diff --git a/public/course/classes/route/controller/course_navigation.php b/public/course/classes/route/controller/course_navigation.php index c4131aeb7aa..64c45d04637 100644 --- a/public/course/classes/route/controller/course_navigation.php +++ b/public/course/classes/route/controller/course_navigation.php @@ -143,7 +143,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 a24abee5bf0..90b1ca0e093 100644 --- a/public/course/tests/route/controller/course_navigation_test.php +++ b/public/course/tests/route/controller/course_navigation_test.php @@ -566,6 +566,41 @@ final class course_navigation_test extends route_testcase { 'statuscode' => 404, ], ]; + 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', + ]; } /** @@ -1032,6 +1067,41 @@ final class course_navigation_test extends route_testcase { 'statuscode' => 404, ], ]; + 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', + ]; } /**