Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

(no description)

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

Defines 1 class

questionlib_test:: (64 methods):
  setUp()
  setup_quiz_and_questions()
  assert_category_contains_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_delete_question_missing_context()
  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_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()
  find_next_unused_idnumber_cases()
  test_core_question_find_next_unused_idnumber()
  test_core_question_find_next_unused_idnumber_skips_used()
  test_question_move_questions_to_category()
  test_idnumber_exist_in_question_category()
  test_is_latest()
  test_delete_question_bank_entry()
  test_get_question_bank_entry()
  test_get_question_version()
  test_get_next_version()


Class: questionlib_test  - 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

assert_category_contains_questions(int $categoryid, int $numberofquestions)   X-Ref
Assert that a category contains a specific number of questions.

param: int $categoryid int Category id.
param: int $numberofquestions Number of question in a category.
return: void Questions in a category.

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_delete_question_missing_context()   X-Ref
Test deleting a broken question whose category refers to a missing context


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_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.


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|null $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

test_question_move_questions_to_category()   X-Ref
Tests for the question_move_questions_to_category function.


test_idnumber_exist_in_question_category()   X-Ref
Tests for the idnumber_exist_in_question_category function.


test_is_latest()   X-Ref
Test method is_latest().


test_delete_question_bank_entry()   X-Ref
Test question bank entry deletion.


test_get_question_bank_entry()   X-Ref
Test question bank entry object.


test_get_question_version()   X-Ref
Test the version objects for a question.


test_get_next_version()   X-Ref
Test get next version of a question.