Class core_question_generator for generating question data.
More...
|
| create_categories_and_questions (context $context, array $structure, ?int $parentid=null) |
| Given a context and a structure of categories and questions, generate that structure.
|
|
| create_question ($qtype, $which=null, $overrides=null) |
| Create a new question.
|
|
| create_question_category ($record=null) |
| Create a new question category.
|
|
| create_question_tag (array $data) |
| Create a tag on a question.
|
|
| 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.
|
|
| 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.
|
|
| reset () |
| Make the category count to zero.
|
|
| setup_course_and_questions () |
| Set up a course category, a course, a mod_qbank instance, a question category for the mod_qbank instance, and 2 questions for testing.
|
|
| update_question ($question, $which=null, $overrides=null) |
| Update an existing question.
|
|
|
| insert_files (stdClass $instance, stdClass $record, string $table, context $context, string $component, string $filearea, int $targetitemid) |
| Update the instance record, inserting any files that are referenced.
|
|
| set_user (?stdClass $user=null) |
| Set the current user during data generation.
|
|
|
number | $categorycount = 0 |
| of created instances
|
|
testing_data_generator | $datagenerator |
|
◆ create_categories_and_questions()
core_question_generator::create_categories_and_questions |
( |
context | $context, |
|
|
array | $structure, |
|
|
?int | $parentid = null ) |
Given a context and a structure of categories and questions, generate that structure.
The $structure parameter takes a multi-dimensional array of categories and questions, like this: [ 'categoryname' => [ 'question1name' => 'questiontype', 'question2name' => 'questiontype', 'subcategoryname' => [ 'subquestion1name' => 'questiontype', ], ], ] Arrays are treated as categories, strings are treated as questions. The key in each case is used for the name of the category or question. For subcategories, the method is called recursively to create all descendants. The 'questiontype' string is the type of question to be generated, and will be passed to create_question.
- Parameters
-
context | $context | The context to create the structure in. |
array | $structure | The array of categories and questions, see above. |
?int | $parentid | The category to create the category or question within. |
- Return values
-
array | The input structure, with the generated questions in place of the question types. |
◆ 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 | $qtype | the question type to create an example of. |
string | $which | as for the corresponding argument of question_test_helper::get_question_form_data. null for the default one. |
array | stdClass | $overrides | any fields that should be different from the base example. |
- Return values
-
stdClass | the question data. |
◆ create_question_category()
core_question_generator::create_question_category |
( |
| $record = null | ) |
|
Create a new question category.
- Parameters
-
- Return values
-
stdClass | question_categories record. |
◆ create_question_tag()
core_question_generator::create_question_tag |
( |
array | $data | ) |
|
Create a tag on a question.
- Parameters
-
array | $data | with 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 | $qa | the question attempt for which we are generating POST data. |
string | $responsesummary | a textual summary of the response, as described above. |
bool | $checkbutton | if simulate a click on the check button, else simulate save. This should only be used with behaviours that have a check button. |
- Return values
-
array | the 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 questions 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 | $quba | the question usage. |
array | $responses | the responses to submit, in the format described above. |
bool | $checkbutton | if 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
-
array | that can be passed to methods like $quba->process_all_actions as simulated POST data. |
◆ insert_files()
component_generator_base::insert_files |
( |
stdClass | $instance, |
|
|
stdClass | $record, |
|
|
string | $table, |
|
|
context | $context, |
|
|
string | $component, |
|
|
string | $filearea, |
|
|
int | $targetitemid ) |
|
protectedinherited |
Update the instance record, inserting any files that are referenced.
- Parameters
-
stdClass | $instance | The instance record of the already-created record |
stdClass | $record | The data passed in to create the instance |
string | $table | The table that the data exists in |
context | $context | The context of the instance |
string | $component | The component of the owning plugin |
string | $filearea | The name of the file area |
int | $targetitemid | The itemid to use when saving the files |
- Return values
-
stdClass | The updated instance record |
◆ reset()
core_question_generator::reset |
( |
| ) |
|
◆ set_user()
component_generator_base::set_user |
( |
?stdClass | $user = null | ) |
|
|
protectedinherited |
Set the current user during data generation.
This should be avoided wherever possible, but in some situations underlying code will insert data as the current user.
- Parameters
-
◆ setup_course_and_questions()
core_question_generator::setup_course_and_questions |
( |
| ) |
|
Set up a course category, a course, a mod_qbank instance, a question category for the mod_qbank instance, and 2 questions for testing.
- Return values
-
array | of the data objects mentioned above |
◆ update_question()
core_question_generator::update_question |
( |
| $question, |
|
|
| $which = null, |
|
|
| $overrides = null ) |
Update an existing question.
- Parameters
-
stdClass | $question | the question data to update. |
string | $which | as for the corresponding argument of question_test_helper::get_question_form_data. null for the default one. |
array | stdClass | $overrides | any fields that should be different from the base example. |
- Return values
-
stdClass | the question data, including version info and questionbankentryid |
The documentation for this class was generated from the following file:
- question/tests/generator/lib.php