From abf8debd532b1bcfdf67ea111fcce6fd50e5dc22 Mon Sep 17 00:00:00 2001 From: Matt Davidson Date: Mon, 16 Dec 2024 13:16:42 -0500 Subject: [PATCH] Attempt to improve testing and comments. --- classes/actions.php | 6 ++++-- tests/behat/actions.feature | 25 ++++++++++++++++++++++--- tests/massaction_test.php | 26 ++++++++++++++------------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/classes/actions.php b/classes/actions.php index e699a5b..367154e 100644 --- a/classes/actions.php +++ b/classes/actions.php @@ -99,7 +99,7 @@ public static function set_visibility(array $modules, bool $visible, bool $visib $visibleint = $visible ? 1 : 0; $visibleonpageint = $visibleonpage ? 1 : 0; - // Stealth activies, if enabled are stored differently in visible and hidden sections. + // Stealth activities, if enabled, are stored differently in visible and hidden sections. // So we still need to do a little bit of extra work here. if ($visible && !$visibleonpage) { // We want to have an available but hidden activity. @@ -116,8 +116,10 @@ public static function set_visibility(array $modules, bool $visible, bool $visib $format = course_get_format($modinfo->get_course()); $cm = $modinfo->get_cm($cm->id); + // Modules in hidden sections cannot by definition be visible on the course page. $allowstealth = $format->allow_stealth_module_visibility($cm, $cm->get_section_info()); - $visibleonpageint = ($allowstealth) ? 0 : 1; + // Only modules in visible sections need a visibleonpage of 0. + $visibleonpageint = $allowstealth ? 0 : 1; } // Set visibility. diff --git a/tests/behat/actions.feature b/tests/behat/actions.feature index 9d22ae8..54bba7f 100644 --- a/tests/behat/actions.feature +++ b/tests/behat/actions.feature @@ -22,6 +22,9 @@ Feature: Check if all the different type of actions of the mass actions block wo | label | TC | 3 | Test Activity3 | Test Activity3 | 2 | | page | TC | 4 | Test Activity4 | Test page description4 | 4 | | assign | TC | 5 | Test Activity5 | Test page description5 | 4 | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | recent_activity | Course | TC | course-view-* | side-pre | When I log in as "teacher1" And I am on "Test course" course homepage with editing mode on And I add the "Mass Actions" block @@ -42,15 +45,31 @@ Feature: Check if all the different type of actions of the mass actions block wo And "Test Activity4" activity should be visible When I click on "Enable bulk editing" "button" And I click on "Test Activity1" "checkbox" - And I click on "Test Activity4" "checkbox" And I click on "Make available" "button" in the "Mass Actions" "block" Then I should see "Available but not shown on course page" in the "Test Activity1" "activity" + When I hide section "4" + And I click on "Enable bulk editing" "button" + And I click on "Test Activity4" "checkbox" + And I click on "Test Activity5" "checkbox" + And I click on "Make available" "button" in the "Mass Actions" "block" And I should see "Available but not shown on course page" in the "Test Activity4" "activity" + And I should see "Available but not shown on course page" in the "Test Activity5" "activity" + When I click on "Enable bulk editing" "button" + And I click on "Test Activity5" "checkbox" + And I click on "Hide" "button" in the "Mass Actions" "block" And I log out When I log in as "student1" And I am on "Test course" course homepage - Then I should not see "Test Activity1" - And I should not see "Test Activity4" + Then "Test Activity1" activity should be hidden + And "Test Activity4" activity should be hidden + And "Test Activity5" activity should be hidden + When I click on "Test Activity1" "link" in the "Recent activity" "block" + Then I should see "Test Activity1" + When I am on the "TC" "course" page logged in as student1 + And I click on "Test Activity4" "link" in the "Recent activity" "block" + Then I should see "Test Activity4" + When I am on the "TC" "course" page logged in as student1 + Then I should not see"Test Activity5" "link" in the "Recent activity" "block" @javascript Scenario: Check if mass action 'move to section' works diff --git a/tests/massaction_test.php b/tests/massaction_test.php index 1bbd945..c488de1 100644 --- a/tests/massaction_test.php +++ b/tests/massaction_test.php @@ -384,40 +384,42 @@ public function test_mass_hide_unhide_modules(): void { $CFG->allowstealth = 1; $moduleid = reset($selectedmoduleids); $module = get_fast_modinfo($this->course)->get_cm($moduleid); - $this->assertEquals(1, $module->visible); - $this->assertEquals(1, $module->visibleoncoursepage); + $this->assertEquals(1, $module->visible); // Visible in a visible section. + $this->assertEquals(1, $module->visibleoncoursepage); // Visible on course page in a visible section. // Hide section. set_section_visible($this->course->id, $module->sectionnum, 0); $module = get_fast_modinfo($this->course)->get_cm($moduleid); // After section has been hidden the course module should also be hidden. - $this->assertEquals(0, $module->visible); - $this->assertEquals(1, $module->visibleoncoursepage); - - // In case the section is hidden, moodle only knows 2 states only depending on the attribute 'visible': - // 'visible' => 1 means that module is 'available, but not visible on course page', - // 'visible' => 0 means that module is completely hidden. + $this->assertEquals(0, $module->visible); // Hidden in a hidden section. + // Hidden on module in a hidden section: visibleoncoursepage can be 1 or 0. + // Makes no difference so we don't need to test it. - // Try to set it visible. + // Set module in a hidden section to be visible (defaults to available). actions::set_visibility([$module], true); $module = get_fast_modinfo($this->course)->get_cm($moduleid); // The section is still hidden, so instead it should be set to 'available, but not visible on course page'. $this->assertEquals(1, $module->visible); - $this->assertEquals(1, $module->visibleoncoursepage); + $this->assertEquals(1, $module->visibleoncoursepage); // Seems strange but this is how it works. + // Set module in a hidden section to be hidden. actions::set_visibility([$module], false); $module = get_fast_modinfo($this->course)->get_cm($moduleid); // We make sure the module is completely hidden again. $this->assertEquals(0, $module->visible); - $this->assertEquals(1, $module->visibleoncoursepage); + // Hidden on module in a hidden section: visibleoncoursepage can be 1 or 0. + // Makes no difference so we don't need to test it. // Now we use the 'make available' feature for setting it to 'available, but not visible on course page'. + // If modules in hidden sections have visible = 1 and visibleoncoursepage = 0, it will show an available tag on + // the course page, but when editing the module it will show the Availability as "Hide on the course page". actions::set_visibility([$module], true, false); $module = get_fast_modinfo($this->course)->get_cm($moduleid); $this->assertEquals(1, $module->visible); - $this->assertEquals(1, $module->visibleoncoursepage); + $this->assertEquals(1, $module->visibleoncoursepage); // Seems strange but this is how it works. // Just to doublecheck that a visible section behaves differently. + // Available modules in visible sections are not visible on course page. set_section_visible($this->course->id, $module->sectionnum, 1); actions::set_visibility([$module], true, false); $module = get_fast_modinfo($this->course)->get_cm($moduleid);