Merge branch 'MDL-88111-main' of https://github.com/sarjona/moodle

This commit is contained in:
cescobedo
2026-03-06 11:42:25 +01:00
2 changed files with 85 additions and 7 deletions
@@ -80,7 +80,9 @@ class course_navigation {
return $this->redirect($response, $nextcm->get_navigation_url());
}
}
return $this->redirect_to_course($response, $cm->get_course()->id);
// If there is no next module, redirect to the next section.
return $this->redirect_to_next_section($response, $modinfo, $section);
}
/**
@@ -129,7 +131,9 @@ class course_navigation {
return $this->redirect($response, $prevcm->get_navigation_url());
}
}
return $this->redirect_to_course($response, $cm->get_course()->id);
// If there is no previous module, redirect to the previous section.
return $this->redirect_to_previous_section($response, $modinfo, $section);
}
/**
@@ -137,6 +137,48 @@ final class course_navigation_test extends route_testcase {
'id' => 'cm3', // Students cannot see stealth modules in the course page.
],
];
yield 'Hidden last module (teacher)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'cm2', 'options' => ['section' => 2, 'visible' => false]],
],
'current' => 'cm1',
'expected' => [
'id' => 'cm2',
],
'role' => 'teacher',
];
yield 'Hidden last module (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'cm2', 'options' => ['section' => 2, 'visible' => false]],
],
'current' => 'cm1',
'expected' => [
'type' => 'course', // Students cannot see hidden modules.
],
];
yield 'Stealth last module (teacher)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'cm2', 'options' => ['section' => 2, 'visibleoncoursepage' => false]],
],
'current' => 'cm1',
'expected' => [
'id' => 'cm2',
],
'role' => 'teacher',
];
yield 'Stealth last module (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'cm2', 'options' => ['section' => 2, 'visibleoncoursepage' => false]],
],
'current' => 'cm1',
'expected' => [
'type' => 'course', // Students cannot see stealth modules in the course page.
],
];
yield 'Restricted module visible (editingteacher)' => [
'cmsdef' => [
['name' => 'cm1'],
@@ -220,6 +262,16 @@ final class course_navigation_test extends route_testcase {
'id' => 'cm2',
],
];
yield 'Subsection: With next module being a subsection in the last section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'subsection1', 'type' => 'subsection', 'options' => ['section' => 2]],
],
'current' => 'cm1',
'expected' => [
'type' => 'course',
],
];
yield 'Subsection: With next module being a label and subsections (student)' => [
'cmsdef' => [
['name' => 'cm1'],
@@ -734,10 +786,21 @@ final class course_navigation_test extends route_testcase {
'type' => 'course',
],
];
yield 'With last module without url (student)' => [
yield 'With last module without url in the first section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 0]],
['name' => 'cm2', 'type' => 'label', 'options' => ['section' => 0]],
],
'current' => 'cm1',
'expected' => [
'type' => 'section',
'id' => '1',
],
];
yield 'With last module without url in the last section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 2]],
['name' => 'cm2', 'type' => 'label'],
['name' => 'cm2', 'type' => 'label', 'options' => ['section' => 2]],
],
'current' => 'cm1',
'expected' => [
@@ -889,7 +952,7 @@ final class course_navigation_test extends route_testcase {
],
'current' => 'cm2',
'expected' => [
'id' => 'cm1', // Students cannot see stealth modules in the course page.
'id' => 'cm1',
],
'role' => 'teacher',
];
@@ -1439,6 +1502,17 @@ final class course_navigation_test extends route_testcase {
'type' => 'course',
],
];
yield 'First activity of a section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'options' => ['section' => 1]],
['name' => 'cm2', 'options' => ['section' => 1]],
],
'current' => 'cm1',
'expected' => [
'type' => 'section',
'id' => '1',
],
];
yield 'With first module without url in the first section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'type' => 'label'],
@@ -1449,9 +1523,9 @@ final class course_navigation_test extends route_testcase {
'type' => 'course',
],
];
yield 'With first module without url (student)' => [
yield 'With first module without url in the last section (student)' => [
'cmsdef' => [
['name' => 'cm1', 'type' => 'label'],
['name' => 'cm1', 'type' => 'label', 'options' => ['section' => 2]],
['name' => 'cm2', 'options' => ['section' => 2]],
],
'current' => 'cm2',