MDL-63812 qtype_gapselect: test data generator to standard qtype pattern
This commit is contained in:
@@ -32,12 +32,60 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_gapselect_test_helper {
|
||||
class qtype_gapselect_test_helper extends question_test_helper {
|
||||
public function get_test_questions() {
|
||||
return array('fox', 'maths', 'currency', 'multilang');
|
||||
}
|
||||
|
||||
public static function get_gapselect_question_data_fox() {
|
||||
global $USER;
|
||||
|
||||
$gapselect = new stdClass();
|
||||
$gapselect->id = 0;
|
||||
$gapselect->category = 0;
|
||||
$gapselect->contextid = 0;
|
||||
$gapselect->parent = 0;
|
||||
$gapselect->questiontextformat = FORMAT_HTML;
|
||||
$gapselect->generalfeedbackformat = FORMAT_HTML;
|
||||
$gapselect->defaultmark = 1;
|
||||
$gapselect->penalty = 0.3333333;
|
||||
$gapselect->length = 1;
|
||||
$gapselect->stamp = make_unique_id_code();
|
||||
$gapselect->version = make_unique_id_code();
|
||||
$gapselect->hidden = 0;
|
||||
$gapselect->idnumber = null;
|
||||
$gapselect->timecreated = time();
|
||||
$gapselect->timemodified = time();
|
||||
$gapselect->createdby = $USER->id;
|
||||
$gapselect->modifiedby = $USER->id;
|
||||
|
||||
$gapselect->name = 'Selection from drop down list question';
|
||||
$gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
|
||||
$gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
|
||||
$gapselect->qtype = 'gapselect';
|
||||
|
||||
$gapselect->options = new stdClass();
|
||||
$gapselect->options->shuffleanswers = true;
|
||||
|
||||
test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
|
||||
|
||||
$gapselect->options->answers = array(
|
||||
(object) array('answer' => 'quick', 'feedback' => '1'),
|
||||
(object) array('answer' => 'fox', 'feedback' => '2'),
|
||||
(object) array('answer' => 'lazy', 'feedback' => '3'),
|
||||
(object) array('answer' => 'assiduous', 'feedback' => '3'),
|
||||
(object) array('answer' => 'dog', 'feedback' => '2'),
|
||||
(object) array('answer' => 'slow', 'feedback' => '1'),
|
||||
);
|
||||
|
||||
return $gapselect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an example gapselect question to use for testing. This examples has one of each item.
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_gapselect_question() {
|
||||
public static function make_gapselect_question_fox() {
|
||||
question_bank::load_question_definition_classes('gapselect');
|
||||
$gapselect = new qtype_gapselect_question();
|
||||
|
||||
@@ -75,7 +123,7 @@ class qtype_gapselect_test_helper {
|
||||
* Get an example gapselect question to use for testing. This exmples had unlimited items.
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_maths_gapselect_question() {
|
||||
public static function make_gapselect_question_maths() {
|
||||
question_bank::load_question_definition_classes('gapselect');
|
||||
$gapselect = new qtype_gapselect_question();
|
||||
|
||||
@@ -93,10 +141,10 @@ class qtype_gapselect_test_helper {
|
||||
|
||||
$gapselect->choices = array(
|
||||
1 => array(
|
||||
1 => new qtype_gapselect_choice('+', 1, true),
|
||||
2 => new qtype_gapselect_choice('-', 1, true),
|
||||
3 => new qtype_gapselect_choice('*', 1, true),
|
||||
4 => new qtype_gapselect_choice('/', 1, true),
|
||||
1 => new qtype_gapselect_choice('+', 1),
|
||||
2 => new qtype_gapselect_choice('-', 1),
|
||||
3 => new qtype_gapselect_choice('*', 1),
|
||||
4 => new qtype_gapselect_choice('/', 1),
|
||||
));
|
||||
|
||||
$gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1);
|
||||
@@ -110,7 +158,7 @@ class qtype_gapselect_test_helper {
|
||||
* Get an example gapselect question with multilang entries to use for testing.
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_multilang_gapselect_question() {
|
||||
public static function make_gapselect_question_multilang() {
|
||||
question_bank::load_question_definition_classes('gapselect');
|
||||
$gapselect = new qtype_gapselect_question();
|
||||
|
||||
@@ -129,14 +177,14 @@ class qtype_gapselect_test_helper {
|
||||
$gapselect->choices = array(
|
||||
1 => array(
|
||||
1 => new qtype_gapselect_choice('<span lang="en" class="multilang">cat</span><span lang="ru" ' .
|
||||
'class="multilang">кошка</span>', 1, true),
|
||||
'class="multilang">кошка</span>', 1),
|
||||
2 => new qtype_gapselect_choice('<span lang="en" class="multilang">dog</span><span lang="ru" ' .
|
||||
'class="multilang">пес</span>', 1, true)),
|
||||
'class="multilang">пес</span>', 1)),
|
||||
2 => array(
|
||||
1 => new qtype_gapselect_choice('<span lang="en" class="multilang">mat</span><span lang="ru" ' .
|
||||
'class="multilang">коврике</span>', 2, true),
|
||||
'class="multilang">коврике</span>', 2),
|
||||
2 => new qtype_gapselect_choice('<span lang="en" class="multilang">bat</span><span lang="ru" ' .
|
||||
'class="multilang">бита</span>', 2, true))
|
||||
'class="multilang">бита</span>', 2))
|
||||
);
|
||||
|
||||
$gapselect->places = array(1 => 1, 2 => 2);
|
||||
@@ -151,7 +199,7 @@ class qtype_gapselect_test_helper {
|
||||
* This examples includes choices with currency like options.
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_currency_gapselect_question() {
|
||||
public static function make_gapselect_question_currency() {
|
||||
question_bank::load_question_definition_classes('gapselect');
|
||||
$gapselect = new qtype_gapselect_question();
|
||||
|
||||
@@ -181,4 +229,48 @@ class qtype_gapselect_test_helper {
|
||||
|
||||
return $gapselect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility.
|
||||
*
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_gapselect_question() {
|
||||
debugging('qtype_gapselect_test_helper::make_a_gapselect_question is deprecated. ' .
|
||||
"Please use test_question_maker::make_question('gapselect') instead.");
|
||||
return self::make_gapselect_question_fox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility.
|
||||
*
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_maths_gapselect_question() {
|
||||
debugging('qtype_gapselect_test_helper::make_a_maths_gapselect_question is deprecated. ' .
|
||||
"Please use test_question_maker::make_question('gapselect', 'maths') instead.");
|
||||
return self::make_gapselect_question_maths();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility.
|
||||
*
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_currency_gapselect_question() {
|
||||
debugging('qtype_gapselect_test_helper::make_a_currency_gapselect_question is deprecated. ' .
|
||||
"Please use test_question_maker::make_question('gapselect', 'currency') instead.");
|
||||
return self::make_gapselect_question_currency();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility.
|
||||
*
|
||||
* @return qtype_gapselect_question
|
||||
*/
|
||||
public static function make_a_multilang_gapselect_question() {
|
||||
debugging('qtype_gapselect_test_helper::make_a_multilang_gapselect_question is deprecated. ' .
|
||||
"Please use test_question_maker::make_question('gapselect', 'multilang') instead.");
|
||||
return self::make_gapselect_question_multilang();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,21 +39,21 @@ require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
|
||||
class qtype_gapselect_question_test extends basic_testcase {
|
||||
|
||||
public function test_get_question_summary() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$this->assertEquals('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
|
||||
'[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
|
||||
$gapselect->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_get_question_summary_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$this->assertEquals('Fill in the operators to make this equation work: ' .
|
||||
'7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; [[1]] -> {+ / - / * / /}',
|
||||
$gapselect->get_question_summary());
|
||||
}
|
||||
|
||||
public function test_summarise_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -62,7 +62,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_summarise_response_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -71,17 +71,17 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$this->assertEquals(0.5, $gapselect->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_random_guess_score_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$this->assertEquals(0.25, $gapselect->get_random_guess_score());
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -90,7 +90,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_right_choice_for_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -99,7 +99,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_clear_wrong_from_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -109,7 +109,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_num_parts_right() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -120,7 +120,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_num_parts_right_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -129,7 +129,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_expected_data() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertEquals(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
|
||||
@@ -137,7 +137,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_correct_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -146,7 +146,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_get_correct_response_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -155,7 +155,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_is_same_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertTrue($gapselect->is_same_response(
|
||||
@@ -179,7 +179,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
array('p1' => '1', 'p2' => '2', 'p3' => '2')));
|
||||
}
|
||||
public function test_is_complete_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertFalse($gapselect->is_complete_response(array()));
|
||||
@@ -191,7 +191,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_is_gradable_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
$this->assertFalse($gapselect->is_gradable_response(array()));
|
||||
@@ -205,7 +205,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_grading() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -218,7 +218,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_grading_maths() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect', 'maths');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
@@ -231,7 +231,7 @@ class qtype_gapselect_question_test extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_classify_response() {
|
||||
$gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$gapselect = test_question_maker::make_question('gapselect');
|
||||
$gapselect->shufflechoices = false;
|
||||
$gapselect->start_attempt(new question_attempt_step(), 1);
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,7 @@ class qtype_gapselect_test extends question_testcase {
|
||||
protected $qtype;
|
||||
|
||||
protected function setUp() {
|
||||
$this->qtype = question_bank::get_qtype('gapselect');;
|
||||
$this->qtype = question_bank::get_qtype('gapselect');
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
@@ -50,8 +49,9 @@ class qtype_gapselect_test extends question_testcase {
|
||||
|
||||
/**
|
||||
* Asserts that two strings containing XML are the same ignoring the line-endings.
|
||||
* @param unknown $expectedxml
|
||||
* @param unknown $xml
|
||||
*
|
||||
* @param string $expectedxml
|
||||
* @param string $xml
|
||||
*/
|
||||
public function assert_same_xml($expectedxml, $xml) {
|
||||
$this->assertEquals(str_replace("\r\n", "\n", $expectedxml),
|
||||
@@ -61,50 +61,10 @@ class qtype_gapselect_test extends question_testcase {
|
||||
/**
|
||||
* Get some test question data.
|
||||
* @return object the data to construct a question like
|
||||
* {@link qtype_gapselect_test_helper::make_a_gapselect_question()}.
|
||||
* {@link test_question_maker::make_question('gapselect')}.
|
||||
*/
|
||||
protected function get_test_question_data() {
|
||||
global $USER;
|
||||
|
||||
$gapselect = new stdClass();
|
||||
$gapselect->id = 0;
|
||||
$gapselect->category = 0;
|
||||
$gapselect->contextid = 0;
|
||||
$gapselect->parent = 0;
|
||||
$gapselect->questiontextformat = FORMAT_HTML;
|
||||
$gapselect->generalfeedbackformat = FORMAT_HTML;
|
||||
$gapselect->defaultmark = 1;
|
||||
$gapselect->penalty = 0.3333333;
|
||||
$gapselect->length = 1;
|
||||
$gapselect->stamp = make_unique_id_code();
|
||||
$gapselect->version = make_unique_id_code();
|
||||
$gapselect->hidden = 0;
|
||||
$gapselect->idnumber = null;
|
||||
$gapselect->timecreated = time();
|
||||
$gapselect->timemodified = time();
|
||||
$gapselect->createdby = $USER->id;
|
||||
$gapselect->modifiedby = $USER->id;
|
||||
|
||||
$gapselect->name = 'Selection from drop down list question';
|
||||
$gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.';
|
||||
$gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
|
||||
$gapselect->qtype = 'gapselect';
|
||||
|
||||
$gapselect->options = new stdClass();
|
||||
$gapselect->options->shuffleanswers = true;
|
||||
|
||||
test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
|
||||
|
||||
$gapselect->options->answers = array(
|
||||
(object) array('answer' => 'quick', 'feedback' => '1'),
|
||||
(object) array('answer' => 'fox', 'feedback' => '2'),
|
||||
(object) array('answer' => 'lazy', 'feedback' => '3'),
|
||||
(object) array('answer' => 'assiduous', 'feedback' => '3'),
|
||||
(object) array('answer' => 'dog', 'feedback' => '2'),
|
||||
(object) array('answer' => 'slow', 'feedback' => '1'),
|
||||
);
|
||||
|
||||
return $gapselect;
|
||||
return test_question_maker::get_question_data('gapselect');
|
||||
}
|
||||
|
||||
public function test_name() {
|
||||
@@ -118,7 +78,7 @@ class qtype_gapselect_test extends question_testcase {
|
||||
public function test_initialise_question_instance() {
|
||||
$qdata = $this->get_test_question_data();
|
||||
|
||||
$expected = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$expected = test_question_maker::make_question('gapselect');
|
||||
$expected->stamp = $qdata->stamp;
|
||||
$expected->version = $qdata->version;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
public function test_interactive_behaviour() {
|
||||
|
||||
// Create a gapselect question.
|
||||
$q = qtype_gapselect_test_helper::make_a_gapselect_question();
|
||||
$q = test_question_maker::make_question('gapselect');
|
||||
$q->hints = array(
|
||||
new question_hint_with_parts(1, 'This is the first hint.', FORMAT_HTML, false, false),
|
||||
new question_hint_with_parts(2, 'This is the second hint.', FORMAT_HTML, true, true),
|
||||
@@ -160,7 +160,7 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
$filtermanager->reset_caches();
|
||||
|
||||
// Create a multilang gapselect question.
|
||||
$q = qtype_gapselect_test_helper::make_a_multilang_gapselect_question();
|
||||
$q = test_question_maker::make_question('gapselect', 'multilang');
|
||||
$q->shufflechoices = false;
|
||||
$this->start_attempt_at_question($q, 'interactive', 3);
|
||||
|
||||
@@ -177,7 +177,7 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
|
||||
public function test_choices_containing_dollars() {
|
||||
|
||||
// Choices with a currency like entry (e.g. $3) should display.
|
||||
$q = qtype_gapselect_test_helper::make_a_currency_gapselect_question();
|
||||
$q = test_question_maker::make_question('gapselect', 'currency');
|
||||
$q->shufflechoices = false;
|
||||
$this->start_attempt_at_question($q, 'interactive', 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user