Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Tests of the upgrade to the new Moodle question engine for attempts at
  19   * random questions.
  20   *
  21   * @package    qtype
  22   * @subpackage random
  23   * @copyright  2009 The Open University
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  global $CFG;
  31  require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php');
  32  
  33  
  34  /**
  35   * Testing the upgrade of random question attempts.
  36   *
  37   * @copyright  2009 The Open University
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class qtype_random_attempt_upgrader_test extends question_attempt_upgrader_test_base {
  41  
  42      public function test_random_deferredfeedback_history620() {
  43          $quiz = (object) array(
  44              'id' => '2177',
  45              'course' => '5174',
  46              'name' => 'iCMA 41',
  47              'intro' => '<p>Welcome. This is the first K101 Interactive Computer Marked Assignment (iCMA).</p>
  48          <p>After the open date, begin by clicking <b>Start attempt</b> and a pop-up box will appear. Click OK and this will take you to the questions.</p>
  49          <p> </p>',
  50              'introformat' => FORMAT_HTML,
  51              'questiondecimalpoints' => '-1',
  52              'showuserpicture' => '1',
  53              'showblocks' => '1',
  54              'timeopen' => '1236556800',
  55              'timeclose' => '1238713140',
  56              'preferredbehaviour' => 'deferredfeedback',
  57              'attempts' => '1',
  58              'attemptonlast' => '0',
  59              'grademethod' => '1',
  60              'decimalpoints' => '0',
  61              'review' => '67268673',
  62              'questionsperpage' => '1',
  63              'shufflequestions' => '0',
  64              'shuffleanswers' => '0',
  65              'sumgrades' => '5',
  66              'grade' => '100',
  67              'timecreated' => '0',
  68              'timemodified' => '1236269160',
  69              'password' => '',
  70              'subnet' => '',
  71              'popup' => '0',
  72              'delay1' => '0',
  73              'delay2' => '0',
  74              'timelimit' => '0',
  75          );
  76          $attempt = (object) array(
  77              'id' => '125687',
  78              'uniqueid' => '125688',
  79              'quiz' => '2177',
  80              'userid' => '509191',
  81              'attempt' => '1',
  82              'sumgrades' => '5',
  83              'timestart' => '1236590532',
  84              'timefinish' => '1238184306',
  85              'timemodified' => '1238182560',
  86              'layout' => '28698,0,34245,0,34248,0,35005,0,35009,0,35013,0',
  87              'preview' => '0',
  88          );
  89          $question = (object) array(
  90              'id' => '34248',
  91              'category' => '3762',
  92              'parent' => '34248',
  93              'name' => 'Random Question (Q2)',
  94              'questiontext' => '1',
  95              'questiontextformat' => '0',
  96              'defaultmark' => '1',
  97              'penalty' => '0',
  98              'qtype' => 'random',
  99              'length' => '1',
 100              'stamp' => 'learn.open.ac.uk+090218115858+6H1FBE',
 101              'version' => 'learn.open.ac.uk+090218115858+REDwJ6',
 102              'hidden' => '0',
 103              'generalfeedback' => '',
 104              'generalfeedbackformat' => '1',
 105              'timecreated' => '1234958338',
 106              'timemodified' => '1234958338',
 107              'createdby' => '219095',
 108              'modifiedby' => '219095',
 109              'unlimited' => '0',
 110              'maxmark' => '1',
 111          );
 112          $qsession = (object) array(
 113              'id' => '1512603',
 114              'attemptid' => '125688',
 115              'questionid' => '34248',
 116              'newest' => '4010008',
 117              'newgraded' => '4010008',
 118              'sumpenalty' => '0.1',
 119              'manualcomment' => '',
 120              'manualcommentformat' => '1',
 121              'flagged' => '1',
 122          );
 123          $qstates = array(
 124              3820084 => (object) array(
 125                  'attempt' => '125688',
 126                  'question' => '34248',
 127                  'originalquestion' => '0',
 128                  'seq_number' => '0',
 129                  'answer' => 'random34999-103135,103136,103137:',
 130                  'timestamp' => '1236590532',
 131                  'event' => '0',
 132                  'grade' => '0',
 133                  'raw_grade' => '0',
 134                  'penalty' => '0',
 135                  'id' => 3820084,
 136              ),
 137              4009916 => (object) array(
 138                  'attempt' => '125688',
 139                  'question' => '34248',
 140                  'originalquestion' => '0',
 141                  'seq_number' => '1',
 142                  'answer' => 'random34999-103135,103136,103137:103137',
 143                  'timestamp' => '1238182723',
 144                  'event' => '2',
 145                  'grade' => '0',
 146                  'raw_grade' => '1',
 147                  'penalty' => '0.1',
 148                  'id' => 4009916,
 149              ),
 150              4010008 => (object) array(
 151                  'attempt' => '125688',
 152                  'question' => '34248',
 153                  'originalquestion' => '0',
 154                  'seq_number' => '2',
 155                  'answer' => 'random34999-103135,103136,103137:103137',
 156                  'timestamp' => '1238182723',
 157                  'event' => '6',
 158                  'grade' => '1',
 159                  'raw_grade' => '1',
 160                  'penalty' => '0.1',
 161                  'id' => 4010008,
 162              ),
 163          );
 164          $realquestion = (object) array(
 165              'id' => '34999',
 166              'category' => '3762',
 167              'parent' => '0',
 168              'name' => 'K101 iCMA41 Qs 2-v2',
 169              'questiontext' => '<p>(Notice in the panel at the left that the question you have just done is now greyed out. Remember that you can <b>revisit any questions</b> by clicking on the <b>numbered boxes</b>. Click Q1 now to try this out and then click Q2 to return here.)</p>
 170  <p><img style="margin-left: 0px; margin-right: 0px;" src="http://learn.open.ac.uk/file.php/5174/K101images/icma41/K101CMA41-Q1-v0.gif" alt="Table 1 showing Number of households receiving home care (England)" title="Table 1 showing Number of households receiving home care (England)" width="512" height="284" /></p>
 171  <p><b>(<a target="_blank" href="http://learn.open.ac.uk/file.php/5174/iCMA-PDFs-resizableimages/k101-iCMA41-Q2-v2-ResizableFigure.pdf" title="PDF document containing iCMA image - to enable enlargement">Link to resizable Table 1</a>) </b></p>
 172  <p>Which was the first year when more than a quarter of a million households received care from independent agencies?</p>',
 173              'questiontextformat' => '1',
 174              'defaultmark' => '1',
 175              'penalty' => '0.1',
 176              'qtype' => 'multichoice',
 177              'length' => '1',
 178              'stamp' => 'learn.open.ac.uk+090227173002+mbdE0X',
 179              'version' => 'learn.open.ac.uk+090304190917+xAB5Nf',
 180              'hidden' => '0',
 181              'generalfeedback' => '',
 182              'generalfeedbackformat' => '1',
 183              'timecreated' => '1235755802',
 184              'timemodified' => '1236193757',
 185              'createdby' => '25299',
 186              'modifiedby' => '25299',
 187              'unlimited' => '0',
 188              'options' => (object) array(
 189                  'id' => '15211',
 190                  'question' => '34999',
 191                  'layout' => '0',
 192                  'answers' => array(
 193                      103135 => (object) array(
 194                          'question' => '34999',
 195                          'answer' => '2001',
 196                          'fraction' => '0',
 197                          'feedback' => '',
 198                          'id' => 103135,
 199                      ),
 200                      103136 => (object) array(
 201                          'question' => '34999',
 202                          'answer' => '2003',
 203                          'fraction' => '0',
 204                          'feedback' => '',
 205                          'id' => 103136,
 206                      ),
 207                      103137 => (object) array(
 208                          'question' => '34999',
 209                          'answer' => '2005',
 210                          'fraction' => '1',
 211                          'feedback' => '',
 212                          'id' => 103137,
 213                      ),
 214                  ),
 215                  'single' => '1',
 216                  'shuffleanswers' => '1',
 217                  'correctfeedback' => 'Your answer is correct. Well done.',
 218                  'partiallycorrectfeedback' => '',
 219                  'incorrectfeedback' => 'Your answer is incorrect. The correct answer is: 2005.',
 220                  'answernumbering' => 'abc',
 221              ),
 222          );
 223          $this->loader->put_question_in_cache($realquestion);
 224  
 225          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 226  
 227          $expectedqa = (object) array(
 228              'behaviour' => 'deferredfeedback',
 229              'questionid' => 34999,
 230              'variant' => 1,
 231              'maxmark' => 1,
 232              'minfraction' => 0,
 233              'maxfraction' => 1,
 234              'flagged' => 0,
 235              'questionsummary' => "(Notice in the panel at the left that the question you have just done is now greyed out. Remember that you can REVISIT ANY QUESTIONS by clicking on the NUMBERED BOXES. Click Q1 now to try this out and then click Q2 to return here.) \n\n[Table 1 showing Number of households receiving home care (England)] \n\n(LINK TO RESIZABLE TABLE 1)  \n\nWhich was the first year when more than a quarter of a million households received care from independent agencies?",
 236              'rightanswer' => '2005',
 237              'responsesummary' => '2005',
 238              'timemodified' => 1238182723,
 239              'steps' => array(
 240                  0 => (object) array(
 241                      'sequencenumber' => 0,
 242                      'state' => 'todo',
 243                      'fraction' => null,
 244                      'timecreated' => 1236590532,
 245                      'userid' => 509191,
 246                      'data' => array('_order' => '103135,103136,103137'),
 247                  ),
 248                  1 => (object) array(
 249                      'sequencenumber' => 1,
 250                      'state' => 'complete',
 251                      'fraction' => null,
 252                      'timecreated' => 1238182723,
 253                      'userid' => 509191,
 254                      'data' => array('answer' => 2),
 255                  ),
 256                  2 => (object) array(
 257                      'sequencenumber' => 2,
 258                      'state' => 'gradedright',
 259                      'fraction' => 1,
 260                      'timecreated' => 1238182723,
 261                      'userid' => 509191,
 262                      'data' => array('answer' => 2, '-finish' => 1),
 263                  ),
 264              ),
 265          );
 266  
 267          $this->compare_qas($expectedqa, $qa);
 268      }
 269  
 270      public function test_random_deferredfeedback_qsession4225582() {
 271          $quiz = (object) array(
 272              'id' => '4410',
 273              'course' => '5444',
 274              'name' => 'Block 3, Session 5 Quiz',
 275              'intro' => 'Pour chacune des questions suivantes vous avez trois réponses possibles.  Cochez la bonne. (Cliquez sur « Check » pour vérifier votre réponse.)',
 276              'introformat' => FORMAT_HTML,
 277              'questiondecimalpoints' => '-1',
 278              'showuserpicture' => '1',
 279              'showblocks' => '1',
 280              'timeopen' => '0',
 281              'timeclose' => '0',
 282              'optionflags' => '0',
 283              'attempts' => '0',
 284              'attemptonlast' => '0',
 285              'grademethod' => '1',
 286              'decimalpoints' => '2',
 287              'review' => '71727591',
 288              'questionsperpage' => '3',
 289              'shufflequestions' => '1',
 290              'shuffleanswers' => '1',
 291              'sumgrades' => '15',
 292              'grade' => '10',
 293              'timecreated' => '0',
 294              'timemodified' => '1269429396',
 295              'password' => '',
 296              'subnet' => '',
 297              'popup' => '0',
 298              'delay1' => '0',
 299              'delay2' => '0',
 300              'timelimit' => '0',
 301              'preferredbehaviour' => 'deferredfeedback',
 302          );
 303          $attempt = (object) array(
 304              'id' => '418702',
 305              'uniqueid' => '418703',
 306              'quiz' => '4410',
 307              'userid' => '62892',
 308              'attempt' => '2',
 309              'sumgrades' => '9',
 310              'timestart' => '1274178725',
 311              'timefinish' => '1274179255',
 312              'timemodified' => '1274178763',
 313              'layout' => '101989,101985,101994,0,101988,101986,101992,0,101997,101990,101991,0,101984,101995,101987,0,101983,101993,101996,0',
 314              'preview' => '0',
 315          );
 316          $question = (object) array(
 317              'id' => '101984',
 318              'category' => '9148',
 319              'parent' => '101984',
 320              'name' => 'Random Question (Block 3, Session 5 Quiz)',
 321              'questiontext' => '1',
 322              'questiontextformat' => '0',
 323              'image' => '',
 324              'defaultmark' => '1',
 325              'penalty' => '0',
 326              'qtype' => 'random',
 327              'length' => '1',
 328              'stamp' => 'learn.open.ac.uk+100416133531+H1yive',
 329              'version' => 'learn.open.ac.uk+100416133531+KrpbHq',
 330              'hidden' => '0',
 331              'generalfeedback' => '',
 332              'generalfeedbackformat' => '1',
 333              'timecreated' => '1271424931',
 334              'timemodified' => '1271424931',
 335              'createdby' => '220574',
 336              'modifiedby' => '220574',
 337              'unlimited' => '0',
 338              'maxmark' => '1',
 339          );
 340          $qsession = (object) array(
 341              'id' => '4225582',
 342              'attemptid' => '418703',
 343              'questionid' => '101984',
 344              'newest' => '10786541',
 345              'newgraded' => '10786541',
 346              'sumpenalty' => '0.33',
 347              'manualcomment' => '',
 348              'manualcommentformat' => '1',
 349              'flagged' => '1',
 350          );
 351          $qstates = array(
 352              10786382 => (object) array(
 353                  'attempt' => '418703',
 354                  'question' => '101984',
 355                  'originalquestion' => '0',
 356                  'seq_number' => '0',
 357                  'answer' => 'random98355-341067,341066,341068:',
 358                  'timestamp' => '1274178725',
 359                  'event' => '0',
 360                  'grade' => '0',
 361                  'raw_grade' => '0',
 362                  'penalty' => '0',
 363                  'id' => 10786382,
 364              ),
 365              10786398 => (object) array(
 366                  'attempt' => '418703',
 367                  'question' => '101984',
 368                  'originalquestion' => '0',
 369                  'seq_number' => '1',
 370                  'answer' => 'random98355-341067,341066,341068:341061',
 371                  'timestamp' => '1274178725',
 372                  'event' => '2',
 373                  'grade' => '0',
 374                  'raw_grade' => '0',
 375                  'penalty' => '0.33',
 376                  'id' => 10786398,
 377              ),
 378              10786515 => (object) array(
 379                  'attempt' => '418703',
 380                  'question' => '101984',
 381                  'originalquestion' => '0',
 382                  'seq_number' => '2',
 383                  'answer' => 'random98355-341067,341066,341068:341067',
 384                  'timestamp' => '1274179164',
 385                  'event' => '2',
 386                  'grade' => '0',
 387                  'raw_grade' => '1',
 388                  'penalty' => '0.33',
 389                  'id' => 10786515,
 390              ),
 391              10786541 => (object) array(
 392                  'attempt' => '418703',
 393                  'question' => '101984',
 394                  'originalquestion' => '0',
 395                  'seq_number' => '3',
 396                  'answer' => 'random98355-341067,341066,341068:341067',
 397                  'timestamp' => '1274179164',
 398                  'event' => '6',
 399                  'grade' => '1',
 400                  'raw_grade' => '1',
 401                  'penalty' => '0.33',
 402                  'id' => 10786541,
 403              ),
 404          );
 405          $realquestion = (object) array(
 406              'id' => '98355',
 407              'category' => '9148',
 408              'parent' => '0',
 409              'name' => '20',
 410              'questiontext' => 'En France, le covoiturage est une pratique qui a été au départ préconisé par « les écolos et les verts », mais depuis, elle :',
 411              'questiontextformat' => '1',
 412              'defaultmark' => '1',
 413              'penalty' => '0.33',
 414              'qtype' => 'multichoice',
 415              'length' => '1',
 416              'stamp' => 'learn.open.ac.uk+100324131532+CExeWh',
 417              'version' => 'learn.open.ac.uk+100326162411+qEo2Bg',
 418              'hidden' => '0',
 419              'generalfeedback' => '',
 420              'generalfeedbackformat' => '1',
 421              'timecreated' => '1269436532',
 422              'timemodified' => '1269620651',
 423              'createdby' => '220574',
 424              'modifiedby' => '220574',
 425              'unlimited' => '0',
 426              'options' => (object) array(
 427                  'id' => '37042',
 428                  'question' => '98355',
 429                  'layout' => '0',
 430                  'answers' => array(
 431                      341066 => (object) array(
 432                          'question' => '98355',
 433                          'answer' => 'a été soutenue par les partis de droite.',
 434                          'fraction' => '0',
 435                          'feedback' => '',
 436                          'id' => 341066,
 437                      ),
 438                      341067 => (object) array(
 439                          'question' => '98355',
 440                          'answer' => 'n’est plus uniquement un positionnement écologiste.',
 441                          'fraction' => '1',
 442                          'feedback' => '',
 443                          'id' => 341067,
 444                      ),
 445                      341068 => (object) array(
 446                          'question' => '98355',
 447                          'answer' => 'est une idée de gauche, du centre, de droite, d’extrême gauche ou d’extrême droite.',
 448                          'fraction' => '0',
 449                          'feedback' => '',
 450                          'id' => 341068,
 451                      ),
 452                  ),
 453                  'single' => '1',
 454                  'shuffleanswers' => '1',
 455                  'correctfeedback' => 'Vrai.',
 456                  'partiallycorrectfeedback' => '',
 457                  'incorrectfeedback' => 'Faux.',
 458                  'answernumbering' => 'abc',
 459              ),
 460              'hints' => false,
 461              'maxmark' => '1',
 462          );
 463          $this->loader->put_question_in_cache($realquestion);
 464  
 465          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 466  
 467          $expectedqa = (object) array(
 468              'behaviour' => 'deferredfeedback',
 469              'questionid' => 98355,
 470              'variant' => 1,
 471              'maxmark' => 1,
 472              'minfraction' => 0,
 473              'maxfraction' => 1,
 474              'flagged' => 0,
 475              'questionsummary' => 'En France, le covoiturage est une pratique qui a été au départ préconisé par « les écolos et les verts », mais depuis, elle :',
 476              'rightanswer' => 'n’est plus uniquement un positionnement écologiste.',
 477              'responsesummary' => 'n’est plus uniquement un positionnement écologiste.',
 478              'timemodified' => 1274179164,
 479              'steps' => array(
 480                  0 => (object) array(
 481                      'sequencenumber' => 0,
 482                      'state' => 'todo',
 483                      'fraction' => null,
 484                      'timecreated' => 1274178725,
 485                      'userid' => 62892,
 486                      'data' => array('_order' => '341067,341066,341068'),
 487                  ),
 488                  1 => (object) array(
 489                      'sequencenumber' => 1,
 490                      'state' => 'complete',
 491                      'fraction' => null,
 492                      'timecreated' => 1274178725,
 493                      'userid' => 62892,
 494                      'data' => array('answer' => '-1'),
 495                  ),
 496                  2 => (object) array(
 497                      'sequencenumber' => 2,
 498                      'state' => 'complete',
 499                      'fraction' => null,
 500                      'timecreated' => 1274179164,
 501                      'userid' => 62892,
 502                      'data' => array('answer' => '0'),
 503                  ),
 504                  3 => (object) array(
 505                      'sequencenumber' => 3,
 506                      'state' => 'gradedright',
 507                      'fraction' => 1,
 508                      'timecreated' => 1274179164,
 509                      'userid' => 62892,
 510                      'data' => array('answer' => '0', '-finish' => '1'),
 511                  ),
 512              ),
 513          );
 514  
 515          $this->compare_qas($expectedqa, $qa);
 516      }
 517  
 518      public function test_random_deferredfeedback_qsession3481928() {
 519          $quiz = (object) array(
 520              'id' => '2624',
 521              'course' => '5233',
 522              'name' => 'iCMA 42',
 523              'intro' => '',
 524              'introformat' => FORMAT_HTML,
 525              'questiondecimalpoints' => '-1',
 526              'showuserpicture' => '1',
 527              'showblocks' => '1',
 528              'timeopen' => '1267056000',
 529              'timeclose' => '1271890740',
 530              'optionflags' => '0',
 531              'attempts' => '1',
 532              'attemptonlast' => '0',
 533              'grademethod' => '1',
 534              'decimalpoints' => '2',
 535              'review' => '67268673',
 536              'questionsperpage' => '1',
 537              'shufflequestions' => '0',
 538              'shuffleanswers' => '1',
 539              'sumgrades' => '18',
 540              'grade' => '18',
 541              'timecreated' => '0',
 542              'timemodified' => '1271852647',
 543              'password' => '',
 544              'subnet' => '',
 545              'popup' => '0',
 546              'delay1' => '0',
 547              'delay2' => '0',
 548              'timelimit' => '0',
 549              'preferredbehaviour' => 'deferredfeedback',
 550          );
 551          $attempt = (object) array(
 552              'id' => '331814',
 553              'uniqueid' => '331815',
 554              'quiz' => '2624',
 555              'userid' => '239341',
 556              'attempt' => '1',
 557              'sumgrades' => '9.13333',
 558              'timestart' => '1267605659',
 559              'timefinish' => '1270202969',
 560              'timemodified' => '1269508052',
 561              'layout' => '68646,0,81245,0,81246,0,81247,0,81248,0,81249,0,81250,0,82795,0,82797,0,82798,0,82799,0,82800,0,82801,0,82802,0,82803,0,82804,0,82805,0,82806,0,82807,0',
 562              'preview' => '0',
 563          );
 564          $question = (object) array(
 565              'id' => '81247',
 566              'category' => '6882',
 567              'parent' => '81247',
 568              'name' => 'Random Question (42.02.03.GraphConvert)',
 569              'questiontext' => '1',
 570              'questiontextformat' => '0',
 571              'image' => '',
 572              'defaultmark' => '1',
 573              'penalty' => '0',
 574              'qtype' => 'random',
 575              'length' => '1',
 576              'stamp' => 'learn.open.ac.uk+091215084951+AYsG5O',
 577              'version' => 'learn.open.ac.uk+091215084951+VSqp4u',
 578              'hidden' => '0',
 579              'generalfeedback' => '',
 580              'generalfeedbackformat' => '1',
 581              'timecreated' => '1260866991',
 582              'timemodified' => '1260866991',
 583              'createdby' => '27595',
 584              'modifiedby' => '27595',
 585              'unlimited' => '0',
 586              'maxmark' => '1',
 587          );
 588          $qsession = (object) array(
 589              'id' => '3481928',
 590              'attemptid' => '331815',
 591              'questionid' => '81247',
 592              'newest' => '9646306',
 593              'newgraded' => '9646306',
 594              'sumpenalty' => '0.333333',
 595              'manualcomment' => '',
 596              'manualcommentformat' => '1',
 597              'flagged' => '1',
 598          );
 599          $qstates = array(
 600              8809801 => (object) array(
 601                  'attempt' => '331815',
 602                  'question' => '81247',
 603                  'originalquestion' => '0',
 604                  'seq_number' => '0',
 605                  'answer' => 'random83248-',
 606                  'timestamp' => '1267605659',
 607                  'event' => '0',
 608                  'grade' => '0',
 609                  'raw_grade' => '0',
 610                  'penalty' => '0',
 611                  'id' => 8809801,
 612              ),
 613              9081885 => (object) array(
 614                  'attempt' => '331815',
 615                  'question' => '81247',
 616                  'originalquestion' => '0',
 617                  'seq_number' => '1',
 618                  'answer' => '64',
 619                  'timestamp' => '1268384692',
 620                  'event' => '2',
 621                  'grade' => '0',
 622                  'raw_grade' => '1',
 623                  'penalty' => '0.333333',
 624                  'id' => 9081885,
 625              ),
 626              9107452 => (object) array(
 627                  'attempt' => '331815',
 628                  'question' => '81247',
 629                  'originalquestion' => '0',
 630                  'seq_number' => '1',
 631                  'answer' => 'random83248-64',
 632                  'timestamp' => '1268471437',
 633                  'event' => '2',
 634                  'grade' => '0',
 635                  'raw_grade' => '1',
 636                  'penalty' => '0.333333',
 637                  'id' => 9107452,
 638              ),
 639              9646306 => (object) array(
 640                  'attempt' => '331815',
 641                  'question' => '81247',
 642                  'originalquestion' => '0',
 643                  'seq_number' => '2',
 644                  'answer' => 'random83248-64',
 645                  'timestamp' => '1268471437',
 646                  'event' => '6',
 647                  'grade' => '1',
 648                  'raw_grade' => '1',
 649                  'penalty' => '0.333333',
 650                  'id' => 9646306,
 651              ),
 652          );
 653          $realquestion = (object) array(
 654              'id' => '83248',
 655              'category' => '6882',
 656              'parent' => '0',
 657              'name' => '42.02.03.GraphConvert.E',
 658              'questiontext' => '<p> The figure below shows a graph for converting between miles and kilometres. </p><p><img src="http://learnacct.open.ac.uk/file.php/5233/quizImages/u2/figs/42.02.07.GraphConvert.png" alt=" The graph has a horizontal axis, labelled miles, with a scale marked from 0 to 50 in steps of 5, and a vertical axis, labelled kilometres, with a scale from 0 to 80 in steps of 10. The straight line of the graph starts at the origin and slopes up to the right, and appears to pass through the point corresponding to 25 miles and 40 kilometres, and through the point corresponding to 50 miles and 80 kilometres. "></img> </p><p>By taking a reading from the graph, estimate how many kilometres are equivalent to 40 miles. </p><p>Round your answer to the nearest kilometre and type it in the box below. </p><p>(Your answer should be a single number, without units.) </p>',
 659              'questiontextformat' => '0',
 660              'defaultmark' => '3',
 661              'penalty' => '0.333333',
 662              'qtype' => 'numerical',
 663              'length' => '1',
 664              'stamp' => 'learn.open.ac.uk+100108135957+SZhkKF',
 665              'version' => 'learn.open.ac.uk+100108135957+ej40PM',
 666              'hidden' => '0',
 667              'generalfeedback' => '<p> Conversion graph for miles and kilometres. </p><p><img src="http://learnacct.open.ac.uk/file.php/5233/quizImages/u2/figs/42.02.07.GraphConvert.E.png" alt=" The figure is the same as in the question, with some two additional lines drawn. So, the graph has a horizontal axis, labelled miles, with a scale marked from 0 to 50 in steps of 5, and a vertical axis, labelled kilometres, with a scale from 0 to 80 in steps of 10. The straight line of the graph starts at the origin and slopes up to the right, and appears to pass through the point corresponding to 25 miles and 40 kilometres, and through the point corresponding to 50 miles and 80 kilometres. The first additional line is vertical line drawn upwards from the horizontal axis from the point corresponding to 40 miles to the point where it meets the sloping line of the graph. From that point a horizontal line is drawn to meet the vertical axis at the point corresponding to 64 kilometres approximately."></img> </p><p>So 40 miles is approximately 64 km. </p><p>See Unit 2, Subsection 2.3. </p>',
 668              'generalfeedbackformat' => '1',
 669              'timecreated' => '1262959197',
 670              'timemodified' => '0',
 671              'createdby' => '123783',
 672              'modifiedby' => null,
 673              'unlimited' => '0',
 674              'options' => (object) array(
 675                  'answers' => array(
 676                      278332 => (object) array(
 677                          'question' => '83248',
 678                          'answer' => '64',
 679                          'fraction' => '1',
 680                          'feedback' => 'Your answer is correct.',
 681                          'tolerance' => '1',
 682                          'id' => 278332,
 683                      ),
 684                      278333 => (object) array(
 685                          'question' => '83248',
 686                          'answer' => '64',
 687                          'fraction' => '0',
 688                          'feedback' => 'Your answer is incorrect. It is close, but not quite accurate enough.',
 689                          'tolerance' => '5',
 690                          'id' => 278333,
 691                      ),
 692                      278334 => (object) array(
 693                          'question' => '83248',
 694                          'answer' => '25',
 695                          'fraction' => '0',
 696                          'feedback' => 'Your answer is incorrect. Remember you are converting from miles to kilometres.',
 697                          'tolerance' => '5',
 698                          'id' => 278334,
 699                      ),
 700                      278335 => (object) array(
 701                          'question' => '83248',
 702                          'answer' => '*',
 703                          'fraction' => '0',
 704                          'feedback' => 'Your answer is incorrect.',
 705                          'tolerance' => '0',
 706                          'id' => 278335,
 707                      ),
 708                  ),
 709                  'units' => array(
 710                      0 => (object) array(
 711                          'question' => '83248',
 712                          'multiplier' => 1,
 713                          'unit' => 'km',
 714                          'id' => 2030,
 715                      ),
 716                      1 => (object) array(
 717                          'question' => '83248',
 718                          'multiplier' => 1,
 719                          'unit' => 'kilometres',
 720                          'id' => 2031,
 721                      ),
 722                  ),
 723              ),
 724              'hints' => array(
 725                  44315 => (object) array(
 726                          'questionid' => '83248',
 727                          'hint' => 'See Unit 2, Subsection 2.3.',
 728                          'rest' => null,
 729                          'id' => 44315,
 730                  ),
 731                  44316 => (object) array(
 732                          'questionid' => '83248',
 733                          'hint' => '<p> Find the measurement on the horizontal axis, draw a line vertically up to meet the conversion line and read off the corresponding value on the vertical axis. </p><p>See Unit 2, Subsection 2.3. </p>',
 734                          'rest' => null,
 735                          'id' => 44316,
 736                  ),
 737              ),
 738              'maxmark' => '1',
 739          );
 740          $this->loader->put_question_in_cache($realquestion);
 741  
 742          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 743  
 744          $expectedqa = (object) array(
 745              'behaviour' => 'deferredfeedback',
 746              'questionid' => 83248,
 747              'variant' => 1,
 748              'maxmark' => 1,
 749              'minfraction' => 0,
 750              'maxfraction' => 1,
 751              'flagged' => 0,
 752              'questionsummary' => "The figure below shows a graph for converting between miles and kilometres. \n\n[ The graph has a horizontal axis, labelled miles, with a scale marked from 0 to 50 in steps of 5, and a vertical axis, labelled kilometres, with a scale from 0 to 80 in steps of 10. The straight line of the graph starts at the origin and slopes up to the right, and appears to pass through the point corresponding to 25 miles and 40 kilometres, and through the point corresponding to 50 miles and 80 kilometres. ] \n\nBy taking a reading from the graph, estimate how many kilometres are equivalent to 40 miles. \n\nRound your answer to the nearest kilometre and type it in the box below. \n\n(Your answer should be a single number, without units.)",
 753              'rightanswer' => '64 km',
 754              'responsesummary' => '64',
 755              'timemodified' => 1268471437,
 756              'steps' => array(
 757                  0 => (object) array(
 758                      'sequencenumber' => 0,
 759                      'state' => 'todo',
 760                      'fraction' => null,
 761                      'timecreated' => 1267605659,
 762                      'userid' => 239341,
 763                      'data' => array('_separators' => '.$,'),
 764                  ),
 765                  1 => (object) array(
 766                      'sequencenumber' => 1,
 767                      'state' => 'complete',
 768                      'fraction' => null,
 769                      'timecreated' => 1268471437,
 770                      'userid' => 239341,
 771                      'data' => array('answer' => '64'),
 772                  ),
 773                  2 => (object) array(
 774                      'sequencenumber' => 2,
 775                      'state' => 'gradedright',
 776                      'fraction' => 1,
 777                      'timecreated' => 1268471437,
 778                      'userid' => 239341,
 779                      'data' => array('answer' => '64', '-finish' => '1'),
 780                  ),
 781              ),
 782          );
 783  
 784          $this->compare_qas($expectedqa, $qa);
 785      }
 786  
 787      public function test_numerical_deferredfeedback_qsession55() {
 788          $quiz = (object) array(
 789              'id' => '2',
 790              'course' => '2',
 791              'name' => 'Numerical quiz',
 792              'intro' => '',
 793              'introformat' => '1',
 794              'timeopen' => '0',
 795              'timeclose' => '0',
 796              'attempts' => '0',
 797              'attemptonlast' => '0',
 798              'grademethod' => '1',
 799              'decimalpoints' => '2',
 800              'questiondecimalpoints' => '-1',
 801              'review' => '4459503',
 802              'questionsperpage' => '1',
 803              'shufflequestions' => '0',
 804              'shuffleanswers' => '1',
 805              'sumgrades' => '5.00000',
 806              'grade' => '10.00000',
 807              'timecreated' => '0',
 808              'timemodified' => '1305273177',
 809              'timelimit' => '0',
 810              'password' => '',
 811              'subnet' => '',
 812              'popup' => '0',
 813              'delay1' => '0',
 814              'delay2' => '0',
 815              'showuserpicture' => '0',
 816              'showblocks' => '0',
 817              'preferredbehaviour' => 'deferredfeedback',
 818          );
 819          $attempt = (object) array(
 820              'id' => '7',
 821              'uniqueid' => '7',
 822              'quiz' => '2',
 823              'userid' => '3',
 824              'attempt' => '1',
 825              'sumgrades' => '5.00000',
 826              'timestart' => '1305273645',
 827              'timefinish' => '1305273672',
 828              'timemodified' => '1305273672',
 829              'layout' => '6,12,13,15,14,0',
 830              'preview' => '0',
 831          );
 832          $question = (object) array(
 833              'id' => '14',
 834              'category' => '2',
 835              'parent' => '0',
 836              'name' => 'MC units',
 837              'questiontext' => '<p>What is twice 1.5 m?</p>',
 838              'questiontextformat' => '1',
 839              'generalfeedback' => '',
 840              'generalfeedbackformat' => '1',
 841              'penalty' => '0.1000000',
 842              'qtype' => 'numerical',
 843              'length' => '1',
 844              'stamp' => 'tjh238.vledev2.open.ac.uk+110513075703+anXKfw',
 845              'version' => 'tjh238.vledev2.open.ac.uk+110513075807+HiXe4P',
 846              'hidden' => '0',
 847              'timecreated' => '1305273423',
 848              'timemodified' => '1305273487',
 849              'createdby' => '2',
 850              'modifiedby' => '2',
 851              'maxmark' => '1.0000000',
 852              'options' => (object) array(
 853                  'answers' => array(
 854                      21 => (object) array(
 855                          'id' => '21',
 856                          'question' => '14',
 857                          'answer' => '3',
 858                          'answerformat' => '0',
 859                          'fraction' => '1.0000000',
 860                          'feedback' => '',
 861                          'feedbackformat' => '1',
 862                          'tolerance' => '',
 863                      ),
 864                  ),
 865                  'units' => array(
 866                      0 => (object) array(
 867                          'id' => '5',
 868                          'question' => '14',
 869                          'multiplier' => 1,
 870                          'unit' => 'm',
 871                      ),
 872                      1 => (object) array(
 873                          'id' => '6',
 874                          'question' => '14',
 875                          'multiplier' => 100,
 876                          'unit' => 'cm',
 877                      ),
 878                  ),
 879                  'unitgradingtype' => '2',
 880                  'unitpenalty' => '0.5000000',
 881                  'showunits' => '1',
 882                  'unitsleft' => '0',
 883                  'instructions' => '<p>Write an answer like 3 m.</p>',
 884                  'instructionsformat' => '1',
 885              ),
 886              'defaultmark' => '1.0000000',
 887          );
 888          $qsession = (object) array(
 889              'id' => '55',
 890              'attemptid' => '7',
 891              'questionid' => '14',
 892              'newest' => '155',
 893              'newgraded' => '155',
 894              'sumpenalty' => '0.1000000',
 895              'manualcomment' => '',
 896              'manualcommentformat' => '1',
 897              'flagged' => '0',
 898          );
 899          $qstates = array(
 900              145 => (object) array(
 901                  'id' => '145',
 902                  'attempt' => '7',
 903                  'question' => '14',
 904                  'seq_number' => '0',
 905                  'answer' => '|||||',
 906                  'timestamp' => '1305273645',
 907                  'event' => '0',
 908                  'grade' => '0.0000000',
 909                  'raw_grade' => '0.0000000',
 910                  'penalty' => '0.0000000',
 911              ),
 912              150 => (object) array(
 913                  'id' => '150',
 914                  'attempt' => '7',
 915                  'question' => '14',
 916                  'seq_number' => '1',
 917                  'answer' => '300|||||cm',
 918                  'timestamp' => '1305273666',
 919                  'event' => '2',
 920                  'grade' => '0.0000000',
 921                  'raw_grade' => '1.0000000',
 922                  'penalty' => '0.1000000',
 923              ),
 924              155 => (object) array(
 925                  'id' => '155',
 926                  'attempt' => '7',
 927                  'question' => '14',
 928                  'seq_number' => '2',
 929                  'answer' => '300|||||cm',
 930                  'timestamp' => '1305273666',
 931                  'event' => '6',
 932                  'grade' => '1.0000000',
 933                  'raw_grade' => '1.0000000',
 934                  'penalty' => '0.1000000',
 935              ),
 936          );
 937  
 938          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 939  
 940          $expectedqa = (object) array(
 941              'behaviour' => 'deferredfeedback',
 942              'questionid' => 14,
 943              'variant' => 1,
 944              'maxmark' => 1.0000000,
 945              'minfraction' => 0,
 946              'maxfraction' => 1,
 947              'flagged' => 0,
 948              'questionsummary' => 'What is twice 1.5 m?',
 949              'rightanswer' => '3 m',
 950              'responsesummary' => '300 cm',
 951              'timemodified' => 1305273666,
 952              'steps' => array(
 953                  0 => (object) array(
 954                      'sequencenumber' => 0,
 955                      'state' => 'todo',
 956                      'fraction' => null,
 957                      'timecreated' => 1305273645,
 958                      'userid' => 3,
 959                      'data' => array('_separators' => '.$,'),
 960                  ),
 961                  1 => (object) array(
 962                      'sequencenumber' => 1,
 963                      'state' => 'complete',
 964                      'fraction' => null,
 965                      'timecreated' => 1305273666,
 966                      'userid' => 3,
 967                      'data' => array('answer' => '300', 'unit' => 'cm'),
 968                  ),
 969                  2 => (object) array(
 970                      'sequencenumber' => 2,
 971                      'state' => 'gradedright',
 972                      'fraction' => 1,
 973                      'timecreated' => 1305273666,
 974                      'userid' => 3,
 975                      'data' => array('answer' => '300', 'unit' => 'cm', '-finish' => 1),
 976                  ),
 977              ),
 978          );
 979  
 980          $this->compare_qas($expectedqa, $qa);
 981      }
 982  }