MDL-47494 ddimageortext: Better way of handling the creation of test questions for different question types.
This commit is contained in:
@@ -34,11 +34,15 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2010 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_ddwtos_test_helper {
|
||||
class qtype_ddwtos_test_helper extends question_test_helper {
|
||||
public function get_test_questions() {
|
||||
return array('fox', 'maths');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return qtype_ddwtos_question
|
||||
*/
|
||||
public static function make_a_ddwtos_question() {
|
||||
public function make_ddwtos_question_fox() {
|
||||
question_bank::load_question_definition_classes('ddwtos');
|
||||
$dd = new qtype_ddwtos_question();
|
||||
|
||||
@@ -75,7 +79,7 @@ class qtype_ddwtos_test_helper {
|
||||
/**
|
||||
* @return qtype_ddwtos_question
|
||||
*/
|
||||
public static function make_a_maths_ddwtos_question() {
|
||||
public function make_ddwtos_question_maths() {
|
||||
question_bank::load_question_definition_classes('ddwtos');
|
||||
$dd = new qtype_ddwtos_question();
|
||||
|
||||
|
||||
@@ -40,21 +40,21 @@ require_once($CFG->dirroot . '/question/type/ddwtos/simpletest/helper.php');
|
||||
class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
|
||||
public function test_get_question_summary() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$this->assertEqual('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
|
||||
'[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
|
||||
$dd->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_get_question_summary_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$this->assertEqual('Fill in the operators to make this equation work: ' .
|
||||
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; [[1]] -> {+ / - / * / /}',
|
||||
$dd->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_summarise_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -63,7 +63,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_summarise_response_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -72,17 +72,17 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$this->assertEqual(0.5, $dd->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$this->assertEqual(0.25, $dd->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -91,7 +91,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -100,7 +100,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_clear_wrong_from_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -110,7 +110,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_num_parts_right() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -121,7 +121,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_num_parts_right_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -131,7 +131,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_expected_data() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
$this->assertEqual(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
|
||||
@@ -139,7 +139,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_correct_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -148,7 +148,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_correct_response_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -157,7 +157,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_is_same_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
$this->assertTrue($dd->is_same_response(
|
||||
@@ -181,7 +181,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2')));
|
||||
}
|
||||
public function test_is_complete_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
$this->assertFalse($dd->is_complete_response(array()));
|
||||
@@ -193,7 +193,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_is_gradable_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
$this->assertFalse($dd->is_gradable_response(array()));
|
||||
@@ -207,7 +207,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_grading() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -220,7 +220,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_grading_maths() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_maths_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos', 'maths');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
@@ -233,7 +233,7 @@ class qtype_ddwtos_question_test extends UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_classify_response() {
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$dd->start_attempt(new question_attempt_step());
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class qtype_ddwtos_test extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @return object the data to construct a question like
|
||||
* {@link qtype_ddwtos_test_helper::make_a_ddwtos_question()}.
|
||||
* {@link qtype_ddwtos_test_helper::make_ddwtos_question_fox()}.
|
||||
*/
|
||||
protected function get_test_question_data() {
|
||||
global $USER;
|
||||
@@ -117,7 +117,7 @@ class qtype_ddwtos_test extends UnitTestCase {
|
||||
public function test_initialise_question_instance() {
|
||||
$qdata = $this->get_test_question_data();
|
||||
|
||||
$expected = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$expected = test_question_maker::make_question('ddwtos');
|
||||
$expected->stamp = $qdata->stamp;
|
||||
$expected->version = $qdata->version;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_interactive_behaviour() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(13, 'This is the first hint.', FORMAT_HTML, false, false),
|
||||
new question_hint_with_parts(14, 'This is the second hint.', FORMAT_HTML, true, true),
|
||||
@@ -175,7 +175,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_deferred_feedback() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
@@ -258,7 +258,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_deferred_feedback_unanswered() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
@@ -314,7 +314,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_deferred_feedback_partial_answer() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->shufflechoices = false;
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
@@ -369,7 +369,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_interactive_grading() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(1, 'This is the first hint.',
|
||||
FORMAT_MOODLE, true, true),
|
||||
@@ -529,7 +529,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_interactive_correct_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
@@ -585,7 +585,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_interactive_partial_no_submit() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.',
|
||||
FORMAT_MOODLE, false, false),
|
||||
@@ -641,7 +641,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_interactive_no_right_clears() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$dd->hints = array(
|
||||
new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, true),
|
||||
new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true),
|
||||
@@ -708,7 +708,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
|
||||
public function test_display_of_right_answer_when_shuffled() {
|
||||
|
||||
// Create a drag-and-drop question.
|
||||
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
|
||||
$dd = test_question_maker::make_question('ddwtos');
|
||||
$this->start_attempt_at_question($dd, 'deferredfeedback', 3);
|
||||
|
||||
// Check the initial state.
|
||||
|
||||
Reference in New Issue
Block a user