Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

Unit tests for (some of) ../questionlib.php.

Copyright: 2006 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 2152 lines (99 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

core_questionlib_testcase:: (57 methods):
  setUp()
  setup_quiz_and_questions()
  test_question_reorder_qtypes()
  test_match_grade_options()
  test_altering_tag_instance_context()
  test_question_delete_question()
  test_question_delete_question_broken_data()
  test_question_category_delete_safe()
  test_question_delete_activity()
  test_question_delete_context()
  test_question_delete_course()
  test_question_delete_course_category()
  test_question_delete_course_category_move_qcats()
  test_question_save_from_deletion()
  test_question_save_from_deletion_quiz_with_long_name()
  test_question_remove_stale_questions_from_category()
  test_get_question_options_includes_category_object_single_question()
  test_get_question_options_includes_category_object_multiple_questions()
  test_get_question_options_includes_question_tags()
  test_get_question_options_includes_course_tags()
  test_get_question_options_course_tags_in_course_question_context()
  test_get_question_options_includes_question_and_course_tags()
  test_get_question_options_normalises_question_tags()
  test_get_question_options_includes_course_context_question_tags()
  test_get_question_options_includes_multiple_courses_tags()
  test_get_question_options_includes_filter_course_tags()
  test_question_move_question_tags_to_new_context_system_to_course_cat_qtags()
  test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags()
  test_question_move_question_tags_to_new_context_course_cat_to_system_qtags()
  test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags()
  test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags()
  test_question_move_question_tags_to_new_context_remove_other_course_tags()
  test_question_move_question_tags_to_new_context_course_to_course_cat()
  test_question_move_question_tags_to_new_context_orphaned_tag_contexts()
  test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags()
  test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags()
  test_question_move_question_tags_to_new_context_course_to_activity_qtags()
  test_question_move_question_tags_to_new_context_activity_to_course_qtags()
  test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags()
  test_question_sort_tags_includes_question_tags()
  test_question_sort_tags_includes_question_course_tags()
  test_question_sort_tags_includes_multiple_courses_tags()
  test_question_sort_tags_includes_filter_course_tags()
  question_capability_on_question_provider()
  test_question_has_capability_on_broken_question()
  test_question_has_capability_on_using_stdclass()
  test_question_has_capability_on_using_question_definition()
  test_question_has_capability_on_using_question_id()
  test_question_has_capability_on_using_question_string_id()
  test_question_has_capability_on_using_moved_question()
  test_question_has_capability_on_using_question()
  test_question_has_capability_on_wrong_param_type()
  test_question_categorylist_parents()
  test_question_get_export_single_question_url()
  find_next_unused_idnumber_cases()
  test_core_question_find_next_unused_idnumber()
  test_core_question_find_next_unused_idnumber_skips_used()


Class: core_questionlib_testcase  - X-Ref

Unit tests for (some of) ../questionlib.php.

setUp()   X-Ref
Test set up.

This is executed before running any test in this file.

setup_quiz_and_questions($type = 'module')   X-Ref
Setup a course, a quiz, a question category and a question for testing.

param: string $type The type of question category to create.
return: array The created data objects

test_question_reorder_qtypes()   X-Ref
No description

test_match_grade_options()   X-Ref
No description

test_altering_tag_instance_context()   X-Ref
This function tests that the functions responsible for moving questions to
different contexts also updates the tag instances associated with the questions.


test_question_delete_question()   X-Ref
Test that deleting a question from the question bank works in the normal case.


test_question_delete_question_broken_data()   X-Ref
Test that deleting a broken question from the question bank does not cause fatal errors.


test_question_category_delete_safe()   X-Ref
This function tests the question_category_delete_safe function.


test_question_delete_activity()   X-Ref
This function tests the question_delete_activity function.


test_question_delete_context()   X-Ref
This function tests the question_delete_context function.


test_question_delete_course()   X-Ref
This function tests the question_delete_course function.


test_question_delete_course_category()   X-Ref
This function tests the question_delete_course_category function.


test_question_delete_course_category_move_qcats()   X-Ref
This function tests the question_delete_course_category function when it is supposed to move question categories.


test_question_save_from_deletion()   X-Ref
This function tests the question_save_from_deletion function when it is supposed to make a new category and
move question categories to that new category.


test_question_save_from_deletion_quiz_with_long_name()   X-Ref
This function tests the question_save_from_deletion function when it is supposed to make a new category and
move question categories to that new category when quiz name is very long but less than 256 characters.


test_question_remove_stale_questions_from_category()   X-Ref
No description

test_get_question_options_includes_category_object_single_question()   X-Ref
get_question_options should add the category object to the given question.


test_get_question_options_includes_category_object_multiple_questions()   X-Ref
get_question_options should add the category object to all of the questions in
the given list.


test_get_question_options_includes_question_tags()   X-Ref
get_question_options includes the tags for all questions in the list.


test_get_question_options_includes_course_tags()   X-Ref
get_question_options includes the course tags for all questions in the list.


test_get_question_options_course_tags_in_course_question_context()   X-Ref
get_question_options only categorises a tag as a course tag if it is in a
course context that is different from the question context.


test_get_question_options_includes_question_and_course_tags()   X-Ref
get_question_options includes the tags and course tags for all questions in the list
if each question has course and question level tags.


test_get_question_options_normalises_question_tags()   X-Ref
get_question_options should update the context id to the question category
context id for any non-course context tag that isn't in the question category
context.


test_get_question_options_includes_course_context_question_tags()   X-Ref
get_question_options if the question is a course level question then tags
in that context should not be consdered course tags, they are question tags.


test_get_question_options_includes_multiple_courses_tags()   X-Ref
get_question_options should return tags from all course contexts by default.


test_get_question_options_includes_filter_course_tags()   X-Ref
get_question_options should filter the course tags by the given list of courses.


test_question_move_question_tags_to_new_context_system_to_course_cat_qtags()   X-Ref
question_move_question_tags_to_new_context should update all of the
question tags contexts when they are moving down (from system to course
category context).


test_question_move_question_tags_to_new_context_system_to_course_cat_qtags_and_course_tags()   X-Ref
question_move_question_tags_to_new_context should update all of the question tags
contexts when they are moving down (from system to course category context)
but leave any tags in the course context where they are.


test_question_move_question_tags_to_new_context_course_cat_to_system_qtags()   X-Ref
question_move_question_tags_to_new_context should update all of the question
contexts tags when they are moving up (from course category to system context).


test_question_move_question_tags_to_new_context_course_cat_to_system_qtags_and_course_tags()   X-Ref
question_move_question_tags_to_new_context should update all of the question
tags contexts when they are moving up (from course category context to system
context) but leave any tags in the course context where they are.


test_question_move_question_tags_to_new_context_course_cat_to_coures_qtags_and_course_tags()   X-Ref
question_move_question_tags_to_new_context should merge all tags into the course
context when moving down from course category context into course context.


test_question_move_question_tags_to_new_context_remove_other_course_tags()   X-Ref
question_move_question_tags_to_new_context should delete all of the tag
instances from sibling courses when moving the context of a question down
from a course category into a course context because the other courses will
no longer have access to the question.


test_question_move_question_tags_to_new_context_course_to_course_cat()   X-Ref
question_move_question_tags_to_new_context should update all of the question
tags to be the course category context when moving the tags from a course
context to a course category context.


test_question_move_question_tags_to_new_context_orphaned_tag_contexts()   X-Ref
question_move_question_tags_to_new_context should update all of the
question tags contexts when they are moving down (from system to course
category context).


test_question_move_question_tags_to_new_context_course_cat_to_activity_qtags_and_course_tags()   X-Ref
When moving from a course category context down into an activity context
all question context tags and course tags (where the course is a parent of
the activity) should move into the new context.


test_question_move_question_tags_to_new_context_course_cat_to_activity_orphaned_tags()   X-Ref
When moving from a course category context down into an activity context
all question context tags and course tags (where the course is a parent of
the activity) should move into the new context. Tags in course contexts
that are not a parent of the activity context should be deleted.


test_question_move_question_tags_to_new_context_course_to_activity_qtags()   X-Ref
When moving from a course context down into an activity context all of the
course tags should move into the activity context.


test_question_move_question_tags_to_new_context_activity_to_course_qtags()   X-Ref
When moving from a course context down into an activity context all of the
course tags should move into the activity context.


test_question_move_question_tags_to_new_context_system_to_course_cat_with_orphaned_tags()   X-Ref
question_move_question_tags_to_new_context should update all of the
question tags contexts when they are moving down (from system to course
category context).

Course tags within the new category context should remain while any course
tags in course contexts that can no longer access the question should be
deleted.

test_question_sort_tags_includes_question_tags()   X-Ref
question_sort_tags() includes the tags for all questions in the list.


test_question_sort_tags_includes_question_course_tags()   X-Ref
question_sort_tags() includes course tags for all questions in the list.


test_question_sort_tags_includes_multiple_courses_tags()   X-Ref
question_sort_tags() should return tags from all course contexts by default.


test_question_sort_tags_includes_filter_course_tags()   X-Ref
question_sort_tags() should filter the course tags by the given list of courses.


question_capability_on_question_provider()   X-Ref
Data provider for tests of question_has_capability_on_context and question_require_capability_on_context.

return: array

test_question_has_capability_on_broken_question()   X-Ref
Tests that question_has_capability_on does not throw exception on broken questions.


test_question_has_capability_on_using_stdclass($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the deprecated question_has_capability_on function when passing a stdClass as parameter.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_using_question_definition($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the deprecated question_has_capability_on function when using question definition.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_using_question_id($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the deprecated question_has_capability_on function when using a real question id.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_using_question_string_id($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the deprecated question_has_capability_on function when using a string as question id.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_using_moved_question($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the question_has_capability_on function when using a moved question.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_using_question($capabilities, $capability, $isowner, $expect)   X-Ref
Tests for the question_has_capability_on function when using a real question.

param: array   $capabilities The capability assignments to set.
param: string  $capability The capability to test
param: bool    $isowner Whether the user to create the question should be the owner or not.
param: bool    $expect The expected result.

test_question_has_capability_on_wrong_param_type()   X-Ref
Tests that question_has_capability_on throws an exception for wrong parameter types.


test_question_categorylist_parents()   X-Ref
Test of question_categorylist_parents function.


test_question_get_export_single_question_url()   X-Ref
No description

find_next_unused_idnumber_cases()   X-Ref
Get test cases for test_core_question_find_next_unused_idnumber.

return: array test cases.

test_core_question_find_next_unused_idnumber(string $oldidnumber, ?string $expectednewidnumber)   X-Ref
Test core_question_find_next_unused_idnumber in the case when there are no other questions.

param: string $oldidnumber value to pass to core_question_find_next_unused_idnumber.
param: string|null $expectednewidnumber expected result.

test_core_question_find_next_unused_idnumber_skips_used()   X-Ref
No description