Search moodle.org's
Developer Documentation

See Release Notes

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