From 0366ef262aa40cd7f83f14d7d42334f469d5586f Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 27 Jun 2011 17:02:32 +0100 Subject: [PATCH] MDL-28035 problems with upgrade/restore of ataptive quizzes from 2.0 There were two main problems: 1. The unit tests for upgrading adaptive quiz attempts had slighly the wrong $expectedqa, and so matching that the upgrade was doing the wrong thing in certain situations. The main issue was that it was setting -_try = 1 on the first step, which broke the penalty calculation when the quiz was regraded. There were also some other subtleties with incrementing -_try that were not right before. 2. It was possible in 2.0 and earlier for two question_states to get the same seq_number, and restoring 2.0 backups was rashly assuming that that was unique. --- backup/moodle2/restore_stepslib.php | 7 +- local/qeupgradehelper/locallib.php | 2 +- .../engine/upgrade/behaviourconverters.php | 10 +- .../db/simpletest/testupgradelibnewqe.php | 14 +- .../db/simpletest/testupgradelibnewqe.php | 23 +- .../db/simpletest/testupgradelibnewqe.php | 12 +- .../db/simpletest/testupgradelibnewqe.php | 28 +- .../db/simpletest/testupgradelibnewqe.php | 381 ++++++++++++++++++ question/type/truefalse/version.php | 2 +- 9 files changed, 434 insertions(+), 45 deletions(-) diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 6178a04c790..760dc0f042c 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2846,10 +2846,15 @@ abstract class restore_questions_activity_structure_step extends restore_activit $qstates = array(); foreach ($data->states['state'] as $state) { if ($state['question'] == $questionid) { - $qstates[$state['seq_number']] = (object) $state; + // It would be natural to use $state['seq_number'] as the array-key + // here, but it seems that buggy behaviour in 2.0 and early can + // mean that that is not unique, so we use id, which is guaranteed + // to be unique. + $qstates[$state['id']] = (object) $state; } } ksort($qstates); + $qstates = array_values($qstates); return array($qsession, $qstates); } diff --git a/local/qeupgradehelper/locallib.php b/local/qeupgradehelper/locallib.php index dfb7d1ae7ad..e27388d7b19 100644 --- a/local/qeupgradehelper/locallib.php +++ b/local/qeupgradehelper/locallib.php @@ -531,7 +531,7 @@ function local_qeupgradehelper_generate_unit_test($questionsessionid, $namesuffi if (!local_qeupgradehelper_is_upgraded()) { if (!$quiz->optionflags) { $quiz->preferredbehaviour = 'deferredfeedback'; - } else if (!$quiz->penaltyscheme) { + } else if ($quiz->penaltyscheme) { $quiz->preferredbehaviour = 'adaptive'; } else { $quiz->preferredbehaviour = 'adaptivenopenalty'; diff --git a/question/engine/upgrade/behaviourconverters.php b/question/engine/upgrade/behaviourconverters.php index 3a9f50ad62a..0553b4e2f6e 100644 --- a/question/engine/upgrade/behaviourconverters.php +++ b/question/engine/upgrade/behaviourconverters.php @@ -435,6 +435,7 @@ class qbehaviour_informationitem_converter extends question_behaviour_attempt_up class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater { protected $try; + protected $laststepwasatry = false; protected $finished = false; protected $bestrawgrade = 0; @@ -455,7 +456,7 @@ class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater { protected function process0($step, $state) { $this->try = 1; - $step->data['-_try'] = $this->try; + $this->laststepwasatry = false; parent::process0($step, $state); } @@ -471,6 +472,7 @@ class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater { $step->fraction = $state->grade / $this->question->maxmark; } + $this->laststepwasatry = false; parent::process2($step, $state); } @@ -488,8 +490,9 @@ class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater { $this->bestrawgrade = max($state->raw_grade, $this->bestrawgrade); - $this->try += 1; $step->data['-_try'] = $this->try; + $this->try += 1; + $this->laststepwasatry = true; if ($this->question->maxmark > 0) { $step->data['-_rawfraction'] = $state->raw_grade / $this->question->maxmark; } else { @@ -524,6 +527,9 @@ class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater { } $step->data['-finish'] = 1; + if ($this->laststepwasatry) { + $this->try -= 1; + } $step->data['-_try'] = $this->try; if ($this->question->maxmark > 0) { $step->data['-_rawfraction'] = $state->raw_grade / $this->question->maxmark; diff --git a/question/type/calculated/db/simpletest/testupgradelibnewqe.php b/question/type/calculated/db/simpletest/testupgradelibnewqe.php index 315dd3ce02a..6a3f3159b3a 100644 --- a/question/type/calculated/db/simpletest/testupgradelibnewqe.php +++ b/question/type/calculated/db/simpletest/testupgradelibnewqe.php @@ -219,7 +219,7 @@ Remember to type a unit.', 'fraction' => null, 'timecreated' => 1305830650, 'userid' => 4, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '7.5', '_var_b' => '4.9'), ), 1 => (object) array( @@ -442,7 +442,7 @@ Remember to type a unit.', 'fraction' => null, 'timecreated' => 1305830661, 'userid' => 4, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '5.1', '_var_b' => '4.5'), ), 1 => (object) array( @@ -451,7 +451,7 @@ Remember to type a unit.', 'fraction' => 0.5, 'timecreated' => 1305830714, 'userid' => 4, - 'data' => array('answer' => 9.6, '-_try' => 2, + 'data' => array('answer' => 9.6, '-_try' => 1, '-_rawfraction' => 0.5, '-submit' => 1), ), 2 => (object) array( @@ -460,7 +460,7 @@ Remember to type a unit.', 'fraction' => 0.9, 'timecreated' => 1305830722, 'userid' => 4, - 'data' => array('answer' => '9.6 m', '-_try' => 3, + 'data' => array('answer' => '9.6 m', '-_try' => 2, '-_rawfraction' => 1, '-submit' => 1), ), 3 => (object) array( @@ -469,7 +469,7 @@ Remember to type a unit.', 'fraction' => 0.9, 'timecreated' => 1305830722, 'userid' => 4, - 'data' => array('answer' => '9.6 m', '-_try' => 3, + 'data' => array('answer' => '9.6 m', '-_try' => 2, '-_rawfraction' => 1, '-finish' => 1), ), ), @@ -672,7 +672,7 @@ Remember to type a unit.', 'fraction' => null, 'timecreated' => 1305830744, 'userid' => 3, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '9.9', '_var_b' => '2.5'), ), 1 => (object) array( @@ -681,7 +681,7 @@ Remember to type a unit.', 'fraction' => 0, 'timecreated' => 1305830775, 'userid' => 3, - 'data' => array('answer' => '123 cm', '-_try' => 2, + 'data' => array('answer' => '123 cm', '-_try' => 1, '-_rawfraction' => 0, '-submit' => 1), ), 2 => (object) array( diff --git a/question/type/calculatedmulti/db/simpletest/testupgradelibnewqe.php b/question/type/calculatedmulti/db/simpletest/testupgradelibnewqe.php index ba7a4429d13..50b506d46d7 100644 --- a/question/type/calculatedmulti/db/simpletest/testupgradelibnewqe.php +++ b/question/type/calculatedmulti/db/simpletest/testupgradelibnewqe.php @@ -242,8 +242,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => null, 'timecreated' => 1305830650, 'userid' => 4, - 'data' => array('-_try' => 1, - '_order' => '24,26,27,25', '_var_a' => '4.3', '_var_b' => '5.4'), + 'data' => array('_order' => '24,26,27,25', '_var_a' => '4.3', '_var_b' => '5.4'), ), 1 => (object) array( 'sequencenumber' => 1, @@ -476,8 +475,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => null, 'timecreated' => 1305830661, 'userid' => 4, - 'data' => array('-_try' => 1, - '_order' => '25,24,27,26', '_var_a' => '3.7', '_var_b' => '6.0'), + 'data' => array('_order' => '25,24,27,26', '_var_a' => '3.7', '_var_b' => '6.0'), ), 1 => (object) array( 'sequencenumber' => 1, @@ -485,7 +483,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 1, 'timecreated' => 1305830699, 'userid' => 4, - 'data' => array('answer' => '0', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 1), + 'data' => array('answer' => '0', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 1), ), 2 => (object) array( 'sequencenumber' => 2, @@ -493,7 +491,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 1, 'timecreated' => 1305830699, 'userid' => 4, - 'data' => array('answer' => '0', '-finish' => 1, '-_try' => 2, '-_rawfraction' => 1), + 'data' => array('answer' => '0', '-finish' => 1, '-_try' => 1, '-_rawfraction' => 1), ), ), ); @@ -754,8 +752,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => null, 'timecreated' => 1305830744, 'userid' => 3, - 'data' => array('-_try' => 1, - '_order' => '26,24,25,27', '_var_a' => '4.4', '_var_b' => '8.2'), + 'data' => array('_order' => '26,24,25,27', '_var_a' => '4.4', '_var_b' => '8.2'), ), 1 => (object) array( 'sequencenumber' => 1, @@ -763,7 +760,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 0, 'timecreated' => 1305830759, 'userid' => 3, - 'data' => array('answer' => '3', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 0), + 'data' => array('answer' => '3', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 0), ), 2 => (object) array( 'sequencenumber' => 2, @@ -771,7 +768,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 0, 'timecreated' => 1305830761, 'userid' => 3, - 'data' => array('answer' => '1', '-submit' => 1, '-_try' => 3, '-_rawfraction' => 0), + 'data' => array('answer' => '1', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 0), ), 3 => (object) array( 'sequencenumber' => 3, @@ -779,7 +776,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 0, 'timecreated' => 1305830764, 'userid' => 3, - 'data' => array('answer' => '0', '-submit' => 1, '-_try' => 4, '-_rawfraction' => 0), + 'data' => array('answer' => '0', '-submit' => 1, '-_try' => 3, '-_rawfraction' => 0), ), 4 => (object) array( 'sequencenumber' => 4, @@ -787,7 +784,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 0.7, 'timecreated' => 1305830766, 'userid' => 3, - 'data' => array('answer' => '2', '-submit' => 1, '-_try' => 5, '-_rawfraction' => 1), + 'data' => array('answer' => '2', '-submit' => 1, '-_try' => 4, '-_rawfraction' => 1), ), 5 => (object) array( 'sequencenumber' => 5, @@ -795,7 +792,7 @@ class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgra 'fraction' => 0.7, 'timecreated' => 1305830768, 'userid' => 3, - 'data' => array('answer' => '1', '-submit' => 1, '-_try' => 6, '-_rawfraction' => 0), + 'data' => array('answer' => '1', '-submit' => 1, '-_try' => 5, '-_rawfraction' => 0), ), ), ); diff --git a/question/type/calculatedsimple/db/simpletest/testupgradelibnewqe.php b/question/type/calculatedsimple/db/simpletest/testupgradelibnewqe.php index a98b7ce6368..885ed19a2be 100644 --- a/question/type/calculatedsimple/db/simpletest/testupgradelibnewqe.php +++ b/question/type/calculatedsimple/db/simpletest/testupgradelibnewqe.php @@ -206,7 +206,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => null, 'timecreated' => 1305830650, 'userid' => 4, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '3', '_var_b' => '6'), ), 1 => (object) array( @@ -416,7 +416,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => null, 'timecreated' => 1305830661, 'userid' => 4, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '6.4', '_var_b' => '9'), ), 1 => (object) array( @@ -425,7 +425,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => 0, 'timecreated' => 1305830668, 'userid' => 4, - 'data' => array('answer' => '9.00', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 0), + 'data' => array('answer' => '9.00', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 0), ), 2 => (object) array( 'sequencenumber' => 2, @@ -433,7 +433,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => 0.9, 'timecreated' => 1305830679, 'userid' => 4, - 'data' => array('answer' => '15.40', '-submit' => 1, '-_try' => 3, '-_rawfraction' => 1), + 'data' => array('answer' => '15.40', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 1), ), 3 => (object) array( 'sequencenumber' => 3, @@ -441,7 +441,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => 0.9, 'timecreated' => 1305830679, 'userid' => 4, - 'data' => array('answer' => '15.40', '-finish' => 1, '-_try' => 3, '-_rawfraction' => 1), + 'data' => array('answer' => '15.40', '-finish' => 1, '-_try' => 2, '-_rawfraction' => 1), ), ), ); @@ -618,7 +618,7 @@ class qtype_calculatedsimple_attempt_upgrader_test extends question_attempt_upgr 'fraction' => null, 'timecreated' => 1305830744, 'userid' => 3, - 'data' => array('-_try' => 1, '_separators' => '.$,', + 'data' => array('_separators' => '.$,', '_var_a' => '6.1', '_var_b' => '7'), ), 1 => (object) array( diff --git a/question/type/multianswer/db/simpletest/testupgradelibnewqe.php b/question/type/multianswer/db/simpletest/testupgradelibnewqe.php index 2b384221b79..2d5db918254 100644 --- a/question/type/multianswer/db/simpletest/testupgradelibnewqe.php +++ b/question/type/multianswer/db/simpletest/testupgradelibnewqe.php @@ -216,7 +216,7 @@ class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_ 'fraction' => null, 'timecreated' => 1306425691, 'userid' => 4, - 'data' => array('-_try' => 1), + 'data' => array(), ), 1 => (object) array( 'sequencenumber' => 1, @@ -408,7 +408,7 @@ class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_ 'fraction' => null, 'timecreated' => 1306425757, 'userid' => 4, - 'data' => array('-_try' => '1'), + 'data' => array(), ), 1 => (object) array( 'sequencenumber' => 1, @@ -615,7 +615,7 @@ class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_ 'fraction' => null, 'timecreated' => 1306425784, 'userid' => 3, - 'data' => array('-_try' => '1'), + 'data' => array(), ), 1 => (object) array( 'sequencenumber' => 1, @@ -631,7 +631,7 @@ class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_ 'fraction' => 1, 'timecreated' => 1306425917, 'userid' => 3, - 'data' => array('sub1_answer' => 'frog', '-_try' => 2, + 'data' => array('sub1_answer' => 'frog', '-_try' => 1, '-_rawfraction' => 1.0, '-submit' => 1), ), 3 => (object) array( @@ -640,7 +640,7 @@ class qtype_multianswer_attempt_upgrader_test extends question_attempt_upgrader_ 'fraction' => 1, 'timecreated' => 1306425917, 'userid' => 3, - 'data' => array('sub1_answer' => 'frog', '-_try' => 2, + 'data' => array('sub1_answer' => 'frog', '-_try' => 1, '-_rawfraction' => 1.0, '-finish' => 1), ), ), @@ -1300,7 +1300,7 @@ b) What grade would you give it? _____', 'fraction' => null, 'timecreated' => 1306425691, 'userid' => 4, - 'data' => array('-_try' => '1', '_sub1_order' => '29,30,31,32', + 'data' => array('_sub1_order' => '29,30,31,32', '_sub3_separators' => '.$,', '_sub4_order' => '38,39,40,41', '_sub5_order' => '42,43,44,45', '_sub7_order' => '49,50', '_sub8_separators' => '.$,'), @@ -1314,7 +1314,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '2', 'sub2_answer' => 'dsf', 'sub3_answer' => 'sadf', 'sub4_answer' => '1', 'sub5_answer' => '2', 'sub6_answer' => 'MOODLE', - 'sub7_answer' => 'sadf', 'sub8_answer' => '100%', '-_try' => '2', + 'sub7_answer' => 'sadf', 'sub8_answer' => '100%', '-_try' => '1', '-_rawfraction' => '0.38461538461538466', '-submit' => '1'), ), 2 => (object) array( @@ -1326,7 +1326,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '2', 'sub2_answer' => 'dsf', 'sub3_answer' => 'sadf', 'sub4_answer' => '1', 'sub5_answer' => '2', 'sub6_answer' => 'MOODLE', - 'sub7_answer' => 'sadf', 'sub8_answer' => '100%', '-_try' => '2', + 'sub7_answer' => 'sadf', 'sub8_answer' => '100%', '-_try' => '1', '-_rawfraction' => '0.38461538461538466', '-finish' => '1'), ), ), @@ -1974,7 +1974,7 @@ b) What grade would you give it? _____', 'fraction' => null, 'timecreated' => 1306425757, 'userid' => 4, - 'data' => array('-_try' => '1', '_sub1_order' => '29,30,31,32', + 'data' => array('_sub1_order' => '29,30,31,32', '_sub3_separators' => '.$,', '_sub4_order' => '38,39,40,41', '_sub5_order' => '42,43,44,45', '_sub7_order' => '49,50', '_sub8_separators' => '.$,'), @@ -2668,7 +2668,7 @@ b) What grade would you give it? _____', 'fraction' => null, 'timecreated' => 1306425784, 'userid' => 3, - 'data' => array('-_try' => '1', '_sub1_order' => '29,30,31,32', + 'data' => array('_sub1_order' => '29,30,31,32', '_sub3_separators' => '.$,', '_sub4_order' => '38,39,40,41', '_sub5_order' => '42,43,44,45', '_sub7_order' => '49,50', '_sub8_separators' => '.$,'), @@ -2682,7 +2682,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '3', 'sub2_answer' => 'asdgf', 'sub3_answer' => 'saedf', 'sub4_answer' => '1', 'sub5_answer' => '1', 'sub6_answer' => 'sadf', - '-_try' => '2', + '-_try' => '1', '-_rawfraction' => '0.038461538461538464', '-submit' => '1'), ), 2 => (object) array( @@ -2694,7 +2694,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '2', 'sub2_answer' => 'asdgf', 'sub3_answer' => '28.3', 'sub4_answer' => '2', 'sub5_answer' => '2', 'sub6_answer' => 'MOODLE', - 'sub7_answer' => '0', 'sub8_answer' => '13', '-_try' => '3', + 'sub7_answer' => '0', 'sub8_answer' => '13', '-_try' => '2', '-_rawfraction' => '0.53846153846153845', '-submit' => '1'), ), 3 => (object) array( @@ -2706,7 +2706,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '2', 'sub2_answer' => 'Correct answer', 'sub3_answer' => '23.8', 'sub4_answer' => '2', 'sub5_answer' => '2', 'sub6_answer' => 'MOODLE', - 'sub7_answer' => '0', 'sub8_answer' => '3', '-_try' => '4', + 'sub7_answer' => '0', 'sub8_answer' => '3', '-_try' => '3', '-_rawfraction' => '0.92307692307692311', '-submit' => '1'), ), 4 => (object) array( @@ -2718,7 +2718,7 @@ b) What grade would you give it? _____', 'data' => array('sub1_answer' => '2', 'sub2_answer' => 'Correct answer', 'sub3_answer' => '23.8', 'sub4_answer' => '2', 'sub5_answer' => '2', 'sub6_answer' => 'MOODLE', - 'sub7_answer' => '0', 'sub8_answer' => '3', '-_try' => '4', + 'sub7_answer' => '0', 'sub8_answer' => '3', '-_try' => '3', '-_rawfraction' => '0.92307692307692311', '-finish' => '1'), ), ), diff --git a/question/type/truefalse/db/simpletest/testupgradelibnewqe.php b/question/type/truefalse/db/simpletest/testupgradelibnewqe.php index 22d5868570f..78db2ed9a39 100644 --- a/question/type/truefalse/db/simpletest/testupgradelibnewqe.php +++ b/question/type/truefalse/db/simpletest/testupgradelibnewqe.php @@ -583,4 +583,385 @@ class qtype_truefalse_attempt_upgrader_test extends question_attempt_upgrader_te $this->compare_qas($expectedqa, $qa); } + + public function test_truefalse_adaptive_qsession119() { + $quiz = (object) array( + 'id' => '6', + 'course' => '3', + 'name' => 'Simply quiz', + 'intro' => '

One quiz with 1 true/false Q

', + 'introformat' => '1', + 'timeopen' => '0', + 'timeclose' => '0', + 'attempts' => '0', + 'attemptonlast' => '0', + 'grademethod' => '1', + 'decimalpoints' => '2', + 'questiondecimalpoints' => '-1', + 'review' => '4459503', + 'questionsperpage' => '1', + 'shufflequestions' => '0', + 'shuffleanswers' => '1', + 'questions' => '30,0', + 'sumgrades' => '10.00000', + 'grade' => '10.00000', + 'timecreated' => '0', + 'timemodified' => '1309103209', + 'timelimit' => '0', + 'password' => '', + 'subnet' => '', + 'popup' => '0', + 'delay1' => '0', + 'delay2' => '0', + 'showuserpicture' => '0', + 'showblocks' => '0', + 'preferredbehaviour' => 'adaptive', + ); + $attempt = (object) array( + 'id' => '20', + 'uniqueid' => '20', + 'quiz' => '6', + 'userid' => '7', + 'attempt' => '1', + 'sumgrades' => '10.00000', + 'timestart' => '1309103112', + 'timefinish' => '1309103120', + 'timemodified' => '1309103120', + 'layout' => '30,0', + 'preview' => '0', + 'needsupgradetonewqe' => 1, + ); + $question = (object) array( + 'id' => '30', + 'category' => '10', + 'parent' => '0', + 'name' => '1 + 1 = 2 ?', + 'questiontext' => '

1 +1 = 2 ?

', + 'questiontextformat' => '1', + 'generalfeedback' => '

this is general feedback

', + 'generalfeedbackformat' => '1', + 'penalty' => '1.0000000', + 'qtype' => 'truefalse', + 'length' => '1', + 'stamp' => '127.0.0.1+110626154410+wFrWwP', + 'version' => '127.0.0.1+110626154410+u7CoaA', + 'hidden' => '0', + 'timecreated' => '1309103050', + 'timemodified' => '1309103050', + 'createdby' => '6', + 'modifiedby' => '6', + 'maxmark' => '10.0000000', + 'options' => (object) array( + 'id' => '4', + 'question' => '30', + 'trueanswer' => '53', + 'falseanswer' => '54', + 'answers' => array( + 53 => (object) array( + 'id' => '53', + 'question' => '30', + 'answer' => 'True', + 'answerformat' => '0', + 'fraction' => '1.0000000', + 'feedback' => '

this is correct (for true) feedback

', + 'feedbackformat' => '1', + ), + 54 => (object) array( + 'id' => '54', + 'question' => '30', + 'answer' => 'False', + 'answerformat' => '0', + 'fraction' => '0.0000000', + 'feedback' => '

this is incorrect (for false) feedback

', + 'feedbackformat' => '1', + ), + ), + ), + 'defaultmark' => '1.0000000', + ); + $qsession = (object) array( + 'id' => '119', + 'attemptid' => '20', + 'questionid' => '30', + 'newest' => '312', + 'newgraded' => '312', + 'sumpenalty' => '10.0000000', + 'manualcomment' => '', + 'manualcommentformat' => '1', + 'flagged' => '0', + ); + $qstates = array( + 310 => (object) array( + 'id' => '310', + 'attempt' => '20', + 'question' => '30', + 'seq_number' => '0', + 'answer' => '', + 'timestamp' => '1309103112', + 'event' => '0', + 'grade' => '0.0000000', + 'raw_grade' => '0.0000000', + 'penalty' => '0.0000000', + ), + 311 => (object) array( + 'id' => '311', + 'attempt' => '20', + 'question' => '30', + 'seq_number' => '1', + 'answer' => '53', + 'timestamp' => '1309103115', + 'event' => '3', + 'grade' => '10.0000000', + 'raw_grade' => '10.0000000', + 'penalty' => '10.0000000', + ), + 312 => (object) array( + 'id' => '312', + 'attempt' => '20', + 'question' => '30', + 'seq_number' => '1', + 'answer' => '53', + 'timestamp' => '1309103115', + 'event' => '6', + 'grade' => '10.0000000', + 'raw_grade' => '10.0000000', + 'penalty' => '10.0000000', + ), + ); + + $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); + + $expectedqa = (object) array( + 'behaviour' => 'adaptive', + 'questionid' => 30, + 'variant' => 1, + 'maxmark' => 10.0000000, + 'minfraction' => 0, + 'flagged' => 0, + 'questionsummary' => '1 +1 = 2 ?', + 'rightanswer' => 'True', + 'responsesummary' => 'True', + 'timemodified' => 1309103115, + 'steps' => array( + 0 => (object) array( + 'sequencenumber' => 0, + 'state' => 'todo', + 'fraction' => null, + 'timecreated' => 1309103112, + 'userid' => 7, + 'data' => array(), + ), + 1 => (object) array( + 'sequencenumber' => 1, + 'state' => 'complete', + 'fraction' => 1.0, + 'timecreated' => 1309103115, + 'userid' => 7, + 'data' => array('answer' => '1', '-_try' => '1', + '-_rawfraction' => '1', '-submit' => '1'), + ), + 2 => (object) array( + 'sequencenumber' => 2, + 'state' => 'gradedright', + 'fraction' => 1.0, + 'timecreated' => 1309103115, + 'userid' => 7, + 'data' => array('answer' => '1', '-_try' => '1', + '-_rawfraction' => '1', '-finish' => '1'), + ), + ), + ); + + $this->compare_qas($expectedqa, $qa); + } + + public function test_truefalse_adaptive_qsession120() { + $quiz = (object) array( + 'id' => '6', + 'course' => '3', + 'name' => 'Simply quiz', + 'intro' => '

One quiz with 1 true/false Q

', + 'introformat' => '1', + 'timeopen' => '0', + 'timeclose' => '0', + 'attempts' => '0', + 'attemptonlast' => '0', + 'grademethod' => '1', + 'decimalpoints' => '2', + 'questiondecimalpoints' => '-1', + 'review' => '4459503', + 'questionsperpage' => '1', + 'shufflequestions' => '0', + 'shuffleanswers' => '1', + 'questions' => '30,0', + 'sumgrades' => '10.00000', + 'grade' => '10.00000', + 'timecreated' => '0', + 'timemodified' => '1309103209', + 'timelimit' => '0', + 'password' => '', + 'subnet' => '', + 'popup' => '0', + 'delay1' => '0', + 'delay2' => '0', + 'showuserpicture' => '0', + 'showblocks' => '0', + 'preferredbehaviour' => 'adaptive', + ); + $attempt = (object) array( + 'id' => '21', + 'uniqueid' => '21', + 'quiz' => '6', + 'userid' => '7', + 'attempt' => '2', + 'sumgrades' => '0.00000', + 'timestart' => '1309103130', + 'timefinish' => '1309103136', + 'timemodified' => '1309103136', + 'layout' => '30,0', + 'preview' => '0', + 'needsupgradetonewqe' => 1, + ); + $question = (object) array( + 'id' => '30', + 'category' => '10', + 'parent' => '0', + 'name' => '1 + 1 = 2 ?', + 'questiontext' => '

1 +1 = 2 ?

', + 'questiontextformat' => '1', + 'generalfeedback' => '

this is general feedback

', + 'generalfeedbackformat' => '1', + 'penalty' => '1.0000000', + 'qtype' => 'truefalse', + 'length' => '1', + 'stamp' => '127.0.0.1+110626154410+wFrWwP', + 'version' => '127.0.0.1+110626154410+u7CoaA', + 'hidden' => '0', + 'timecreated' => '1309103050', + 'timemodified' => '1309103050', + 'createdby' => '6', + 'modifiedby' => '6', + 'maxmark' => '10.0000000', + 'options' => (object) array( + 'id' => '4', + 'question' => '30', + 'trueanswer' => '53', + 'falseanswer' => '54', + 'answers' => array( + 53 => (object) array( + 'id' => '53', + 'question' => '30', + 'answer' => 'True', + 'answerformat' => '0', + 'fraction' => '1.0000000', + 'feedback' => '

this is correct (for true) feedback

', + 'feedbackformat' => '1', + ), + 54 => (object) array( + 'id' => '54', + 'question' => '30', + 'answer' => 'False', + 'answerformat' => '0', + 'fraction' => '0.0000000', + 'feedback' => '

this is incorrect (for false) feedback

', + 'feedbackformat' => '1', + ), + ), + ), + 'defaultmark' => '1.0000000', + ); + $qsession = (object) array( + 'id' => '120', + 'attemptid' => '21', + 'questionid' => '30', + 'newest' => '315', + 'newgraded' => '315', + 'sumpenalty' => '10.0000000', + 'manualcomment' => '', + 'manualcommentformat' => '1', + 'flagged' => '0', + ); + $qstates = array( + 313 => (object) array( + 'id' => '313', + 'attempt' => '21', + 'question' => '30', + 'seq_number' => '0', + 'answer' => '', + 'timestamp' => '1309103130', + 'event' => '0', + 'grade' => '0.0000000', + 'raw_grade' => '0.0000000', + 'penalty' => '0.0000000', + ), + 314 => (object) array( + 'id' => '314', + 'attempt' => '21', + 'question' => '30', + 'seq_number' => '1', + 'answer' => '54', + 'timestamp' => '1309103132', + 'event' => '2', + 'grade' => '0.0000000', + 'raw_grade' => '0.0000000', + 'penalty' => '10.0000000', + ), + 315 => (object) array( + 'id' => '315', + 'attempt' => '21', + 'question' => '30', + 'seq_number' => '2', + 'answer' => '54', + 'timestamp' => '1309103132', + 'event' => '6', + 'grade' => '0.0000000', + 'raw_grade' => '0.0000000', + 'penalty' => '10.0000000', + ), + ); + + $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); + + $expectedqa = (object) array( + 'behaviour' => 'adaptive', + 'questionid' => 30, + 'variant' => 1, + 'maxmark' => 10.0000000, + 'minfraction' => 0, + 'flagged' => 0, + 'questionsummary' => '1 +1 = 2 ?', + 'rightanswer' => 'True', + 'responsesummary' => 'False', + 'timemodified' => 1309103132, + 'steps' => array( + 0 => (object) array( + 'sequencenumber' => 0, + 'state' => 'todo', + 'fraction' => null, + 'timecreated' => 1309103130, + 'userid' => 7, + 'data' => array(), + ), + 1 => (object) array( + 'sequencenumber' => 1, + 'state' => 'complete', + 'fraction' => null, + 'timecreated' => 1309103132, + 'userid' => 7, + 'data' => array('answer' => '0'), + ), + 2 => (object) array( + 'sequencenumber' => 2, + 'state' => 'gradedwrong', + 'fraction' => 0.0, + 'timecreated' => 1309103132, + 'userid' => 7, + 'data' => array('answer' => 0, '-finish' => 1, + '-_try' => 1, '-_rawfraction' => 0), + ), + ), + ); + + $this->compare_qas($expectedqa, $qa); + } } diff --git a/question/type/truefalse/version.php b/question/type/truefalse/version.php index 0e1dc78db3c..5f19896a788 100644 --- a/question/type/truefalse/version.php +++ b/question/type/truefalse/version.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Version information for the true/fales question type. + * Version information for the true/false question type. * * @package qtype * @subpackage truefalse