From b4f62d2426390d6ea4cb692749372b807a1da6c8 Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Wed, 23 Mar 2022 17:13:20 +0100 Subject: [PATCH] MDL-74257 core_courseforrmat: fix make available badge --- course/format/classes/base.php | 27 ++++++++-- .../tests/behat/section_visibility.feature | 51 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 course/format/tests/behat/section_visibility.feature diff --git a/course/format/classes/base.php b/course/format/classes/base.php index c75c95946e2..9824ee90220 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -217,6 +217,7 @@ abstract class base { // In case somebody keeps the reference to course format object. self::$instances[$courseid][$format]->course = false; self::$instances[$courseid][$format]->formatoptions = array(); + self::$instances[$courseid][$format]->modinfo = null; } unset(self::$instances[$courseid]); } @@ -1639,9 +1640,30 @@ abstract class base { throw new moodle_exception('sectionactionnotsupported', 'core', null, s($action)); } + return ['modules' => $this->get_section_modules_updated($section)]; + } + + /** + * Return an array with all section modules content. + * + * This method is used in section_action method to generate the updated modules content + * after a modinfo change. + * + * @param section_info $section the section + * @return string[] the full modules content. + */ + protected function get_section_modules_updated(section_info $section): array { + global $PAGE; + $modules = []; - // Load the cmlist output. + if (!$this->uses_sections() || !$section->section) { + return $modules; + } + + // Load the cmlist output from the updated modinfo. + $renderer = $this->get_renderer($PAGE); + $modinfo = $this->get_modinfo(); $coursesections = $modinfo->sections; if (array_key_exists($section->section, $coursesections)) { foreach ($coursesections[$section->section] as $cmid) { @@ -1649,8 +1671,7 @@ abstract class base { $modules[] = $renderer->course_section_updated_cm_item($this, $section, $cm); } } - - return ['modules' => $modules]; + return $modules; } /** diff --git a/course/format/tests/behat/section_visibility.feature b/course/format/tests/behat/section_visibility.feature new file mode 100644 index 00000000000..e6538564363 --- /dev/null +++ b/course/format/tests/behat/section_visibility.feature @@ -0,0 +1,51 @@ +@core @core_courseformat +Feature: Varify section visibility interface. + In order to edit the course sections visibility + As a teacher + I need to be able to see the updateds visibility information + + Background: + Given the following "course" exists: + | fullname | Course 1 | + | shortname | C1 | + | category | 0 | + | numsections | 3 | + And the following "activities" exist: + | activity | name | intro | course | idnumber | section | + | assign | Activity sample 1 | Test assignment description | C1 | sample1 | 1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + Given I am on the "C1" "Course" page logged in as "teacher1" + And I turn editing mode on + + @javascript + Scenario: Activities available but not shown on course page only apply to hidden sections. + Given I hide section "1" + And I open "Activity sample 1" actions menu + And I click on "Make available" "link" in the "Activity sample 1" "activity" + And I should see "Available but not shown on course page" in the "Activity sample 1" "activity" + When I show section "1" + Then I should not see "Available but not shown on course page" in the "Activity sample 1" "activity" + + @javascript + Scenario: Hide a section also hides the activities. + When I hide section "1" + Then I should see "Hidden from students" in the "Topic 1" "section" + And I should see "Hidden from students" in the "Activity sample 1" "activity" + And I show section "1" + And I should not see "Hidden from students" in the "Topic 1" "section" + And I should not see "Hidden from students" in the "Activity sample 1" "activity" + + @javascript + Scenario: Hiden activities in hidden sections stay hidden when the section is shown. + Given I open "Activity sample 1" actions menu + And I click on "Hide" "link" in the "Activity sample 1" "activity" + And I should see "Hidden from students" in the "Activity sample 1" "activity" + And I hide section "1" + And I should see "Hidden from students" in the "Activity sample 1" "activity" + When I show section "1" + Then I should see "Hidden from students" in the "Activity sample 1" "activity"