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 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

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

Defines 1 class

courselib_test:: (128 methods):
  setUpBeforeClass()
  forum_create_set_values()
  forum_create_run_asserts()
  assign_create_set_values()
  assign_create_run_asserts()
  create_specific_module_test()
  create_module_asscociated_blog()
  test_create_module()
  test_update_module()
  forum_update_set_values()
  forum_update_run_asserts()
  update_specific_module_test()
  provider_course_delete_module()
  test_create_course()
  test_create_course_with_generator()
  test_create_course_sections()
  test_update_course()
  test_update_course_section_time_modified()
  create_course_relative_dates_provider()
  test_relative_dates_mode_for_course_creation()
  test_relative_dates_mode_for_course_update()
  test_course_add_cm_to_section()
  test_reorder_sections()
  test_move_section_down()
  test_move_section_up()
  test_move_section_marker()
  test_move_section_with_section_cache()
  test_move_section_to()
  test_course_can_delete_section()
  test_course_delete_section()
  test_get_course_display_name_for_list()
  test_move_module_in_course()
  test_module_visibility()
  test_module_visibility_no_rebuild()
  test_section_visibility_events()
  test_section_visibility()
  check_module_visibility()
  test_course_page_type_list()
  test_compare_activities_by_time_desc()
  test_compare_activities_by_time_asc()
  test_moveto_module_between_hidden_sections()
  test_moveto_module_in_same_section()
  test_course_delete_module()
  test_course_created_event()
  test_course_updated_event()
  test_course_updated_event_with_changes()
  test_course_deleted_event()
  test_course_content_deleted_event()
  test_course_category_deleted_event()
  test_course_backup_created_event()
  test_course_restored_event()
  test_course_section_updated_event()
  test_course_section_deleted_event()
  test_course_integrity_check()
  test_course_module_created_event()
  test_course_module_created_event_exceptions()
  test_course_module_updated_event()
  test_course_module_create_from_cm()
  test_course_module_updated_event_exceptions()
  test_course_module_deleted_event()
  test_course_module_deleted_event_exceptions()
  get_user_objects()
  test_course_change_sortorder_after_course()
  test_course_change_visibility()
  test_course_change_sortorder_by_one()
  test_view_resources_list()
  test_duplicate_module()
  test_empty_availability_settings()
  test_update_module_name_inplace()
  test_course_get_tagged_course_modules()
  test_course_get_user_navigation_options_for_frontpage()
  test_course_get_user_navigation_options_for_managers()
  test_course_get_user_navigation_options_for_students()
  test_course_get_user_administration_options_for_frontpage()
  test_course_get_user_administration_options_for_managers()
  test_course_get_user_administration_options_for_students()
  test_update_course_frontpage_category()
  test_course_enddate()
  course_enddate_provider()
  test_course_dates_reset()
  course_dates_reset_provider()
  test_course_roles_reset()
  test_course_check_module_updates_since()
  test_async_module_deletion_hook_implemented()
  test_async_module_deletion_hook_not_implemented()
  test_async_section_deletion_hook_implemented()
  test_async_section_deletion_hook_not_implemented()
  test_classify_course_for_timeline()
  test_course_module_calendar_event_update_process()
  test_course_module_update_calendar_events()
  test_course_module_bulk_update_calendar_events()
  test_course_can_view_participants_as_student()
  test_course_can_view_participants_as_student_on_site()
  test_course_can_view_participants_as_admin_on_site()
  test_course_can_view_participants_as_teacher()
  test_course_can_view_participants_as_teacher_without_view_participants_cap()
  test_course_can_view_participants_as_teacher_without_enrol_review_cap()
  test_course_can_view_participants_as_teacher_without_required_caps()
  test_course_require_view_participants()
  test_course_require_view_participants_as_student_on_site()
  test_can_download_from_backup_filearea()
  get_course_classify_courses_for_timeline_test_cases()
  test_course_classify_courses_for_timeline()
  get_course_get_enrolled_courses_for_logged_in_user_test_cases()
  test_course_get_enrolled_courses_for_logged_in_user()
  get_course_filter_courses_by_timeline_classification_test_cases()
  test_course_get_enrolled_courses_for_logged_in_user_from_search()
  test_course_filter_courses_by_timeline_classification()
  get_course_filter_courses_by_customfield_test_cases()
  test_course_filter_courses_by_customfield()
  get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases()
  test_course_filter_courses_by_timeline_classification_with_hidden_courses()
  test_core_course_core_calendar_get_valid_event_timestart_range_no_enddate()
  test_core_course_core_calendar_get_valid_event_timestart_range_with_enddate()
  test_course_get_recent_courses()
  test_course_get_recent_courses_sort_validation()
  course_get_recent_courses_sort_validation_provider()
  test_course_get_recent_courses_with_guest()
  get_course_get_course_dates_for_user_ids_test_cases()
  test_course_get_course_dates_for_user_ids()
  test_course_get_course_dates_for_user_ids_multiple_calls()
  provider_course_modules_pending_deletion()
  test_course_modules_pending_deletion()
  test_can_request_course()
  test_can_approve_course_request()
  test_course_allowed_module()
  test_average_number_of_participants()
  test_set_downloadcontent()


