Skip to content

Commit

Permalink
Attempt to improve testing and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syxton committed Dec 16, 2024
1 parent 126036c commit 43f7370
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
6 changes: 4 additions & 2 deletions classes/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions tests/behat/actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 | C1 | 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
Expand All @@ -42,6 +45,9 @@ 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 "Make available" "button" in the "Mass Actions" "block"
When I hide section "4"
And I click on "Enable bulk editing" "button"
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"
Expand All @@ -51,6 +57,12 @@ Feature: Check if all the different type of actions of the mass actions block wo
And I am on "Test course" course homepage
Then I should not see "Test Activity1"
And I should not see "Test Activity4"
And I should not see "Test Activity5"
And I click on "Test Activity1" "link" in the "Recent activity" "block"
And I should see "Test Activity1"
And I click on "Test Activity4" "link" in the "Recent activity" "block"
And I should see "Test Activity4"
And I should not see"Test Activity5" "link" in the "Recent activity" "block"

@javascript
Scenario: Check if mass action 'move to section' works
Expand Down
26 changes: 14 additions & 12 deletions tests/massaction_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 43f7370

Please sign in to comment.