From 06872a4ebd70886fd898e32b1edc60b22498af30 Mon Sep 17 00:00:00 2001 From: Stephan Robotta Date: Thu, 23 Feb 2023 21:00:42 +0100 Subject: [PATCH] MDL-77392 calendar: calendar items are hidden because of settings --- calendar/lib.php | 4 +- calendar/tests/behat/calender_filter.feature | 75 ++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 calendar/tests/behat/calender_filter.feature diff --git a/calendar/lib.php b/calendar/lib.php index bf5f15c279f..061fa8daf43 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -2592,7 +2592,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; @@ -2615,7 +2615,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) { diff --git a/calendar/tests/behat/calender_filter.feature b/calendar/tests/behat/calender_filter.feature new file mode 100644 index 00000000000..7266720fc7f --- /dev/null +++ b/calendar/tests/behat/calender_filter.feature @@ -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"