Class: courselib_test  - X-Ref

Course related unit tests

setUpBeforeClass()   X-Ref
Load required libraries and fixtures.


forum_create_set_values(&$moduleinfo)   X-Ref
Set forum specific test values for calling create_module().

param: object $moduleinfo - the moduleinfo to add some specific values - passed in reference.

forum_create_run_asserts($moduleinfo, $dbmodinstance)   X-Ref
Execute test asserts on the saved DB data by create_module($forum).

param: object $moduleinfo - the specific forum values that were used to create a forum.
param: object $dbmodinstance - the DB values of the created forum.

assign_create_set_values(&$moduleinfo)   X-Ref
Set assign module specific test values for calling create_module().

param: object $moduleinfo - the moduleinfo to add some specific values - passed in reference.

assign_create_run_asserts($moduleinfo, $dbmodinstance)   X-Ref
Execute test asserts on the saved DB data by create_module($assign).

param: object $moduleinfo - the specific assign module values that were used to create an assign module.
param: object $dbmodinstance - the DB values of the created assign module.

create_specific_module_test($modulename)   X-Ref
Run some asserts test for a specific module for the function create_module().

The function has been created (and is called) for $this->test_create_module().
Note that the call to MODULE_create_set_values and MODULE_create_run_asserts are done after the common set values/run asserts.
So if you want, you can overwrite the default values/asserts in the respective functions.
param: string $modulename Name of the module ('forum', 'assign', 'book'...).

create_module_asscociated_blog($course, $modulecontext)   X-Ref
Create module associated blog and tags.

param: object $course Course.
param: object $modulecontext The context of the module.

test_create_module()   X-Ref
Test create_module() for multiple modules defined in the $modules array (first declaration of the function).


test_update_module()   X-Ref
Test update_module() for multiple modules defined in the $modules array (first declaration of the function).


forum_update_set_values(&$moduleinfo)   X-Ref
Set forum specific test values for calling update_module().

param: object $moduleinfo - the moduleinfo to add some specific values - passed in reference.

forum_update_run_asserts($moduleinfo, $dbmodinstance)   X-Ref
Execute test asserts on the saved DB data by update_module($forum).

param: object $moduleinfo - the specific forum values that were used to update a forum.
param: object $dbmodinstance - the DB values of the updated forum.

update_specific_module_test($modulename)   X-Ref
Test a specific type of module.

param: string $modulename - the module name to test

provider_course_delete_module()   X-Ref
Data provider for course_delete module

return: array An array of arrays contain test data

test_create_course()   X-Ref
Test the create_course function


test_create_course_with_generator()   X-Ref
No description

test_create_course_sections()   X-Ref
No description

test_update_course()   X-Ref
No description

test_update_course_section_time_modified()   X-Ref
No description

create_course_relative_dates_provider()   X-Ref
Relative dates mode settings provider for course creation.


test_relative_dates_mode_for_course_creation($setting, $mode, $expectedvalue)   X-Ref
Test create_course by attempting to change the relative dates mode.

param: int $setting The value for the 'enablecourserelativedates' admin setting.
param: int $mode The value for the course's 'relativedatesmode' field.
param: int $expectedvalue The expected value of the 'relativedatesmode' field after course creation.

test_relative_dates_mode_for_course_update()   X-Ref
Test update_course by attempting to change the relative dates mode.


test_course_add_cm_to_section()   X-Ref
No description

test_reorder_sections()   X-Ref
No description

test_move_section_down()   X-Ref
No description

test_move_section_up()   X-Ref
No description

test_move_section_marker()   X-Ref
No description

test_move_section_with_section_cache()   X-Ref
Test move_section_to method with caching

return: void

test_move_section_to()   X-Ref
Test move_section_to method.
Make sure that we only update the moving sections, not all the sections in the current course.

