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]

Quiz module test data generator.

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

Defines 1 class


Class: core_question_generator  - X-Ref

Class core_question_generator for generating question data.

reset()   X-Ref
Make the category count to zero.


create_question_category($record = null)   X-Ref
Create a new question category.

param: array|stdClass $record
return: stdClass question_categories record.

create_question($qtype, $which = null, $overrides = null)   X-Ref
Create a new question. The question is initialised using one of the
examples from the appropriate {@link question_test_helper} subclass.
Then, any files you want to change from the value in the base example you
can override using $overrides.

param: string $qtype the question type to create an example of.
param: string $which as for the corresponding argument of
param: array|stdClass $overrides any fields that should be different from the base example.
return: stdClass the question data.

create_question_tag(array $data)   X-Ref
Create a tag on a question.

param: array $data with two elements ['questionid' => 123, 'tag' => 'mytag'].

update_question($question, $which = null, $overrides = null)   X-Ref
Update an existing question.

param: stdClass $question the question data to update.
param: string $which as for the corresponding argument of
param: array|stdClass $overrides any fields that should be different from the base example.
return: stdClass the question data, including version info and questionbankentryid

setup_course_and_questions($type = 'course')   X-Ref
Setup a course category, course, a question category, and 2 questions
for testing.

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

get_simulated_post_data_for_questions_in_usage(question_usage_by_activity $quba, array $responses, $checkbutton)   X-Ref
This method can construct what the post data would be to simulate a user submitting
responses to a number of questions within a question usage.

In the responses array, the array keys are the slot numbers for which a response will
be submitted. You can submit a response to any number of responses within the usage.
There is no need to do them all. The values are a string representation of the response.
The exact meaning of that depends on the particular question type. These strings
are passed to the un_summarise_response method of the question to decode.

param: question_usage_by_activity $quba the question usage.
param: array $responses the resonses to submit, in the format described above.
param: bool $checkbutton if simulate a click on the check button for each question, else simulate save.
return: array that can be passed to methods like $quba->process_all_actions as simulated POST data.

get_simulated_post_data_for_question_attempt(question_attempt $qa, $responsesummary, $checkbutton)   X-Ref
This method can construct what the post data would be to simulate a user submitting
responses to one particular question attempt.

The $responsesummary is a string representation of the response to be submitted.
The exact meaning of that depends on the particular question type. These strings
are passed to the un_summarise_response method of the question to decode.

param: question_attempt $qa the question attempt for which we are generating POST data.
param: string $responsesummary a textual summary of the response, as described above.
param: bool $checkbutton if simulate a click on the check button, else simulate save.
return: array the simulated post data that can be passed to $quba->process_all_actions.