Search moodle.org's
Developer Documentation

See Release Notes

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