return: void

test_course_can_delete_section()   X-Ref
No description

test_course_delete_section()   X-Ref
No description

test_get_course_display_name_for_list()   X-Ref
No description

test_move_module_in_course()   X-Ref
No description

test_module_visibility()   X-Ref
No description

test_module_visibility_no_rebuild()   X-Ref
Test rebuildcache = false behaviour.

When we pass rebuildcache = false to set_coursemodule_visible, the corusemodinfo cache will still contain
the original visibility until we trigger a rebuild.

return: void

test_section_visibility_events()   X-Ref
No description

test_section_visibility()   X-Ref
No description

check_module_visibility($mod, $visibility, $visibleold)   X-Ref
Helper function to assert that a module has correctly been made visible, or hidden.

param: stdClass $mod module information
param: int $visibility the current state of the module
param: int $visibleold the current state of the visibleold property
return: void

test_course_page_type_list()   X-Ref
No description

test_compare_activities_by_time_desc()   X-Ref
No description

test_compare_activities_by_time_asc()   X-Ref
No description

test_moveto_module_between_hidden_sections()   X-Ref
Tests moving a module between hidden/visible sections and
verifies that the course/module visiblity seettings are
retained.


test_moveto_module_in_same_section()   X-Ref
Tests moving a module around in the same section. moveto_module()
is called this way in modduplicate.


test_course_delete_module($type, $options)   X-Ref
Tests the function that deletes a course module

param: string $type The type of module for the test
param: array $options The options for the module creation

test_course_created_event()   X-Ref
Test that triggering a course_created event works as expected.


test_course_updated_event()   X-Ref
Test that triggering a course_updated event works as expected.


test_course_updated_event_with_changes()   X-Ref
Test that triggering a course_updated event logs changes.


test_course_deleted_event()   X-Ref
Test that triggering a course_deleted event works as expected.


test_course_content_deleted_event()   X-Ref
Test that triggering a course_content_deleted event works as expected.


test_course_category_deleted_event()   X-Ref
Test that triggering a course_category_deleted event works as expected.


test_course_backup_created_event()   X-Ref
Test that triggering a course_backup_created event works as expected.


test_course_restored_event()   X-Ref
Test that triggering a course_restored event works as expected.


test_course_section_updated_event()   X-Ref
Test that triggering a course_section_updated event works as expected.


test_course_section_deleted_event()   X-Ref
Test that triggering a course_section_deleted event works as expected.


test_course_integrity_check()   X-Ref
No description

test_course_module_created_event()   X-Ref
Tests for event related to course module creation.


test_course_module_created_event_exceptions()   X-Ref
Tests for event validations related to course module creation.


test_course_module_updated_event()   X-Ref
Tests for event related to course module updates.


test_course_module_create_from_cm()   X-Ref
Tests for create_from_cm method.


test_course_module_updated_event_exceptions()   X-Ref
Tests for event validations related to course module update.


test_course_module_deleted_event()   X-Ref
Tests for event related to course module delete.


test_course_module_deleted_event_exceptions()   X-Ref
Tests for event validations related to course module deletion.


get_user_objects(testing_data_generator $generator, $contextid)   X-Ref
Returns a user object and its assigned new role.

param: testing_data_generator $generator
param: $contextid
return: array The user object and the role ID

test_course_change_sortorder_after_course()   X-Ref
Test course move after course.


test_course_change_visibility()   X-Ref
Tests changing the visibility of a course.


test_course_change_sortorder_by_one()   X-Ref
Tests moving the course up and down by one.


test_view_resources_list()   X-Ref
No description

test_duplicate_module()   X-Ref
Test duplicate_module()


test_empty_availability_settings()   X-Ref
Tests that when creating or updating a module, if the availability settings
are present but set to an empty tree, availability is set to null in
database.


test_update_module_name_inplace()   X-Ref
Test update_inplace_editable()


test_course_get_tagged_course_modules()   X-Ref
Testing function course_get_tagged_course_modules - search tagged course modules


test_course_get_user_navigation_options_for_frontpage()   X-Ref
Test course_get_user_navigation_options for frontpage.


test_course_get_user_navigation_options_for_managers()   X-Ref
Test course_get_user_navigation_options for managers in a normal course.


test_course_get_user_navigation_options_for_students()   X-Ref
Test course_get_user_navigation_options for students in a normal course.


test_course_get_user_administration_options_for_frontpage()   X-Ref
Test course_get_user_administration_options for frontpage.


