Skip to content

Commit

Permalink
Merge branch 'MDL-72387-master' of git://github.com/aanabit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Sep 20, 2021
2 parents 9c6489d + 5c54b1a commit 0f04ec2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
9 changes: 7 additions & 2 deletions course/format/classes/output/local/content/section/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ public function export_for_template(\renderer_base $output): stdClass {
// 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) {
Expand All @@ -92,7 +95,9 @@ public function export_for_template(\renderer_base $output): stdClass {
$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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function export_for_template(\renderer_base $output): stdClass {
$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' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public function export_for_template(\renderer_base $output): stdClass {
$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++;
Expand Down
3 changes: 1 addition & 2 deletions course/format/classes/output/section_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,7 @@ protected function section_nav_selection($course, $sections, $displaysection) {
$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++;
Expand Down
65 changes: 62 additions & 3 deletions course/tests/behat/section_visibility.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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
Expand All @@ -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"

0 comments on commit 0f04ec2

Please sign in to comment.