Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
test_question_maker Class Reference

This class creates questions of various types, which can then be used when testing. More...

Static Public Member Functions

static get_a_qa ($question, $maxmark=3)
 Just make a question_attempt at a question.
 
static get_question_data ($qtype, $which=null)
 Like make_question() but returns the datastructure from get_question_options instead of the question_definition object.
 
static get_question_form_data ($qtype, $which=null)
 Like make_question() but returns the data what would be saved from the question editing form instead of the question_definition object.
 
static get_test_helper ($qtype)
 Get the test helper class for a particular question type.
 
static initialise_a_question ($q)
 Initialise the common fields of a question of any type.
 
static initialise_question_data ($qdata)
 
static make_a_matching_question ()
 Makes a matching question to classify 'Dog', 'Frog', 'Toad' and 'Cat' as 'Mammal', 'Amphibian' or 'Insect'.
 
static make_a_multichoice_multi_question ()
 Makes a multichoice question with choices 'A', 'B', 'C' and 'D' shuffled.
 
static make_a_multichoice_single_question ()
 Makes a multichoice question with choices 'A', 'B' and 'C' shuffled.
 
static make_an_essay_question ()
 Makes a truefalse question with correct ansewer true, defaultmark 1.
 
static make_question ($qtype, $which=null)
 Question types can provide a number of test question defintions.
 
static set_standard_combined_feedback_fields ($q)
 Add some standard overall feedback to a question.
 
static set_standard_combined_feedback_form_data ($form)
 Add some standard overall feedback to a question's form data.
 

Public Attributes

const STANDARD_OVERALL_CORRECT_FEEDBACK = 'Well done!'
 
const STANDARD_OVERALL_INCORRECT_FEEDBACK = 'That is not right at all.'
 
const STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK
 

Static Protected Member Functions

static call_question_helper_method ($methodtemplate, $qtype, $which=null)
 Call a method on a qtype_{$qtype}_test_helper class and return the result.
 

Static Protected Attributes

static array $testhelpers = array()
 qtype => qtype test helper class.
 

Detailed Description

This class creates questions of various types, which can then be used when testing.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ call_question_helper_method()

static test_question_maker::call_question_helper_method ( $methodtemplate,
$qtype,
$which = null )
staticprotected

Call a method on a qtype_{$qtype}_test_helper class and return the result.

Parameters
string$methodtemplatee.g. 'make_{qtype}_question_{which}';
string$qtypethe question type to get a test question for.
string$whichone of the names returned by the get_test_questions method of the relevant qtype_{$qtype}_test_helper class.
unknown_type$which

◆ get_a_qa()

static test_question_maker::get_a_qa ( $question,
$maxmark = 3 )
static

Just make a question_attempt at a question.

Useful for unit tests that need to pass a $qa to methods that call format_text. Probably not safe to use for anything beyond that.

Parameters
question_definition$questiona question.
number$maxmarkthe max mark to set.
Return values
question_attemptthe question attempt.

◆ get_question_data()

static test_question_maker::get_question_data ( $qtype,
$which = null )
static

Like make_question() but returns the datastructure from get_question_options instead of the question_definition object.

Parameters
string$qtypethe question type to get a test question for.
string$whichone of the names returned by the get_test_questions method of the relevant qtype_{$qtype}_test_helper class.
Return values
stdClassthe requested question object.

◆ get_question_form_data()

static test_question_maker::get_question_form_data ( $qtype,
$which = null )
static

Like make_question() but returns the data what would be saved from the question editing form instead of the question_definition object.

Parameters
string$qtypethe question type to get a test question for.
string$whichone of the names returned by the get_test_questions method of the relevant qtype_{$qtype}_test_helper class.
Return values
stdClassthe requested question object.

◆ get_test_helper()

static test_question_maker::get_test_helper ( $qtype)
static

Get the test helper class for a particular question type.

Parameters
$qtypethe question type name, e.g. 'multichoice'.
Return values
question_test_helperthe test helper class.

◆ make_a_matching_question()

static test_question_maker::make_a_matching_question ( )
static

Makes a matching question to classify 'Dog', 'Frog', 'Toad' and 'Cat' as 'Mammal', 'Amphibian' or 'Insect'.

defaultmark 1. Stems are shuffled by default.

Return values
qtype_match_question

◆ make_a_multichoice_multi_question()

static test_question_maker::make_a_multichoice_multi_question ( )
static

Makes a multichoice question with choices 'A', 'B', 'C' and 'D' shuffled.

'A' and 'C' is correct, defaultmark 1.

Return values
qtype_multichoice_multi_question

◆ make_a_multichoice_single_question()

static test_question_maker::make_a_multichoice_single_question ( )
static

Makes a multichoice question with choices 'A', 'B' and 'C' shuffled.

'A' is correct, defaultmark 1.

Return values
qtype_multichoice_single_question

◆ make_an_essay_question()

static test_question_maker::make_an_essay_question ( )
static

Makes a truefalse question with correct ansewer true, defaultmark 1.

Return values
qtype_essay_question

◆ make_question()

static test_question_maker::make_question ( $qtype,
$which = null )
static

Question types can provide a number of test question defintions.

They do this by creating a qtype_{$qtype}_test_helper class that extends question_test_helper. The get_test_questions method returns the list of test questions available for this question type.

Parameters
string$qtypethe question type to get a test question for.
string$whichone of the names returned by the get_test_questions method of the relevant qtype_{$qtype}_test_helper class.
Return values
question_definitionthe requested question object.

◆ set_standard_combined_feedback_fields()

static test_question_maker::set_standard_combined_feedback_fields ( $q)
static

Add some standard overall feedback to a question.

You need to use these specific feedback strings for the corresponding contains_..._feedback methods in qbehaviour_walkthrough_test_base to works.

Parameters
question_definition | stdClass$qthe question to add the feedback to.

Member Data Documentation

◆ STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK

const test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK
Initial value:
=
'Parts, but only parts, of your response are correct.'

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