test_course_get_user_administration_options_for_managers()   X-Ref
Test course_get_user_administration_options for managers in a normal course.


test_course_get_user_administration_options_for_students()   X-Ref
Test course_get_user_administration_options for students in a normal course.


test_update_course_frontpage_category()   X-Ref
Test test_update_course_frontpage_category.


test_course_enddate($startdate, $enddate, $errorcode)   X-Ref
test_course_enddate

param: int $startdate
param: int $enddate
param: string $errorcode

course_enddate_provider()   X-Ref
Provider for test_course_enddate.

return: array

test_course_dates_reset($startdate, $enddate, $resetstartdate, $resetenddate, $resultingstartdate, $resultingenddate)   X-Ref
test_course_dates_reset

param: int $startdate
param: int $enddate
param: int $resetstartdate
param: int $resetenddate
param: int $resultingstartdate
param: int $resultingenddate

course_dates_reset_provider()   X-Ref
Provider for test_course_dates_reset.

return: array

test_course_roles_reset()   X-Ref
Test reset_course_userdata()
- with reset_roles_overrides enabled
- with selective role unenrolments


test_course_check_module_updates_since()   X-Ref
No description

test_async_module_deletion_hook_implemented()   X-Ref
No description

test_async_module_deletion_hook_not_implemented()   X-Ref
No description

test_async_section_deletion_hook_implemented()   X-Ref
No description

test_async_section_deletion_hook_not_implemented()   X-Ref
No description

test_classify_course_for_timeline()   X-Ref
No description

test_course_module_calendar_event_update_process()   X-Ref
Test the main function for updating all calendar events for a module.


test_course_module_update_calendar_events()   X-Ref
Test the higher level checks for updating calendar events for an instance.


test_course_module_bulk_update_calendar_events()   X-Ref
Test the higher level checks for updating calendar events for a module.


test_course_can_view_participants_as_student()   X-Ref
Test that a student can view participants in a course they are enrolled in.


test_course_can_view_participants_as_student_on_site()   X-Ref
Test that a student in a course can not view participants on the site.


test_course_can_view_participants_as_admin_on_site()   X-Ref
Test that an admin can view participants on the site.


test_course_can_view_participants_as_teacher()   X-Ref
Test teachers can view participants in a course they are enrolled in.


test_course_can_view_participants_as_teacher_without_view_participants_cap()   X-Ref
Check the teacher can still view the participants page without the 'viewparticipants' cap.


test_course_can_view_participants_as_teacher_without_enrol_review_cap()   X-Ref
Check the teacher can still view the participants page without the 'moodle/course:enrolreview' cap.


test_course_can_view_participants_as_teacher_without_required_caps()   X-Ref
Check the teacher can not view the participants page without the required caps.


test_course_require_view_participants()   X-Ref
Check that an exception is not thrown if we can view the participants page.


test_course_require_view_participants_as_student_on_site()   X-Ref
Check that an exception is thrown if we can't view the participants page.


test_can_download_from_backup_filearea()   X-Ref
Testing the can_download_from_backup_filearea fn.


get_course_classify_courses_for_timeline_test_cases()   X-Ref
Test cases for the course_classify_courses_for_timeline test.


test_course_classify_courses_for_timeline($coursesdata, $expected)   X-Ref
Test the course_classify_courses_for_timeline function.

param: array $coursesdata Courses to create
param: array $expected Expected test results.

get_course_get_enrolled_courses_for_logged_in_user_test_cases()   X-Ref
Test cases for the course_get_enrolled_courses_for_logged_in_user tests.


test_course_get_enrolled_courses_for_logged_in_user($dbquerylimit,$totalcourses,$limit,$offset,$expecteddbqueries,$expectedresult)   X-Ref
Test the course_get_enrolled_courses_for_logged_in_user function.

param: int $dbquerylimit Number of records to load per DB request
param: int $totalcourses Number of courses to create
param: int $limit Maximum number of results to get.
param: int $offset Skip this number of results from the start of the result set.
param: int $expecteddbqueries The number of DB queries expected during the test.
param: array $expectedresult Expected test results.

get_course_filter_courses_by_timeline_classification_test_cases()   X-Ref
Test cases for the course_filter_courses_by_timeline_classification tests.


test_course_get_enrolled_courses_for_logged_in_user_from_search()   X-Ref
Test the course_get_enrolled_courses_for_logged_in_user_from_search function.


test_course_filter_courses_by_timeline_classification($coursedata,$classification,$limit,$offset,$expectedcourses,$expectedprocessedcount)   X-Ref
Test the course_filter_courses_by_timeline_classification function.

