Merge branch 'MDL-72387-master' of git://github.com/aanabit/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2021-09-20 23:23:24 +02:00
commit 0f04ec2ef6
5 changed files with 72 additions and 10 deletions

View File

@ -80,9 +80,12 @@ class header implements renderable, templatable {
// Regular section title.
$data->title = $output->section_title_without_link($section, $course);
$data->issinglesection = true;
} else {
} else if ($section->uservisible) {
// Regular section title.
$data->title = $output->section_title($section, $course);
} else {
// Regular section title without link.
$data->title = $output->section_title_without_link($section, $course);
}
if (!$section->visible) {
@ -92,7 +95,9 @@ class header implements renderable, templatable {
$coursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE;
if (!$format->show_editor() && $coursedisplay == COURSE_DISPLAY_MULTIPAGE && empty($data->issinglesection)) {
$data->url = course_get_url($course, $section->section);
if ($section->uservisible) {
$data->url = course_get_url($course, $section->section);
}
$data->name = get_section_name($course, $section);
}

View File

@ -80,7 +80,7 @@ class sectionnavigation implements renderable, templatable {
$sections = $modinfo->get_section_info_all();
// FIXME: This is really evil and should by using the navigation API.
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER) || !$course->hiddensections;
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER);
$data = (object)[
'previousurl' => '',

View File

@ -82,9 +82,8 @@ class sectionselector implements renderable, templatable {
$numsections = $format->get_last_section_number();
while ($section <= $numsections) {
$thissection = $modinfo->get_section_info($section);
$showsection = $thissection->uservisible || !$course->hiddensections;
$url = course_get_url($course, $section);
if ($showsection && $url && $section != $data->currentsection) {
if ($thissection->uservisible && $url && $section != $data->currentsection) {
$sectionmenu[$url->out(false)] = get_section_name($course, $section);
}
$section++;

View File

@ -801,8 +801,7 @@ abstract class section_renderer extends core_course_renderer {
$numsections = course_get_format($course)->get_last_section_number();
while ($section <= $numsections) {
$thissection = $modinfo->get_section_info($section);
$showsection = $thissection->uservisible or !$course->hiddensections;
if (($showsection) && ($section != $displaysection) && ($url = course_get_url($course, $section))) {
if (($thissection->uservisible) && ($section != $displaysection) && ($url = course_get_url($course, $section))) {
$sectionmenu[$url->out(false)] = get_section_name($course, $section);
}
$section++;

View File

@ -4,8 +4,7 @@ Feature: Show/hide course sections
As a teacher
I need to show or hide sections
@javascript
Scenario: Show / hide section icon functions correctly
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
@ -43,7 +42,10 @@ Feature: Show/hide course sections
| Forum name | Test hidden forum 32 name |
| Description | Test hidden forum 32 description |
| Availability | Show on course page |
And I am on "Course 1" course homepage
@javascript
Scenario: Show / hide section icon functions correctly
Given I am on "Course 1" course homepage
When I hide section "1"
Then section "1" should be hidden
And section "2" should be visible
@ -70,3 +72,60 @@ Feature: Show/hide course sections
And section "2" should be visible
And section "3" should be hidden
And all activities in section "1" should be hidden
@javascript
Scenario: Students can not navigate to hidden sections
Given I am on "Course 1" course homepage
And I hide section "2"
Given I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Course layout | Show one section per page |
And I press "Save and display"
When I click on "Topic 1" "link" in the "region-main" "region"
Then I should see "Topic 2" in the "region-main" "region"
And I click on "Topic 2" "link" in the "region-main" "region"
And I should see "Topic 1" in the "region-main" "region"
And I should see "Topic 3" in the "region-main" "region"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I click on "Topic 1" "link" in the "region-main" "region"
And I should not see "Topic 2" in the "region-main" "region"
And I should see "Topic 3" in the "region-main" "region"
And I click on "Topic 3" "link" in the "region-main" "region"
And I should not see "Topic 2" in the "region-main" "region"
And I should see "Topic 1" in the "region-main" "region"
@javascript
Scenario: Students can not navigate to restricted sections
Given I am on "Course 1" course homepage
Given I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Course layout | Show one section per page |
| Enable completion tracking | Yes |
And I press "Save and display"
And I add a "Label" to section "1" and I fill the form with:
| Label text | Test label |
| Completion tracking | Students can manually mark the activity as completed |
And I edit the section "2"
And I expand all fieldsets
And I click on "Add restriction..." "button"
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I set the following fields to these values:
| cm | Test label |
| Required completion status | must be marked complete |
And I press "Save changes"
When I click on "Topic 1" "link" in the "region-main" "region"
Then I should see "Topic 2" in the "region-main" "region"
And I click on "Topic 2" "link" in the "region-main" "region"
And I should see "Topic 1" in the "region-main" "region"
And I should see "Topic 3" in the "region-main" "region"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I click on "Topic 1" "link" in the "region-main" "region"
And I should not see "Topic 2" in the "region-main" "region"
And I should see "Topic 3" in the "region-main" "region"
And I click on "Topic 3" "link" in the "region-main" "region"
And I should not see "Topic 2" in the "region-main" "region"
And I should see "Topic 1" in the "region-main" "region"