Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 3259 lines (143 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

externallib_test:: (58 methods):
  setUp()
  create_calendar_event()
  test_create_calendar_events()
  test_delete_calendar_events()
  test_get_calendar_events()
  test_get_calendar_events_with_mathjax()
  test_core_create_calendar_events()
  test_get_calendar_action_events_by_timesort_after_time()
  test_get_calendar_action_events_by_timesort_before_time()
  test_get_calendar_events_override()
  test_get_calendar_action_events_by_timesort_time_range()
  test_get_calendar_action_events_by_timesort_time_limit_offset()
  test_get_calendar_action_events_by_timesort_suspended_course()
  test_get_calendar_action_events_by_timesort_for_other_users()
  test_get_calendar_action_events_by_course_after_time()
  test_get_calendar_action_events_by_course_before_time()
  test_get_calendar_action_events_by_course_time_range()
  test_get_calendar_action_events_by_course_time_limit_offset()
  test_get_calendar_action_events_by_course_with_search()
  test_get_action_events_by_courses()
  test_get_action_events_by_courses_with_search()
  test_delete_calendar_events_for_modules()
  test_update_event_start_day()
  test_update_event_start_day_no_permission()
  test_update_event_start_day_module_event()
  test_submit_create_update_form_validation_error()
  test_submit_create_update_form_create_user_event()
  test_submit_create_update_form_create_user_event_no_permission()
  test_submit_create_update_form_create_site_event()
  test_submit_create_update_form_create_site_event_no_permission()
  test_submit_create_update_form_create_course_event()
  test_submit_create_update_form_create_course_event_no_permission()
  test_submit_create_update_form_create_course_event_not_enrolled()
  test_submit_create_update_form_create_group_event_group_member_manage_course()
  test_submit_create_update_form_create_group_event_group_member_manage_group_entries()
  test_submit_create_update_form_create_group_event_access_all_groups()
  test_submit_create_update_form_create_group_event_non_member_no_permission()
  test_get_calendar_monthly_view_no_course_permission()
  test_get_calendar_monthly_view_with_day_provided()
  test_get_calendar_day_view_no_course_permission()
  test_get_calendar_upcoming_view_no_course_permission()
  test_get_calendar_event_by_id_no_course_permission()
  get_calendar_event_by_id_prevent_read_other_users_events_data_provider()
  test_get_calendar_event_by_id_prevent_read_other_users_events()
  edit_or_delete_other_users_events_data_provider()
  test_delete_other_users_events()
  test_edit_other_users_events()
  test_get_calendar_events_hidden_category()
  test_get_calendar_access_information_for_admins()
  test_get_calendar_access_information_for_authenticated_users()
  test_get_calendar_access_information_for_student_users()
  test_get_calendar_access_information_for_teacher_users()
  test_get_allowed_event_types_for_admins()
  test_get_allowed_event_types_for_authenticated_users()
  test_get_allowed_event_types_for_student_users()
  test_get_allowed_event_types_for_teacher_users()
  test_get_timestamps_string_keys()
  test_get_timestamps_no_keys()


Class: externallib_test  - X-Ref

External course functions unit tests

setUp()   X-Ref
Tests set up


create_calendar_event($name, $userid = 0, $type = 'user', $repeats = 0, $timestart = null, $prop = null)   X-Ref
No description

test_create_calendar_events()   X-Ref
No description

test_delete_calendar_events()   X-Ref
Test delete_calendar_events


test_get_calendar_events()   X-Ref
Test get_calendar_events


test_get_calendar_events_with_mathjax()   X-Ref
Test get_calendar_events with mathjax in the name.


test_core_create_calendar_events()   X-Ref
Test core_calendar_external::create_calendar_events


test_get_calendar_action_events_by_timesort_after_time()   X-Ref
Requesting calendar events from a given time should return all events with a sort
time at or after the requested time. All events prior to that time should not
be return.

If there are no events on or after the given time then an empty result set should
be returned.

test_get_calendar_action_events_by_timesort_before_time()   X-Ref
Requesting calendar events before a given time should return all events with a sort
time at or before the requested time (inclusive). All events after that time
should not be returned.

If there are no events before the given time then an empty result set should be
returned.

test_get_calendar_events_override()   X-Ref
Test retrieving event that was overridden for a user


test_get_calendar_action_events_by_timesort_time_range()   X-Ref
Requesting calendar events within a given time range should return all events with
a sort time between the lower and upper time bound (inclusive).

If there are no events in the given time range then an empty result set should be
returned.

test_get_calendar_action_events_by_timesort_time_limit_offset()   X-Ref
Requesting calendar events within a given time range and a limit and offset should return
the number of events up to the given limit value that have a sort time between the lower
and uppper time bound (inclusive) where the result set is shifted by the offset value.

If there are no events in the given time range then an empty result set should be
returned.

test_get_calendar_action_events_by_timesort_suspended_course()   X-Ref
Check that it is possible to restrict the calendar events to events where the user is not suspended in the course.


test_get_calendar_action_events_by_timesort_for_other_users()   X-Ref
Check that it is possible to get other user's events without the permission.


test_get_calendar_action_events_by_course_after_time()   X-Ref
Requesting calendar events from a given course and time should return all
events with a sort time at or after the requested time. All events prior
to that time should not be return.

If there are no events on or after the given time then an empty result set should
be returned.

test_get_calendar_action_events_by_course_before_time()   X-Ref
Requesting calendar events for a course and before a given time should return
all events with a sort time at or before the requested time (inclusive). All
events after that time should not be returned.

If there are no events before the given time then an empty result set should be
returned.

test_get_calendar_action_events_by_course_time_range()   X-Ref
Requesting calendar events for a course and within a given time range should
return all events with a sort time between the lower and upper time bound
(inclusive).

If there are no events in the given time range then an empty result set should be
returned.

test_get_calendar_action_events_by_course_time_limit_offset()   X-Ref
Requesting calendar events for a course and within a given time range and a limit
and offset should return the number of events up to the given limit value that have
a sort time between the lower and uppper time bound (inclusive) where the result
set is shifted by the offset value.

If there are no events in the given time range then an empty result set should be
returned.

test_get_calendar_action_events_by_course_with_search()   X-Ref
Test get_calendar_action_events_by_course with search feature


test_get_action_events_by_courses()   X-Ref
Test that get_action_events_by_courses will return a list of events for each
course you provided as long as the user is enrolled in the course.


test_get_action_events_by_courses_with_search()   X-Ref
Test get_action_events_by_courses with search feature


test_delete_calendar_events_for_modules()   X-Ref
Test for deleting module events.


test_update_event_start_day()   X-Ref
Updating the event start day should change the date value but leave
the time of day unchanged.


test_update_event_start_day_no_permission()   X-Ref
A user should not be able to edit an event that they don't have
capabilities for.


test_update_event_start_day_module_event()   X-Ref
A user should not be able to update a module event.


test_submit_create_update_form_validation_error()   X-Ref
Submit a request where the time duration until is earlier than the time
start in order to get a validation error from the server.


test_submit_create_update_form_create_user_event()   X-Ref
A user with the moodle/calendar:manageownentries capability at the
system context should be able to create a user event.


test_submit_create_update_form_create_user_event_no_permission()   X-Ref
A user without the moodle/calendar:manageownentries capability at the
system context should not be able to create a user event.


test_submit_create_update_form_create_site_event()   X-Ref
A user with the moodle/calendar:manageentries capability at the
site course context should be able to create a site event.


test_submit_create_update_form_create_site_event_no_permission()   X-Ref
A user without the moodle/calendar:manageentries capability at the
site course context should not be able to create a site event.


test_submit_create_update_form_create_course_event()   X-Ref
A user that has the moodle/calendar:manageentries in a course that they
are enrolled in should be able to create a course event in that course.


test_submit_create_update_form_create_course_event_no_permission()   X-Ref
A user without the moodle/calendar:manageentries capability in a course
that they are enrolled in should not be able to create a course event in that course.


test_submit_create_update_form_create_course_event_not_enrolled()   X-Ref
A user should not be able to create an event for a course that they are
not enrolled in.


test_submit_create_update_form_create_group_event_group_member_manage_course()   X-Ref
A user should be able to create an event for a group that they are a member of in
a course in which they are enrolled and have the moodle/calendar:manageentries capability.


test_submit_create_update_form_create_group_event_group_member_manage_group_entries()   X-Ref
A user should be able to create an event for a group that they are a member of in
a course in which they are enrolled and have the moodle/calendar:managegroupentries capability.


test_submit_create_update_form_create_group_event_access_all_groups()   X-Ref
A user should be able to create an event for any group in a course in which
they are enrolled and have the moodle/site:accessallgroups capability.


test_submit_create_update_form_create_group_event_non_member_no_permission()   X-Ref
A user should not be able to create an event for any group that they are not a
member of in a course in which they are enrolled but don't have the
moodle/site:accessallgroups capability.


test_get_calendar_monthly_view_no_course_permission()   X-Ref
A user should not be able load the calendar monthly view for a course they cannot access.


test_get_calendar_monthly_view_with_day_provided()   X-Ref
Test get_calendar_monthly_view when a day parameter is provided.


test_get_calendar_day_view_no_course_permission()   X-Ref
A user should not be able load the calendar day view for a course they cannot access.


test_get_calendar_upcoming_view_no_course_permission()   X-Ref
A user should not be able load the calendar upcoming view for a course they cannot access.


test_get_calendar_event_by_id_no_course_permission()   X-Ref
A user should not be able load the calendar event for a course they cannot access.


get_calendar_event_by_id_prevent_read_other_users_events_data_provider()   X-Ref
User data for testing reading calendar events.

return: array

test_get_calendar_event_by_id_prevent_read_other_users_events(bool $isadminevent, bool $isadmin, ?\stdClass $readerrolecontext,?string $readerrolename, bool $expectexception)   X-Ref
Prevent user from reading other user's event.

param: bool          $isadminevent      Is admin's event
param: bool          $isadmin           Is current user admin user
param: null|stdClass $readerrolecontext Reader role context
param: null|string   $readerrolename    Role name
param: bool          $expectexception   Should the test throw exception

edit_or_delete_other_users_events_data_provider()   X-Ref
User data for testing editing or deleting calendar events.

return: array

test_delete_other_users_events(bool $isadmin, bool $isadminevent,?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception)   X-Ref
Test the behavior of deleting other users' user events.

param: bool          $isadmin Whether the current user is admin.
param: bool          $isadminevent Whether it's an admin event or not.
param: stdClass|null $writerrolecontext The reader role context.
param: string|null   $writerrolename The role name.
param: bool          $expectexception Whether the test should throw an exception or not.

test_edit_other_users_events(bool $isadmin, bool $isadminevent,?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception)   X-Ref
Test the behavior of editing other users' user events

param: bool          $isadmin Whether the current user is admin.
param: bool          $isadminevent Whether it's an admin event or not.
param: stdClass|null $writerrolecontext The reader role context.
param: string|null   $writerrolename The role name.
param: bool          $expectexception Whether the test should throw an exception or not.

test_get_calendar_events_hidden_category()   X-Ref
A user should not be able load the calendar events for a category they cannot see.


test_get_calendar_access_information_for_admins()   X-Ref
Test get_calendar_access_information for admins.


test_get_calendar_access_information_for_authenticated_users()   X-Ref
Test get_calendar_access_information for authenticated users.


test_get_calendar_access_information_for_student_users()   X-Ref
Test get_calendar_access_information for student users.


test_get_calendar_access_information_for_teacher_users()   X-Ref
Test get_calendar_access_information for teacher users.


test_get_allowed_event_types_for_admins()   X-Ref
Test get_allowed_event_types for admins.


test_get_allowed_event_types_for_authenticated_users()   X-Ref
Test get_allowed_event_types for authenticated users.


test_get_allowed_event_types_for_student_users()   X-Ref
Test get_allowed_event_types for student users.


test_get_allowed_event_types_for_teacher_users()   X-Ref
Test get_allowed_event_types for teacher users.


test_get_timestamps_string_keys()   X-Ref
Test get_timestamps with string keys, with and without optional hour/minute values.


test_get_timestamps_no_keys()   X-Ref
Test get_timestamps with no keys specified, with and without optional hour/minute values.