1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace qtype_calculated; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 require_once($CFG->dirroot . '/question/engine/upgrade/tests/helper.php'); 23 24 25 /** 26 * Testing the upgrade of calculated question attempts. 27 * 28 * @package qtype_calculated 29 * @copyright 2011 The Open University 30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class upgrade_old_attempt_data_test extends \question_attempt_upgrader_test_base { 33 public function test_calculated_adaptive_qsession97() { 34 $quiz = (object) array( 35 'id' => '4', 36 'course' => '2', 37 'name' => 'Calculated quiz', 38 'intro' => '', 39 'introformat' => '1', 40 'timeopen' => '0', 41 'timeclose' => '0', 42 'attempts' => '0', 43 'attemptonlast' => '0', 44 'grademethod' => '1', 45 'decimalpoints' => '2', 46 'questiondecimalpoints' => '-1', 47 'questionsperpage' => '1', 48 'shufflequestions' => '0', 49 'shuffleanswers' => '1', 50 'sumgrades' => '3.00000', 51 'grade' => '10.00000', 52 'timecreated' => '0', 53 'timemodified' => '1305648351', 54 'timelimit' => '0', 55 'password' => '', 56 'subnet' => '', 57 'popup' => '0', 58 'delay1' => '0', 59 'delay2' => '0', 60 'showuserpicture' => '0', 61 'showblocks' => '0', 62 'preferredbehaviour' => 'adaptive', 63 'reviewattempt' => '69888', 64 'reviewcorrectness' => '69888', 65 'reviewmarks' => '69888', 66 'reviewspecificfeedback' => '69888', 67 'reviewgeneralfeedback' => '69888', 68 'reviewrightanswer' => '69888', 69 'reviewoverallfeedback' => '4352', 70 ); 71 $attempt = (object) array( 72 'id' => '13', 73 'uniqueid' => '13', 74 'quiz' => '4', 75 'userid' => '4', 76 'attempt' => '1', 77 'sumgrades' => '0.00000', 78 'timestart' => '1305830650', 79 'timefinish' => '1305830656', 80 'timemodified' => '1305830656', 81 'layout' => '16,0,17,0,18,0', 82 'preview' => '0', 83 ); 84 $question = (object) array( 85 'id' => '18', 86 'category' => '2', 87 'parent' => '0', 88 'name' => 'Calculated', 89 'questiontext' => '<p>What is {a} m + {b} m?</p><p>_______________</p><p>Remember to type a unit.</p>', 90 'questiontextformat' => '1', 91 'generalfeedback' => '', 92 'generalfeedbackformat' => '1', 93 'defaultmark' => '1.0000000', 94 'penalty' => '0.1', 95 'qtype' => 'calculated', 96 'length' => '1', 97 'stamp' => 'tjh238.vledev2.open.ac.uk+110519184316+ELvZeg', 98 'version' => 'tjh238.vledev2.open.ac.uk+110519184317+exx1Bm', 99 'hidden' => '0', 100 'timecreated' => '1305830596', 101 'timemodified' => '1305830596', 102 'createdby' => '2', 103 'modifiedby' => '2', 104 'maxmark' => '1.0000000', 105 'options' => (object) array( 106 'id' => '2', 107 'question' => '18', 108 'synchronize' => '0', 109 'single' => '0', 110 'shuffleanswers' => '1', 111 'correctfeedback' => '', 112 'correctfeedbackformat' => '0', 113 'partiallycorrectfeedback' => '', 114 'partiallycorrectfeedbackformat' => '0', 115 'incorrectfeedback' => '', 116 'incorrectfeedbackformat' => '0', 117 'answernumbering' => 'abc', 118 'shownumcorrect' => '0', 119 'answers' => array( 120 28 => (object) array( 121 'id' => '28', 122 'question' => '18', 123 'answer' => '{a} + {b}', 124 'answerformat' => '0', 125 'fraction' => '1.0000000', 126 'feedback' => '', 127 'feedbackformat' => '1', 128 'tolerance' => '0.01', 129 'tolerancetype' => '1', 130 'correctanswerlength' => '2', 131 'correctanswerformat' => '1', 132 ), 133 ), 134 'units' => array( 135 0 => (object) array( 136 'id' => '9', 137 'question' => '18', 138 'multiplier' => 1, 139 'unit' => 'm', 140 ), 141 ), 142 'unitgradingtype' => '1', 143 'unitpenalty' => '0.5000000', 144 'showunits' => '0', 145 'unitsleft' => '0', 146 ), 147 'hints' => array( 148 ), 149 ); 150 $qsession = (object) array( 151 'id' => '97', 152 'attemptid' => '13', 153 'questionid' => '18', 154 'newest' => '258', 155 'newgraded' => '258', 156 'sumpenalty' => '0.1000000', 157 'manualcomment' => '', 158 'manualcommentformat' => '1', 159 'flagged' => '0', 160 ); 161 $qstates = array( 162 255 => (object) array( 163 'id' => '255', 164 'attempt' => '13', 165 'question' => '18', 166 'seq_number' => '0', 167 'answer' => 'dataset10-|||||', 168 'timestamp' => '1305830650', 169 'event' => '0', 170 'grade' => '0.0000000', 171 'raw_grade' => '0.0000000', 172 'penalty' => '0.0000000', 173 ), 174 258 => (object) array( 175 'id' => '258', 176 'attempt' => '13', 177 'question' => '18', 178 'seq_number' => '1', 179 'answer' => 'dataset10-|||||', 180 'timestamp' => '1305830650', 181 'event' => '6', 182 'grade' => '0.0000000', 183 'raw_grade' => '0.0000000', 184 'penalty' => '0.1000000', 185 ), 186 ); 187 $this->loader->put_dataset_in_cache($question->id, 10, array('a' => '7.5', 'b' => '4.9')); 188 189 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); 190 191 $expectedqa = (object) array( 192 'behaviour' => 'adaptive', 193 'questionid' => 18, 194 'variant' => 10, 195 'maxmark' => 1.0000000, 196 'minfraction' => 0, 197 'maxfraction' => 1, 198 'flagged' => 0, 199 'questionsummary' => 'What is 7.5 m + 4.9 m? 200 201 _______________ 202 203 Remember to type a unit.', 204 'rightanswer' => '12.4 m', 205 'responsesummary' => '', 206 'timemodified' => 1305830650, 207 'steps' => array( 208 0 => (object) array( 209 'sequencenumber' => 0, 210 'state' => 'todo', 211 'fraction' => null, 212 'timecreated' => 1305830650, 213 'userid' => 4, 214 'data' => array('_separators' => '.$,', 215 '_var_a' => '7.5', '_var_b' => '4.9'), 216 ), 217 1 => (object) array( 218 'sequencenumber' => 1, 219 'state' => 'gradedwrong', 220 'fraction' => null, 221 'timecreated' => 1305830650, 222 'userid' => 4, 223 'data' => array('answer' => '', '-finish' => 1, '-_try' => 1, '-_rawfraction' => 0), 224 ), 225 ), 226 ); 227 228 $this->compare_qas($expectedqa, $qa); 229 } 230 231 public function test_calculated_adaptive_qsession100() { 232 $quiz = (object) array( 233 'id' => '4', 234 'course' => '2', 235 'name' => 'Calculated quiz', 236 'intro' => '', 237 'introformat' => '1', 238 'timeopen' => '0', 239 'timeclose' => '0', 240 'attempts' => '0', 241 'attemptonlast' => '0', 242 'grademethod' => '1', 243 'decimalpoints' => '2', 244 'questiondecimalpoints' => '-1', 245 'questionsperpage' => '1', 246 'shufflequestions' => '0', 247 'shuffleanswers' => '1', 248 'sumgrades' => '3.00000', 249 'grade' => '10.00000', 250 'timecreated' => '0', 251 'timemodified' => '1305648351', 252 'timelimit' => '0', 253 'password' => '', 254 'subnet' => '', 255 'popup' => '0', 256 'delay1' => '0', 257 'delay2' => '0', 258 'showuserpicture' => '0', 259 'showblocks' => '0', 260 'preferredbehaviour' => 'adaptive', 261 'reviewattempt' => '69888', 262 'reviewcorrectness' => '69888', 263 'reviewmarks' => '69888', 264 'reviewspecificfeedback' => '69888', 265 'reviewgeneralfeedback' => '69888', 266 'reviewrightanswer' => '69888', 267 'reviewoverallfeedback' => '4352', 268 ); 269 $attempt = (object) array( 270 'id' => '14', 271 'uniqueid' => '14', 272 'quiz' => '4', 273 'userid' => '4', 274 'attempt' => '2', 275 'sumgrades' => '2.80000', 276 'timestart' => '1305830661', 277 'timefinish' => '1305830729', 278 'timemodified' => '1305830729', 279 'layout' => '16,0,17,0,18,0', 280 'preview' => '0', 281 ); 282 $question = (object) array( 283 'id' => '18', 284 'category' => '2', 285 'parent' => '0', 286 'name' => 'Calculated', 287 'questiontext' => '<p>What is {a} m + {b} m?</p><p>_______________</p><p>Remember to type a unit.</p>', 288 'questiontextformat' => '1', 289 'generalfeedback' => '', 290 'generalfeedbackformat' => '1', 291 'defaultmark' => '1.0000000', 292 'penalty' => '0.1', 293 'qtype' => 'calculated', 294 'length' => '1', 295 'stamp' => 'tjh238.vledev2.open.ac.uk+110519184316+ELvZeg', 296 'version' => 'tjh238.vledev2.open.ac.uk+110519184317+exx1Bm', 297 'hidden' => '0', 298 'timecreated' => '1305830596', 299 'timemodified' => '1305830596', 300 'createdby' => '2', 301 'modifiedby' => '2', 302 'maxmark' => '1.0000000', 303 'options' => (object) array( 304 'id' => '2', 305 'question' => '18', 306 'synchronize' => '0', 307 'single' => '0', 308 'shuffleanswers' => '1', 309 'correctfeedback' => '', 310 'correctfeedbackformat' => '0', 311 'partiallycorrectfeedback' => '', 312 'partiallycorrectfeedbackformat' => '0', 313 'incorrectfeedback' => '', 314 'incorrectfeedbackformat' => '0', 315 'answernumbering' => 'abc', 316 'shownumcorrect' => '0', 317 'answers' => array( 318 28 => (object) array( 319 'id' => '28', 320 'question' => '18', 321 'answer' => '{a} + {b}', 322 'answerformat' => '0', 323 'fraction' => '1.0000000', 324 'feedback' => '', 325 'feedbackformat' => '1', 326 'tolerance' => '0.01', 327 'tolerancetype' => '1', 328 'correctanswerlength' => '2', 329 'correctanswerformat' => '1', 330 ), 331 ), 332 'units' => array( 333 0 => (object) array( 334 'id' => '9', 335 'question' => '18', 336 'multiplier' => 1, 337 'unit' => 'm', 338 ), 339 ), 340 'unitgradingtype' => '1', 341 'unitpenalty' => '0.5000000', 342 'showunits' => '0', 343 'unitsleft' => '0', 344 ), 345 'hints' => array( 346 ), 347 ); 348 $qsession = (object) array( 349 'id' => '100', 350 'attemptid' => '14', 351 'questionid' => '18', 352 'newest' => '269', 353 'newgraded' => '269', 354 'sumpenalty' => '0.3000000', 355 'manualcomment' => '', 356 'manualcommentformat' => '1', 357 'flagged' => '0', 358 ); 359 $qstates = array( 360 261 => (object) array( 361 'id' => '261', 362 'attempt' => '14', 363 'question' => '18', 364 'seq_number' => '0', 365 'answer' => 'dataset11-|||||', 366 'timestamp' => '1305830661', 367 'event' => '0', 368 'grade' => '0.0000000', 369 'raw_grade' => '0.0000000', 370 'penalty' => '0.0000000', 371 ), 372 265 => (object) array( 373 'id' => '265', 374 'attempt' => '14', 375 'question' => '18', 376 'seq_number' => '1', 377 'answer' => 'dataset11-9.6|||||', 378 'timestamp' => '1305830714', 379 'event' => '3', 380 'grade' => '0.5000000', 381 'raw_grade' => '0.5000000', 382 'penalty' => '0.1000000', 383 ), 384 266 => (object) array( 385 'id' => '266', 386 'attempt' => '14', 387 'question' => '18', 388 'seq_number' => '2', 389 'answer' => 'dataset11-9.6|||||m', 390 'timestamp' => '1305830722', 391 'event' => '3', 392 'grade' => '0.9000000', 393 'raw_grade' => '1.0000000', 394 'penalty' => '0.1000000', 395 ), 396 269 => (object) array( 397 'id' => '269', 398 'attempt' => '14', 399 'question' => '18', 400 'seq_number' => '3', 401 'answer' => 'dataset11-9.6|||||m', 402 'timestamp' => '1305830722', 403 'event' => '6', 404 'grade' => '0.9000000', 405 'raw_grade' => '1.0000000', 406 'penalty' => '0.1000000', 407 ), 408 ); 409 $this->loader->put_dataset_in_cache($question->id, 11, array('a' => '5.1', 'b' => '4.5')); 410 411 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); 412 413 $expectedqa = (object) array( 414 'behaviour' => 'adaptive', 415 'questionid' => 18, 416 'variant' => 11, 417 'maxmark' => 1.0000000, 418 'minfraction' => 0, 419 'maxfraction' => 1, 420 'flagged' => 0, 421 'questionsummary' => 'What is 5.1 m + 4.5 m? 422 423 _______________ 424 425 Remember to type a unit.', 426 'rightanswer' => '9.6 m', 427 'responsesummary' => '9.6 m', 428 'timemodified' => 1305830722, 429 'steps' => array( 430 0 => (object) array( 431 'sequencenumber' => 0, 432 'state' => 'todo', 433 'fraction' => null, 434 'timecreated' => 1305830661, 435 'userid' => 4, 436 'data' => array('_separators' => '.$,', 437 '_var_a' => '5.1', '_var_b' => '4.5'), 438 ), 439 1 => (object) array( 440 'sequencenumber' => 1, 441 'state' => 'todo', 442 'fraction' => 0.5, 443 'timecreated' => 1305830714, 444 'userid' => 4, 445 'data' => array('answer' => 9.6, '-_try' => 1, 446 '-_rawfraction' => 0.5, '-submit' => 1), 447 ), 448 2 => (object) array( 449 'sequencenumber' => 2, 450 'state' => 'todo', 451 'fraction' => 0.9, 452 'timecreated' => 1305830722, 453 'userid' => 4, 454 'data' => array('answer' => '9.6 m', '-_try' => 2, 455 '-_rawfraction' => 1, '-submit' => 1), 456 ), 457 3 => (object) array( 458 'sequencenumber' => 3, 459 'state' => 'gradedright', 460 'fraction' => 0.9, 461 'timecreated' => 1305830722, 462 'userid' => 4, 463 'data' => array('answer' => '9.6 m', '-_try' => 2, 464 '-_rawfraction' => 1, '-finish' => 1), 465 ), 466 ), 467 ); 468 469 $this->compare_qas($expectedqa, $qa); 470 } 471 472 public function test_calculated_adaptive_qsession103() { 473 $quiz = (object) array( 474 'id' => '4', 475 'course' => '2', 476 'name' => 'Calculated quiz', 477 'intro' => '', 478 'introformat' => '1', 479 'timeopen' => '0', 480 'timeclose' => '0', 481 'attempts' => '0', 482 'attemptonlast' => '0', 483 'grademethod' => '1', 484 'decimalpoints' => '2', 485 'questiondecimalpoints' => '-1', 486 'questionsperpage' => '1', 487 'shufflequestions' => '0', 488 'shuffleanswers' => '1', 489 'sumgrades' => '3.00000', 490 'grade' => '10.00000', 491 'timecreated' => '0', 492 'timemodified' => '1305648351', 493 'timelimit' => '0', 494 'password' => '', 495 'subnet' => '', 496 'popup' => '0', 497 'delay1' => '0', 498 'delay2' => '0', 499 'showuserpicture' => '0', 500 'showblocks' => '0', 501 'preferredbehaviour' => 'adaptive', 502 'reviewattempt' => '69888', 503 'reviewcorrectness' => '69888', 504 'reviewmarks' => '69888', 505 'reviewspecificfeedback' => '69888', 506 'reviewgeneralfeedback' => '69888', 507 'reviewrightanswer' => '69888', 508 'reviewoverallfeedback' => '4352', 509 ); 510 $attempt = (object) array( 511 'id' => '15', 512 'uniqueid' => '15', 513 'quiz' => '4', 514 'userid' => '3', 515 'attempt' => '1', 516 'sumgrades' => '0.70000', 517 'timestart' => '1305830744', 518 'timefinish' => '0', 519 'timemodified' => '1305830792', 520 'layout' => '16,0,17,0,18,0', 521 'preview' => '0', 522 ); 523 $question = (object) array( 524 'id' => '18', 525 'category' => '2', 526 'parent' => '0', 527 'name' => 'Calculated', 528 'questiontext' => '<p>What is {a} m + {b} m?</p><p>_______________</p><p>Remember to type a unit.</p>', 529 'questiontextformat' => '1', 530 'generalfeedback' => '', 531 'generalfeedbackformat' => '1', 532 'defaultmark' => '1.0000000', 533 'penalty' => '0.1', 534 'qtype' => 'calculated', 535 'length' => '1', 536 'stamp' => 'tjh238.vledev2.open.ac.uk+110519184316+ELvZeg', 537 'version' => 'tjh238.vledev2.open.ac.uk+110519184317+exx1Bm', 538 'hidden' => '0', 539 'timecreated' => '1305830596', 540 'timemodified' => '1305830596', 541 'createdby' => '2', 542 'modifiedby' => '2', 543 'maxmark' => '1.0000000', 544 'options' => (object) array( 545 'id' => '2', 546 'question' => '18', 547 'synchronize' => '0', 548 'single' => '0', 549 'shuffleanswers' => '1', 550 'correctfeedback' => '', 551 'correctfeedbackformat' => '0', 552 'partiallycorrectfeedback' => '', 553 'partiallycorrectfeedbackformat' => '0', 554 'incorrectfeedback' => '', 555 'incorrectfeedbackformat' => '0', 556 'answernumbering' => 'abc', 557 'shownumcorrect' => '0', 558 'answers' => array( 559 28 => (object) array( 560 'id' => '28', 561 'question' => '18', 562 'answer' => '{a} + {b}', 563 'answerformat' => '0', 564 'fraction' => '1.0000000', 565 'feedback' => '', 566 'feedbackformat' => '1', 567 'tolerance' => '0.01', 568 'tolerancetype' => '1', 569 'correctanswerlength' => '2', 570 'correctanswerformat' => '1', 571 ), 572 ), 573 'units' => array( 574 0 => (object) array( 575 'id' => '9', 576 'question' => '18', 577 'multiplier' => 1, 578 'unit' => 'm', 579 ), 580 ), 581 'unitgradingtype' => '1', 582 'unitpenalty' => '0.5000000', 583 'showunits' => '0', 584 'unitsleft' => '0', 585 ), 586 'hints' => array( 587 ), 588 ); 589 $qsession = (object) array( 590 'id' => '103', 591 'attemptid' => '15', 592 'questionid' => '18', 593 'newest' => '280', 594 'newgraded' => '279', 595 'sumpenalty' => '0.1000000', 596 'manualcomment' => '', 597 'manualcommentformat' => '1', 598 'flagged' => '0', 599 ); 600 $qstates = array( 601 272 => (object) array( 602 'id' => '272', 603 'attempt' => '15', 604 'question' => '18', 605 'seq_number' => '0', 606 'answer' => 'dataset1-|||||', 607 'timestamp' => '1305830744', 608 'event' => '0', 609 'grade' => '0.0000000', 610 'raw_grade' => '0.0000000', 611 'penalty' => '0.0000000', 612 ), 613 279 => (object) array( 614 'id' => '279', 615 'attempt' => '15', 616 'question' => '18', 617 'seq_number' => '1', 618 'answer' => 'dataset1-123|||||cm', 619 'timestamp' => '1305830775', 620 'event' => '3', 621 'grade' => '0.0000000', 622 'raw_grade' => '0.0000000', 623 'penalty' => '0.1000000', 624 ), 625 280 => (object) array( 626 'id' => '280', 627 'attempt' => '15', 628 'question' => '18', 629 'seq_number' => '2', 630 'answer' => 'dataset1-12.4|||||', 631 'timestamp' => '1305830787', 632 'event' => '2', 633 'grade' => '0.0000000', 634 'raw_grade' => '0.5000000', 635 'penalty' => '0.1000000', 636 ), 637 ); 638 $this->loader->put_dataset_in_cache($question->id, 1, array('a' => '9.9', 'b' => '2.5')); 639 640 $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); 641 642 $expectedqa = (object) array( 643 'behaviour' => 'adaptive', 644 'questionid' => 18, 645 'variant' => 1, 646 'maxmark' => 1.0000000, 647 'minfraction' => 0, 648 'maxfraction' => 1, 649 'flagged' => 0, 650 'questionsummary' => 'What is 9.9 m + 2.5 m? 651 652 _______________ 653 654 Remember to type a unit.', 655 'rightanswer' => '12.4 m', 656 'responsesummary' => '12.4', 657 'timemodified' => 1305830787, 658 'steps' => array( 659 0 => (object) array( 660 'sequencenumber' => 0, 661 'state' => 'todo', 662 'fraction' => null, 663 'timecreated' => 1305830744, 664 'userid' => 3, 665 'data' => array('_separators' => '.$,', 666 '_var_a' => '9.9', '_var_b' => '2.5'), 667 ), 668 1 => (object) array( 669 'sequencenumber' => 1, 670 'state' => 'todo', 671 'fraction' => 0, 672 'timecreated' => 1305830775, 673 'userid' => 3, 674 'data' => array('answer' => '123 cm', '-_try' => 1, 675 '-_rawfraction' => 0, '-submit' => 1), 676 ), 677 2 => (object) array( 678 'sequencenumber' => 2, 679 'state' => 'complete', 680 'fraction' => 0, 681 'timecreated' => 1305830787, 682 'userid' => 3, 683 'data' => array('answer' => '12.4'), 684 ), 685 ), 686 ); 687 688 $this->compare_qas($expectedqa, $qa); 689 } 690 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body