diff --git a/course/format/classes/sectiondelegatemodule.php b/course/format/classes/sectiondelegatemodule.php index 39cc4af4c64..4834d17ac73 100644 --- a/course/format/classes/sectiondelegatemodule.php +++ b/course/format/classes/sectiondelegatemodule.php @@ -177,6 +177,11 @@ abstract class sectiondelegatemodule extends sectiondelegate { $cmrecord['availability'] = $sectionrecord->availability; } + if (isset($sectionrecord->visible) && $sectionrecord->visible !== $this->cm->visible) { + $cmrecord['visible'] = $sectionrecord->visible; + $cmrecord['visibleold'] = $sectionrecord->visible; + } + if (empty($cmrecord)) { return; } diff --git a/course/format/tests/behat/section_visibility.feature b/course/format/tests/behat/section_visibility.feature index c4b7cef1ff9..125d059d4a4 100644 --- a/course/format/tests/behat/section_visibility.feature +++ b/course/format/tests/behat/section_visibility.feature @@ -1,5 +1,5 @@ @core @core_courseformat -Feature: Varify section visibility interface +Feature: Verify section visibility interface In order to edit the course sections visibility As a teacher I need to be able to see the updated visibility information diff --git a/lib/behat/classes/partial_named_selector.php b/lib/behat/classes/partial_named_selector.php index 89dcc36772e..4ca9f59258b 100644 --- a/lib/behat/classes/partial_named_selector.php +++ b/lib/behat/classes/partial_named_selector.php @@ -265,6 +265,9 @@ XPATH .//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h3] [normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] | +.//li[contains(concat(' ', normalize-space(@class), ' '), ' section ')][./descendant::*[self::h4] + [normalize-space(.) = %locator%][contains(concat(' ', normalize-space(@class), ' '), ' sectionname ') or + contains(concat(' ', normalize-space(@class), ' '), ' section-title ')]] | .//div[contains(concat(' ', normalize-space(@class), ' '), ' sitetopic ')] [./descendant::*[self::h2][normalize-space(.) = %locator%] or %locator% = 'frontpage'] XPATH diff --git a/mod/subsection/lib.php b/mod/subsection/lib.php index 8c1fa4d7dbf..bc1a38cc953 100644 --- a/mod/subsection/lib.php +++ b/mod/subsection/lib.php @@ -78,6 +78,7 @@ function subsection_add_instance($moduleinstance, $mform = null) { $id, (object)[ 'name' => $moduleinstance->name, + 'visible' => $moduleinstance->visible, 'availability' => $cmavailability, ] ); diff --git a/mod/subsection/tests/behat/subsection_visibility.feature b/mod/subsection/tests/behat/subsection_visibility.feature new file mode 100644 index 00000000000..5d2c5b7ef23 --- /dev/null +++ b/mod/subsection/tests/behat/subsection_visibility.feature @@ -0,0 +1,60 @@ +@mod @mod_subsection +Feature: Subsection visibility should work as a module + In order to hide and show subsections + As a teacher + I need subsections to behave as any other module + + Background: + Given I enable "subsection" "mod" plugin + And the following "course" exists: + | fullname | Course 1 | + | shortname | C1 | + | category | 0 | + | numsections | 2 | + | initsections | 1 | + And the following "users" exist: + | username | firstname | lastname | + | teacher1 | Teacher | 1 | + | student1 | Student | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + + @javascript + Scenario: Subsections created on a hidden section behave like a normal module when parent visibility is toggled + Given I should not see "Hidden from student" + When I hide section "Section 1" + And I should see "Hidden from students" in the "Section 1" "section" + # We cannot use generators because they don't check the parent section visibility. + And I add a subsection activity to course "Course 1" section "1" and I fill the form with: + | Name | Subsection 1 | + And I add a assign activity to course "Course 1" section "1" and I fill the form with: + | Assignment name | Hidden assignment name | + | ID number | assign1 | + | Description | Hidden assignment description | + | assignsubmission_onlinetext_enabled | 1 | + Then I should see "Hidden from students" in the "Subsection 1" "section" + And I should see "Hidden from students" in the "Hidden assignment name" "activity" + And I show section "Section 1" + And I should see "Hidden from students" in the "Subsection 1" "section" + And I should see "Hidden from students" in the "Hidden assignment name" "activity" + + @javascript + Scenario: Subsections created on a visible section behave like a normal module when parent visibility is toggled + Given I should not see "Hidden from student" + And the following "activities" exist: + | activity | name | course | idnumber | section | + | subsection | Subsection 1 | C1 | subsection1 | 1 | + | page | Page 1 | C1 | page1 | 1 | + When I am on "Course 1" course homepage + And I should not see "Hidden from students" in the "Subsection 1" "section" + And I should not see "Hidden from students" in the "Page 1" "activity" + Then I hide section "Section 1" + And I should see "Hidden from students" in the "Subsection 1" "section" + And I should see "Hidden from students" in the "Page 1" "activity" + And I show section "Section 1" + And I should not see "Hidden from students" in the "Subsection 1" "section" + And I should not see "Hidden from students" in the "Page 1" "activity"