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.

Class: externallib_test  - X-Ref

Question external functions tests

setUp()   X-Ref
Set up for every test


test_core_question_update_flag()   X-Ref
Test update question flag


get_random_question_summaries_test_cases()   X-Ref
Data provider for the get_random_question_summaries test.


test_get_random_question_summaries_variations($categoryindex,$includesubcategories,$usetagnames,$expectedquestionindexes)   X-Ref
Test the get_random_question_summaries function with various parameter combinations.

This function creates a data set as follows:
Category: cat1
Question: cat1q1
Tags: 'cat1', 'foo'
Question: cat1q2
Category: cat2
Question: cat2q1
Tags: 'cat2', 'foo'
Question: cat2q2
Category: subcat
Question: subcatq1
Tags: 'subcat', 'foo'
Question: subcatq2
Parent: cat1
Category: emptycat

param: string $categoryindex The named index for the category to use
param: bool $includesubcategories If the search should include subcategories
param: string[] $usetagnames The tag names to include in the search
param: string[] $expectedquestionindexes The questions expected in the result

test_get_random_question_summaries_invalid_category_id_param()   X-Ref
get_random_question_summaries should throw an invalid_parameter_exception if not
given an integer for the category id.


test_get_random_question_summaries_invalid_includesubcategories_param()   X-Ref
get_random_question_summaries should throw an invalid_parameter_exception if not
given a boolean for the $includesubcategories parameter.


test_get_random_question_summaries_invalid_tagids_param()   X-Ref
get_random_question_summaries should throw an invalid_parameter_exception if not
given an array of integers for the tag ids parameter.


test_get_random_question_summaries_invalid_context()   X-Ref
get_random_question_summaries should throw an invalid_parameter_exception if not
given a context.


test_get_random_question_summaries_restricted_context()   X-Ref
get_random_question_summaries should throw an restricted_context_exception
if the given context is outside of the set of restricted contexts the user
is allowed to call external functions in.


test_get_random_question_summaries_formats_returned_questions()   X-Ref
get_random_question_summaries should return a question that is formatted correctly.


test_get_random_question_summaries_with_limit_and_offset()   X-Ref
get_random_question_summaries should allow limiting and offsetting of the result set.


test_get_random_question_summaries_without_capability()   X-Ref
get_random_question_summaries should throw an exception if the user doesn't
have the capability to use the questions in the requested category.


create_category_and_questions($questioncount, $tagnames = [], $parentcategory = null)   X-Ref
Create a question category and create questions in that category. Tag
the first question in each category with the given tags.

param: int $questioncount How many questions to create.
param: string[] $tagnames The list of tags to use.
param: stdClass|null $parentcategory The category to set as the parent of the created category.
return: array The category and questions.