Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Attributes | List of all members
core_question_generator Class Reference
Inheritance diagram for core_question_generator:
component_generator_base

Public Member Functions

 create_question ($qtype, $which=null, $overrides=null)
 Create a new question. More...
 
 create_question_category ($record=null)
 Create a new question category. More...
 
 create_question_tag (array $data)
 Create a tag on a question. More...
 
 get_simulated_post_data_for_question_attempt (question_attempt $qa, $responsesummary, $checkbutton)
 This method can construct what the post data would be to simulate a user submitting responses to one particular question attempt. More...
 
 get_simulated_post_data_for_questions_in_usage (question_usage_by_activity $quba, array $responses, $checkbutton)
 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. More...
 
 reset ()
 To be called from data reset code only, do not use in tests. More...
 
 setup_course_and_questions ($type='course')
 Setup a course category, course, a question category, and 2 questions for testing. More...
 
 update_question ($question, $which=null, $overrides=null)
 Update an existing question. More...
 

Protected Attributes

number $categorycount = 0
 of created instances
 
testing_data_generator $datagenerator
 

Member Function Documentation

◆ create_question()

core_question_generator::create_question (   $qtype,
  $which = null,
  $overrides = null 
)

Create a new question.

The question is initialised using one of the examples from the appropriate question_test_helper subclass. Then, any files you want to change from the value in the base example you can override using $overrides.

Parameters
string$qtypethe question type to create an example of.
string$whichas for the corresponding argument of question_test_helper::get_question_form_data. null for the default one.
array | stdClass$overridesany fields that should be different from the base example.
Return values
stdClassthe question data.

◆ create_question_category()

core_question_generator::create_question_category (   $record = null)

Create a new question category.

Parameters
array | stdClass$record
Return values
stdClassquestion_categories record.

◆ create_question_tag()

core_question_generator::create_question_tag ( array  $data)

Create a tag on a question.

Parameters
array$datawith two elements ['questionid' => 123, 'tag' => 'mytag'].

◆ get_simulated_post_data_for_question_attempt()

core_question_generator::get_simulated_post_data_for_question_attempt ( question_attempt  $qa,
  $responsesummary,
  $checkbutton 
)

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.

Parameters
question_attempt$qathe question attempt for which we are generating POST data.
string$responsesummarya textual summary of the response, as described above.
bool$checkbuttonif simulate a click on the check button, else simulate save. This should only be used with behaviours that have a check button.
Return values
arraythe simulated post data that can be passed to $quba->process_all_actions.

◆ get_simulated_post_data_for_questions_in_usage()

core_question_generator::get_simulated_post_data_for_questions_in_usage ( question_usage_by_activity  $quba,
array  $responses,
  $checkbutton 
)

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.

Parameters
question_usage_by_activity$qubathe question usage.
array$responsesthe resonses to submit, in the format described above.
bool$checkbuttonif simulate a click on the check button for each question, else simulate save. This should only be used with behaviours that have a check button.
Return values
arraythat can be passed to methods like $quba->process_all_actions as simulated POST data.

◆ reset()

core_question_generator::reset ( )

To be called from data reset code only, do not use in tests.

Return values
void

Reimplemented from component_generator_base.

◆ setup_course_and_questions()

core_question_generator::setup_course_and_questions (   $type = 'course')

Setup a course category, course, a question category, and 2 questions for testing.

Parameters
string$typeThe type of question category to create.
Return values
arrayThe created data objects

◆ update_question()

core_question_generator::update_question (   $question,
  $which = null,
  $overrides = null 
)

Update an existing question.

Parameters
stdClass$questionthe question data to update.
string$whichas for the corresponding argument of question_test_helper::get_question_form_data. null for the default one.
array | stdClass$overridesany fields that should be different from the base example.
Return values
stdClassthe question data.

The documentation for this class was generated from the following file: