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   * calculated multiple-choice questions.
  20   *
  21   * @package    qtype
  22   * @subpackage calculatedmulti
  23   * @copyright  2011 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 calculated multiple-choice question attempts.
  36   *
  37   * @copyright  2011 The Open University
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class qtype_calculatedmulti_attempt_upgrader_test extends question_attempt_upgrader_test_base {
  41      public function test_calculatedmulti_adaptive_qsession96() {
  42          $quiz = (object) array(
  43              'id' => '4',
  44              'course' => '2',
  45              'name' => 'Calculated quiz',
  46              'intro' => '',
  47              'introformat' => '1',
  48              'timeopen' => '0',
  49              'timeclose' => '0',
  50              'attempts' => '0',
  51              'attemptonlast' => '0',
  52              'grademethod' => '1',
  53              'decimalpoints' => '2',
  54              'questiondecimalpoints' => '-1',
  55              'questionsperpage' => '1',
  56              'shufflequestions' => '0',
  57              'shuffleanswers' => '1',
  58              'sumgrades' => '3.00000',
  59              'grade' => '10.00000',
  60              'timecreated' => '0',
  61              'timemodified' => '1305648351',
  62              'timelimit' => '0',
  63              'password' => '',
  64              'subnet' => '',
  65              'popup' => '0',
  66              'delay1' => '0',
  67              'delay2' => '0',
  68              'showuserpicture' => '0',
  69              'showblocks' => '0',
  70              'preferredbehaviour' => 'adaptive',
  71              'reviewattempt' => '69888',
  72              'reviewcorrectness' => '69888',
  73              'reviewmarks' => '69888',
  74              'reviewspecificfeedback' => '69888',
  75              'reviewgeneralfeedback' => '69888',
  76              'reviewrightanswer' => '69888',
  77              'reviewoverallfeedback' => '4352',
  78          );
  79          $attempt = (object) array(
  80              'id' => '13',
  81              'uniqueid' => '13',
  82              'quiz' => '4',
  83              'userid' => '4',
  84              'attempt' => '1',
  85              'sumgrades' => '0.00000',
  86              'timestart' => '1305830650',
  87              'timefinish' => '1305830656',
  88              'timemodified' => '1305830656',
  89              'layout' => '16,0,17,0,18,0',
  90              'preview' => '0',
  91          );
  92          $question = (object) array(
  93              'id' => '17',
  94              'category' => '2',
  95              'parent' => '0',
  96              'name' => 'Calculated multiple-choice',
  97              'questiontext' => '<p>What is {a} + {b}?</p>',
  98              'questiontextformat' => '1',
  99              'generalfeedback' => '',
 100              'generalfeedbackformat' => '1',
 101              'defaultmark' => '1.0000000',
 102              'penalty' => '0.1',
 103              'qtype' => 'calculatedmulti',
 104              'length' => '1',
 105              'stamp' => 'tjh238.vledev2.open.ac.uk+110519184120+gpbLCv',
 106              'version' => 'tjh238.vledev2.open.ac.uk+110519184120+P5jpWJ',
 107              'hidden' => '0',
 108              'timecreated' => '1305830480',
 109              'timemodified' => '1305830480',
 110              'createdby' => '2',
 111              'modifiedby' => '2',
 112              'maxmark' => '1.0000000',
 113              'options' => (object) array(
 114                  'id' => '1',
 115                  'question' => '17',
 116                  'synchronize' => '0',
 117                  'single' => '1',
 118                  'shuffleanswers' => '1',
 119                  'correctfeedback' => '',
 120                  'correctfeedbackformat' => '1',
 121                  'partiallycorrectfeedback' => '',
 122                  'partiallycorrectfeedbackformat' => '1',
 123                  'incorrectfeedback' => '',
 124                  'incorrectfeedbackformat' => '1',
 125                  'answernumbering' => 'abc',
 126                  'shownumcorrect' => '0',
 127                  'answers' => array(
 128                      24 => (object) array(
 129                          'id' => '24',
 130                          'question' => '17',
 131                          'answer' => '{={a} - {b}}',
 132                          'answerformat' => '0',
 133                          'fraction' => '0.0000000',
 134                          'feedback' => '',
 135                          'feedbackformat' => '1',
 136                          'tolerance' => '0.01',
 137                          'tolerancetype' => '1',
 138                          'correctanswerlength' => '2',
 139                          'correctanswerformat' => '1',
 140                      ),
 141                      25 => (object) array(
 142                          'id' => '25',
 143                          'question' => '17',
 144                          'answer' => '{={a} + {b}}',
 145                          'answerformat' => '0',
 146                          'fraction' => '1.0000000',
 147                          'feedback' => '',
 148                          'feedbackformat' => '1',
 149                          'tolerance' => '0.01',
 150                          'tolerancetype' => '1',
 151                          'correctanswerlength' => '2',
 152                          'correctanswerformat' => '1',
 153                      ),
 154                      26 => (object) array(
 155                          'id' => '26',
 156                          'question' => '17',
 157                          'answer' => '{={a} / {b}}',
 158                          'answerformat' => '0',
 159                          'fraction' => '0.0000000',
 160                          'feedback' => '',
 161                          'feedbackformat' => '1',
 162                          'tolerance' => '0.01',
 163                          'tolerancetype' => '1',
 164                          'correctanswerlength' => '2',
 165                          'correctanswerformat' => '1',
 166                      ),
 167                      27 => (object) array(
 168                          'id' => '27',
 169                          'question' => '17',
 170                          'answer' => '{={a} * {b}}',
 171                          'answerformat' => '0',
 172                          'fraction' => '0.0000000',
 173                          'feedback' => '',
 174                          'feedbackformat' => '1',
 175                          'tolerance' => '0.01',
 176                          'tolerancetype' => '1',
 177                          'correctanswerlength' => '2',
 178                          'correctanswerformat' => '1',
 179                      ),
 180                  ),
 181              ),
 182              'hints' => array(
 183              ),
 184          );
 185          $qsession = (object) array(
 186              'id' => '96',
 187              'attemptid' => '13',
 188              'questionid' => '17',
 189              'newest' => '257',
 190              'newgraded' => '257',
 191              'sumpenalty' => '0.1000000',
 192              'manualcomment' => '',
 193              'manualcommentformat' => '1',
 194              'flagged' => '0',
 195          );
 196          $qstates = array(
 197              254 => (object) array(
 198                  'id' => '254',
 199                  'attempt' => '13',
 200                  'question' => '17',
 201                  'seq_number' => '0',
 202                  'answer' => 'dataset3-24,26,27,25:',
 203                  'timestamp' => '1305830650',
 204                  'event' => '0',
 205                  'grade' => '0.0000000',
 206                  'raw_grade' => '0.0000000',
 207                  'penalty' => '0.0000000',
 208              ),
 209              257 => (object) array(
 210                  'id' => '257',
 211                  'attempt' => '13',
 212                  'question' => '17',
 213                  'seq_number' => '1',
 214                  'answer' => 'dataset3-24,26,27,25:',
 215                  'timestamp' => '1305830650',
 216                  'event' => '6',
 217                  'grade' => '0.0000000',
 218                  'raw_grade' => '0.0000000',
 219                  'penalty' => '0.1000000',
 220              ),
 221          );
 222          $this->loader->put_dataset_in_cache($question->id, 3, array('a' => '4.3', 'b' => '5.4'));
 223  
 224          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 225  
 226          $expectedqa = (object) array(
 227              'behaviour' => 'adaptive',
 228              'questionid' => 17,
 229              'variant' => 3,
 230              'maxmark' => 1.0000000,
 231              'minfraction' => 0,
 232              'maxfraction' => 1,
 233              'flagged' => 0,
 234              'questionsummary' => 'What is 4.3 + 5.4?',
 235              'rightanswer' => '9.7',
 236              'responsesummary' => '',
 237              'timemodified' => 1305830650,
 238              'steps' => array(
 239                  0 => (object) array(
 240                      'sequencenumber' => 0,
 241                      'state' => 'todo',
 242                      'fraction' => null,
 243                      'timecreated' => 1305830650,
 244                      'userid' => 4,
 245                      'data' => array('_order' => '24,26,27,25', '_var_a' => '4.3', '_var_b' => '5.4'),
 246                  ),
 247                  1 => (object) array(
 248                      'sequencenumber' => 1,
 249                      'state' => 'gradedwrong',
 250                      'fraction' => null,
 251                      'timecreated' => 1305830650,
 252                      'userid' => 4,
 253                      'data' => array('-finish' => 1, '-_try' => 1, '-_rawfraction' => 0),
 254                  ),
 255              ),
 256          );
 257  
 258          $this->compare_qas($expectedqa, $qa);
 259      }
 260  
 261      public function test_calculatedmulti_adaptive_qsession99() {
 262          $quiz = (object) array(
 263              'id' => '4',
 264              'course' => '2',
 265              'name' => 'Calculated quiz',
 266              'intro' => '',
 267              'introformat' => '1',
 268              'timeopen' => '0',
 269              'timeclose' => '0',
 270              'attempts' => '0',
 271              'attemptonlast' => '0',
 272              'grademethod' => '1',
 273              'decimalpoints' => '2',
 274              'questiondecimalpoints' => '-1',
 275              'questionsperpage' => '1',
 276              'shufflequestions' => '0',
 277              'shuffleanswers' => '1',
 278              'sumgrades' => '3.00000',
 279              'grade' => '10.00000',
 280              'timecreated' => '0',
 281              'timemodified' => '1305648351',
 282              'timelimit' => '0',
 283              'password' => '',
 284              'subnet' => '',
 285              'popup' => '0',
 286              'delay1' => '0',
 287              'delay2' => '0',
 288              'showuserpicture' => '0',
 289              'showblocks' => '0',
 290              'preferredbehaviour' => 'adaptive',
 291              'reviewattempt' => '69888',
 292              'reviewcorrectness' => '69888',
 293              'reviewmarks' => '69888',
 294              'reviewspecificfeedback' => '69888',
 295              'reviewgeneralfeedback' => '69888',
 296              'reviewrightanswer' => '69888',
 297              'reviewoverallfeedback' => '4352',
 298          );
 299          $attempt = (object) array(
 300              'id' => '14',
 301              'uniqueid' => '14',
 302              'quiz' => '4',
 303              'userid' => '4',
 304              'attempt' => '2',
 305              'sumgrades' => '2.80000',
 306              'timestart' => '1305830661',
 307              'timefinish' => '1305830729',
 308              'timemodified' => '1305830729',
 309              'layout' => '16,0,17,0,18,0',
 310              'preview' => '0',
 311          );
 312          $question = (object) array(
 313              'id' => '17',
 314              'category' => '2',
 315              'parent' => '0',
 316              'name' => 'Calculated multiple-choice',
 317              'questiontext' => '<p>What is {a} + {b}?</p>',
 318              'questiontextformat' => '1',
 319              'generalfeedback' => '',
 320              'generalfeedbackformat' => '1',
 321              'defaultmark' => '1.0000000',
 322              'penalty' => '0.1',
 323              'qtype' => 'calculatedmulti',
 324              'length' => '1',
 325              'stamp' => 'tjh238.vledev2.open.ac.uk+110519184120+gpbLCv',
 326              'version' => 'tjh238.vledev2.open.ac.uk+110519184120+P5jpWJ',
 327              'hidden' => '0',
 328              'timecreated' => '1305830480',
 329              'timemodified' => '1305830480',
 330              'createdby' => '2',
 331              'modifiedby' => '2',
 332              'maxmark' => '1.0000000',
 333              'options' => (object) array(
 334                  'id' => '1',
 335                  'question' => '17',
 336                  'synchronize' => '0',
 337                  'single' => '1',
 338                  'shuffleanswers' => '1',
 339                  'correctfeedback' => '',
 340                  'correctfeedbackformat' => '1',
 341                  'partiallycorrectfeedback' => '',
 342                  'partiallycorrectfeedbackformat' => '1',
 343                  'incorrectfeedback' => '',
 344                  'incorrectfeedbackformat' => '1',
 345                  'answernumbering' => 'abc',
 346                  'shownumcorrect' => '0',
 347                  'answers' => array(
 348                      24 => (object) array(
 349                          'id' => '24',
 350                          'question' => '17',
 351                          'answer' => '{={a} - {b}}',
 352                          'answerformat' => '0',
 353                          'fraction' => '0.0000000',
 354                          'feedback' => '',
 355                          'feedbackformat' => '1',
 356                          'tolerance' => '0.01',
 357                          'tolerancetype' => '1',
 358                          'correctanswerlength' => '2',
 359                          'correctanswerformat' => '1',
 360                      ),
 361                      25 => (object) array(
 362                          'id' => '25',
 363                          'question' => '17',
 364                          'answer' => '{={a} + {b}}',
 365                          'answerformat' => '0',
 366                          'fraction' => '1.0000000',
 367                          'feedback' => '',
 368                          'feedbackformat' => '1',
 369                          'tolerance' => '0.01',
 370                          'tolerancetype' => '1',
 371                          'correctanswerlength' => '2',
 372                          'correctanswerformat' => '1',
 373                      ),
 374                      26 => (object) array(
 375                          'id' => '26',
 376                          'question' => '17',
 377                          'answer' => '{={a} / {b}}',
 378                          'answerformat' => '0',
 379                          'fraction' => '0.0000000',
 380                          'feedback' => '',
 381                          'feedbackformat' => '1',
 382                          'tolerance' => '0.01',
 383                          'tolerancetype' => '1',
 384                          'correctanswerlength' => '2',
 385                          'correctanswerformat' => '1',
 386                      ),
 387                      27 => (object) array(
 388                          'id' => '27',
 389                          'question' => '17',
 390                          'answer' => '{={a} * {b}}',
 391                          'answerformat' => '0',
 392                          'fraction' => '0.0000000',
 393                          'feedback' => '',
 394                          'feedbackformat' => '1',
 395                          'tolerance' => '0.01',
 396                          'tolerancetype' => '1',
 397                          'correctanswerlength' => '2',
 398                          'correctanswerformat' => '1',
 399                      ),
 400                  ),
 401              ),
 402              'hints' => array(
 403              ),
 404          );
 405          $qsession = (object) array(
 406              'id' => '99',
 407              'attemptid' => '14',
 408              'questionid' => '17',
 409              'newest' => '268',
 410              'newgraded' => '268',
 411              'sumpenalty' => '0.2000000',
 412              'manualcomment' => '',
 413              'manualcommentformat' => '1',
 414              'flagged' => '0',
 415          );
 416          $qstates = array(
 417              260 => (object) array(
 418                  'id' => '260',
 419                  'attempt' => '14',
 420                  'question' => '17',
 421                  'seq_number' => '0',
 422                  'answer' => 'dataset8-25,24,27,26:',
 423                  'timestamp' => '1305830661',
 424                  'event' => '0',
 425                  'grade' => '0.0000000',
 426                  'raw_grade' => '0.0000000',
 427                  'penalty' => '0.0000000',
 428              ),
 429              264 => (object) array(
 430                  'id' => '264',
 431                  'attempt' => '14',
 432                  'question' => '17',
 433                  'seq_number' => '1',
 434                  'answer' => 'dataset8-25,24,27,26:25',
 435                  'timestamp' => '1305830699',
 436                  'event' => '3',
 437                  'grade' => '1.0000000',
 438                  'raw_grade' => '1.0000000',
 439                  'penalty' => '0.1000000',
 440              ),
 441              268 => (object) array(
 442                  'id' => '268',
 443                  'attempt' => '14',
 444                  'question' => '17',
 445                  'seq_number' => '2',
 446                  'answer' => 'dataset8-25,24,27,26:25',
 447                  'timestamp' => '1305830699',
 448                  'event' => '6',
 449                  'grade' => '1.0000000',
 450                  'raw_grade' => '1.0000000',
 451                  'penalty' => '0.1000000',
 452              ),
 453          );
 454          $this->loader->put_dataset_in_cache($question->id, 8, array('a' => '3.7', 'b' => '6.0'));
 455  
 456          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 457  
 458          $expectedqa = (object) array(
 459              'behaviour' => 'adaptive',
 460              'questionid' => 17,
 461              'variant' => 8,
 462              'maxmark' => 1.0000000,
 463              'minfraction' => 0,
 464              'maxfraction' => 1,
 465              'flagged' => 0,
 466              'questionsummary' => 'What is 3.7 + 6.0?',
 467              'rightanswer' => '9.7',
 468              'responsesummary' => '9.7',
 469              'timemodified' => 1305830699,
 470              'steps' => array(
 471                  0 => (object) array(
 472                      'sequencenumber' => 0,
 473                      'state' => 'todo',
 474                      'fraction' => null,
 475                      'timecreated' => 1305830661,
 476                      'userid' => 4,
 477                      'data' => array('_order' => '25,24,27,26', '_var_a' => '3.7', '_var_b' => '6.0'),
 478                  ),
 479                  1 => (object) array(
 480                      'sequencenumber' => 1,
 481                      'state' => 'complete',
 482                      'fraction' => 1,
 483                      'timecreated' => 1305830699,
 484                      'userid' => 4,
 485                      'data' => array('answer' => '0', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 1),
 486                  ),
 487                  2 => (object) array(
 488                      'sequencenumber' => 2,
 489                      'state' => 'gradedright',
 490                      'fraction' => 1,
 491                      'timecreated' => 1305830699,
 492                      'userid' => 4,
 493                      'data' => array('answer' => '0', '-finish' => 1, '-_try' => 1, '-_rawfraction' => 1),
 494                  ),
 495              ),
 496          );
 497  
 498          $this->compare_qas($expectedqa, $qa);
 499      }
 500  
 501      public function test_calculatedmulti_adaptive_qsession102() {
 502          $quiz = (object) array(
 503              'id' => '4',
 504              'course' => '2',
 505              'name' => 'Calculated quiz',
 506              'intro' => '',
 507              'introformat' => '1',
 508              'timeopen' => '0',
 509              'timeclose' => '0',
 510              'attempts' => '0',
 511              'attemptonlast' => '0',
 512              'grademethod' => '1',
 513              'decimalpoints' => '2',
 514              'questiondecimalpoints' => '-1',
 515              'questionsperpage' => '1',
 516              'shufflequestions' => '0',
 517              'shuffleanswers' => '1',
 518              'sumgrades' => '3.00000',
 519              'grade' => '10.00000',
 520              'timecreated' => '0',
 521              'timemodified' => '1305648351',
 522              'timelimit' => '0',
 523              'password' => '',
 524              'subnet' => '',
 525              'popup' => '0',
 526              'delay1' => '0',
 527              'delay2' => '0',
 528              'showuserpicture' => '0',
 529              'showblocks' => '0',
 530              'preferredbehaviour' => 'adaptive',
 531              'reviewattempt' => '69888',
 532              'reviewcorrectness' => '69888',
 533              'reviewmarks' => '69888',
 534              'reviewspecificfeedback' => '69888',
 535              'reviewgeneralfeedback' => '69888',
 536              'reviewrightanswer' => '69888',
 537              'reviewoverallfeedback' => '4352',
 538          );
 539          $attempt = (object) array(
 540              'id' => '15',
 541              'uniqueid' => '15',
 542              'quiz' => '4',
 543              'userid' => '3',
 544              'attempt' => '1',
 545              'sumgrades' => '0.70000',
 546              'timestart' => '1305830744',
 547              'timefinish' => '0',
 548              'timemodified' => '1305830792',
 549              'layout' => '16,0,17,0,18,0',
 550              'preview' => '0',
 551          );
 552          $question = (object) array(
 553              'id' => '17',
 554              'category' => '2',
 555              'parent' => '0',
 556              'name' => 'Calculated multiple-choice',
 557              'questiontext' => '<p>What is {a} + {b}?</p>',
 558              'questiontextformat' => '1',
 559              'generalfeedback' => '',
 560              'generalfeedbackformat' => '1',
 561              'defaultmark' => '1.0000000',
 562              'penalty' => '0.1',
 563              'qtype' => 'calculatedmulti',
 564              'length' => '1',
 565              'stamp' => 'tjh238.vledev2.open.ac.uk+110519184120+gpbLCv',
 566              'version' => 'tjh238.vledev2.open.ac.uk+110519184120+P5jpWJ',
 567              'hidden' => '0',
 568              'timecreated' => '1305830480',
 569              'timemodified' => '1305830480',
 570              'createdby' => '2',
 571              'modifiedby' => '2',
 572              'maxmark' => '1.0000000',
 573              'options' => (object) array(
 574                  'id' => '1',
 575                  'question' => '17',
 576                  'synchronize' => '0',
 577                  'single' => '1',
 578                  'shuffleanswers' => '1',
 579                  'correctfeedback' => '',
 580                  'correctfeedbackformat' => '1',
 581                  'partiallycorrectfeedback' => '',
 582                  'partiallycorrectfeedbackformat' => '1',
 583                  'incorrectfeedback' => '',
 584                  'incorrectfeedbackformat' => '1',
 585                  'answernumbering' => 'abc',
 586                  'shownumcorrect' => '0',
 587                  'answers' => array(
 588                      24 => (object) array(
 589                          'id' => '24',
 590                          'question' => '17',
 591                          'answer' => '{={a} - {b}}',
 592                          'answerformat' => '0',
 593                          'fraction' => '0.0000000',
 594                          'feedback' => '',
 595                          'feedbackformat' => '1',
 596                          'tolerance' => '0.01',
 597                          'tolerancetype' => '1',
 598                          'correctanswerlength' => '2',
 599                          'correctanswerformat' => '1',
 600                      ),
 601                      25 => (object) array(
 602                          'id' => '25',
 603                          'question' => '17',
 604                          'answer' => '{={a} + {b}}',
 605                          'answerformat' => '0',
 606                          'fraction' => '1.0000000',
 607                          'feedback' => '',
 608                          'feedbackformat' => '1',
 609                          'tolerance' => '0.01',
 610                          'tolerancetype' => '1',
 611                          'correctanswerlength' => '2',
 612                          'correctanswerformat' => '1',
 613                      ),
 614                      26 => (object) array(
 615                          'id' => '26',
 616                          'question' => '17',
 617                          'answer' => '{={a} / {b}}',
 618                          'answerformat' => '0',
 619                          'fraction' => '0.0000000',
 620                          'feedback' => '',
 621                          'feedbackformat' => '1',
 622                          'tolerance' => '0.01',
 623                          'tolerancetype' => '1',
 624                          'correctanswerlength' => '2',
 625                          'correctanswerformat' => '1',
 626                      ),
 627                      27 => (object) array(
 628                          'id' => '27',
 629                          'question' => '17',
 630                          'answer' => '{={a} * {b}}',
 631                          'answerformat' => '0',
 632                          'fraction' => '0.0000000',
 633                          'feedback' => '',
 634                          'feedbackformat' => '1',
 635                          'tolerance' => '0.01',
 636                          'tolerancetype' => '1',
 637                          'correctanswerlength' => '2',
 638                          'correctanswerformat' => '1',
 639                      ),
 640                  ),
 641              ),
 642              'hints' => array(
 643              ),
 644          );
 645          $qsession = (object) array(
 646              'id' => '102',
 647              'attemptid' => '15',
 648              'questionid' => '17',
 649              'newest' => '278',
 650              'newgraded' => '278',
 651              'sumpenalty' => '0.5000000',
 652              'manualcomment' => '',
 653              'manualcommentformat' => '1',
 654              'flagged' => '0',
 655          );
 656          $qstates = array(
 657              271 => (object) array(
 658                  'id' => '271',
 659                  'attempt' => '15',
 660                  'question' => '17',
 661                  'seq_number' => '0',
 662                  'answer' => 'dataset7-26,24,25,27:',
 663                  'timestamp' => '1305830744',
 664                  'event' => '0',
 665                  'grade' => '0.0000000',
 666                  'raw_grade' => '0.0000000',
 667                  'penalty' => '0.0000000',
 668              ),
 669              274 => (object) array(
 670                  'id' => '274',
 671                  'attempt' => '15',
 672                  'question' => '17',
 673                  'seq_number' => '1',
 674                  'answer' => 'dataset7-26,24,25,27:27',
 675                  'timestamp' => '1305830759',
 676                  'event' => '3',
 677                  'grade' => '0.0000000',
 678                  'raw_grade' => '0.0000000',
 679                  'penalty' => '0.1000000',
 680              ),
 681              275 => (object) array(
 682                  'id' => '275',
 683                  'attempt' => '15',
 684                  'question' => '17',
 685                  'seq_number' => '2',
 686                  'answer' => 'dataset7-26,24,25,27:24',
 687                  'timestamp' => '1305830761',
 688                  'event' => '3',
 689                  'grade' => '0.0000000',
 690                  'raw_grade' => '0.0000000',
 691                  'penalty' => '0.1000000',
 692              ),
 693              276 => (object) array(
 694                  'id' => '276',
 695                  'attempt' => '15',
 696                  'question' => '17',
 697                  'seq_number' => '3',
 698                  'answer' => 'dataset7-26,24,25,27:26',
 699                  'timestamp' => '1305830764',
 700                  'event' => '3',
 701                  'grade' => '0.0000000',
 702                  'raw_grade' => '0.0000000',
 703                  'penalty' => '0.1000000',
 704              ),
 705              277 => (object) array(
 706                  'id' => '277',
 707                  'attempt' => '15',
 708                  'question' => '17',
 709                  'seq_number' => '4',
 710                  'answer' => 'dataset7-26,24,25,27:25',
 711                  'timestamp' => '1305830766',
 712                  'event' => '3',
 713                  'grade' => '0.7000000',
 714                  'raw_grade' => '1.0000000',
 715                  'penalty' => '0.1000000',
 716              ),
 717              278 => (object) array(
 718                  'id' => '278',
 719                  'attempt' => '15',
 720                  'question' => '17',
 721                  'seq_number' => '5',
 722                  'answer' => 'dataset7-26,24,25,27:24',
 723                  'timestamp' => '1305830768',
 724                  'event' => '3',
 725                  'grade' => '0.7000000',
 726                  'raw_grade' => '0.0000000',
 727                  'penalty' => '0.1000000',
 728              ),
 729          );
 730          $this->loader->put_dataset_in_cache($question->id, 7, array('a' => '4.4', 'b' => '8.2'));
 731  
 732          $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates);
 733  
 734          $expectedqa = (object) array(
 735              'behaviour' => 'adaptive',
 736              'questionid' => 17,
 737              'variant' => 7,
 738              'maxmark' => 1.0000000,
 739              'minfraction' => 0,
 740              'maxfraction' => 1,
 741              'flagged' => 0,
 742              'questionsummary' => 'What is 4.4 + 8.2?',
 743              'rightanswer' => '12.6',
 744              'responsesummary' => '-3.8',
 745              'timemodified' => 1305830768,
 746              'steps' => array(
 747                  0 => (object) array(
 748                      'sequencenumber' => 0,
 749                      'state' => 'todo',
 750                      'fraction' => null,
 751                      'timecreated' => 1305830744,
 752                      'userid' => 3,
 753                      'data' => array('_order' => '26,24,25,27', '_var_a' => '4.4', '_var_b' => '8.2'),
 754                  ),
 755                  1 => (object) array(
 756                      'sequencenumber' => 1,
 757                      'state' => 'todo',
 758                      'fraction' => 0,
 759                      'timecreated' => 1305830759,
 760                      'userid' => 3,
 761                      'data' => array('answer' => '3', '-submit' => 1, '-_try' => 1, '-_rawfraction' => 0),
 762                  ),
 763                  2 => (object) array(
 764                      'sequencenumber' => 2,
 765                      'state' => 'todo',
 766                      'fraction' => 0,
 767                      'timecreated' => 1305830761,
 768                      'userid' => 3,
 769                      'data' => array('answer' => '1', '-submit' => 1, '-_try' => 2, '-_rawfraction' => 0),
 770                  ),
 771                  3 => (object) array(
 772                      'sequencenumber' => 3,
 773                      'state' => 'todo',
 774                      'fraction' => 0,
 775                      'timecreated' => 1305830764,
 776                      'userid' => 3,
 777                      'data' => array('answer' => '0', '-submit' => 1, '-_try' => 3, '-_rawfraction' => 0),
 778                  ),
 779                  4 => (object) array(
 780                      'sequencenumber' => 4,
 781                      'state' => 'todo',
 782                      'fraction' => 0.7,
 783                      'timecreated' => 1305830766,
 784                      'userid' => 3,
 785                      'data' => array('answer' => '2', '-submit' => 1, '-_try' => 4, '-_rawfraction' => 1),
 786                  ),
 787                  5 => (object) array(
 788                      'sequencenumber' => 5,
 789                      'state' => 'todo',
 790                      'fraction' => 0.7,
 791                      'timecreated' => 1305830768,
 792                      'userid' => 3,
 793                      'data' => array('answer' => '1', '-submit' => 1, '-_try' => 5, '-_rawfraction' => 0),
 794                  ),
 795              ),
 796          );
 797  
 798          $this->compare_qas($expectedqa, $qa);
 799      }
 800  }