param: array $coursedata Course test data to create.
param: string $classification Timeline classification.
param: int $limit Maximum number of results to return.
param: int $offset Results to skip at the start of the result set.
param: string[] $expectedcourses Expected courses in results.
param: int $expectedprocessedcount Expected number of course records to be processed.

get_course_filter_courses_by_customfield_test_cases()   X-Ref
Test cases for the course_filter_courses_by_timeline_classification tests.


test_course_filter_courses_by_customfield($coursedata,$customfield,$customfieldvalue,$limit,$offset,$expectedcourses,$expectedprocessedcount)   X-Ref
Test the course_filter_courses_by_customfield function.

param: array $coursedata Course test data to create.
param: string $customfield Shortname of the customfield.
param: string $customfieldvalue the value to filter by.
param: int $limit Maximum number of results to return.
param: int $offset Results to skip at the start of the result set.
param: string[] $expectedcourses Expected courses in results.
param: int $expectedprocessedcount Expected number of course records to be processed.

get_course_filter_courses_by_timeline_classification_hidden_courses_test_cases()   X-Ref
Test cases for the course_filter_courses_by_timeline_classification w/ hidden courses tests.


test_course_filter_courses_by_timeline_classification_with_hidden_courses($coursedata,$classification,$limit,$offset,$expectedcourses,$expectedprocessedcount,$hiddencourse)   X-Ref
Test the course_filter_courses_by_timeline_classification function hidden courses.

param: array $coursedata Course test data to create.
param: string $classification Timeline classification.
param: int $limit Maximum number of results to return.
param: int $offset Results to skip at the start of the result set.
param: string[] $expectedcourses Expected courses in results.
param: int $expectedprocessedcount Expected number of course records to be processed.
param: int $hiddencourse The course to hide as part of this process

test_core_course_core_calendar_get_valid_event_timestart_range_no_enddate()   X-Ref
Testing core_course_core_calendar_get_valid_event_timestart_range when the course has no end date.


test_core_course_core_calendar_get_valid_event_timestart_range_with_enddate()   X-Ref
Testing core_course_core_calendar_get_valid_event_timestart_range when the course has end date.


test_course_get_recent_courses()   X-Ref
Test the course_get_recent_courses function.


test_course_get_recent_courses_sort_validation(string $sort, string $expectedexceptionmsg)   X-Ref
Test the validation of the sort value in course_get_recent_courses().

param: string $sort The sort value
param: string $expectedexceptionmsg The expected exception message

course_get_recent_courses_sort_validation_provider()   X-Ref
Data provider for test_course_get_recent_courses_sort_validation().

return: array

test_course_get_recent_courses_with_guest()   X-Ref
Test the course_get_recent_courses function.


get_course_get_course_dates_for_user_ids_test_cases()   X-Ref
Test cases for the course_get_course_dates_for_user_ids tests.


test_course_get_course_dates_for_user_ids($relativedatemode,$coursestart,$usercount,$enrolmentmethods,$enrolled,$expected)   X-Ref
Test the course_get_course_dates_for_user_ids function.

param: bool $relativedatemode Set the course to relative dates mode
param: int $coursestart Course start date
param: int $usercount Number of users to create
param: array $enrolmentmethods Enrolment methods to set for the course
param: array $enrolled Enrolment config for to set for the users
param: array $expected Expected output

test_course_get_course_dates_for_user_ids_multiple_calls()   X-Ref
Test that calling course_get_course_dates_for_user_ids multiple times in the
same request fill fetch the correct data for the user.


provider_course_modules_pending_deletion()   X-Ref
Data provider for test_course_modules_pending_deletion.

return: array An array of arrays contain test data

test_course_modules_pending_deletion(array $modules, int $indextodelete, bool $gradable, bool $expected)   X-Ref
Tests the function course_modules_pending_deletion.

param: string[] $modules A complete list aff all available modules before deletion
param: int $indextodelete The index of the module in the $modules array that we want to test with
param: bool $gradable The value to pass to the gradable argument of the course_modules_pending_deletion function
param: bool $expected The expected result

test_can_request_course()   X-Ref
Tests for the course_request::can_request


test_can_approve_course_request()   X-Ref
Tests for the course_request::can_approve


test_course_allowed_module()   X-Ref
Test the course allowed module method.


test_average_number_of_participants()   X-Ref
Test the {@link average_number_of_participants()} function.


test_set_downloadcontent()   X-Ref
Test the set_downloadcontent() function.