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_multichoice;
  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 multichoice question attempts.
  27   *
  28   * @package    qtype_multichoice
  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_multichoice_deferredfeedback_history960() {
  35          $quiz = (object) array(
  36              'id' => '1',
  37              'course' => '3',
  38              'name' => 'Test quiz 1',
  39              'intro' => '',
  40              'introformat' => FORMAT_HTML,
  41              'questiondecimalpoints' => '-1',
  42              'showuserpicture' => '1',
  43              'showblocks' => '1',
  44              'timeopen' => '0',
  45              'timeclose' => '0',
  46              'preferredbehaviour' => 'deferredfeedback',
  47              'attempts' => '0',
  48              'attemptonlast' => '0',
  49              'grademethod' => '1',
  50              'decimalpoints' => '2',
  51              'questionsperpage' => '0',
  52              'shufflequestions' => '0',
  53              'shuffleanswers' => '1',
  54              'timecreated' => '0',
  55              'timemodified' => '1278603396',
  56              'timelimit' => '0',
  57              'password' => '',
  58              'subnet' => '',
  59              'popup' => '0',
  60              'delay1' => '0',
  61              'delay2' => '0',
  62              'sumgrades' => '1.00000',
  63              'grade' => '10.00000',
  64              'questiondecimalpoints' => '-1',
  65              'showuserpicture' => '0',
  66              'introformat' => '0',
  67              'preferredbehaviour' => 'deferredfeedback',
  68              'reviewattempt' => '69904',
  69              'reviewcorrectness' => '69904',
  70              'reviewmarks' => '69904',
  71              'reviewspecificfeedback' => '69904',
  72              'reviewgeneralfeedback' => '69904',
  73              'reviewrightanswer' => '69904',
  74              'reviewoverallfeedback' => '4368',
  75          );
  76          $attempt = (object) array(
  77              'id' => '2',
  78              'uniqueid' => '2',
  79              'quiz' => '2',
  80              'userid' => '4',
  81              'attempt' => '1',
  82              'timestart' => '1278604557',
  83              'timefinish' => '1278604570',
  84              'timemodified' => '1278604597',
  85              'layout' => '2,0',
  86              'preview' => '0',
  87              'sumgrades' => '0.90000',
  88          );
  89          $question = (object) array(
  90              'id' => '2',
  91              'category' => '2',
  92              'parent' => '0',
  93              'name' => 'Which is the amphibian',
  94              'questiontext' => 'Which is the amphibian?',
  95              'questiontextformat' => '1',
  96              'generalfeedback' => '',
  97              'generalfeedbackformat' => '1',
  98              'qtype' => 'multichoice',
  99              'length' => '1',
 100              'stamp' => 'tjh238.vledev.open.ac.uk+100708154547+JrHygi',
 101              'version' => 'tjh238.vledev.open.ac.uk+100708154548+a3zh8v',
 102              'hidden' => '0',
 103              'timecreated' => '1278603947',
 104              'timemodified' => '1278603947',
 105              'createdby' => '3',
 106              'modifiedby' => '3',
 107              'defaultmark' => '1.0000000',
 108              'penalty' => '0.3333333',
 109              'maxmark' => '1.00000',
 110              'options' => (object) array(
 111                  'id' => '1',
 112                  'question' => '2',
 113                  'layout' => '0',
 114                  'answers' => array(
 115                      3 => (object) array(
 116                          'question' => '2',
 117                          'answer' => 'Cat',
 118                          'feedback' => '',
 119                          'fraction' => '0.0000000',
 120                          'id' => 3,
 121                      ),
 122                      4 => (object) array(
 123                          'question' => '2',
 124                          'answer' => 'Frog',
 125                          'feedback' => '',
 126                          'fraction' => '1.0000000',
 127                          'id' => 4,
 128                      ),
 129                      5 => (object) array(
 130                          'question' => '2',
 131                          'answer' => 'Ant',
 132                          'feedback' => '',
 133                          'fraction' => '0.0000000',
 134                          'id' => 5,
 135                      ),
 136                      6 => (object) array(
 137                          'question' => '2',
 138                          'answer' => 'Dog',
 139                          'feedback' => '',
 140                          'fraction' => '0.0000000',
 141                          'id' => 6,
 142                      ),
 143                  ),
 144                  'single' => '1',
 145                  'shuffleanswers' => '1',
 146                  'correctfeedback' => '',
 147                  'partiallycorrectfeedback' => '',
 148                  'incorrectfeedback' => '',
 149                  'answernumbering' => 'none',
 150                  'showstandardinstruction' => 0,
 151                  'shownumcorrect' => '0',
 152              ),
 153              'hints' => array (
 154                  1 => (object) array(
 155                      'hint' => 'First hint',
 156                      'questionid' => '2',
 157                      'shownumcorrect' => null,
 158                      'clearwrong' => null,
 159                      'options' => null,
 160                      'id' => 1,
 161                  ),
 162                  2 => (object) array(
 163                      'hint' => 'Second hint',
 164                      'questionid' => '2',
 165                      'shownumcorrect' => null,
 166                      'clearwrong' => null,
 167                      'options' => null,
 168                      'id' => 2,
 169                  ),
 170              ),
 171          );
 172          $qsession = (object) array(
 173              'id' => '2',
 174              'attemptid' => '2',
 175              'questionid' => '2',
 176              'newest' => '6',
 177              'newgraded' => '6',
 178              'sumpenalty' => '0.3333333',
 179              'manualcomment' => 'Well done!',
 180              'manualcommentformat' => '1',
 181              'flagged' => '1',
 182          );
 183          $qstates = array(
 184              0 => (object) array(
 185                  'id' => '4',
 186                  'attempt' => '2',
 187                  'question' => '2',
 188                  'originalquestion' => '0',
 189                  'seq_number' => '0',
 190                  'answer' => '5,4,6,3:',
 191                  'timestamp' => '1278604557',
 192                  'event' => '0',
 193                  'grade' => '0',
 194                  'raw_grade' => '0',
 195                  'penalty' => '0',
 196              ),
 197              1 => (object) array(
 198                  'id' => '5',
 199                  'attempt' => '2',
 200                  'question' => '2',
 201                  'originalquestion' => '0',
 202                  'seq_number' => '1',
 203                  'answer' => '5,4,6,3:4',
 204                  'timestamp' => '1278604562',
 205                  'event' => '6',
 206                  'grade' => '1',
 207                  'raw_grade' => '1',
 208                  'penalty' => '0.3333333',
 209              ),
 210              2 => (object) array(
 211                  'id' => '6',
 212                  'attempt' => '2',
 213                  'question' => '2',
 214                  'originalquestion' => '0',
 215                  'seq_number' => '2',
 216                  'answer' => '5,4,6,3:4',
 217                  'timestamp' => '1278604597',
 218                  'event' => '9',
 219                  'grade' => '0.9',
 220                  'raw_grade' => '0.9',
 221                  'penalty' => '0',
 222              ),
 223          );
 224  
 225          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 226  
 227          $expectedqa = (object) array(
 228              'behaviour' => 'deferredfeedback',
 229              'questionid' => 2,
 230              'variant' => 1,
 231              'maxmark' => 1,
 232              'minfraction' => 0,
 233              'maxfraction' => 1,
 234              'flagged' => 0,
 235              'questionsummary' => 'Which is the amphibian?',
 236              'rightanswer' => 'Frog',
 237              'responsesummary' => 'Frog',
 238              'timemodified' => 1278604597,
 239              'steps' => array(
 240                  0 => (object) array(
 241                      'sequencenumber' => 0,
 242                      'state' => 'todo',
 243                      'fraction' => null,
 244                      'timecreated' => 1278604557,
 245                      'userid' => 4,
 246                      'data' => array('_order' => '5,4,6,3'),
 247                  ),
 248                  1 => (object) array(
 249                      'sequencenumber' => 1,
 250                      'state' => 'gradedright',
 251                      'fraction' => 1,
 252                      'timecreated' => 1278604562,
 253                      'userid' => 4,
 254                      'data' => array('-finish' => '1', 'answer' => '1'),
 255                  ),
 256                  2 => (object) array(
 257                      'sequencenumber' => 2,
 258                      'state' => 'mangrpartial',
 259                      'fraction' => 0.9,
 260                      'timecreated' => 1278604597,
 261                      'userid' => null,
 262                      'data' => array('-comment' => 'Well done!', '-mark' => '0.9', '-maxmark' => 1),
 263                  ),
 264              ),
 265          );
 266  
 267          $this->compare_qas($expectedqa, $qa);
 268      }
 269  
 270      public function test_multichoice_deferredfeedback_history0() {
 271          $quiz = (object) array(
 272              'id' => '8',
 273              'course' => '1095',
 274              'name' => 'End of course quiz',
 275              'intro' => 'Use this self-assessment quiz to judge your overall understanding. ',
 276              'introformat' => FORMAT_HTML,
 277              'questiondecimalpoints' => '-1',
 278              'showuserpicture' => '1',
 279              'showblocks' => '1',
 280              'timeopen' => '1150107600',
 281              'timeclose' => '0',
 282              'preferredbehaviour' => 'deferredfeedback',
 283              'attempts' => '0',
 284              'attemptonlast' => '0',
 285              'grademethod' => '1',
 286              'decimalpoints' => '2',
 287              'review' => '71760879',
 288              'questionsperpage' => '0',
 289              'shufflequestions' => '1',
 290              'shuffleanswers' => '1',
 291              'sumgrades' => '25',
 292              'grade' => '25',
 293              'timecreated' => '0',
 294              'timemodified' => '1150107596',
 295              'password' => '',
 296              'subnet' => '',
 297              'popup' => '0',
 298              'delay1' => '0',
 299              'delay2' => '0',
 300              'timelimit' => '0',
 301          );
 302          $attempt = (object) array(
 303              'id' => '17',
 304              'uniqueid' => '17',
 305              'quiz' => '8',
 306              'userid' => '26290',
 307              'attempt' => '1',
 308              'sumgrades' => '0',
 309              'timestart' => '1150203042',
 310              'timefinish' => '0',
 311              'timemodified' => '1150203042',
 312              'layout' => '93,76,82,75,87,74,90,94,73,77,81,95,79,92,88,80,91,86,72,83,84,89,85,78,71,0',
 313              'preview' => '1',
 314          );
 315          $question = (object) array(
 316              'id' => '72',
 317              'category' => '10',
 318              'parent' => '0',
 319              'name' => 'Q02',
 320              'questiontext' => 'Why were standards such an important driver in the growth of systems integration?',
 321              'questiontextformat' => '1',
 322              'defaultmark' => '1',
 323              'penalty' => '0.1',
 324              'qtype' => 'multichoice',
 325              'length' => '1',
 326              'stamp' => 'learn.open.ac.uk+060612113403+Fz0GGO',
 327              'version' => 'learn.open.ac.uk+060612160802+I6ctMQ',
 328              'hidden' => '0',
 329              'generalfeedback' => '',
 330              'generalfeedbackformat' => '1',
 331              'timecreated' => '0',
 332              'timemodified' => '0',
 333              'createdby' => null,
 334              'modifiedby' => null,
 335              'unlimited' => null,
 336              'maxmark' => '1',
 337              'options' => (object) array(
 338                  'id' => '44',
 339                  'question' => '72',
 340                  'layout' => '0',
 341                  'answers' => array(
 342                      200 => (object) array(
 343                          'question' => '72',
 344                          'answer' => 'Because they enable stored data and interfaces to be standardised.',
 345                          'fraction' => '1',
 346                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 347                          'id' => 200,
 348                      ),
 349                      201 => (object) array(
 350                          'question' => '72',
 351                          'answer' => 'Because they enable the members of an integration team to communicate together.',
 352                          'fraction' => '0',
 353                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 354                          'id' => 201,
 355                      ),
 356                      202 => (object) array(
 357                          'question' => '72',
 358                          'answer' => 'Because they produce good quality documentation.',
 359                          'fraction' => '0',
 360                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 361                          'id' => 202,
 362                      ),
 363                  ),
 364                  'single' => '1',
 365                  'shuffleanswers' => '1',
 366                  'correctfeedback' => '',
 367                  'partiallycorrectfeedback' => '',
 368                  'incorrectfeedback' => '',
 369                  'answernumbering' => 'abc',
 370                  'showstandardinstruction' => 0,
 371              ),
 372              'hints' => false,
 373          );
 374          $qsession = (object) array(
 375              'id' => '132',
 376              'attemptid' => '17',
 377              'questionid' => '72',
 378              'newest' => '196',
 379              'newgraded' => '196',
 380              'sumpenalty' => '0',
 381              'manualcomment' => '',
 382              'manualcommentformat' => '1',
 383              'flagged' => '1',
 384          );
 385          $qstates = array(
 386              196 => (object) array(
 387                  'attempt' => '17',
 388                  'question' => '72',
 389                  'originalquestion' => '0',
 390                  'seq_number' => '0',
 391                  'answer' => '200,202,201:',
 392                  'timestamp' => '1150203042',
 393                  'event' => '0',
 394                  'grade' => '0',
 395                  'raw_grade' => '0',
 396                  'penalty' => '0',
 397                  'id' => 196,
 398              ),
 399          );
 400  
 401          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 402  
 403          $expectedqa = (object) array(
 404              'behaviour' => 'deferredfeedback',
 405              'questionid' => 72,
 406              'variant' => 1,
 407              'maxmark' => 1,
 408              'minfraction' => 0,
 409              'maxfraction' => 1,
 410              'flagged' => 0,
 411              'questionsummary' => 'Why were standards such an important driver in the growth of systems integration?',
 412              'rightanswer' => 'Because they enable stored data and interfaces to be standardised.',
 413              'responsesummary' => '',
 414              'timemodified' => 1150203042,
 415              'steps' => array(
 416                  0 => (object) array(
 417                      'sequencenumber' => 0,
 418                      'state' => 'todo',
 419                      'fraction' => null,
 420                      'timecreated' => 1150203042,
 421                      'userid' => 26290,
 422                      'data' => array('_order' => '200,202,201'),
 423                  ),
 424              ),
 425          );
 426  
 427          $this->compare_qas($expectedqa, $qa);
 428      }
 429  
 430      public function test_multichoice_deferredfeedback_history60() {
 431          $quiz = (object) array(
 432              'id' => '13',
 433              'course' => '1416',
 434              'name' => 'Self assessment',
 435              'intro' => '<p>This quiz enables you to rate how much you have demonstrated certain skills in assignments.
 436          </p>
 437          <p>Each question is phrased so that you agree or disagree with a statement that describes your level of attainment, and is accompanied by a link to advice on recognising and practising the skill.
 438          </p>
 439          <p>The quiz is intended to form part of a dialogue on skills improvement between you and your tutor. Hence there is no "right" answer to it, and it is awarded no marks towards the course result.
 440          </p>
 441          <p>Any benefits to you depend on your being realistic about what you have demonstrated. Reserve the extreme ratings for when you think you have demonstrated mastery or complete incompetence!
 442              <br />
 443          </p>',
 444              'introformat' => FORMAT_HTML,
 445              'questiondecimalpoints' => '-1',
 446              'showuserpicture' => '1',
 447              'showblocks' => '1',
 448              'timeopen' => '0',
 449              'timeclose' => '0',
 450              'preferredbehaviour' => 'deferredfeedback',
 451              'attempts' => '0',
 452              'attemptonlast' => '1',
 453              'grademethod' => '4',
 454              'decimalpoints' => '0',
 455              'review' => '71760879',
 456              'questionsperpage' => '0',
 457              'shufflequestions' => '0',
 458              'shuffleanswers' => '0',
 459              'sumgrades' => '7',
 460              'grade' => '0',
 461              'timecreated' => '0',
 462              'timemodified' => '1160991947',
 463              'password' => '',
 464              'subnet' => '',
 465              'popup' => '0',
 466              'delay1' => '0',
 467              'delay2' => '0',
 468              'timelimit' => '0',
 469          );
 470          $attempt = (object) array(
 471              'id' => '181',
 472              'uniqueid' => '181',
 473              'quiz' => '13',
 474              'userid' => '9932',
 475              'attempt' => '1',
 476              'sumgrades' => '0',
 477              'timestart' => '1161946984',
 478              'timefinish' => '1161947130',
 479              'timemodified' => '1161947130',
 480              'layout' => '218,221,219,220,223,224,222,0',
 481              'preview' => '0',
 482          );
 483          $question = (object) array(
 484              'id' => '218',
 485              'category' => '21',
 486              'parent' => '0',
 487              'name' => 'Answering the question that is asked',
 488              'questiontext' => '<p>I have demonstrated the ability to analyse and <strong>answer the question</strong> that is asked. (<a title="Advice" href="http://learnacct.open.ac.uk/mod/resourcepage/view.php?id=5989">Click for advice on this skill</a>)',
 489              'questiontextformat' => '1',
 490              'defaultmark' => '1',
 491              'penalty' => '0',
 492              'qtype' => 'multichoice',
 493              'length' => '1',
 494              'stamp' => 'learn.open.ac.uk+060822084343+5JvlNr',
 495              'version' => 'learn.open.ac.uk+060822084343+CQPfhb',
 496              'hidden' => '0',
 497              'generalfeedback' => '',
 498              'generalfeedbackformat' => '1',
 499              'timecreated' => '0',
 500              'timemodified' => '0',
 501              'createdby' => null,
 502              'modifiedby' => null,
 503              'unlimited' => null,
 504              'maxmark' => '1',
 505              'options' => (object) array(
 506                  'id' => '152',
 507                  'question' => '218',
 508                  'layout' => '0',
 509                  'answers' => array(
 510                      664 => (object) array(
 511                          'question' => '218',
 512                          'answer' => 'Agree',
 513                          'fraction' => '0',
 514                          'feedback' => ' ',
 515                          'id' => 664,
 516                      ),
 517                      665 => (object) array(
 518                          'question' => '218',
 519                          'answer' => 'Uncertain',
 520                          'fraction' => '0',
 521                          'feedback' => ' ',
 522                          'id' => 665,
 523                      ),
 524                      666 => (object) array(
 525                          'question' => '218',
 526                          'answer' => 'Disagree',
 527                          'fraction' => '0',
 528                          'feedback' => ' ',
 529                          'id' => 666,
 530                      ),
 531                      667 => (object) array(
 532                          'question' => '218',
 533                          'answer' => 'Strongly disagree',
 534                          'fraction' => '0',
 535                          'feedback' => ' ',
 536                          'id' => 667,
 537                      ),
 538                      668 => (object) array(
 539                          'question' => '218',
 540                          'answer' => 'Strongly agree',
 541                          'fraction' => '0',
 542                          'feedback' => ' ',
 543                          'id' => 668,
 544                      ),
 545                  ),
 546                  'single' => '0',
 547                  'shuffleanswers' => '0',
 548                  'correctfeedback' => '',
 549                  'partiallycorrectfeedback' => '',
 550                  'incorrectfeedback' => '',
 551                  'answernumbering' => 'abc',
 552                  'showstandardinstruction' => 0,
 553              ),
 554              'hints' => false,
 555          );
 556          $qsession = (object) array(
 557              'id' => '2412',
 558              'attemptid' => '181',
 559              'questionid' => '218',
 560              'newest' => '3891',
 561              'newgraded' => '3891',
 562              'sumpenalty' => '0',
 563              'manualcomment' => '',
 564              'manualcommentformat' => '1',
 565              'flagged' => '1',
 566          );
 567          $qstates = array(
 568              3888 => (object) array(
 569                  'attempt' => '181',
 570                  'question' => '218',
 571                  'originalquestion' => '0',
 572                  'seq_number' => '0',
 573                  'answer' => '664,665,666,667,668:',
 574                  'timestamp' => '1161946984',
 575                  'event' => '0',
 576                  'grade' => '0',
 577                  'raw_grade' => '0',
 578                  'penalty' => '0',
 579                  'id' => 3888,
 580              ),
 581              3891 => (object) array(
 582                  'attempt' => '181',
 583                  'question' => '218',
 584                  'originalquestion' => '0',
 585                  'seq_number' => '1',
 586                  'answer' => '664,665,666,667,668:664',
 587                  'timestamp' => '1161947130',
 588                  'event' => '6',
 589                  'grade' => '0',
 590                  'raw_grade' => '0',
 591                  'penalty' => '0',
 592                  'id' => 3891,
 593              ),
 594          );
 595  
 596          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 597  
 598          $expectedqa = (object) array(
 599              'behaviour' => 'deferredfeedback',
 600              'questionid' => 218,
 601              'variant' => 1,
 602              'maxmark' => 1,
 603              'minfraction' => 0,
 604              'maxfraction' => 1,
 605              'flagged' => 0,
 606              'questionsummary' => 'I have demonstrated the ability to analyse and ANSWER THE QUESTION that is asked. (Click for advice on this skill)',
 607              'rightanswer' => '',
 608              'responsesummary' => 'Agree',
 609              'timemodified' => 1161947130,
 610              'steps' => array(
 611                  0 => (object) array(
 612                      'sequencenumber' => 0,
 613                      'state' => 'todo',
 614                      'fraction' => null,
 615                      'timecreated' => 1161946984,
 616                      'userid' => 9932,
 617                      'data' => array('_order' => '664,665,666,667,668'),
 618                  ),
 619                  1 => (object) array(
 620                      'sequencenumber' => 1,
 621                      'state' => 'gradedwrong',
 622                      'fraction' => 0,
 623                      'timecreated' => 1161947130,
 624                      'userid' => 9932,
 625                      'data' => array('choice0' => 1, 'choice1' => 0, 'choice2' => 0, 'choice3' => 0, 'choice4' => 0, '-finish' => 1),
 626                  ),
 627              ),
 628          );
 629  
 630          $this->compare_qas($expectedqa, $qa);
 631      }
 632  
 633      public function test_multichoice_deferredfeedback_history6220() {
 634          $quiz = (object) array(
 635              'id' => '95',
 636              'course' => '1181',
 637              'name' => 'Study Guide 7 Quiz',
 638              'intro' => '',
 639              'introformat' => FORMAT_HTML,
 640              'questiondecimalpoints' => '-1',
 641              'showuserpicture' => '1',
 642              'showblocks' => '1',
 643              'timeopen' => '0',
 644              'timeclose' => '0',
 645              'preferredbehaviour' => 'deferredfeedback',
 646              'attempts' => '0',
 647              'attemptonlast' => '1',
 648              'grademethod' => '1',
 649              'decimalpoints' => '2',
 650              'review' => '71760879',
 651              'questionsperpage' => '2',
 652              'shufflequestions' => '0',
 653              'shuffleanswers' => '0',
 654              'sumgrades' => '59',
 655              'grade' => '59',
 656              'timecreated' => '0',
 657              'timemodified' => '1170427431',
 658              'password' => '',
 659              'subnet' => '',
 660              'popup' => '0',
 661              'delay1' => '0',
 662              'delay2' => '0',
 663              'timelimit' => '0',
 664          );
 665          $attempt = (object) array(
 666              'id' => '3237',
 667              'uniqueid' => '3237',
 668              'quiz' => '95',
 669              'userid' => '120555',
 670              'attempt' => '1',
 671              'sumgrades' => '35.4166',
 672              'timestart' => '1177006492',
 673              'timefinish' => '1177008802',
 674              'timemodified' => '1177008794',
 675              'layout' => '2855,2856,0,2857,2858,0,2859,2860,0,2861,2862,0,2863,2864,0,2865,0',
 676              'preview' => '0',
 677          );
 678          $question = (object) array(
 679              'id' => '2855',
 680              'category' => '114',
 681              'parent' => '0',
 682              'name' => 'Question 1',
 683              'questiontext' => '<p>Which of the following techniques can identify non-functional requirements?</p>',
 684              'questiontextformat' => '1',
 685              'defaultmark' => '1',
 686              'penalty' => '0',
 687              'qtype' => 'multichoice',
 688              'length' => '1',
 689              'stamp' => 'learn.open.ac.uk+061221143845+nohATp',
 690              'version' => 'learn.open.ac.uk+070131102906+bviJOZ',
 691              'hidden' => '0',
 692              'generalfeedback' => 'The correct answers are b and c.
 693          For further information about this question see Study Guide 7 SAQ 2.1(b and c)
 694          Misuse cases were discussed in SG4',
 695              'generalfeedbackformat' => '1',
 696              'timecreated' => '0',
 697              'timemodified' => '0',
 698              'createdby' => null,
 699              'modifiedby' => null,
 700              'unlimited' => null,
 701              'maxmark' => '5',
 702              'options' => (object) array(
 703                  'id' => '943',
 704                  'question' => '2855',
 705                  'layout' => '0',
 706                  'answers' => array(
 707                      8356 => (object) array(
 708                          'question' => '2855',
 709                          'answer' => 'Use cases.',
 710                          'fraction' => '-0.33333',
 711                          'feedback' => '',
 712                          'id' => 8356,
 713                      ),
 714                      8357 => (object) array(
 715                          'question' => '2855',
 716                          'answer' => 'Verb identification.',
 717                          'fraction' => '0.5',
 718                          'feedback' => '',
 719                          'id' => 8357,
 720                      ),
 721                      8358 => (object) array(
 722                          'question' => '2855',
 723                          'answer' => 'Misuse cases.',
 724                          'fraction' => '0.5',
 725                          'feedback' => '',
 726                          'id' => 8358,
 727                      ),
 728                      8359 => (object) array(
 729                          'question' => '2855',
 730                          'answer' => 'Adjective identification.',
 731                          'fraction' => '-0.33333',
 732                          'feedback' => '',
 733                          'id' => 8359,
 734                      ),
 735                      8360 => (object) array(
 736                          'question' => '2855',
 737                          'answer' => 'Noun identification.',
 738                          'fraction' => '-0.33333',
 739                          'feedback' => '',
 740                          'id' => 8360,
 741                      ),
 742                  ),
 743                  'single' => '0',
 744                  'shuffleanswers' => '0',
 745                  'correctfeedback' => 'Your answer is correct.',
 746                  'partiallycorrectfeedback' => 'Your answer is partially correct.',
 747                  'incorrectfeedback' => 'Your answer is incorrect.',
 748                  'answernumbering' => 'abc',
 749                  'showstandardinstruction' => 0,
 750              ),
 751              'hints' => false,
 752          );
 753          $qsession = (object) array(
 754              'id' => '30584',
 755              'attemptid' => '3237',
 756              'questionid' => '2855',
 757              'newest' => '72341',
 758              'newgraded' => '72341',
 759              'sumpenalty' => '0',
 760              'manualcomment' => '',
 761              'manualcommentformat' => '1',
 762              'flagged' => '1',
 763          );
 764          $qstates = array(
 765              72307 => (object) array(
 766                  'attempt' => '3237',
 767                  'question' => '2855',
 768                  'originalquestion' => '0',
 769                  'seq_number' => '0',
 770                  'answer' => '8356,8357,8358,8359,8360:',
 771                  'timestamp' => '1177006492',
 772                  'event' => '0',
 773                  'grade' => '0',
 774                  'raw_grade' => '0',
 775                  'penalty' => '0',
 776                  'id' => 72307,
 777              ),
 778              72318 => (object) array(
 779                  'attempt' => '3237',
 780                  'question' => '2855',
 781                  'originalquestion' => '0',
 782                  'seq_number' => '1',
 783                  'answer' => '8356,8357,8358,8359,8360:8357,8359',
 784                  'timestamp' => '1177007066',
 785                  'event' => '2',
 786                  'grade' => '0',
 787                  'raw_grade' => '0.83335',
 788                  'penalty' => '0',
 789                  'id' => 72318,
 790              ),
 791              72328 => (object) array(
 792                  'attempt' => '3237',
 793                  'question' => '2855',
 794                  'originalquestion' => '0',
 795                  'seq_number' => '2',
 796                  'answer' => '8356,8357,8358,8359,8360:8357,8359',
 797                  'timestamp' => '1177008016',
 798                  'event' => '2',
 799                  'grade' => '0',
 800                  'raw_grade' => '0.83335',
 801                  'penalty' => '0',
 802                  'id' => 72328,
 803              ),
 804              72341 => (object) array(
 805                  'attempt' => '3237',
 806                  'question' => '2855',
 807                  'originalquestion' => '0',
 808                  'seq_number' => '3',
 809                  'answer' => '8356,8357,8358,8359,8360:8357,8359',
 810                  'timestamp' => '1177008016',
 811                  'event' => '6',
 812                  'grade' => '0.83335',
 813                  'raw_grade' => '0.83335',
 814                  'penalty' => '0',
 815                  'id' => 72341,
 816              ),
 817          );
 818  
 819          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 820  
 821          $expectedqa = (object) array(
 822              'behaviour' => 'deferredfeedback',
 823              'questionid' => 2855,
 824              'variant' => 1,
 825              'maxmark' => 5,
 826              'minfraction' => 0,
 827              'maxfraction' => 1,
 828              'flagged' => 0,
 829              'questionsummary' => 'Which of the following techniques can identify non-functional requirements?',
 830              'rightanswer' => 'Verb identification.; Misuse cases.',
 831              'responsesummary' => 'Verb identification.; Adjective identification.',
 832              'timemodified' => 1177008016,
 833              'steps' => array(
 834                  0 => (object) array(
 835                      'sequencenumber' => 0,
 836                      'state' => 'todo',
 837                      'fraction' => null,
 838                      'timecreated' => 1177006492,
 839                      'userid' => 120555,
 840                      'data' => array('_order' => '8356,8357,8358,8359,8360'),
 841                  ),
 842                  1 => (object) array(
 843                      'sequencenumber' => 1,
 844                      'state' => 'complete',
 845                      'fraction' => null,
 846                      'timecreated' => 1177007066,
 847                      'userid' => 120555,
 848                      'data' => array('choice0' => 0, 'choice1' => 1, 'choice2' => 0, 'choice3' => 1, 'choice4' => 0),
 849                  ),
 850                  2 => (object) array(
 851                      'sequencenumber' => 2,
 852                      'state' => 'complete',
 853                      'fraction' => null,
 854                      'timecreated' => 1177008016,
 855                      'userid' => 120555,
 856                      'data' => array('choice0' => 0, 'choice1' => 1, 'choice2' => 0, 'choice3' => 1, 'choice4' => 0),
 857                  ),
 858                  3 => (object) array(
 859                      'sequencenumber' => 3,
 860                      'state' => 'gradedpartial',
 861                      'fraction' => 0.16667,
 862                      'timecreated' => 1177008016,
 863                      'userid' => 120555,
 864                      'data' => array('choice0' => 0, 'choice1' => 1, 'choice2' => 0, 'choice3' => 1, 'choice4' => 0, '-finish' => 1),
 865                  ),
 866              ),
 867          );
 868  
 869          $this->compare_qas($expectedqa, $qa);
 870      }
 871  
 872      public function test_multichoice_deferredfeedback_missing() {
 873          $quiz = (object) array(
 874              'id' => '8',
 875              'course' => '1095',
 876              'name' => 'End of course quiz',
 877              'intro' => 'Use this self-assessment quiz to judge your overall understanding. ',
 878              'introformat' => FORMAT_HTML,
 879              'questiondecimalpoints' => '-1',
 880              'showuserpicture' => '1',
 881              'showblocks' => '1',
 882              'timeopen' => '1150107600',
 883              'timeclose' => '0',
 884              'preferredbehaviour' => 'deferredfeedback',
 885              'attempts' => '0',
 886              'attemptonlast' => '0',
 887              'grademethod' => '1',
 888              'decimalpoints' => '2',
 889              'review' => '71760879',
 890              'questionsperpage' => '0',
 891              'shufflequestions' => '1',
 892              'shuffleanswers' => '1',
 893              'sumgrades' => '25',
 894              'grade' => '25',
 895              'timecreated' => '0',
 896              'timemodified' => '1150107596',
 897              'password' => '',
 898              'subnet' => '',
 899              'popup' => '0',
 900              'delay1' => '0',
 901              'delay2' => '0',
 902              'timelimit' => '0',
 903          );
 904          $attempt = (object) array(
 905              'id' => '17',
 906              'uniqueid' => '17',
 907              'quiz' => '8',
 908              'userid' => '26290',
 909              'attempt' => '1',
 910              'sumgrades' => '0',
 911              'timestart' => '1150203042',
 912              'timefinish' => '0',
 913              'timemodified' => '1150203042',
 914              'layout' => '93,76,82,75,87,74,90,94,73,77,81,95,79,92,88,80,91,86,72,83,84,89,85,78,71,0',
 915              'preview' => '1',
 916          );
 917          $question = (object) array(
 918              'id' => '72',
 919              'category' => '10',
 920              'parent' => '0',
 921              'name' => 'Q02',
 922              'questiontext' => 'Why were standards such an important driver in the growth of systems integration?',
 923              'questiontextformat' => '1',
 924              'defaultmark' => '1',
 925              'penalty' => '0.1',
 926              'qtype' => 'multichoice',
 927              'length' => '1',
 928              'stamp' => 'learn.open.ac.uk+060612113403+Fz0GGO',
 929              'version' => 'learn.open.ac.uk+060612160802+I6ctMQ',
 930              'hidden' => '0',
 931              'generalfeedback' => '',
 932              'generalfeedbackformat' => '1',
 933              'timecreated' => '0',
 934              'timemodified' => '0',
 935              'createdby' => null,
 936              'modifiedby' => null,
 937              'unlimited' => null,
 938              'maxmark' => '1',
 939              'options' => (object) array(
 940                  'id' => '44',
 941                  'question' => '72',
 942                  'layout' => '0',
 943                  'answers' => array(
 944                      200 => (object) array(
 945                          'question' => '72',
 946                          'answer' => 'Because they enable stored data and interfaces to be standardised.',
 947                          'fraction' => '1',
 948                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 949                          'id' => 200,
 950                      ),
 951                      201 => (object) array(
 952                          'question' => '72',
 953                          'answer' => 'Because they enable the members of an integration team to communicate together.',
 954                          'fraction' => '0',
 955                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 956                          'id' => 201,
 957                      ),
 958                      202 => (object) array(
 959                          'question' => '72',
 960                          'answer' => 'Because they produce good quality documentation.',
 961                          'fraction' => '0',
 962                          'feedback' => 'Standards enable the various components of an integrated system to communicate using well defined mechanisms and enable the components to have a standard view of stored data.',
 963                          'id' => 202,
 964                      ),
 965                  ),
 966                  'single' => '1',
 967                  'shuffleanswers' => '1',
 968                  'correctfeedback' => '',
 969                  'partiallycorrectfeedback' => '',
 970                  'incorrectfeedback' => '',
 971                  'answernumbering' => 'abc',
 972                  'showstandardinstruction' => 0,
 973              ),
 974              'hints' => false,
 975          );
 976  
 977          $qa = $this->updater->supply_missing_question_attempt($quiz, $attempt, $question);
 978  
 979          $expectedqa = (object) array(
 980              'behaviour' => 'deferredfeedback',
 981              'questionid' => 72,
 982              'variant' => 1,
 983              'maxmark' => 1,
 984              'minfraction' => 0,
 985              'maxfraction' => 1,
 986              'flagged' => 0,
 987              'questionsummary' => 'Why were standards such an important driver in the growth of systems integration?',
 988              'rightanswer' => 'Because they enable stored data and interfaces to be standardised.',
 989              'responsesummary' => '',
 990              'timemodified' => 1150203042,
 991              'steps' => array(
 992                  0 => (object) array(
 993                      'sequencenumber' => 0,
 994                      'state' => 'todo',
 995                      'fraction' => null,
 996                      'timecreated' => 1150203042,
 997                      'userid' => 26290,
 998                      'data' => array('_order' => '200,201,202'),
 999                  ),
1000              ),
1001          );
1002  
1003          $this->compare_qas($expectedqa, $qa);
1004      }
1005  
1006  public function test_multichoice_deferredfeedback_qsession140() {
1007          $quiz = (object) array(
1008              'id' => '58',
1009              'course' => '3420',
1010              'name' => 'Practice Quiz',
1011              'intro' => '',
1012              'introformat' => FORMAT_HTML,
1013              'questiondecimalpoints' => '-1',
1014              'showuserpicture' => '1',
1015              'showblocks' => '1',
1016              'timeopen' => '0',
1017              'timeclose' => '0',
1018              'optionflags' => '0',
1019              'attempts' => '0',
1020              'attemptonlast' => '0',
1021              'grademethod' => '3',
1022              'decimalpoints' => '2',
1023              'review' => '71760879',
1024              'questionsperpage' => '2',
1025              'shufflequestions' => '0',
1026              'shuffleanswers' => '1',
1027              'sumgrades' => '10',
1028              'grade' => '10',
1029              'timecreated' => '0',
1030              'timemodified' => '1200043605',
1031              'password' => '',
1032              'subnet' => '',
1033              'popup' => '0',
1034              'delay1' => '0',
1035              'delay2' => '0',
1036              'timelimit' => '0',
1037              'preferredbehaviour' => 'deferredfeedback',
1038          );
1039          $attempt = (object) array(
1040              'id' => '38',
1041              'uniqueid' => '38',
1042              'quiz' => '58',
1043              'userid' => '51335',
1044              'attempt' => '1',
1045              'sumgrades' => '5',
1046              'timestart' => '1198254245',
1047              'timefinish' => '1198254438',
1048              'timemodified' => '1198254352',
1049              'layout' => '178,179,180,181,182,183,184,185,189,187,0',
1050              'preview' => '0',
1051          );
1052          $question = (object) array(
1053              'id' => '179',
1054              'category' => '51',
1055              'parent' => '0',
1056              'name' => 'Question 2',
1057              'questiontext' => '<p>Where will the 19th International Biology Olympiad be held?</p>',
1058              'questiontextformat' => '1',
1059              'defaultmark' => '1',
1060              'penalty' => '0.1',
1061              'qtype' => 'multichoice',
1062              'length' => '1',
1063              'stamp' => 'openlearn.open.ac.uk+071210172238+HpCRWO',
1064              'version' => 'openlearn.open.ac.uk+071211115640+SZulvf',
1065              'hidden' => '0',
1066              'generalfeedback' => '<p></p>',
1067              'generalfeedbackformat' => '1',
1068              'timecreated' => '0',
1069              'timemodified' => '0',
1070              'createdby' => null,
1071              'modifiedby' => null,
1072              'unlimited' => null,
1073              'maxmark' => '1',
1074              'options' => (object) array(
1075                  'id' => '71',
1076                  'question' => '179',
1077                  'layout' => '0',
1078                  'answers' => array(
1079                      372 => (object) array(
1080                          'question' => '179',
1081                          'answer' => 'Mumbai, India',
1082                          'fraction' => '1',
1083                          'feedback' => '',
1084                          'id' => 372,
1085                      ),
1086                      373 => (object) array(
1087                          'question' => '179',
1088                          'answer' => 'Rome, Italy',
1089                          'fraction' => '-1',
1090                          'feedback' => '',
1091                          'id' => 373,
1092                      ),
1093                      374 => (object) array(
1094                          'question' => '179',
1095                          'answer' => 'Oslo, Norway',
1096                          'fraction' => '-1',
1097                          'feedback' => '',
1098                          'id' => 374,
1099                      ),
1100                      375 => (object) array(
1101                          'question' => '179',
1102                          'answer' => 'Tokyo, Japan',
1103                          'fraction' => '-1',
1104                          'feedback' => '',
1105                          'id' => 375,
1106                      ),
1107                  ),
1108                  'single' => '1',
1109                  'shuffleanswers' => '1',
1110                  'correctfeedback' => '',
1111                  'partiallycorrectfeedback' => '',
1112                  'incorrectfeedback' => '',
1113                  'answernumbering' => 'abc',
1114                  'showstandardinstruction' => 0,
1115              ),
1116              'hints' => false,
1117          );
1118          $qsession = (object) array(
1119              'id' => '140',
1120              'attemptid' => '38',
1121              'questionid' => '179',
1122              'newest' => '273',
1123              'newgraded' => '273',
1124              'sumpenalty' => '0.2',
1125              'manualcomment' => '',
1126              'manualcommentformat' => '1',
1127              'flagged' => '1',
1128          );
1129          $qstates = array(
1130              243 => (object) array(
1131                  'attempt' => '38',
1132                  'question' => '179',
1133                  'originalquestion' => '0',
1134                  'seq_number' => '0',
1135                  'answer' => '375,372,374,373:',
1136                  'timestamp' => '1198254245',
1137                  'event' => '0',
1138                  'grade' => '0',
1139                  'raw_grade' => '0',
1140                  'penalty' => '0',
1141                  'id' => 243,
1142              ),
1143              254 => (object) array(
1144                  'attempt' => '38',
1145                  'question' => '179',
1146                  'originalquestion' => '0',
1147                  'seq_number' => '1',
1148                  'answer' => '375,372,374,373:375',
1149                  'timestamp' => '1198254261',
1150                  'event' => '3',
1151                  'grade' => '0',
1152                  'raw_grade' => '0',
1153                  'penalty' => '0.1',
1154                  'id' => 254,
1155              ),
1156              273 => (object) array(
1157                  'attempt' => '38',
1158                  'question' => '179',
1159                  'originalquestion' => '0',
1160                  'seq_number' => '2',
1161                  'answer' => '375,372,374,373:375',
1162                  'timestamp' => '1198254261',
1163                  'event' => '6',
1164                  'grade' => '0',
1165                  'raw_grade' => '0',
1166                  'penalty' => '0.1',
1167                  'id' => 273,
1168              ),
1169          );
1170  
1171          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1172  
1173          $expectedqa = (object) array(
1174              'behaviour' => 'deferredfeedback',
1175              'questionid' => 179,
1176              'variant' => 1,
1177              'maxmark' => 1,
1178              'minfraction' => 0,
1179              'maxfraction' => 1,
1180              'flagged' => 0,
1181              'questionsummary' => 'Where will the 19th International Biology Olympiad be held?',
1182              'rightanswer' => 'Mumbai, India',
1183              'responsesummary' => 'Tokyo, Japan',
1184              'timemodified' => 1198254261,
1185              'steps' => array(
1186                  0 => (object) array(
1187                      'sequencenumber' => 0,
1188                      'state' => 'todo',
1189                      'fraction' => null,
1190                      'timecreated' => 1198254245,
1191                      'userid' => 51335,
1192                      'data' => array('_order' => '375,372,374,373'),
1193                  ),
1194                  1 => (object) array(
1195                      'sequencenumber' => 1,
1196                      'state' => 'gradedwrong',
1197                      'fraction' => 0,
1198                      'timecreated' => 1198254261,
1199                      'userid' => 51335,
1200                      'data' => array('answer' => '0', '-finish' => '1'),
1201                  ),
1202              ),
1203          );
1204  
1205          $this->compare_qas($expectedqa, $qa);
1206      }
1207  
1208      public function test_multichoice_deferredfeedback_qsession2018195() {
1209          $quiz = (object) array(
1210              'id' => '1832',
1211              'course' => '4912',
1212              'name' => 'Unit 12 IL & ICT review quiz',
1213              'intro' => '<p>This quiz has been developed to help you review your skills development in information literacy and ICT and to gather feedback on the use of the skills activities within K315 and within the Social Work degree Practice Learning courses.</p>
1214          <p>We would welcome your input (allow 10-15 minutes). The data you provide will be anonymised and used for research purposes only. This project is administered under the OU’s general data protection policy guidelines, which can be seen here: <a href="http://www3.open.ac.uk/our-student-policies/pdf/dataprotection.pdf">http://www3.open.ac.uk/our-student-policies/pdf/dataprotection.pdf</a></p>',
1215              'introformat' => FORMAT_HTML,
1216              'questiondecimalpoints' => '-1',
1217              'showuserpicture' => '1',
1218              'showblocks' => '1',
1219              'timeopen' => '0',
1220              'timeclose' => '0',
1221              'optionflags' => '0',
1222              'penaltyscheme' => '1',
1223              'attempts' => '0',
1224              'attemptonlast' => '0',
1225              'grademethod' => '1',
1226              'decimalpoints' => '2',
1227              'review' => '71565312',
1228              'questionsperpage' => '2',
1229              'shufflequestions' => '0',
1230              'shuffleanswers' => '0',
1231              'sumgrades' => '0',
1232              'grade' => '0',
1233              'timecreated' => '0',
1234              'timemodified' => '1232636874',
1235              'password' => '',
1236              'subnet' => '',
1237              'popup' => '0',
1238              'delay1' => '0',
1239              'delay2' => '0',
1240              'timelimit' => '0',
1241              'preferredbehaviour' => 'deferredfeedback',
1242          );
1243          $attempt = (object) array(
1244              'id' => '174744',
1245              'uniqueid' => '174745',
1246              'quiz' => '1832',
1247              'userid' => '181806',
1248              'attempt' => '1',
1249              'sumgrades' => '0',
1250              'timestart' => '1249488674',
1251              'timefinish' => '1250702880',
1252              'timemodified' => '1249488674',
1253              'layout' => '26132,26128,0,26143,26140,0,26144,26141,0,26145,26142,0,26126,26127,0,26134,26135,0,26131,26133,0,26130,26129,0,26136,26137,0,26139,26138,0',
1254              'preview' => '0',
1255          );
1256          $question = (object) array(
1257              'id' => '26132',
1258              'category' => '2506',
1259              'parent' => '0',
1260              'name' => '01 most useful',
1261              'questiontext' => 'Which was the most useful K315 information literacy or ICT activity?',
1262              'questiontextformat' => '1',
1263              'defaultmark' => '1',
1264              'penalty' => '0.1',
1265              'qtype' => 'multichoice',
1266              'length' => '1',
1267              'stamp' => 'learn.open.ac.uk+080529101041+d4XuNI',
1268              'version' => 'learn.open.ac.uk+100725192556+KIetVC',
1269              'hidden' => '0',
1270              'generalfeedback' => '',
1271              'generalfeedbackformat' => '1',
1272              'timecreated' => '1212055841',
1273              'timemodified' => '1280085956',
1274              'createdby' => '28856',
1275              'modifiedby' => '25299',
1276              'unlimited' => '0',
1277              'maxmark' => '0',
1278              'options' => (object) array(
1279                  'id' => '11628',
1280                  'question' => '26132',
1281                  'layout' => '0',
1282                  'answers' => array(
1283                      77406 => (object) array(
1284                          'question' => '26132',
1285                          'answer' => 'Introduction to & evaluation of MyStuff (Course Introduction)',
1286                          'fraction' => '0',
1287                          'feedback' => '',
1288                          'id' => 77406,
1289                      ),
1290                      77407 => (object) array(
1291                          'question' => '26132',
1292                          'answer' => 'Values Exchange case studies',
1293                          'fraction' => '1',
1294                          'feedback' => '',
1295                          'id' => 77407,
1296                      ),
1297                      77408 => (object) array(
1298                          'question' => '26132',
1299                          'answer' => 'Secure accommodation orders (Unit 2, Activity 3.3)',
1300                          'fraction' => '0',
1301                          'feedback' => '',
1302                          'id' => 77408,
1303                      ),
1304                      77409 => (object) array(
1305                          'question' => '26132',
1306                          'answer' => 'Advanced search tools (Unit 3, Activity 1.3)',
1307                          'fraction' => '0',
1308                          'feedback' => '',
1309                          'id' => 77409,
1310                      ),
1311                      77410 => (object) array(
1312                          'question' => '26132',
1313                          'answer' => 'Different types of information (Unit 7, Activity 1.2)',
1314                          'fraction' => '0',
1315                          'feedback' => '',
1316                          'id' => 77410,
1317                      ),
1318                      77411 => (object) array(
1319                          'question' => '26132',
1320                          'answer' => 'Informing your practice with empirical evidence (Unit 8, Activity 3.1)',
1321                          'fraction' => '0',
1322                          'feedback' => '',
1323                          'id' => 77411,
1324                      ),
1325                      77412 => (object) array(
1326                          'question' => '26132',
1327                          'answer' => 'Reviewing and saving your work (Unit 12, Activity 2.2)',
1328                          'fraction' => '0',
1329                          'feedback' => '',
1330                          'id' => 77412,
1331                      ),
1332                  ),
1333                  'single' => '1',
1334                  'shuffleanswers' => '0',
1335                  'correctfeedback' => '',
1336                  'partiallycorrectfeedback' => '',
1337                  'incorrectfeedback' => '',
1338                  'answernumbering' => 'abc',
1339                  'showstandardinstruction' => 0,
1340              ),
1341              'hints' => false,
1342          );
1343          $qsession = (object) array(
1344              'id' => '2018195',
1345              'attemptid' => '174745',
1346              'questionid' => '26132',
1347              'newest' => '5162301',
1348              'newgraded' => '5162301',
1349              'sumpenalty' => '0',
1350              'manualcomment' => '',
1351              'manualcommentformat' => '1',
1352              'flagged' => '1',
1353          );
1354          $qstates = array(
1355              5107187 => (object) array(
1356                  'attempt' => '174745',
1357                  'question' => '26132',
1358                  'originalquestion' => '0',
1359                  'seq_number' => '0',
1360                  'answer' => '77406,77407,77408,77409,77410,77411,77412:',
1361                  'timestamp' => '1249488674',
1362                  'event' => '0',
1363                  'grade' => '0',
1364                  'raw_grade' => '0',
1365                  'penalty' => '0',
1366                  'id' => 5107187,
1367              ),
1368              5107188 => (object) array(
1369                  'attempt' => '174745',
1370                  'question' => '26132',
1371                  'originalquestion' => '0',
1372                  'seq_number' => '0',
1373                  'answer' => '',
1374                  'timestamp' => '1249488674',
1375                  'event' => '0',
1376                  'grade' => '0',
1377                  'raw_grade' => '0',
1378                  'penalty' => '0',
1379                  'id' => 5107188,
1380              ),
1381              5107190 => (object) array(
1382                  'attempt' => '174745',
1383                  'question' => '26132',
1384                  'originalquestion' => '0',
1385                  'seq_number' => '1',
1386                  'answer' => '77406,77407,77408,77409,77410,77411,77412:77407',
1387                  'timestamp' => '1249488763',
1388                  'event' => '2',
1389                  'grade' => '0',
1390                  'raw_grade' => '0',
1391                  'penalty' => '0',
1392                  'id' => 5107190,
1393              ),
1394              5162301 => (object) array(
1395                  'attempt' => '174745',
1396                  'question' => '26132',
1397                  'originalquestion' => '0',
1398                  'seq_number' => '2',
1399                  'answer' => '77406,77407,77408,77409,77410,77411,77412:77407',
1400                  'timestamp' => '1249488763',
1401                  'event' => '6',
1402                  'grade' => '0',
1403                  'raw_grade' => '0',
1404                  'penalty' => '0',
1405                  'id' => 5162301,
1406              ),
1407          );
1408  
1409          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1410  
1411          $expectedqa = (object) array(
1412              'behaviour' => 'deferredfeedback',
1413              'questionid' => 26132,
1414              'variant' => 1,
1415              'maxmark' => 0,
1416              'minfraction' => 0,
1417              'maxfraction' => 1,
1418              'flagged' => 0,
1419              'questionsummary' => 'Which was the most useful K315 information literacy or ICT activity?',
1420              'rightanswer' => 'Values Exchange case studies',
1421              'responsesummary' => 'Values Exchange case studies',
1422              'timemodified' => 1249488763,
1423              'steps' => array(
1424                  0 => (object) array(
1425                      'sequencenumber' => 0,
1426                      'state' => 'todo',
1427                      'fraction' => null,
1428                      'timecreated' => 1249488674,
1429                      'userid' => 181806,
1430                      'data' => array('_order' => '77406,77407,77408,77409,77410,77411,77412'),
1431                  ),
1432                  1 => (object) array(
1433                      'sequencenumber' => 1,
1434                      'state' => 'complete',
1435                      'fraction' => null,
1436                      'timecreated' => 1249488763,
1437                      'userid' => 181806,
1438                      'data' => array('answer' => '1'),
1439                  ),
1440                  2 => (object) array(
1441                      'sequencenumber' => 2,
1442                      'state' => 'finished',
1443                      'fraction' => null,
1444                      'timecreated' => 1249488763,
1445                      'userid' => 181806,
1446                      'data' => array('answer' => '1', '-finish' => '1'),
1447                  ),
1448              ),
1449          );
1450  
1451          $this->compare_qas($expectedqa, $qa);
1452      }
1453  
1454      public function test_multichoice_deferredfeedback_qsession2653368() {
1455          $quiz = (object) array(
1456              'id' => '3273',
1457              'course' => '5862',
1458              'name' => 'Assessing information sources',
1459              'intro' => 'Assessing information sources - literature review table',
1460              'introformat' => FORMAT_HTML,
1461              'questiondecimalpoints' => '-1',
1462              'showuserpicture' => '1',
1463              'showblocks' => '1',
1464              'timeopen' => '0',
1465              'timeclose' => '0',
1466              'optionflags' => '0',
1467              'penaltyscheme' => '1',
1468              'attempts' => '0',
1469              'attemptonlast' => '1',
1470              'grademethod' => '4',
1471              'decimalpoints' => '2',
1472              'review' => '71727591',
1473              'questionsperpage' => '0',
1474              'shufflequestions' => '0',
1475              'shuffleanswers' => '0',
1476              'questions' => '60135,60136,60137,0',
1477              'sumgrades' => '3',
1478              'grade' => '10',
1479              'timecreated' => '0',
1480              'timemodified' => '1223992271',
1481              'password' => '',
1482              'subnet' => '',
1483              'popup' => '0',
1484              'delay1' => '0',
1485              'delay2' => '0',
1486              'timelimit' => '0',
1487              'preferredbehaviour' => 'deferredfeedback',
1488          );
1489          $attempt = (object) array(
1490              'id' => '229025',
1491              'uniqueid' => '229026',
1492              'quiz' => '3273',
1493              'userid' => '597153',
1494              'attempt' => '4',
1495              'sumgrades' => '0.999999',
1496              'timestart' => '1258492857',
1497              'timefinish' => '1258492862',
1498              'timemodified' => '1258492857',
1499              'layout' => '60135,60136,60137,0',
1500              'preview' => '0',
1501          );
1502          $question = (object) array(
1503              'id' => '60137',
1504              'category' => '6026',
1505              'parent' => '0',
1506              'name' => 'Assessing information sources - No. 3',
1507              'questiontext' => 'For source 3, the \'Loose Change\' video, select the statements to indicate \'yes\':',
1508              'questiontextformat' => '1',
1509              'defaultmark' => '1',
1510              'penalty' => '0.1',
1511              'qtype' => 'multichoice',
1512              'length' => '1',
1513              'stamp' => 'learn.open.ac.uk+080811153454+BMEq1t',
1514              'version' => 'learn.open.ac.uk+081010072800+oSu1g3',
1515              'hidden' => '0',
1516              'generalfeedback' => '',
1517              'generalfeedbackformat' => '1',
1518              'timecreated' => '1218468894',
1519              'timemodified' => '1223623680',
1520              'createdby' => '26409',
1521              'modifiedby' => '351133',
1522              'unlimited' => null,
1523              'maxmark' => '1',
1524              'options' => (object) array(
1525                  'id' => '23896',
1526                  'question' => '60137',
1527                  'layout' => '0',
1528                  'answers' => array(
1529                      181821 => (object) array(
1530                          'question' => '60137',
1531                          'answer' => 'Would you regard this source as objective?',
1532                          'fraction' => '0.142857',
1533                          'feedback' => '',
1534                          'id' => 181821,
1535                      ),
1536                      181822 => (object) array(
1537                          'question' => '60137',
1538                          'answer' => 'Does the source provide references?',
1539                          'fraction' => '0.142857',
1540                          'feedback' => '',
1541                          'id' => 181822,
1542                      ),
1543                      181823 => (object) array(
1544                          'question' => '60137',
1545                          'answer' => 'Are all viewpoints considered?',
1546                          'fraction' => '0.142857',
1547                          'feedback' => '',
1548                          'id' => 181823,
1549                      ),
1550                      181824 => (object) array(
1551                          'question' => '60137',
1552                          'answer' => 'Are quotations placed in their full context?',
1553                          'fraction' => '0.142857',
1554                          'feedback' => '',
1555                          'id' => 181824,
1556                      ),
1557                      181825 => (object) array(
1558                          'question' => '60137',
1559                          'answer' => 'Does the source include conclusions based on evidence?',
1560                          'fraction' => '0.142857',
1561                          'feedback' => '',
1562                          'id' => 181825,
1563                      ),
1564                      181826 => (object) array(
1565                          'question' => '60137',
1566                          'answer' => 'Would you trust this source?',
1567                          'fraction' => '0.142857',
1568                          'feedback' => '',
1569                          'id' => 181826,
1570                      ),
1571                      181827 => (object) array(
1572                          'question' => '60137',
1573                          'answer' => 'Has it been peer-reviewed?',
1574                          'fraction' => '0.142857',
1575                          'feedback' => '',
1576                          'id' => 181827,
1577                      ),
1578                  ),
1579                  'single' => '0',
1580                  'shuffleanswers' => '0',
1581                  'correctfeedback' => 'This is a very polemical source which clearly has a standpoint. Whether or not you would use this material would be largely dependent on your reseach question. If you did use it, you would need to be clear that you would require academic sources that would support the claims being made.<br />',
1582                  'partiallycorrectfeedback' => 'This is a very polemical source which clearly has a standpoint. Whether or not you would use this material would be largely dependent on your reseach question. If you did use it, you would need to be clear that you would require academic sources that would support the claims being made.<br /><br />',
1583                  'incorrectfeedback' => 'This is a very polemical source which clearly has a standpoint. Whether or not you would use this material would be largely dependent on your reseach question. If you did use it, you would need to be clear that you would require academic sources that would support the claims being made.<br /><br />',
1584                  'answernumbering' => 'abc',
1585                  'showstandardinstruction' => 0,
1586              ),
1587              'hints' => false,
1588          );
1589          $qsession = (object) array(
1590              'id' => '2653368',
1591              'attemptid' => '229026',
1592              'questionid' => '60137',
1593              'newest' => '6676055',
1594              'newgraded' => '6676055',
1595              'sumpenalty' => '0.1',
1596              'manualcomment' => '',
1597              'manualcommentformat' => '1',
1598              'flagged' => '1',
1599          );
1600          $qstates = array(
1601              6676031 => (object) array(
1602                  'attempt' => '229026',
1603                  'question' => '60137',
1604                  'originalquestion' => '0',
1605                  'seq_number' => '0',
1606                  'answer' => '181821,181822,181823,181824,181825,181826,181827:181821,181822,181823,181824,181825,181826',
1607                  'timestamp' => '1258492857',
1608                  'event' => '0',
1609                  'grade' => '0',
1610                  'raw_grade' => '0.857142',
1611                  'penalty' => '0',
1612                  'id' => 6676031,
1613              ),
1614              6676034 => (object) array(
1615                  'attempt' => '229026',
1616                  'question' => '60137',
1617                  'originalquestion' => '0',
1618                  'seq_number' => '1',
1619                  'answer' => '181821,181822,181823,181824,181825,181826,181827:',
1620                  'timestamp' => '1258492857',
1621                  'event' => '0',
1622                  'grade' => '0',
1623                  'raw_grade' => '0',
1624                  'penalty' => '0.1',
1625                  'id' => 6676034,
1626              ),
1627              6676055 => (object) array(
1628                  'attempt' => '229026',
1629                  'question' => '60137',
1630                  'originalquestion' => '0',
1631                  'seq_number' => '2',
1632                  'answer' => '181821,181822,181823,181824,181825,181826,181827:',
1633                  'timestamp' => '1258492857',
1634                  'event' => '6',
1635                  'grade' => '0',
1636                  'raw_grade' => '0',
1637                  'penalty' => '0.1',
1638                  'id' => 6676055,
1639              ),
1640          );
1641  
1642          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1643  
1644          $expectedqa = (object) array(
1645              'behaviour' => 'deferredfeedback',
1646              'questionid' => 60137,
1647              'variant' => 1,
1648              'maxmark' => 1,
1649              'minfraction' => 0,
1650              'maxfraction' => 1,
1651              'flagged' => 0,
1652              'questionsummary' => "For source 3, the 'Loose Change' video, select the statements to indicate 'yes':",
1653              'rightanswer' => 'Would you regard this source as objective?; Does the source provide references?; Are all viewpoints considered?; Are quotations placed in their full context?; Does the source include conclusions based on evidence?; Would you trust this source?; Has it been peer-reviewed?',
1654              'responsesummary' => 'Would you regard this source as objective?; Does the source provide references?; Are all viewpoints considered?; Are quotations placed in their full context?; Does the source include conclusions based on evidence?; Would you trust this source?',
1655              'timemodified' => 1258492857,
1656              'steps' => array(
1657                  0 => (object) array(
1658                      'sequencenumber' => 0,
1659                      'state' => 'todo',
1660                      'fraction' => null,
1661                      'timecreated' => 1258492857,
1662                      'userid' => 597153,
1663                      'data' => array('_order' => '181821,181822,181823,181824,181825,181826,181827'),
1664                  ),
1665                  1 => (object) array(
1666                      'sequencenumber' => 1,
1667                      'state' => 'gradedwrong',
1668                      'fraction' => 0,
1669                      'timecreated' => 1258492857,
1670                      'userid' => 597153,
1671                      'data' => array('choice0' => 0, 'choice1' => 0, 'choice2' => 0, 'choice3' => 0, 'choice4' => 0, 'choice5' => 0, 'choice6' => 0, '-finish' => '1'),
1672                  ),
1673              ),
1674          );
1675  
1676          $this->compare_qas($expectedqa, $qa);
1677      }
1678  
1679      public function test_multichoice_deferredfeedback_qsession3131() {
1680          $quiz = (object) array(
1681              'id' => '10',
1682              'course' => '608',
1683              'name' => 'TMA 01, Part 1 (Activity 12)',
1684              'intro' => '<p>Activity 12 is a multiple-choice assessment quiz. It is Part 1 of TMA 01 and contributes 20 per cent of the marks for the TMA. It invites you to check your understandings of the topics with which you engaged in Activities 6–11.</p>
1685  
1686          <p>Activity 12 is distinctive in that you are welcome to try as much as you want at any one time and to try as often as you wish. However, you have to get <strong>full marks</strong> on it in order to proceed to the second part of TMA 01, Activity 15.</p>
1687  
1688          <p>There are 30 questions, which can be attempted in any order. When you are ready to attempt a question, choose your answer and then \'Submit\'. You will get feedback. If you need to try again, follow the same process. When you are satisfied with your answer to one question, go on to another. Remember to choose \'Submit\' for each answer that you want to be saved.</p>
1689  
1690          <p>You do not have to do the questions all at one sitting: at any time you can choose \'Save without submitting\'. This saves the current state of all questions so you can come back later to do some more.</p>
1691  
1692          <p>When you are satisfied with your answers to all 30 questions, choose \'Submit all and finish\'. This marks all questions, closes the current quiz attempt and gives the PCAP team formal notification that you have successfully completed this part of the TMA. <strong>Should you inadvertently choose this option you will need to start from scratch when you next attempt the task.</strong></p>',
1693              'introformat' => FORMAT_HTML,
1694              'questiondecimalpoints' => '-1',
1695              'showuserpicture' => '1',
1696              'showblocks' => '1',
1697              'timeopen' => '0',
1698              'timeclose' => '0',
1699              'optionflags' => '0',
1700              'attempts' => '0',
1701              'attemptonlast' => '0',
1702              'grademethod' => '2',
1703              'decimalpoints' => '2',
1704              'review' => '71760879',
1705              'questionsperpage' => '1',
1706              'shufflequestions' => '0',
1707              'shuffleanswers' => '1',
1708              'sumgrades' => '30',
1709              'grade' => '10',
1710              'timecreated' => '0',
1711              'timemodified' => '1266247621',
1712              'password' => '',
1713              'subnet' => '',
1714              'popup' => '0',
1715              'delay1' => '0',
1716              'delay2' => '0',
1717              'timelimit' => '0',
1718              'preferredbehaviour' => 'deferredfeedback',
1719          );
1720          $attempt = (object) array(
1721              'id' => '302',
1722              'uniqueid' => '302',
1723              'quiz' => '10',
1724              'userid' => '63173',
1725              'attempt' => '1',
1726              'sumgrades' => '30',
1727              'timestart' => '1163428543',
1728              'timefinish' => '1166546613',
1729              'timemodified' => '1166546472',
1730              'layout' => '161,0,160,0,162,0,163,0,164,0,165,0,166,0,190,0,191,0,192,0,193,0,194,0,195,0,196,0,197,0,198,0,168,0,169,0,170,0,171,0,172,0,173,0,174,0,175,0,176,0,177,0,178,0,179,0,180,0,181,0',
1731              'preview' => '0',
1732          );
1733          $question = (object) array(
1734              'id' => '163',
1735              'category' => '15',
1736              'parent' => '0',
1737              'name' => 'Question 04',
1738              'questiontext' => 'Can we have a \'realist\' or objective social science?',
1739              'questiontextformat' => '1',
1740              'defaultmark' => '1',
1741              'penalty' => '1',
1742              'qtype' => 'multichoice',
1743              'length' => '1',
1744              'stamp' => 'learn.open.ac.uk+060614160624+gkAYii',
1745              'version' => 'learn.open.ac.uk+060614160624+LYm8Rl',
1746              'hidden' => '0',
1747              'generalfeedback' => '',
1748              'generalfeedbackformat' => '1',
1749              'timecreated' => '0',
1750              'timemodified' => '0',
1751              'createdby' => null,
1752              'modifiedby' => null,
1753              'unlimited' => null,
1754              'maxmark' => '1',
1755              'options' => (object) array(
1756                  'id' => '117',
1757                  'question' => '163',
1758                  'layout' => '0',
1759                  'answers' => array(
1760                      456 => (object) array(
1761                          'question' => '163',
1762                          'answer' => 'No',
1763                          'fraction' => '0',
1764                          'feedback' => 'This is a common position but it does overlook areas in which it is possible to observe, tally and describe in pretty objective (low-inference) ways. Much social geography is of this sort.',
1765                          'id' => 456,
1766                      ),
1767                      457 => (object) array(
1768                          'question' => '163',
1769                          'answer' => 'Yes',
1770                          'fraction' => '0',
1771                          'feedback' => 'A great deal of social science is to do with making sense of subjective phenomena. We might expect social scientists to be honest and careful but, where subjective phenomena are concerned there can be no objective truth. However, there are areas in which it is possible to observe, tally and describe in pretty objective (low-inference) ways. Much social geography is of this sort.',
1772                          'id' => 457,
1773                      ),
1774                      458 => (object) array(
1775                          'question' => '163',
1776                          'answer' => 'Sometimes',
1777                          'fraction' => '1',
1778                          'feedback' => 'This is a judicious response to two positions, each of which has strengths but neither of which covers the range of social science practices.',
1779                          'id' => 458,
1780                      ),
1781                  ),
1782                  'single' => '1',
1783                  'shuffleanswers' => '0',
1784                  'correctfeedback' => '',
1785                  'partiallycorrectfeedback' => '',
1786                  'incorrectfeedback' => '',
1787                  'answernumbering' => 'abc',
1788                  'showstandardinstruction' => 0,
1789              ),
1790              'hints' => false,
1791          );
1792          $qsession = (object) array(
1793              'id' => '3131',
1794              'attemptid' => '302',
1795              'questionid' => '163',
1796              'newest' => '14715',
1797              'newgraded' => '14715',
1798              'sumpenalty' => '0',
1799              'manualcomment' => '',
1800              'manualcommentformat' => '1',
1801              'flagged' => '1',
1802          );
1803          $qstates = array(
1804              5922 => (object) array(
1805                  'attempt' => '302',
1806                  'question' => '163',
1807                  'originalquestion' => '0',
1808                  'seq_number' => '0',
1809                  'answer' => '456,457,458:',
1810                  'timestamp' => '1163428543',
1811                  'event' => '0',
1812                  'grade' => '0',
1813                  'raw_grade' => '0',
1814                  'penalty' => '0',
1815                  'id' => 5922,
1816              ),
1817              5941 => (object) array(
1818                  'attempt' => '302',
1819                  'question' => '163',
1820                  'originalquestion' => '0',
1821                  'seq_number' => '1',
1822                  'answer' => '456,457,458:',
1823                  'timestamp' => '1163428576',
1824                  'event' => '2',
1825                  'grade' => '0',
1826                  'raw_grade' => '0',
1827                  'penalty' => '1',
1828                  'id' => 5941,
1829              ),
1830              5942 => (object) array(
1831                  'attempt' => '302',
1832                  'question' => '163',
1833                  'originalquestion' => '0',
1834                  'seq_number' => '2',
1835                  'answer' => '456,457,458:',
1836                  'timestamp' => '1163428577',
1837                  'event' => '2',
1838                  'grade' => '0',
1839                  'raw_grade' => '0',
1840                  'penalty' => '1',
1841                  'id' => 5942,
1842              ),
1843              14713 => (object) array(
1844                  'attempt' => '302',
1845                  'question' => '163',
1846                  'originalquestion' => '0',
1847                  'seq_number' => '3',
1848                  'answer' => '456,457,458:456',
1849                  'timestamp' => '1165355190',
1850                  'event' => '3',
1851                  'grade' => '0',
1852                  'raw_grade' => '0',
1853                  'penalty' => '1',
1854                  'id' => 14713,
1855              ),
1856              14715 => (object) array(
1857                  'attempt' => '302',
1858                  'question' => '163',
1859                  'originalquestion' => '0',
1860                  'seq_number' => '4',
1861                  'answer' => '456,457,458:458',
1862                  'timestamp' => '1165355352',
1863                  'event' => '3',
1864                  'grade' => '1',
1865                  'raw_grade' => '1',
1866                  'penalty' => '1',
1867                  'id' => 14715,
1868              ),
1869          );
1870  
1871          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
1872  
1873          $expectedqa = (object) array(
1874              'behaviour' => 'deferredfeedback',
1875              'questionid' => 163,
1876              'variant' => 1,
1877              'maxmark' => 1,
1878              'minfraction' => 0,
1879              'maxfraction' => 1,
1880              'flagged' => 0,
1881              'questionsummary' => 'Can we have a \'realist\' or objective social science?',
1882              'rightanswer' => 'Sometimes',
1883              'responsesummary' => 'Sometimes',
1884              'timemodified' => 1165355352,
1885              'steps' => array(
1886                  0 => (object) array(
1887                      'sequencenumber' => 0,
1888                      'state' => 'todo',
1889                      'fraction' => null,
1890                      'timecreated' => 1163428543,
1891                      'userid' => 63173,
1892                      'data' => array('_order' => '456,457,458'),
1893                  ),
1894                  1 => (object) array(
1895                      'sequencenumber' => 1,
1896                      'state' => 'todo',
1897                      'fraction' => null,
1898                      'timecreated' => 1163428576,
1899                      'userid' => 63173,
1900                      'data' => array(),
1901                  ),
1902                  2 => (object) array(
1903                      'sequencenumber' => 2,
1904                      'state' => 'todo',
1905                      'fraction' => null,
1906                      'timecreated' => 1163428577,
1907                      'userid' => 63173,
1908                      'data' => array(),
1909                  ),
1910                  3 => (object) array(
1911                      'sequencenumber' => 3,
1912                      'state' => 'gradedright',
1913                      'fraction' => 1,
1914                      'timecreated' => 1165355352,
1915                      'userid' => 63173,
1916                      'data' => array('answer' => '2', '-finish' => '1'),
1917                  ),
1918              ),
1919          );
1920  
1921          $this->compare_qas($expectedqa, $qa);
1922      }
1923  
1924      public function test_multichoice_deferredfeedback_qsession4307870 () {
1925          $quiz = (object) array(
1926              'id' => '4070',
1927              'course' => '5139',
1928              'name' => 'Reading practice: Session 16',
1929              'intro' => '',
1930              'introformat' => FORMAT_HTML,
1931              'questiondecimalpoints' => '-1',
1932              'showuserpicture' => '1',
1933              'showblocks' => '1',
1934              'timeopen' => '0',
1935              'timeclose' => '0',
1936              'optionflags' => '0',
1937              'penaltyscheme' => '1',
1938              'attempts' => '0',
1939              'attemptonlast' => '0',
1940              'grademethod' => '1',
1941              'decimalpoints' => '0',
1942              'review' => '71727591',
1943              'questionsperpage' => '1',
1944              'shufflequestions' => '0',
1945              'shuffleanswers' => '1',
1946              'sumgrades' => '8',
1947              'grade' => '8',
1948              'timecreated' => '0',
1949              'timemodified' => '1265136533',
1950              'password' => '',
1951              'subnet' => '',
1952              'popup' => '0',
1953              'delay1' => '0',
1954              'delay2' => '0',
1955              'timelimit' => '0',
1956              'showscores' => '1',
1957              'preferredbehaviour' => 'deferredfeedback',
1958          );
1959          $attempt = (object) array(
1960              'id' => '428769',
1961              'uniqueid' => '428770',
1962              'quiz' => '4070',
1963              'userid' => '605575',
1964              'attempt' => '3',
1965              'sumgrades' => '7',
1966              'timestart' => '1275088684',
1967              'timefinish' => '1275089588',
1968              'timemodified' => '1275089451',
1969              'layout' => '89002,0,89040,0,89042,0,89043,0,89044,0,89045,0,89046,0,89047,0',
1970              'preview' => '0',
1971          );
1972          $question = (object) array(
1973              'id' => '89040',
1974              'category' => '6016',
1975              'parent' => '0',
1976              'name' => 'R2S16',
1977              'questiontext' => '<p>Read the text below and then answer the question based on the information given.</p><p><span lang="ZH-CN">我大哥没有我二哥高,我比我二哥高。</span></p><p>Who is the tallest?</p>',
1978              'questiontextformat' => '1',
1979              'defaultmark' => '1',
1980              'penalty' => '0.33',
1981              'qtype' => 'multichoice',
1982              'length' => '1',
1983              'stamp' => 'learn.open.ac.uk+100204101142+Bygd63',
1984              'version' => 'learn.open.ac.uk+100204101142+exBG6F',
1985              'hidden' => '0',
1986              'generalfeedback' => '',
1987              'generalfeedbackformat' => '1',
1988              'timecreated' => '1265278302',
1989              'timemodified' => '1265278302',
1990              'createdby' => '532546',
1991              'modifiedby' => '532546',
1992              'unlimited' => '0',
1993              'maxmark' => '1',
1994              'options' => (object) array(
1995                  'id' => '33730',
1996                  'question' => '89040',
1997                  'layout' => '0',
1998                  'answers' => array(
1999                      300601 => (object) array(
2000                          'question' => '89040',
2001                          'answer' => '我。',
2002                          'fraction' => '1',
2003                          'feedback' => '',
2004                          'id' => 300601,
2005                      ),
2006                      300602 => (object) array(
2007                          'question' => '89040',
2008                          'answer' => '我大哥。',
2009                          'fraction' => '0',
2010                          'feedback' => '',
2011                          'id' => 300602,
2012                      ),
2013                      300603 => (object) array(
2014                          'question' => '89040',
2015                          'answer' => '我二哥。',
2016                          'fraction' => '0',
2017                          'feedback' => '',
2018                          'id' => 300603,
2019                      ),
2020                  ),
2021                  'single' => '1',
2022                  'shuffleanswers' => '1',
2023                  'correctfeedback' => '',
2024                  'partiallycorrectfeedback' => '',
2025                  'incorrectfeedback' => '',
2026                  'answernumbering' => 'none',
2027                  'showstandardinstruction' => 0,
2028              ),
2029              'hints' => false,
2030          );
2031          $qsession = (object) array(
2032              'id' => '4307870',
2033              'attemptid' => '428770',
2034              'questionid' => '89040',
2035              'newest' => '11002905',
2036              'newgraded' => '11002905',
2037              'sumpenalty' => '0.33',
2038              'manualcomment' => '',
2039              'manualcommentformat' => '1',
2040              'flagged' => '1',
2041          );
2042          $qstates = array(
2043              11002780 => (object) array(
2044                  'attempt' => '428770',
2045                  'question' => '89040',
2046                  'originalquestion' => '0',
2047                  'seq_number' => '0',
2048                  'answer' => '300603,300602,300601:',
2049                  'timestamp' => '1275088684',
2050                  'event' => '0',
2051                  'grade' => '0',
2052                  'raw_grade' => '0',
2053                  'penalty' => '0',
2054                  'id' => 11002780,
2055              ),
2056              11002813 => (object) array(
2057                  'attempt' => '428770',
2058                  'question' => '89040',
2059                  'originalquestion' => '0',
2060                  'seq_number' => '1',
2061                  'answer' => '300601',
2062                  'timestamp' => '1275089101',
2063                  'event' => '2',
2064                  'grade' => '0',
2065                  'raw_grade' => '1',
2066                  'penalty' => '0.33',
2067                  'id' => 11002813,
2068              ),
2069              11002905 => (object) array(
2070                  'attempt' => '428770',
2071                  'question' => '89040',
2072                  'originalquestion' => '0',
2073                  'seq_number' => '2',
2074                  'answer' => '300603,300602,300601:300601',
2075                  'timestamp' => '1275089101',
2076                  'event' => '6',
2077                  'grade' => '1',
2078                  'raw_grade' => '1',
2079                  'penalty' => '0.33',
2080                  'id' => 11002905,
2081              ),
2082          );
2083  
2084          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
2085  
2086          $expectedqa = (object) array(
2087              'behaviour' => 'deferredfeedback',
2088              'questionid' => 89040,
2089              'variant' => 1,
2090              'maxmark' => 1,
2091              'minfraction' => 0,
2092              'maxfraction' => 1,
2093              'flagged' => 0,
2094              'questionsummary' => "Read the text below and then answer the question based on the information given.\n\n我大哥没有我二哥高,我比我二哥高。\n\nWho is the tallest?",
2095              'rightanswer' => '我。',
2096              'responsesummary' => '我。',
2097              'timemodified' => 1275089101,
2098              'steps' => array(
2099                  0 => (object) array(
2100                      'sequencenumber' => 0,
2101                      'state' => 'todo',
2102                      'fraction' => null,
2103                      'timecreated' => 1275088684,
2104                      'userid' => 605575,
2105                      'data' => array('_order' => '300603,300602,300601'),
2106                  ),
2107                  1 => (object) array(
2108                      'sequencenumber' => 1,
2109                      'state' => 'complete',
2110                      'fraction' => null,
2111                      'timecreated' => 1275089101,
2112                      'userid' => 605575,
2113                      'data' => array('answer' => '2'),
2114                  ),
2115                  2 => (object) array(
2116                      'sequencenumber' => 2,
2117                      'state' => 'gradedright',
2118                      'fraction' => 1,
2119                      'timecreated' => 1275089101,
2120                      'userid' => 605575,
2121                      'data' => array('answer' => '2', '-finish' => '1'),
2122                  ),
2123              ),
2124          );
2125  
2126          $this->compare_qas($expectedqa, $qa);
2127      }
2128  
2129      public function test_multichoice_deferredfeedback_qsession49446() {
2130          $quiz = (object) array(
2131              'id' => '203',
2132              'course' => '2359',
2133              'name' => 'Quiz 1',
2134              'intro' => '',
2135              'introformat' => FORMAT_HTML,
2136              'questiondecimalpoints' => '-1',
2137              'showuserpicture' => '1',
2138              'showblocks' => '1',
2139              'timeopen' => '0',
2140              'timeclose' => '0',
2141              'preferredbehaviour' => 'deferredfeedback',
2142              'attempts' => '0',
2143              'attemptonlast' => '1',
2144              'grademethod' => '1',
2145              'decimalpoints' => '2',
2146              'review' => '71760879',
2147              'questionsperpage' => '2',
2148              'shufflequestions' => '0',
2149              'shuffleanswers' => '0',
2150              'sumgrades' => '50',
2151              'grade' => '50',
2152              'timecreated' => '0',
2153              'timemodified' => '1176461532',
2154              'password' => '',
2155              'subnet' => '',
2156              'popup' => '0',
2157              'delay1' => '0',
2158              'delay2' => '0',
2159              'timelimit' => '0',
2160          );
2161          $attempt = (object) array(
2162              'id' => '4338',
2163              'uniqueid' => '4338',
2164              'quiz' => '203',
2165              'userid' => '30631',
2166              'attempt' => '2',
2167              'sumgrades' => '30',
2168              'timestart' => '1179303963',
2169              'timefinish' => '1179303960',
2170              'timemodified' => '1179303420',
2171              'layout' => '3859,3860,0,3861,3862,0,3863,3864,0,3865,3866,0,3867,3868,0',
2172              'preview' => '0',
2173          );
2174          $question = (object) array(
2175              'id' => '3863',
2176              'category' => '187',
2177              'parent' => '0',
2178              'name' => 'Question 5',
2179              'questiontext' => 'What is SOAP?',
2180              'questiontextformat' => '1',
2181              'defaultmark' => '1',
2182              'penalty' => '0',
2183              'qtype' => 'multichoice',
2184              'length' => '1',
2185              'stamp' => 'learn.open.ac.uk+070404142540+CpseAv',
2186              'version' => 'learn.open.ac.uk+070405112519+qNb2kt',
2187              'hidden' => '0',
2188              'generalfeedback' => '<p></p>',
2189              'generalfeedbackformat' => '1',
2190              'timecreated' => '0',
2191              'timemodified' => '0',
2192              'createdby' => null,
2193              'modifiedby' => null,
2194              'unlimited' => null,
2195              'maxmark' => '5',
2196              'options' => (object) array(
2197                  'id' => '1439',
2198                  'question' => '3863',
2199                  'layout' => '0',
2200                  'answers' => array(
2201                      11686 => (object) array(
2202                          'question' => '3863',
2203                          'answer' => 'It is a technology used for sending bulk data through the internet.',
2204                          'fraction' => '0',
2205                          'feedback' => 'Your answer is incorrect. <br />The correct answer is b. ',
2206                          'id' => 11686,
2207                      ),
2208                      11687 => (object) array(
2209                          'question' => '3863',
2210                          'answer' => 'It is the transport mechanism used with web services.',
2211                          'fraction' => '1',
2212                          'feedback' => 'Your answer is correct ',
2213                          'id' => 11687,
2214                      ),
2215                      11688 => (object) array(
2216                          'question' => '3863',
2217                          'answer' => 'It is a distributed object technology',
2218                          'fraction' => '0',
2219                          'feedback' => 'Your answer is incorrect. <br />The correct answer is b. ',
2220                          'id' => 11688,
2221                      ),
2222                  ),
2223                  'single' => '1',
2224                  'shuffleanswers' => '0',
2225                  'correctfeedback' => '',
2226                  'partiallycorrectfeedback' => '',
2227                  'incorrectfeedback' => '',
2228                  'answernumbering' => 'abc',
2229                  'showstandardinstruction' => 0,
2230              ),
2231              'hints' => false,
2232          );
2233          $qsession = (object) array(
2234              'id' => '49446',
2235              'attemptid' => '4338',
2236              'questionid' => '3863',
2237              'newest' => '112195',
2238              'newgraded' => '112195',
2239              'sumpenalty' => '0',
2240              'manualcomment' => '',
2241              'manualcommentformat' => '1',
2242              'flagged' => '1',
2243          );
2244          $qstates = array(
2245              112159 => (object) array(
2246                  'attempt' => '4338',
2247                  'question' => '3863',
2248                  'originalquestion' => '0',
2249                  'seq_number' => '0',
2250                  'answer' => '11686,11687,11688:',
2251                  'timestamp' => '1179303963',
2252                  'event' => '8',
2253                  'grade' => '0',
2254                  'raw_grade' => '0',
2255                  'penalty' => '0',
2256                  'id' => 112159,
2257              ),
2258              112164 => (object) array(
2259                  'attempt' => '4338',
2260                  'question' => '3863',
2261                  'originalquestion' => '0',
2262                  'seq_number' => '0',
2263                  'answer' => '11686,11687,11688:',
2264                  'timestamp' => '1179303963',
2265                  'event' => '0',
2266                  'grade' => '0',
2267                  'raw_grade' => '0',
2268                  'penalty' => '0',
2269                  'id' => 112164,
2270              ),
2271              112176 => (object) array(
2272                  'attempt' => '4338',
2273                  'question' => '3863',
2274                  'originalquestion' => '0',
2275                  'seq_number' => '1',
2276                  'answer' => '11686,11687,11688:11687',
2277                  'timestamp' => '1179303218',
2278                  'event' => '2',
2279                  'grade' => '0',
2280                  'raw_grade' => '5',
2281                  'penalty' => '0',
2282                  'id' => 112176,
2283              ),
2284              112195 => (object) array(
2285                  'attempt' => '4338',
2286                  'question' => '3863',
2287                  'originalquestion' => '0',
2288                  'seq_number' => '2',
2289                  'answer' => '11686,11687,11688:11687',
2290                  'timestamp' => '1179303218',
2291                  'event' => '6',
2292                  'grade' => '5',
2293                  'raw_grade' => '5',
2294                  'penalty' => '0',
2295                  'id' => 112195,
2296              ),
2297          );
2298  
2299          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
2300  
2301          $expectedqa = (object) array(
2302              'behaviour' => 'deferredfeedback',
2303              'questionid' => 3863,
2304              'variant' => 1,
2305              'maxmark' => 5,
2306              'minfraction' => 0,
2307              'maxfraction' => 1,
2308              'flagged' => 0,
2309              'questionsummary' => 'What is SOAP?',
2310              'rightanswer' => 'It is the transport mechanism used with web services.',
2311              'responsesummary' => 'It is the transport mechanism used with web services.',
2312              'timemodified' => 1179303963,
2313              'steps' => array(
2314                  0 => (object) array(
2315                      'sequencenumber' => 0,
2316                      'state' => 'todo',
2317                      'fraction' => null,
2318                      'timecreated' => 1179303963,
2319                      'userid' => 30631,
2320                      'data' => array('_order' => '11686,11687,11688'),
2321                  ),
2322                  1 => (object) array(
2323                      'sequencenumber' => 1,
2324                      'state' => 'complete',
2325                      'fraction' => null,
2326                      'timecreated' => 1179303218,
2327                      'userid' => 30631,
2328                      'data' => array('answer' => 1),
2329                  ),
2330                  2 => (object) array(
2331                      'sequencenumber' => 2,
2332                      'state' => 'gradedright',
2333                      'fraction' => 1,
2334                      'timecreated' => 1179303218,
2335                      'userid' => 30631,
2336                      'data' => array('answer' => 1, '-finish' => 1),
2337                  ),
2338              ),
2339          );
2340  
2341          $this->compare_qas($expectedqa, $qa);
2342      }
2343  
2344      public function test_multichoice_deferredfeedback_qsession591() {
2345          $quiz = (object) array(
2346              'id' => '22',
2347              'course' => '272',
2348              'name' => 'ICT self-assessment quiz',
2349              'intro' => '<p>Work through the ICT skills self-assessment quiz in order to assess your ability to use ICT for study on the Youth Justice Programme. Doing this will also help you to plan a short programme of learning.</p>
2350          <p>Use the questions to rate your ability in each area as either:</p>
2351          <ul>
2352              <li>\'Well developed\'</li>
2353              <li>\'Not sure\', or</li>
2354              <li>\'Needs development\'.</li>
2355          </ul>
2356          <p>Once you have done that, and seen the feedback associated with your answers, you will need to think about prioritising the skills that need development. You will also need to allocate some time in order to develop the skills you need to concentrate on. Within the feedback for each question are some subject-related links which you may find useful.</p>',
2357              'introformat' => FORMAT_HTML,
2358              'questiondecimalpoints' => '-1',
2359              'showuserpicture' => '1',
2360              'showblocks' => '1',
2361              'timeopen' => '0',
2362              'timeclose' => '0',
2363              'preferredbehaviour' => 'deferredfeedback',
2364              'attempts' => '0',
2365              'attemptonlast' => '0',
2366              'grademethod' => '4',
2367              'decimalpoints' => '0',
2368              'review' => '71760879',
2369              'questionsperpage' => '1',
2370              'shufflequestions' => '0',
2371              'shuffleanswers' => '0',
2372              'sumgrades' => '0',
2373              'grade' => '0',
2374              'timecreated' => '0',
2375              'timemodified' => '1174581121',
2376              'password' => '',
2377              'subnet' => '',
2378              'popup' => '0',
2379              'delay1' => '0',
2380              'delay2' => '0',
2381              'timelimit' => '0',
2382          );
2383          $attempt = (object) array(
2384              'id' => '95',
2385              'uniqueid' => '94',
2386              'quiz' => '22',
2387              'userid' => '9721',
2388              'attempt' => '1',
2389              'timestart' => '1177777016',
2390              'timefinish' => '1177777128',
2391              'timemodified' => '1177777101',
2392              'layout' => '242,0,243,0,244,0,245,0,246,0,247,0',
2393              'preview' => '0',
2394              'sumgrades' => '0',
2395          );
2396          $question = (object) array(
2397              'id' => '247',
2398              'category' => '12',
2399              'parent' => '0',
2400              'name' => 'Regular access to a computer',
2401              'questiontext' => '[CUT]',
2402              'questiontextformat' => '1',
2403              'defaultmark' => '0',
2404              'penalty' => '0',
2405              'qtype' => 'multichoice',
2406              'length' => '1',
2407              'stamp' => 'learn.open.ac.uk+070321164105+qIeJ9g',
2408              'hidden' => '0',
2409              'version' => 'learn.open.ac.uk+070427170153+plBFqV',
2410              'generalfeedback' => '',
2411              'generalfeedbackformat' => '1',
2412              'timecreated' => '0',
2413              'timemodified' => '0',
2414              'createdby' => null,
2415              'modifiedby' => null,
2416              'unlimited' => null,
2417              'maxmark' => '0',
2418              'options' => (object) array(
2419                  'id' => '180',
2420                  'question' => '247',
2421                  'layout' => '0',
2422                  'answers' => array(
2423                      666 => (object) array(
2424                          'question' => '247',
2425                          'answer' => 'Well developed',
2426                          'feedback' => 'It\'s good that you don\'t feel as though you will have problems accessing a computer in order to study within the Youth Justice Programme. However, you may find the OU Library\'s information page on <a href="http://library.open.ac.uk/libraries/update/access_computers.html" target="blank"><b>Using public access computers in libraries and other venues</b></a> of interest.',
2427                          'fraction' => '1',
2428                          'id' => 666,
2429                      ),
2430                      667 => (object) array(
2431                          'question' => '247',
2432                          'answer' => 'Not sure',
2433                          'feedback' => 'We recommend that you visit the OU Library\'s information page on <a href="http://library.open.ac.uk/libraries/update/access_computers.html" target="blank"><b>Using public access computers in libraries and other venues</b></a>.',
2434                          'fraction' => '1',
2435                          'id' => 667,
2436                      ),
2437                      668 => (object) array(
2438                          'question' => '247',
2439                          'answer' => 'Needs development',
2440                          'feedback' => 'We recommend that you visit the OU Library\'s information page on <a href="http://library.open.ac.uk/libraries/update/access_computers.html" target="blank"><b>Using public access computers in libraries and other venues</b></a>.',
2441                          'fraction' => '1',
2442                          'id' => 668,
2443                      ),
2444                  ),
2445                  'single' => '1',
2446                  'shuffleanswers' => '0',
2447                  'answernumbering' => 'abc',
2448                  'showstandardinstruction' => 0,
2449                  'correctfeedback' => '',
2450                  'partiallycorrectfeedback' => '',
2451                  'incorrectfeedback' => '',
2452              ),
2453              'hints' => false,
2454          );
2455          $qsession = (object) array(
2456              'id' => '591',
2457              'attemptid' => '94',
2458              'questionid' => '247',
2459              'newest' => '1220',
2460              'newgraded' => '1220',
2461              'sumpenalty' => '0',
2462              'manualcomment' => '',
2463              'manualcommentformat' => '1',
2464              'flagged' => '1',
2465          );
2466          $qstates = array(
2467              1208 => (object) array(
2468                  'attempt' => '94',
2469                  'question' => '247',
2470                  'originalquestion' => '0',
2471                  'seq_number' => '0',
2472                  'answer' => '666,667,668:',
2473                  'timestamp' => '1177777016',
2474                  'event' => '0',
2475                  'grade' => '0',
2476                  'raw_grade' => '0',
2477                  'penalty' => '0',
2478                  'id' => 1208,
2479              ),
2480              1219 => (object) array(
2481                  'attempt' => '94',
2482                  'question' => '247',
2483                  'originalquestion' => '0',
2484                  'seq_number' => '1',
2485                  'answer' => '666,667,668:666',
2486                  'timestamp' => '1177777116',
2487                  'event' => '2',
2488                  'grade' => '0',
2489                  'raw_grade' => '0',
2490                  'penalty' => '0',
2491                  'id' => 1219,
2492              ),
2493              1220 => (object) array(
2494                  'attempt' => '94',
2495                  'question' => '247',
2496                  'originalquestion' => '0',
2497                  'seq_number' => '2',
2498                  'answer' => '666,667,668:666',
2499                  'timestamp' => '1177777116',
2500                  'event' => '6',
2501                  'grade' => '0',
2502                  'raw_grade' => '0',
2503                  'penalty' => '0',
2504                  'id' => 1220,
2505              ),
2506          );
2507  
2508          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
2509  
2510          $expectedqa = (object) array(
2511              'behaviour' => 'deferredfeedback',
2512              'questionid' => 247,
2513              'variant' => 1,
2514              'maxmark' => 0,
2515              'minfraction' => 0,
2516              'maxfraction' => 1,
2517              'flagged' => 0,
2518              'questionsummary' => '[CUT]',
2519              'rightanswer' => 'Well developed',
2520              'responsesummary' => 'Well developed',
2521              'timemodified' => 1177777116,
2522              'steps' => array(
2523                  0 => (object) array(
2524                      'sequencenumber' => 0,
2525                      'state' => 'todo',
2526                      'fraction' => null,
2527                      'timecreated' => 1177777016,
2528                      'userid' => 9721,
2529                      'data' => array('_order' => '666,667,668'),
2530                  ),
2531                  1 => (object) array(
2532                      'sequencenumber' => 1,
2533                      'state' => 'complete',
2534                      'fraction' => null,
2535                      'timecreated' => 1177777116,
2536                      'userid' => 9721,
2537                      'data' => array('answer' => 0),
2538                  ),
2539                  2 => (object) array(
2540                      'sequencenumber' => 2,
2541                      'state' => 'finished',
2542                      'fraction' => null,
2543                      'timecreated' => 1177777116,
2544                      'userid' => 9721,
2545                      'data' => array('answer' => 0, '-finish' => 1),
2546                  ),
2547              ),
2548          );
2549  
2550          $this->compare_qas($expectedqa, $qa);
2551      }
2552  
2553      public function test_multichoice_deferredfeedback_qsession594() {
2554          $quiz = (object) array(
2555              'id' => '22',
2556              'course' => '272',
2557              'name' => 'ICT self-assessment quiz',
2558              'intro' => '<p>Work through the ICT skills self-assessment quiz in order to assess your ability to use ICT for study on the Youth Justice Programme. Doing this will also help you to plan a short programme of learning.</p>
2559          <p>Use the questions to rate your ability in each area as either:</p>
2560          <ul>
2561              <li>\'Well developed\'</li>
2562              <li>\'Not sure\', or</li>
2563              <li>\'Needs development\'.</li>
2564          </ul>
2565          <p>Once you have done that, and seen the feedback associated with your answers, you will need to think about prioritising the skills that need development. You will also need to allocate some time in order to develop the skills you need to concentrate on. Within the feedback for each question are some subject-related links which you may find useful.</p>',
2566              'introformat' => FORMAT_HTML,
2567              'questiondecimalpoints' => '-1',
2568              'showuserpicture' => '1',
2569              'showblocks' => '1',
2570              'timeopen' => '0',
2571              'timeclose' => '0',
2572              'preferredbehaviour' => 'deferredfeedback',
2573              'attempts' => '0',
2574              'attemptonlast' => '0',
2575              'grademethod' => '4',
2576              'decimalpoints' => '0',
2577              'review' => '71760879',
2578              'questionsperpage' => '1',
2579              'shufflequestions' => '0',
2580              'shuffleanswers' => '0',
2581              'sumgrades' => '0',
2582              'grade' => '0',
2583              'timecreated' => '0',
2584              'timemodified' => '1174581121',
2585              'password' => '',
2586              'subnet' => '',
2587              'popup' => '0',
2588              'delay1' => '0',
2589              'delay2' => '0',
2590              'timelimit' => '0',
2591          );
2592          $attempt = (object) array(
2593              'id' => '95',
2594              'uniqueid' => '94',
2595              'quiz' => '22',
2596              'userid' => '9721',
2597              'attempt' => '1',
2598              'timestart' => '1177777016',
2599              'timefinish' => '1177777128',
2600              'timemodified' => '1177777101',
2601              'layout' => '242,0,243,0,244,0,245,0,246,0,247,0',
2602              'preview' => '0',
2603              'sumgrades' => '0',
2604          );
2605          $question = (object) array(
2606              'id' => '242',
2607              'category' => '12',
2608              'parent' => '0',
2609              'name' => 'Using the internet',
2610              'questiontext' => '<p><strong>Using the internet</strong></p>
2611          <p><font face="Verdana,Verdana" size="2">Many study resources are available online, and you will also be expected to find things out yourself using the web.</font></p>
2612          <p><i><font face="Verdana,Verdana" size="2">How would you rate your skills in using browsers and managing documents you find on the internet? </font></i></p>',
2613              'questiontextformat' => '1',
2614              'defaultmark' => '0',
2615              'penalty' => '0',
2616              'qtype' => 'multichoice',
2617              'length' => '1',
2618              'stamp' => 'learn.open.ac.uk+070321161800+WlAJ5D',
2619              'hidden' => '0',
2620              'version' => 'learn.open.ac.uk+070329133200+dO4WQO',
2621              'generalfeedback' => '',
2622              'generalfeedbackformat' => '1',
2623              'timecreated' => '0',
2624              'timemodified' => '0',
2625              'createdby' => null,
2626              'modifiedby' => null,
2627              'unlimited' => null,
2628              'maxmark' => '0',
2629              'options' => (object) array(
2630                  'id' => '175',
2631                  'question' => '242',
2632                  'layout' => '0',
2633                  'answers' => array(
2634                      651 => (object) array(
2635                          'question' => '242',
2636                          'answer' => 'Well developed',
2637                          'feedback' => 'You obviously feel confident about using the internet in order to manage your documentation and find information on the World Wide Web. However, you may still find the OU\'s <a href="http://www.open.ac.uk/webguide/" target="blank"><b>Web Guide</b></a> site of interest.',
2638                          'fraction' => '1',
2639                          'id' => 651,
2640                      ),
2641                      652 => (object) array(
2642                          'question' => '242',
2643                          'answer' => 'Not sure',
2644                          'feedback' => 'We recommend that you visit the OU\'s <a href="http://www.open.ac.uk/webguide/" target="blank"><b>Web Guide</b></a> site and work through some of the tips and advice about using the web effectively.',
2645                          'fraction' => '1',
2646                          'id' => 652,
2647                      ),
2648                      653 => (object) array(
2649                          'question' => '242',
2650                          'answer' => 'Needs development',
2651                          'feedback' => 'We recommend that you visit the OU\'s <a href="http://www.open.ac.uk/webguide/" target="blank"><b>Web Guide</b></a> site and work through some of the tips and advice about using the web effectively.',
2652                          'fraction' => '1',
2653                          'id' => 653,
2654                      ),
2655                  ),
2656                  'single' => '1',
2657                  'shuffleanswers' => '0',
2658                  'answernumbering' => 'abc',
2659                  'showstandardinstruction' => 0,
2660                  'correctfeedback' => '',
2661                  'partiallycorrectfeedback' => '',
2662                  'incorrectfeedback' => '',
2663              ),
2664              'hints' => false,
2665          );
2666          $qsession = (object) array(
2667              'id' => '594',
2668              'attemptid' => '94',
2669              'questionid' => '242',
2670              'newest' => '1223',
2671              'newgraded' => '1223',
2672              'sumpenalty' => '0',
2673              'manualcomment' => '',
2674              'manualcommentformat' => '1',
2675              'flagged' => '1',
2676          );
2677          $qstates = array(
2678              1211 => (object) array(
2679                  'attempt' => '94',
2680                  'question' => '242',
2681                  'originalquestion' => '0',
2682                  'seq_number' => '0',
2683                  'answer' => '651,652,653:',
2684                  'timestamp' => '1177777016',
2685                  'event' => '0',
2686                  'grade' => '0',
2687                  'raw_grade' => '0',
2688                  'penalty' => '0',
2689                  'id' => 1211,
2690              ),
2691              1214 => (object) array(
2692                  'attempt' => '94',
2693                  'question' => '242',
2694                  'originalquestion' => '0',
2695                  'seq_number' => '1',
2696                  'answer' => '651,652,653:651',
2697                  'timestamp' => '1177777040',
2698                  'event' => '2',
2699                  'grade' => '0',
2700                  'raw_grade' => '0',
2701                  'penalty' => '0',
2702                  'id' => 1214,
2703              ),
2704              1223 => (object) array(
2705                  'attempt' => '94',
2706                  'question' => '242',
2707                  'originalquestion' => '0',
2708                  'seq_number' => '2',
2709                  'answer' => '651,652,653:651',
2710                  'timestamp' => '1177777040',
2711                  'event' => '6',
2712                  'grade' => '0',
2713                  'raw_grade' => '0',
2714                  'penalty' => '0',
2715                  'id' => 1223,
2716              ),
2717          );
2718  
2719          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
2720  
2721          $expectedqa = (object) array(
2722              'behaviour' => 'deferredfeedback',
2723              'questionid' => 242,
2724              'variant' => 1,
2725              'maxmark' => 0,
2726              'minfraction' => 0,
2727              'maxfraction' => 1,
2728              'flagged' => 0,
2729              'questionsummary' => "USING THE INTERNET \n\nMany study resources are available online, and you will also be expected to find things out yourself using the web. \n\n_How would you rate your skills in using browsers and managing documents you find on the internet? _",
2730              'rightanswer' => 'Well developed',
2731              'responsesummary' => 'Well developed',
2732              'timemodified' => 1177777040,
2733              'steps' => array(
2734                  0 => (object) array(
2735                      'sequencenumber' => 0,
2736                      'state' => 'todo',
2737                      'fraction' => null,
2738                      'timecreated' => 1177777016,
2739                      'userid' => 9721,
2740                      'data' => array('_order' => '651,652,653'),
2741                  ),
2742                  1 => (object) array(
2743                      'sequencenumber' => 1,
2744                      'state' => 'complete',
2745                      'fraction' => null,
2746                      'timecreated' => 1177777040,
2747                      'userid' => 9721,
2748                      'data' => array('answer' => '0'),
2749                  ),
2750                  2 => (object) array(
2751                      'sequencenumber' => 2,
2752                      'state' => 'finished',
2753                      'fraction' => null,
2754                      'timecreated' => 1177777040,
2755                      'userid' => 9721,
2756                      'data' => array('answer' => '0', '-finish' => 1),
2757                  ),
2758              ),
2759          );
2760  
2761          $this->compare_qas($expectedqa, $qa);
2762      }
2763  }