MDL-77392 calendar: calendar items are hidden because of settings

This commit is contained in:
Stephan Robotta 2023-03-14 16:18:00 +01:00
parent 0b973b52e9
commit 66e88ace0f
2 changed files with 77 additions and 2 deletions

View File

@ -2580,7 +2580,7 @@ function calendar_format_event_location(calendar_event $event): string {
function calendar_show_event_type($type, $user = null) {
$default = CALENDAR_EVENT_SITE + CALENDAR_EVENT_COURSE + CALENDAR_EVENT_GROUP + CALENDAR_EVENT_USER;
if (get_user_preferences('calendar_persistflt', 0, $user) === 0) {
if ((int)get_user_preferences('calendar_persistflt', 0, $user) === 0) {
global $SESSION;
if (!isset($SESSION->calendarshoweventtype)) {
$SESSION->calendarshoweventtype = $default;
@ -2603,7 +2603,7 @@ function calendar_show_event_type($type, $user = null) {
* @param stdClass|int $user moodle user object or id, null means current user
*/
function calendar_set_event_type_display($type, $display = null, $user = null) {
$persist = get_user_preferences('calendar_persistflt', 0, $user);
$persist = (int)get_user_preferences('calendar_persistflt', 0, $user);
$default = CALENDAR_EVENT_SITE + CALENDAR_EVENT_COURSE + CALENDAR_EVENT_GROUP
+ CALENDAR_EVENT_USER + CALENDAR_EVENT_COURSECAT;
if ($persist === 0) {

View File

@ -0,0 +1,75 @@
@core @core_calendar @javascript
Feature: Perform calendar filter actions
In order to test the calendar filters with preselected options
As a user
I need to filter calendar events by certain criteria
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "categories" exist:
| name | idnumber | category |
| Year | year | |
| Department C1 | department-c1 | year |
And the following "courses" exist:
| fullname | shortname | format | category |
| Course 1 | C1 | topics | department-c1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "groups" exist:
| name | course | idnumber |
| Group 1 | C1 | G1 |
And the following "group members" exist:
| user | group |
| teacher1 | G1 |
And the following "events" exist:
| name | eventtype |
| Site event | site |
And the following "events" exist:
| name | eventtype | course |
| C1 event | course | C1 |
And the following "events" exist:
| name | eventtype | category |
| Dep1a event | category | department-c1 |
And the following "events" exist:
| name | eventtype | group | course |
| Group1 event | group | G1 | C1 |
Scenario: Teacher of a Course can see his events and filter them
Given I log in as "teacher1"
When I follow "Calendar" in the user menu
Then I should see "C1 event"
And I should see "Dep1a event"
And I should see "Group1 event"
And I click on "Hide category events" "link"
And I should see "C1 event"
And I should not see "Dep1a event"
And I should see "Group1 event"
And I click on "Hide course events" "link"
And I should not see "C1 event"
And I should not see "Dep1a event"
And I should see "Group1 event"
Scenario: Teacher of a Course can see only non filtered events from user preferences calendar_savedflt
Given I log in as "teacher1"
And the following "user preferences" exist:
| user | preference | value |
| teacher1 | calendar_persistflt | 1 |
| teacher1 | calendar_savedflt | 13 |
When I follow "Calendar" in the user menu
Then I should not see "C1 event"
And I should see "Dep1a event"
And I should not see "Group1 event"
Scenario: Teacher of a Course can see all events because session is used and not user preference calendar_savedflt
Given I log in as "teacher1"
And the following "user preferences" exist:
| user | preference | value |
| teacher1 | calendar_persistflt | 0 |
| teacher1 | calendar_savedflt | 13 |
When I follow "Calendar" in the user menu
Then I should see "C1 event"
And I should see "Dep1a event"
And I should see "Group1 event"