MDL-20636 Fix codechecker problems in match, description and ddwtos qtypes.

This commit is contained in:
Tim Hunt
2011-04-05 17:54:39 +01:00
parent 121fd4c12d
commit 3758786f6d
18 changed files with 400 additions and 301 deletions
@@ -50,7 +50,6 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
$elepath = $this->get_pathfor('/ddwtos'); // we used get_recommended_name() so this works
$paths[] = new restore_path_element($elename, $elepath);
return $paths; // And we return the interesting paths
}
@@ -76,8 +75,6 @@ class restore_qtype_ddwtos_plugin extends restore_qtype_plugin {
$newitemid = $DB->insert_record('question_ddwtos', $data);
// Create mapping (needed for decoding links)
$this->set_mapping('question_ddwtos', $oldid, $newitemid);
} else {
// Nothing to remap if the question already existed
}
}
+3 -1
View File
@@ -51,7 +51,9 @@ class qtype_ddwtos_edit_form extends qtype_gapselect_edit_form_base {
protected function choice_group($mform) {
$grouparray = parent::choice_group($mform);
$grouparray[] = $mform->createElement('checkbox', 'infinite', ' ', get_string('infinite', 'qtype_ddwtos'), null, array('size'=>1, 'class'=>'tweakcss'));
$grouparray[] = $mform->createElement('checkbox', 'infinite', ' ',
get_string('infinite', 'qtype_ddwtos'), null,
array('size' => 1, 'class' => 'tweakcss'));
return $grouparray;
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ class qtype_ddwtos_choice {
$this->draggroup = $draggroup;
$this->isinfinite = $isinfinite;
}
public function choice_group(){
public function choice_group() {
return $this->draggroup;
}
}
+9 -98
View File
@@ -40,7 +40,7 @@ require_once($CFG->dirroot . '/question/type/gapselect/questiontypebase.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_ddwtos extends qtype_gapselect_base {
protected function choice_group_key(){
protected function choice_group_key() {
return 'draggroup';
}
@@ -48,21 +48,22 @@ class qtype_ddwtos extends qtype_gapselect_base {
return array('gapselect');
}
protected function choice_options_to_feedback($choice){
protected function choice_options_to_feedback($choice) {
$output = new stdClass();
$output->draggroup = $choice['choicegroup'];
$output->infinite = !empty($choice['infinite']);
return serialize($output);
}
protected function feedback_to_choice_options($feedback){
protected function feedback_to_choice_options($feedback) {
$feedbackobj = unserialize($feedback);
return array('draggroup'=> $feedbackobj->draggroup, 'infinite'=> $feedbackobj->infinite);
return array('draggroup' => $feedbackobj->draggroup, 'infinite' => $feedbackobj->infinite);
}
protected function make_choice($choicedata){
protected function make_choice($choicedata) {
$options = unserialize($choicedata->feedback);
return new qtype_ddwtos_choice($choicedata->answer, $options->draggroup, $options->infinite);
return new qtype_ddwtos_choice(
$choicedata->answer, $options->draggroup, $options->infinite);
}
public function import_from_xml($data, $question, $format, $extra=null) {
@@ -113,7 +114,8 @@ class qtype_ddwtos extends qtype_gapselect_base {
public function export_to_xml($question, $format, $extra = null) {
$output = '';
$output .= ' <shuffleanswers>' . $question->options->shuffleanswers . "</shuffleanswers>\n";
$output .= ' <shuffleanswers>' . $question->options->shuffleanswers .
"</shuffleanswers>\n";
$output .= $format->write_combined_feedback($question->options);
@@ -131,95 +133,4 @@ class qtype_ddwtos extends qtype_gapselect_base {
return $output;
}
/*
* Backup the data in the question
*
* This is used in question/backuplib.php
*/
public function backup($bf, $preferences, $question, $level = 6) {
$status = true;
$ddwtos = get_records("question_ddwtos", "questionid", $question, "id");
//If there are ddwtos
if ($ddwtos) {
//Iterate over each ddwtos
foreach ($ddwtos as $ddws) {
$status = fwrite ($bf,start_tag("DDWORDSSENTENCES",$level,true));
//Print oumultiresponse contents
fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$ddws->shuffleanswers));
fwrite ($bf,full_tag("CORRECTFEEDBACK",$level+1,false,$ddws->correctfeedback));
fwrite ($bf,full_tag("PARTIALLYCORRECTFEEDBACK",$level+1,false,$ddws->partiallycorrectfeedback));
fwrite ($bf,full_tag("INCORRECTFEEDBACK",$level+1,false,$ddws->incorrectfeedback));
fwrite ($bf,full_tag("SHOWNUMCORRECT",$level+1,false,$ddws->shownumcorrect));
$status = fwrite ($bf,end_tag("DDWORDSSENTENCES",$level,true));
}
//Now print question_answers
$status = question_backup_answers($bf,$preferences,$question);
}
return $status;
}
/**
* Restores the data in the question (This is used in question/restorelib.php)
*
*/
public function restore($old_question_id,$new_question_id,$info,$restore) {
$status = true;
//Get the ddwtos array
$ddwtos = $info['#']['DDWORDSSENTENCES'];
//Iterate over oumultiresponses
for($i = 0; $i < sizeof($ddwtos); $i++) {
$mul_info = $ddwtos[$i];
//Now, build the question_ddwtos record structure
$ddwtos = new stdClass();
$ddwtos->questionid = $new_question_id;
$ddwtos->shuffleanswers = isset($mul_info['#']['SHUFFLEANSWERS']['0']['#'])?backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']):'';
if (array_key_exists("CORRECTFEEDBACK", $mul_info['#'])) {
$ddwtos->correctfeedback = backup_todb($mul_info['#']['CORRECTFEEDBACK']['0']['#']);
} else {
$ddwtos->correctfeedback = '';
}
if (array_key_exists("PARTIALLYCORRECTFEEDBACK", $mul_info['#'])) {
$ddwtos->partiallycorrectfeedback = backup_todb($mul_info['#']['PARTIALLYCORRECTFEEDBACK']['0']['#']);
} else {
$ddwtos->partiallycorrectfeedback = '';
}
if (array_key_exists("INCORRECTFEEDBACK", $mul_info['#'])) {
$ddwtos->incorrectfeedback = backup_todb($mul_info['#']['INCORRECTFEEDBACK']['0']['#']);
} else {
$ddwtos->incorrectfeedback = '';
}
if (array_key_exists('SHOWNUMCORRECT', $mul_info['#'])) {
$ddwtos->shownumcorrect = backup_todb($mul_info['#']['SHOWNUMCORRECT']['0']['#']);
} else if (array_key_exists('CORRECTRESPONSESFEEDBACK', $mul_info['#'])) {
$ddwtos->shownumcorrect = backup_todb($mul_info['#']['CORRECTRESPONSESFEEDBACK']['0']['#']);
} else {
$ddwtos->shownumcorrect = 0;
}
$newid = insert_record ("question_ddwtos",$ddwtos);
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
if (!$newid) {
$status = false;
}
}
return $status;
}
}
+7 -4
View File
@@ -38,11 +38,12 @@ require_once($CFG->dirroot . '/question/type/gapselect/rendererbase.php');
*/
class qtype_ddwtos_renderer extends qtype_elements_embedded_in_question_text_renderer {
protected function qtext_classname(){
protected function qtext_classname() {
return 'qtext ddwtos_questionid_for_javascript';
}
protected function post_qtext_elements(question_attempt $qa, question_display_options $options){
protected function post_qtext_elements(question_attempt $qa,
question_display_options $options) {
$result = '';
$question = $qa->get_question();
$dragboxs = '';
@@ -71,7 +72,8 @@ class qtype_ddwtos_renderer extends qtype_elements_embedded_in_question_text_ren
return '<sub>&#160;</sub>' . $string . '<sup>&#160;</sup>';
}
protected function embedded_element(question_attempt $qa, $place, question_display_options $options) {
protected function embedded_element(question_attempt $qa, $place,
question_display_options $options) {
$question = $qa->get_question();
$group = $question->places[$place];
$boxcontents = $this->dodgy_ie_fix('&#160;');
@@ -94,7 +96,8 @@ class qtype_ddwtos_renderer extends qtype_elements_embedded_in_question_text_ren
$response = $qa->get_last_qt_data();
$fieldname = $question->field($place);
if (array_key_exists($fieldname, $response)) {
$fraction = (int) ($response[$fieldname] == $question->get_right_choice_for($place));
$fraction = (int) ($response[$fieldname] ==
$question->get_right_choice_for($place));
$attributes['class'] .= ' ' . $this->feedback_class($fraction);
$feedbackimage = $this->feedback_image($fraction);
}
+3 -3
View File
@@ -104,7 +104,6 @@ var ddwtos_currentzindex = 10;
initPlayer : function(id, sGroup, config) {
this.isTarget = false;
this.currentPos = YAHOO.util.Dom.getXY(this.getEl());
},
//Abstract method called after a drag/drop object is clicked and the drag or mousedown time thresholds have beeen met.
@@ -178,7 +177,6 @@ var ddwtos_currentzindex = 10;
YAHOO.util.Event.onDOMReady(YAHOO.example.DDApp.init, YAHOO.example.DDApp, true);
// Objects///////////////////////////////////////////////////////////////////
var Questions = new Object();
@@ -300,7 +298,9 @@ var ddwtos_currentzindex = 10;
var slot = slots[i];
var hiddenElement = document.getElementById(slot.id + '_hidden');
if (!hiddenElement) continue;
if (!hiddenElement) {
continue;
}
// get group
var group = getGroupForThis(slot.id);
@@ -41,7 +41,8 @@ class qtype_ddwtos_question_test extends UnitTestCase {
public function test_get_question_summary() {
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
$this->assertEqual('The [[1]] brown [[2]] jumped over the [[3]] dog.; [[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
$this->assertEqual('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
'[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
$dd->get_question_summary());
}
@@ -125,7 +126,8 @@ class qtype_ddwtos_question_test extends UnitTestCase {
$dd->start_attempt(new question_attempt_step());
$this->assertEqual(array(2, 4),
$dd->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
$dd->get_num_parts_right(array(
'p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
}
public function test_get_expected_data() {
@@ -89,12 +89,18 @@ class qtype_ddwtos_test extends UnitTestCase {
test_question_maker::set_standard_combined_feedback_fields($dd->options);
$dd->options->answers = array(
(object) array('answer' => 'quick', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'),
(object) array('answer' => 'fox', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'),
(object) array('answer' => 'lazy', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'),
(object) array('answer' => 'assiduous', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'),
(object) array('answer' => 'dog', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'),
(object) array('answer' => 'slow', 'feedback' => 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'),
(object) array('answer' => 'quick', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'),
(object) array('answer' => 'fox', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'),
(object) array('answer' => 'lazy', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'),
(object) array('answer' => 'assiduous', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"3";s:8:"infinite";i:0;}'),
(object) array('answer' => 'dog', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"2";s:8:"infinite";i:0;}'),
(object) array('answer' => 'slow', 'feedback' =>
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";i:0;}'),
);
return $dd;
@@ -209,10 +215,14 @@ class qtype_ddwtos_test extends UnitTestCase {
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = 1;
$expectedq->correctfeedback = array('text' => '<p>Your answer is correct.</p>', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->partiallycorrectfeedback = array('text' => '<p>Your answer is partially correct.</p>', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->correctfeedback = array('text' => '<p>Your answer is correct.</p>',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->partiallycorrectfeedback = array(
'text' => '<p>Your answer is partially correct.</p>',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->shownumcorrect = true;
$expectedq->incorrectfeedback = array('text' => '<p>Your answer is incorrect.</p>', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->incorrectfeedback = array('text' => '<p>Your answer is incorrect.</p>',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->choices = array(
array('answer' => 'Alpha', 'choicegroup' => 1, 'infinite' => false),
@@ -222,7 +232,8 @@ class qtype_ddwtos_test extends UnitTestCase {
$expectedq->hint = array(
array('text' => 'Try again.', 'format' => FORMAT_MOODLE, 'files' => array()),
array('text' => 'These are the first three letters of the Greek alphabet.', 'format' => FORMAT_MOODLE, 'files' => array()));
array('text' => 'These are the first three letters of the Greek alphabet.',
'format' => FORMAT_MOODLE, 'files' => array()));
$expectedq->hintshownumcorrect = array(true, true);
$expectedq->hintclearwrong = array(false, true);
@@ -235,11 +246,19 @@ class qtype_ddwtos_test extends UnitTestCase {
<text>QDandD1 Base definition</text>
</name>
<questiontext format="html">
<text>&lt;p&gt;Drag and drop the words from the list below to fill the blank spaces and correctly complete the sentence.&lt;/p&gt; &lt;p&gt;At 25°C all aqueous basic solutions have [[1]]&#160;ion concentrations less than [[8]]&lt;br /&gt;mol litre&lt;sup&gt;-1&lt;/sup&gt; and pH values [[9]] than [[6]].&lt;/p&gt; &lt;!--DONOTCLEAN--&gt;</text>
<text>&lt;p&gt;Drag and drop the words from the list below to fill the blank spaces ' .
'and correctly complete the sentence.&lt;/p&gt; &lt;p&gt;At 25°C all aqueous basic ' .
'solutions have [[1]]&#160;ion concentrations less than [[8]]&lt;br /&gt;mol ' .
'litre&lt;sup&gt;-1&lt;/sup&gt; and pH values [[9]] than [[6]].&lt;/p&gt; ' .
'&lt;!--DONOTCLEAN--&gt;</text>
</questiontext>
<image></image>
<generalfeedback>
<text>&lt;p&gt;At 25 &amp;#xB0;C all aqueous basic solutions have hydrogen ion concentrations less than 10&lt;sup&gt;&amp;#x2212;7&lt;/sup&gt; mol litre&lt;sup&gt;&amp;#x2212;1&lt;/sup&gt; and pH values greater than 7.&lt;/p&gt; &lt;p&gt;See Section 9 of S103 &lt;em class="italic"&gt;Discovering Science&lt;/em&gt; Block 8.&lt;/p&gt;</text>
<text>&lt;p&gt;At 25 &amp;#xB0;C all aqueous basic solutions have hydrogen ion ' .
'concentrations less than 10&lt;sup&gt;&amp;#x2212;7&lt;/sup&gt; mol ' .
'litre&lt;sup&gt;&amp;#x2212;1&lt;/sup&gt; and pH values greater than 7.&lt;/p&gt; ' .
'&lt;p&gt;See Section 9 of S103 &lt;em class="italic"&gt;Discovering ' .
'Science&lt;/em&gt; Block 8.&lt;/p&gt;</text>
</generalfeedback>
<defaultgrade>1</defaultgrade>
<penalty>0.33</penalty>
@@ -332,7 +351,8 @@ class qtype_ddwtos_test extends UnitTestCase {
<statenumberofcorrectresponses>1</statenumberofcorrectresponses>
<clearincorrectresponses>0</clearincorrectresponses>
<hintcontent>
<text>You may wish to read&#160;Section 9 of&#160;&lt;em class="italic"&gt;Discovering Science&lt;/em&gt; Block 8.</text>
<text>You may wish to read&#160;Section 9 of&#160;&lt;em ' .
'class="italic"&gt;Discovering Science&lt;/em&gt; Block 8.</text>
</hintcontent>
</hint>
<hint>
@@ -352,36 +372,57 @@ class qtype_ddwtos_test extends UnitTestCase {
$expectedq = new stdClass();
$expectedq->qtype = 'ddwtos';
$expectedq->name = 'QDandD1 Base definition';
$expectedq->questiontext = '<p>Drag and drop the words from the list below to fill the blank spaces and correctly complete the sentence.</p><p>At 25°C all aqueous basic solutions have [[1]] ion concentrations less than [[8]]<br />mol litre<sup>-1</sup> and pH values [[9]] than [[6]].</p><!--DONOTCLEAN-->';
$expectedq->questiontext = '<p>Drag and drop the words from the list below ' .
'to fill the blank spaces and correctly complete the sentence.</p>' .
'<p>At 25°C all aqueous basic solutions have [[1]] ion concentrations ' .
'less than [[8]]<br />mol litre<sup>-1</sup> and pH values [[9]] than [[6]].</p>' .
'<!--DONOTCLEAN-->';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = '<p>At 25 &#xB0;C all aqueous basic solutions have hydrogen ion concentrations less than 10<sup>&#x2212;7</sup> mol litre<sup>&#x2212;1</sup> and pH values greater than 7.</p><p>See Section 9 of S103 <em class="italic">Discovering Science</em> Block 8.</p>';
$expectedq->generalfeedback = '<p>At 25 &#xB0;C all aqueous basic solutions ' .
'have hydrogen ion concentrations less than 10<sup>&#x2212;7</sup> ' .
'mol litre<sup>&#x2212;1</sup> and pH values greater than 7.</p><p>See ' .
'Section 9 of S103 <em class="italic">Discovering Science</em> Block 8.</p>';
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = 0;
$expectedq->correctfeedback = array('text' => 'Your answer is correct.', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->partiallycorrectfeedback = array('text' => 'Your answer is partially correct.', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->correctfeedback = array('text' => 'Your answer is correct.',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->partiallycorrectfeedback = array(
'text' => 'Your answer is partially correct.',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->shownumcorrect = true;
$expectedq->incorrectfeedback = array('text' => 'Your answer is incorrect.', 'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->incorrectfeedback = array('text' => 'Your answer is incorrect.',
'format' => FORMAT_MOODLE, 'files' => array());
$expectedq->choices = array(
array('answer' => array('text' => 'hydrogen', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'positive', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'hydroxide', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'negative', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => '10<sup>7</sup>', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '7', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '1', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '10<sup>-7</sup>', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => 'greater', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 3, 'infinite' => false),
array('answer' => array('text' => 'less', 'format' => FORMAT_MOODLE, 'files' => array()), 'choicegroup' => 3, 'infinite' => false),
array('answer' => array('text' => 'hydrogen', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'positive', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'hydroxide', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => 'negative', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 1, 'infinite' => false),
array('answer' => array('text' => '10<sup>7</sup>', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '7', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '1', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => '10<sup>-7</sup>', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 2, 'infinite' => false),
array('answer' => array('text' => 'greater', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 3, 'infinite' => false),
array('answer' => array('text' => 'less', 'format' => FORMAT_MOODLE,
'files' => array()), 'choicegroup' => 3, 'infinite' => false),
);
$expectedq->hint = array(
array('text' => 'You may wish to read Section 9 of <em class="italic">Discovering Science</em> Block 8.',
$expectedq->hint = array(array('text' => 'You may wish to read Section 9 of ' .
'<em class="italic">Discovering Science</em> Block 8.',
'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'Any incorrect choices will be removed before your final try.',
array('text' => 'Any incorrect choices will be removed before your final try.',
'format' => FORMAT_HTML, 'files' => array()),
);
$expectedq->hintshownumcorrect = array(true, true);
@@ -416,14 +457,22 @@ class qtype_ddwtos_test extends UnitTestCase {
$qdata->options->incorrectfeedbackformat = FORMAT_MOODLE;
$qdata->options->answers = array(
13 => new question_answer(13, 'Alpha', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}', FORMAT_MOODLE),
14 => new question_answer(14, 'Beta', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}', FORMAT_MOODLE),
15 => new question_answer(15, 'Gamma', 0, 'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:1;}', FORMAT_MOODLE),
13 => new question_answer(13, 'Alpha', 0,
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}',
FORMAT_MOODLE),
14 => new question_answer(14, 'Beta', 0,
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:0;}',
FORMAT_MOODLE),
15 => new question_answer(15, 'Gamma', 0,
'O:8:"stdClass":2:{s:9:"draggroup";s:1:"1";s:8:"infinite";b:1;}',
FORMAT_MOODLE),
);
$qdata->hints = array(
1 => new question_hint_with_parts(1, 'Try again.', FORMAT_MOODLE, true, false),
2 => new question_hint_with_parts(2, 'These are the first three letters of the Greek alphabet.', FORMAT_MOODLE, true, true),
2 => new question_hint_with_parts(2,
'These are the first three letters of the Greek alphabet.',
FORMAT_MOODLE, true, true),
);
$exporter = new qformat_xml();
@@ -39,7 +39,8 @@ require_once($CFG->dirroot . '/question/type/ddwtos/simpletest/helper.php');
*/
class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
protected function get_contains_drop_box_expectation($place, $group, $readonly, $stateclass = '0') {
protected function get_contains_drop_box_expectation($place, $group, $readonly,
$stateclass = '0') {
$qa = $this->quba->get_question_attempt($this->slot);
$expectedattrs = array(
@@ -77,9 +78,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
@@ -95,9 +99,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '2'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '2'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation(),
@@ -117,7 +124,8 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_submit_button_expectation(false),
$this->get_contains_try_again_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
new PatternExpectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
new PatternExpectation('/' .
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
$this->get_contains_hint_expectation('This is the first hint'));
// Do try again.
@@ -130,9 +138,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '2'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '2'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation(),
@@ -175,9 +186,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_feedback_expectation());
// Save a partial answer.
@@ -190,9 +204,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '2'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
@@ -206,9 +223,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '1'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
@@ -249,9 +269,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
$this->check_step_count(1);
@@ -266,9 +289,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
$this->check_step_count(1);
@@ -299,9 +325,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
@@ -315,9 +344,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
@@ -339,8 +371,10 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
// Create a drag-and-drop question.
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
$dd->hints = array(
new question_hint_with_parts(1, 'This is the first hint.', FORMAT_MOODLE, true, true),
new question_hint_with_parts(2, 'This is the second hint.', FORMAT_MOODLE, true, true),
new question_hint_with_parts(1, 'This is the first hint.',
FORMAT_MOODLE, true, true),
new question_hint_with_parts(2, 'This is the second hint.',
FORMAT_MOODLE, true, true),
);
$dd->shufflechoices = false;
$this->start_attempt_at_question($dd, 'interactive', 9);
@@ -354,9 +388,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
@@ -376,18 +413,23 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_submit_button_expectation(false),
$this->get_contains_try_again_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
new PatternExpectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
new PatternExpectation('/' .
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
$this->get_contains_hint_expectation('This is the first hint'),
$this->get_contains_num_parts_correct(2),
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'));
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'));
// Check that extract responses will return the reset data.
$prefix = $this->quba->get_field_prefix($this->slot);
$this->assertEqual(array('p1' => '1', 'p2' => '1'),
$this->quba->extract_responses($this->slot, array($prefix . 'p1' => '1', $prefix . 'p2' => '1', '-tryagain' => 1)));
$this->quba->extract_responses($this->slot,
array($prefix . 'p1' => '1', $prefix . 'p2' => '1', '-tryagain' => 1)));
// Do try again.
$this->process_submission(array('p1' => '1', 'p2' => '1', '-tryagain' => 1));
@@ -399,9 +441,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_does_not_contain_correctness_expectation(),
@@ -422,13 +467,17 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_submit_button_expectation(false),
$this->get_contains_try_again_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
new PatternExpectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
new PatternExpectation('/' .
preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
$this->get_contains_hint_expectation('This is the second hint'),
$this->get_contains_num_parts_correct(2),
$this->get_contains_standard_partiallycorrect_combined_feedback_expectation(),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '1'));
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '1'));
// Do try again.
$this->process_submission(array('p1' => '1', 'p3' => '1', '-tryagain' => 1));
@@ -440,9 +489,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '1'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_try_again_button_expectation(),
$this->get_does_not_contain_correctness_expectation(),
@@ -466,9 +518,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_no_hint_visible_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_contains_standard_correct_combined_feedback_expectation(),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '1'));
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '1'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '1'));
}
public function test_interactive_correct_no_submit() {
@@ -476,8 +531,10 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
// Create a drag-and-drop question.
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
$dd->hints = array(
new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, false),
new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true),
new question_hint_with_parts(23, 'This is the first hint.',
FORMAT_MOODLE, false, false),
new question_hint_with_parts(24, 'This is the second hint.',
FORMAT_MOODLE, true, true),
);
$dd->shufflechoices = false;
$this->start_attempt_at_question($dd, 'interactive', 3);
@@ -489,9 +546,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
@@ -527,8 +587,10 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
// Create a drag-and-drop question.
$dd = qtype_ddwtos_test_helper::make_a_ddwtos_question();
$dd->hints = array(
new question_hint_with_parts(23, 'This is the first hint.', FORMAT_MOODLE, false, false),
new question_hint_with_parts(24, 'This is the second hint.', FORMAT_MOODLE, true, true),
new question_hint_with_parts(23, 'This is the first hint.',
FORMAT_MOODLE, false, false),
new question_hint_with_parts(24, 'This is the second hint.',
FORMAT_MOODLE, true, true),
);
$dd->shufflechoices = false;
$this->start_attempt_at_question($dd, 'interactive', 3);
@@ -540,9 +602,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
@@ -592,9 +657,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(3),
@@ -625,9 +693,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_tries_remaining_expectation(2),
@@ -647,9 +718,12 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3', '0'),
$this->get_does_not_contain_feedback_expectation());
// Save a partial answer.
@@ -662,9 +736,15 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p1', 1, false),
$this->get_contains_drop_box_expectation('p2', 2, false),
$this->get_contains_drop_box_expectation('p3', 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p1', $dd->get_right_choice_for(1)),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p2', $dd->get_right_choice_for(2)),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'p3', $dd->get_right_choice_for(3)),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p1',
$dd->get_right_choice_for(1)),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p2',
$dd->get_right_choice_for(2)),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'p3',
$dd->get_right_choice_for(3)),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_feedback_expectation());
@@ -681,6 +761,7 @@ class qtype_ddwtos_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_drop_box_expectation('p2', 2, true, 'correct'),
$this->get_contains_drop_box_expectation('p3', 3, true, 'correct'),
$this->get_contains_correct_expectation(),
new PatternExpectation('/' . preg_quote('The [quick] brown [fox] jumped over the [lazy] dog.') . '/'));
new PatternExpectation('/' .
preg_quote('The [quick] brown [fox] jumped over the [lazy] dog.') . '/'));
}
}
@@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/question/type/description/questiontype.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_description_test extends UnitTestCase {
var $qtype;
protected $qtype;
public function setUp() {
$this->qtype = new qtype_description();
@@ -65,8 +65,10 @@ class backup_qtype_match_plugin extends backup_qtype_plugin {
$matches->add_child($match);
// set source to populate the data
$matchoptions->set_source_table('question_match', array('question' => backup::VAR_PARENTID));
$match->set_source_table('question_match_sub', array('question' => backup::VAR_PARENTID));
$matchoptions->set_source_table('question_match',
array('question' => backup::VAR_PARENTID));
$match->set_source_table('question_match_sub',
array('question' => backup::VAR_PARENTID));
// don't need to annotate ids nor files
@@ -44,14 +44,15 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
// Add own qtype stuff
$elename = 'matchoptions';
$elepath = $this->get_pathfor('/matchoptions'); // we used get_recommended_name() so this works
// We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/matchoptions');
$paths[] = new restore_path_element($elename, $elepath);
$elename = 'match';
$elepath = $this->get_pathfor('/matches/match'); // we used get_recommended_name() so this works
// We used get_recommended_name() so this works.
$elepath = $this->get_pathfor('/matches/match');
$paths[] = new restore_path_element($elename, $elepath);
return $paths; // And we return the interesting paths
}
@@ -80,8 +81,6 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$newitemid = $DB->insert_record('question_match', $data);
// Create mapping
$this->set_mapping('question_match', $oldid, $newitemid);
} else {
// Nothing to remap if the question already existed
}
}
@@ -99,8 +98,10 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
// If the question has been created by restore, we need to create its question_match_sub too
if ($questioncreated) {
// If the question has been created by restore, we need to create its
// question_match_sub too
// Adjust some columns
$data->question = $newquestionid;
// Insert record
@@ -108,18 +109,22 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
// Create mapping (there are files and states based on this)
$this->set_mapping('question_match_sub', $oldid, $newitemid);
// match questions require mapping of question_match_sub, because
// they are used by question_states->answer
} else {
// match questions require mapping of question_match_sub, because
// they are used by question_states->answer
// Look for matching subquestion (by question, questiontext and answertext)
$sub = $DB->get_record_select('question_match_sub',
'question = ? AND '.$DB->sql_compare_text('questiontext').' = '.$DB->sql_compare_text('?').' AND answertext = ?',
array($newquestionid, $data->questiontext, $data->answertext), 'id', IGNORE_MULTIPLE);
$sub = $DB->get_record_select('question_match_sub', 'question = ? AND ' .
$DB->sql_compare_text('questiontext') . ' = ' .
$DB->sql_compare_text('?').' AND answertext = ?',
array($newquestionid, $data->questiontext, $data->answertext),
'id', IGNORE_MULTIPLE);
// Found, let's create the mapping
if ($sub) {
$this->set_mapping('question_match_sub', $oldid, $sub->id);
// Something went really wrong, cannot map subquestion for one match question
} else {
// Something went really wrong, cannot map subquestion for one match question
throw restore_step_exception('error_question_match_sub_missing_in_db', $data);
}
}
@@ -138,18 +143,21 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
global $DB;
// Now that all the question_match_subs have been restored, let's process
// the created question_match subquestions (list of question_match_sub ids)
$rs = $DB->get_recordset_sql("SELECT qm.id, qm.subquestions
FROM {question_match} qm
JOIN {backup_ids_temp} bi ON bi.newitemid = qm.question
WHERE bi.backupid = ?
AND bi.itemname = 'question_created'", array($this->get_restoreid()));
$rs = $DB->get_recordset_sql(
"SELECT qm.id, qm.subquestions
FROM {question_match} qm
JOIN {backup_ids_temp} bi ON bi.newitemid = qm.question
WHERE bi.backupid = ?
AND bi.itemname = 'question_created'", array($this->get_restoreid()));
foreach ($rs as $rec) {
$subquestionsarr = explode(',', $rec->subquestions);
foreach ($subquestionsarr as $key => $subquestion) {
$subquestionsarr[$key] = $this->get_mappingid('question_match_sub', $subquestion);
$subquestionsarr[$key] = $this->get_mappingid(
'question_match_sub', $subquestion);
}
$subquestions = implode(',', $subquestionsarr);
$DB->set_field('question_match', 'subquestions', $subquestions, array('id' => $rec->id));
$DB->set_field('question_match', 'subquestions', $subquestions,
array('id' => $rec->id));
}
$rs->close();
}
@@ -181,7 +189,8 @@ class restore_qtype_match_plugin extends restore_qtype_plugin {
$contents = array();
$contents[] = new restore_decode_content('question_match_sub', array('questiontext'), 'question_match_sub');
$contents[] = new restore_decode_content('question_match_sub',
array('questiontext'), 'question_match_sub');
$fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
$contents[] = new restore_decode_content('question_match', $fields, 'question_match');
+24 -12
View File
@@ -41,7 +41,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field questiontextformat to be added to question_match_sub
$table = new xmldb_table('question_match_sub');
$field = new xmldb_field('questiontextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'questiontext');
$field = new xmldb_field('questiontextformat', XMLDB_TYPE_INTEGER, '2', null,
XMLDB_NOTNULL, null, '0', 'questiontext');
// Conditionally launch add field questiontextformat
if (!$dbman->field_exists($table, $field)) {
@@ -56,7 +57,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
FROM {question_match_sub} qms
JOIN {question} q ON qms.question = q.id');
foreach ($rs as $record) {
if ($CFG->texteditors !== 'textarea' && $record->oldquestiontextformat == FORMAT_MOODLE) {
if ($CFG->texteditors !== 'textarea' &&
$record->oldquestiontextformat == FORMAT_MOODLE) {
$record->questiontext = text_to_html($record->questiontext, false, false, true);
$record->questiontextformat = FORMAT_HTML;
} else {
@@ -74,7 +76,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field correctfeedback to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'shuffleanswers');
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null,
null, null, null, 'shuffleanswers');
// Conditionally launch add field correctfeedback
if (!$dbman->field_exists($table, $field)) {
@@ -84,7 +87,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
$DB->set_field('question_match', 'correctfeedback', '');
// Now add the not null constraint.
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'shuffleanswers');
$field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null,
XMLDB_NOTNULL, null, null, 'shuffleanswers');
$dbman->change_field_notnull($table, $field);
}
@@ -96,7 +100,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field correctfeedbackformat to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'correctfeedback');
$field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
XMLDB_NOTNULL, null, '0', 'correctfeedback');
// Conditionally launch add field correctfeedbackformat
if (!$dbman->field_exists($table, $field)) {
@@ -111,7 +116,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field partiallycorrectfeedback to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'correctfeedbackformat');
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
null, null, null, 'correctfeedbackformat');
// Conditionally launch add field partiallycorrectfeedback
if (!$dbman->field_exists($table, $field)) {
@@ -121,7 +127,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
$DB->set_field('question_match', 'partiallycorrectfeedback', '');
// Now add the not null constraint.
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'correctfeedbackformat');
$field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
XMLDB_NOTNULL, null, null, 'correctfeedbackformat');
$dbman->change_field_notnull($table, $field);
}
@@ -133,7 +140,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field partiallycorrectfeedbackformat to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback');
$field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback');
// Conditionally launch add field partiallycorrectfeedbackformat
if (!$dbman->field_exists($table, $field)) {
@@ -148,7 +156,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field incorrectfeedback to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'partiallycorrectfeedbackformat');
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
null, null, null, 'partiallycorrectfeedbackformat');
// Conditionally launch add field incorrectfeedback
if (!$dbman->field_exists($table, $field)) {
@@ -158,7 +167,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
$DB->set_field('question_match', 'incorrectfeedback', '');
// Now add the not null constraint.
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'partiallycorrectfeedbackformat');
$field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
XMLDB_NOTNULL, null, null, 'partiallycorrectfeedbackformat');
$dbman->change_field_notnull($table, $field);
}
@@ -170,7 +180,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field incorrectfeedbackformat to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'incorrectfeedback');
$field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
XMLDB_NOTNULL, null, '0', 'incorrectfeedback');
// Conditionally launch add field incorrectfeedbackformat
if (!$dbman->field_exists($table, $field)) {
@@ -185,7 +196,8 @@ function xmldb_qtype_match_upgrade($oldversion) {
// Define field shownumcorrect to be added to question_match
$table = new xmldb_table('question_match');
$field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'incorrectfeedbackformat');
$field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null,
XMLDB_NOTNULL, null, '0', 'incorrectfeedbackformat');
// Conditionally launch add field shownumcorrect
if (!$dbman->field_exists($table, $field)) {
+27 -17
View File
@@ -36,11 +36,14 @@ defined('MOODLE_INTERNAL') || die();
*/
class qtype_match_edit_form extends question_edit_form {
protected function get_per_answer_fields($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) {
protected function get_per_answer_fields($mform, $label, $gradeoptions,
&$repeatedoptions, &$answersoption) {
$repeated = array();
$repeated[] = $mform->createElement('header', 'answerhdr', $label);
$repeated[] = $mform->createElement('editor', 'subquestions', get_string('question'), array('rows'=>3), $this->editoroptions);
$repeated[] = $mform->createElement('text', 'subanswers', get_string('answer', 'question'), array('size'=>50));
$repeated[] = $mform->createElement('editor', 'subquestions',
get_string('question'), array('rows'=>3), $this->editoroptions);
$repeated[] = $mform->createElement('text', 'subanswers',
get_string('answer', 'question'), array('size'=>50));
$repeatedoptions['subquestions']['type'] = PARAM_RAW;
$repeatedoptions['subanswers']['type'] = PARAM_TEXT;
$answersoption = 'subquestions';
@@ -53,11 +56,14 @@ class qtype_match_edit_form extends question_edit_form {
* @param object $mform the form being built.
*/
protected function definition_inner($mform) {
$mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffle', 'qtype_match'), null, null, array(0,1));
$mform->addElement('advcheckbox', 'shuffleanswers',
get_string('shuffle', 'qtype_match'), null, null, array(0, 1));
$mform->addHelpButton('shuffleanswers', 'shuffle', 'qtype_match');
$mform->setDefault('shuffleanswers', 1);
$mform->addElement('static', 'answersinstruct', get_string('availablechoices', 'qtype_match'), get_string('filloutthreeqsandtwoas', 'qtype_match'));
$mform->addElement('static', 'answersinstruct',
get_string('availablechoices', 'qtype_match'),
get_string('filloutthreeqsandtwoas', 'qtype_match'));
$mform->closeHeaderBefore('answersinstruct');
$this->add_per_answer_fields($mform, get_string('questionno', 'question', '{no}'), 0);
@@ -78,7 +84,7 @@ class qtype_match_edit_form extends question_edit_form {
$question->shuffleanswers = $question->options->shuffleanswers;
$key = 0;
foreach ($question->options->subquestions as $subquestion){
foreach ($question->options->subquestions as $subquestion) {
$question->subanswers[$key] = $subquestion->answertext;
$draftid = file_get_submitted_draft_itemid('subquestions[' . $key . ']');
@@ -106,30 +112,34 @@ class qtype_match_edit_form extends question_edit_form {
$questions = $data['subquestions'];
$questioncount = 0;
$answercount = 0;
foreach ($questions as $key => $question){
foreach ($questions as $key => $question) {
$trimmedquestion = trim($question['text']);
$trimmedanswer = trim($answers[$key]);
if ($trimmedquestion != ''){
if ($trimmedquestion != '') {
$questioncount++;
}
if ($trimmedanswer != '' || $trimmedquestion != ''){
if ($trimmedanswer != '' || $trimmedquestion != '') {
$answercount++;
}
if ($trimmedquestion != '' && $trimmedanswer == ''){
$errors['subanswers['.$key.']'] = get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion);
if ($trimmedquestion != '' && $trimmedanswer == '') {
$errors['subanswers['.$key.']'] =
get_string('nomatchinganswerforq', 'qtype_match', $trimmedquestion);
}
}
$numberqanda = new stdClass();
$numberqanda->q = 2;
$numberqanda->a = 3;
if ($questioncount < 1){
$errors['subquestions[0]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
if ($questioncount < 1) {
$errors['subquestions[0]'] =
get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
if ($questioncount < 2){
$errors['subquestions[1]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
if ($questioncount < 2) {
$errors['subquestions[1]'] =
get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
if ($answercount < 3){
$errors['subanswers[2]'] = get_string('notenoughqsandas', 'qtype_match', $numberqanda);
if ($answercount < 3) {
$errors['subanswers[2]'] =
get_string('notenoughqsandas', 'qtype_match', $numberqanda);
}
return $errors;
}
+7 -4
View File
@@ -105,8 +105,9 @@ class qtype_match_question extends question_graded_automatically_with_countback
$matches = array();
foreach ($this->stemorder as $key => $stemid) {
if (array_key_exists($this->field($key), $response) && $response[$this->field($key)]) {
$matches[] = $this->html_to_text($this->stems[$stemid], $this->stemformat[$stemid]) .
' -> ' . $this->choices[$this->choiceorder[$response[$this->field($key)]]];
$matches[] = $this->html_to_text($this->stems[$stemid],
$this->stemformat[$stemid]) . ' -> ' .
$this->choices[$this->choiceorder[$response[$this->field($key)]]];
}
}
if (empty($matches)) {
@@ -224,7 +225,8 @@ class qtype_match_question extends question_graded_automatically_with_countback
public function is_same_response(array $prevresponse, array $newresponse) {
foreach ($this->stemorder as $key => $notused) {
$fieldname = $this->field($key);
if (!question_utils::arrays_same_at_key_integer($prevresponse, $newresponse, $fieldname)) {
if (!question_utils::arrays_same_at_key_integer(
$prevresponse, $newresponse, $fieldname)) {
return false;
}
}
@@ -283,7 +285,8 @@ class qtype_match_question extends question_graded_automatically_with_countback
return $this->check_hint_file_access($qa, $options, $args);
} else {
return parent::check_file_access($qa, $options, $component, $filearea, $args, $forcedownload);
return parent::check_file_access($qa, $options, $component, $filearea,
$args, $forcedownload);
}
}
}
+11 -6
View File
@@ -43,7 +43,8 @@ class qtype_match extends question_type {
global $DB;
parent::get_question_options($question);
$question->options = $DB->get_record('question_match', array('question' => $question->id));
$question->options->subquestions = $DB->get_records('question_match_sub', array('question' => $question->id), 'id ASC');
$question->options->subquestions = $DB->get_records('question_match_sub',
array('question' => $question->id), 'id ASC');
return true;
}
@@ -73,7 +74,8 @@ class qtype_match extends question_type {
$subquestion = new stdClass();
// Determine a unique random code
$subquestion->code = rand(1, 999999999);
while ($DB->record_exists('question_match_sub', array('code' => $subquestion->code, 'question' => $question->id))) {
while ($DB->record_exists('question_match_sub',
array('code' => $subquestion->code, 'question' => $question->id))) {
$subquestion->code = rand(1, 999999999);
}
$subquestion->question = $question->id;
@@ -94,7 +96,7 @@ class qtype_match extends question_type {
// Delete old subquestions records
$fs = get_file_storage();
foreach($oldsubquestions as $oldsub) {
foreach ($oldsubquestions as $oldsub) {
$fs->delete_area_files($context->id, 'qtype_match', 'subquestion', $oldsub->id);
$DB->delete_records('question_match_sub', array('id' => $oldsub->id));
}
@@ -219,8 +221,11 @@ class qtype_match extends question_type {
$fs->delete_area_files($contextid, 'qtype_match', 'subquestion', $subquestionid);
}
$fs->delete_area_files($contextid, 'qtype_multichoice', 'correctfeedback', $questionid);
$fs->delete_area_files($contextid, 'qtype_multichoice', 'partiallycorrectfeedback', $questionid);
$fs->delete_area_files($contextid, 'qtype_multichoice', 'incorrectfeedback', $questionid);
$fs->delete_area_files($contextid, 'qtype_multichoice',
'correctfeedback', $questionid);
$fs->delete_area_files($contextid, 'qtype_multichoice',
'partiallycorrectfeedback', $questionid);
$fs->delete_area_files($contextid, 'qtype_multichoice',
'incorrectfeedback', $questionid);
}
}
@@ -107,11 +107,14 @@ class qtype_match_question_test extends UnitTestCase {
$this->assertEqual(array(1, question_state::$gradedright),
$question->grade_response(array('sub0' => $orderforchoice[1],
'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1])));
'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2],
'sub3' => $orderforchoice[1])));
$this->assertEqual(array(0.25, question_state::$gradedpartial),
$question->grade_response(array('sub0' => $orderforchoice[1])));
$this->assertEqual(array(0, question_state::$gradedwrong),
$question->grade_response(array('sub0' => $orderforchoice[2], 'sub1' => $orderforchoice[3], 'sub2' => $orderforchoice[1], 'sub3' => $orderforchoice[2])));
$question->grade_response(array('sub0' => $orderforchoice[2],
'sub1' => $orderforchoice[3], 'sub2' => $orderforchoice[1],
'sub3' => $orderforchoice[2])));
}
public function test_get_correct_response() {
@@ -122,7 +125,8 @@ class qtype_match_question_test extends UnitTestCase {
$choiceorder = $question->get_choice_order();
$orderforchoice = array_combine(array_values($choiceorder), array_keys($choiceorder));
$this->assertEqual(array('sub0' => $orderforchoice[1], 'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1]),
$this->assertEqual(array('sub0' => $orderforchoice[1], 'sub1' => $orderforchoice[2],
'sub2' => $orderforchoice[2], 'sub3' => $orderforchoice[1]),
$question->get_correct_response());
}
@@ -357,7 +357,8 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
$rightresponese = array('sub0' => $orderforchoice[1],
'sub1' => $orderforchoice[2], 'sub2' => $orderforchoice[3]);
$rightresponesesummary = '(1, 2] -> 1 < x ≤ 2; [1, 2] -> 1 ≤ x ≤ 2; [1, 2) -> 1 ≤ x < 2';
$rightresponesesummary =
'(1, 2] -> 1 < x ≤ 2; [1, 2] -> 1 ≤ x ≤ 2; [1, 2) -> 1 ≤ x < 2';
$this->process_submission($rightresponese);
$this->process_submission(array('-finish' => 1));
@@ -366,7 +367,8 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->displayoptions->history = 1;
$this->check_current_output(
new PatternExpectation('/' . preg_quote(htmlspecialchars($rightresponesesummary), '/') . '/'));
new PatternExpectation('/' .
preg_quote(htmlspecialchars($rightresponesesummary), '/') . '/'));
}
public function test_match_clear_wrong() {
@@ -413,10 +415,14 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_select_expectation('sub1', $choices, 3, false),
$this->get_contains_select_expectation('sub2', $choices, 3, false),
$this->get_contains_select_expectation('sub3', $choices, 3, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub2', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub3', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub2', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub3', '0'),
$this->get_contains_submit_button_expectation(false),
$this->get_contains_hint_expectation('This is the first hint.'));
@@ -438,7 +444,6 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_tries_remaining_expectation(2),
$this->get_no_hint_visible_expectation());
// Submit a partially wrong response.
$this->process_submission(array('sub0' => $orderforchoice[3],
'sub1' => $orderforchoice[3], 'sub2' => $orderforchoice[2],
@@ -452,10 +457,14 @@ class qtype_match_walkthrough_test extends qbehaviour_walkthrough_test_base {
$this->get_contains_select_expectation('sub1', $choices, 3, false),
$this->get_contains_select_expectation('sub2', $choices, 2, false),
$this->get_contains_select_expectation('sub3', $choices, 1, false),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub1', '0'),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub2', $orderforchoice[2]),
$this->get_contains_hidden_expectation($this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1]),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub0', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub1', '0'),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub2', $orderforchoice[2]),
$this->get_contains_hidden_expectation(
$this->quba->get_field_prefix($this->slot) . 'sub3', $orderforchoice[1]),
$this->get_contains_submit_button_expectation(false),
$this->get_contains_hint_expectation('This is the second hint.'));