Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * This file contains tests that walks a question through the manual graded 19 * behaviour. 20 * 21 * @package qbehaviour_manualgraded 22 * @copyright 2009 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once (__DIR__ . '/../../../engine/lib.php'); 31 require_once (__DIR__ . '/../../../engine/tests/helpers.php'); 32 33 34 /** 35 * Unit tests for the manual graded behaviour. 36 * 37 * @copyright 2009 The Open University 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthrough_test_base { 41 public function test_manual_graded_essay() { 42 global $PAGE; 43 44 // The current text editor depends on the users profile setting - so it needs a valid user. 45 $this->setAdminUser(); 46 // Required to init a text editor. 47 $PAGE->set_url('/'); 48 49 // Create an essay question. 50 $essay = test_question_maker::make_an_essay_question(); 51 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 52 53 // Check the right model is being used. 54 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 55 $this->slot)->get_behaviour_name()); 56 57 // Check the initial state. 58 $this->check_current_state(question_state::$todo); 59 $this->check_current_mark(null); 60 $this->check_current_output($this->get_contains_question_text_expectation($essay), 61 $this->get_does_not_contain_feedback_expectation()); 62 63 // Simulate some data submitted by the student. 64 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 65 66 // Verify. 67 $this->check_current_state(question_state::$complete); 68 $this->check_current_mark(null); 69 $this->check_current_output( 70 new question_contains_tag_with_attribute('textarea', 'name', 71 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 72 $this->get_does_not_contain_feedback_expectation()); 73 74 // Process the same data again, check it does not create a new step. 75 $numsteps = $this->get_step_count(); 76 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 77 $this->check_step_count($numsteps); 78 79 // Process different data, check it creates a new step. 80 $this->process_submission(array('answer' => '', 'answerformat' => FORMAT_HTML)); 81 $this->check_step_count($numsteps + 1); 82 $this->check_current_state(question_state::$todo); 83 84 // Change back, check it creates a new step. 85 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 86 $this->check_step_count($numsteps + 2); 87 88 // Finish the attempt. 89 $this->quba->finish_all_questions(); 90 91 // Verify. 92 $this->check_current_state(question_state::$needsgrading); 93 $this->check_current_mark(null); 94 $this->assertEquals('This is my wonderful essay!', 95 $this->quba->get_response_summary($this->slot)); 96 97 // Process a manual comment. 98 $this->manual_grade('Not good enough!', 10, FORMAT_HTML); 99 100 // Verify. 101 $this->check_current_state(question_state::$mangrright); 102 $this->check_current_mark(10); 103 $this->check_current_output( 104 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 105 106 // Now change the max mark for the question and regrade. 107 $this->quba->regrade_question($this->slot, true, 1); 108 109 // Verify. 110 $this->check_current_state(question_state::$mangrright); 111 $this->check_current_mark(1); 112 } 113 114 public function test_manual_graded_essay_not_answered() { 115 global $PAGE; 116 117 // The current text editor depends on the users profile setting - so it needs a valid user. 118 $this->setAdminUser(); 119 // Required to init a text editor. 120 $PAGE->set_url('/'); 121 122 // Create an essay question. 123 $essay = test_question_maker::make_an_essay_question(); 124 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 125 126 // Check the right model is being used. 127 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 128 $this->slot)->get_behaviour_name()); 129 130 // Check the initial state. 131 $this->check_current_state(question_state::$todo); 132 $this->check_current_mark(null); 133 $this->check_current_output($this->get_contains_question_text_expectation($essay), 134 $this->get_does_not_contain_feedback_expectation()); 135 136 // Finish the attempt. 137 $this->quba->finish_all_questions(); 138 139 // Verify. 140 $this->check_current_state(question_state::$gaveup); 141 $this->check_current_mark(null); 142 $this->assertEquals('', 143 $this->quba->get_response_summary($this->slot)); 144 145 // Process a manual comment. 146 $this->manual_grade('Not good enough!', 1, FORMAT_HTML); 147 148 // Verify. 149 $this->check_current_state(question_state::$mangrpartial); 150 $this->check_current_mark(1); 151 $this->check_current_output( 152 new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/')); 153 154 // Now change the max mark for the question and regrade. 155 $this->quba->regrade_question($this->slot, true, 1); 156 157 // Verify. 158 $this->check_current_state(question_state::$mangrpartial); 159 $this->check_current_mark(0.1); 160 } 161 162 public function test_manual_graded_truefalse() { 163 164 // Create a true-false question with correct answer true. 165 $tf = test_question_maker::make_question('truefalse', 'true'); 166 $this->start_attempt_at_question($tf, 'manualgraded', 2); 167 168 // Check the initial state. 169 $this->check_current_state(question_state::$todo); 170 $this->check_current_mark(null); 171 $this->check_current_output( 172 $this->get_contains_question_text_expectation($tf), 173 $this->get_does_not_contain_feedback_expectation()); 174 175 // Process a true answer and check the expected result. 176 $this->process_submission(array('answer' => 1)); 177 178 $this->check_current_state(question_state::$complete); 179 $this->check_current_mark(null); 180 $this->check_current_output( 181 $this->get_contains_tf_true_radio_expectation(true, true), 182 $this->get_does_not_contain_correctness_expectation(), 183 $this->get_does_not_contain_feedback_expectation()); 184 185 // Finish the attempt. 186 $this->quba->finish_all_questions(); 187 188 // Verify. 189 $this->check_current_state(question_state::$needsgrading); 190 $this->check_current_mark(null); 191 $this->check_current_output( 192 $this->get_does_not_contain_correctness_expectation(), 193 $this->get_does_not_contain_specific_feedback_expectation()); 194 195 // Process a manual comment. 196 $this->manual_grade('Not good enough!', 1, FORMAT_HTML); 197 198 $this->check_current_state(question_state::$mangrpartial); 199 $this->check_current_mark(1); 200 $this->check_current_output( 201 $this->get_does_not_contain_correctness_expectation(), 202 $this->get_does_not_contain_specific_feedback_expectation(), 203 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 204 } 205 206 public function test_manual_grade_ungraded_question() { 207 global $PAGE; 208 209 // The current text editor depends on the users profile setting - so it needs a valid user. 210 $this->setAdminUser(); 211 // Required to init a text editor. 212 $PAGE->set_url('/'); 213 214 // Create an essay question. 215 $essay = test_question_maker::make_an_essay_question(); 216 $this->start_attempt_at_question($essay, 'deferredfeedback', 0); 217 218 // Check the right model is being used. 219 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 220 $this->slot)->get_behaviour_name()); 221 222 // Check the initial state. 223 $this->check_current_state(question_state::$todo); 224 $this->check_current_mark(null); 225 $this->check_current_output($this->get_contains_question_text_expectation($essay), 226 $this->get_does_not_contain_feedback_expectation()); 227 228 // Simulate some data submitted by the student. 229 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 230 231 // Verify. 232 $this->check_current_state(question_state::$complete); 233 $this->check_current_mark(null); 234 $this->check_current_output( 235 new question_contains_tag_with_attribute('textarea', 'name', 236 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 237 $this->get_does_not_contain_feedback_expectation()); 238 239 // Finish the attempt. 240 $this->quba->finish_all_questions(); 241 242 // Verify. 243 $this->check_current_state(question_state::$needsgrading); 244 $this->check_current_mark(null); 245 $this->assertEquals('This is my wonderful essay!', 246 $this->quba->get_response_summary($this->slot)); 247 248 // Process a manual comment. Note: null mark is the whole point here. 249 $this->manual_grade('Not good enough!', null, FORMAT_HTML); 250 251 // Verify. 252 // I am pretty sure this next assertion is incorrect. We should change 253 // the question state to indicate that this quetion has now been commented 254 // on. However, that is tricky, because what if, after that, the mam mark 255 // for the qusetions is changed. So, for now, this assertion verifies 256 // the current behaviour. 257 $this->check_current_state(question_state::$needsgrading); 258 $this->check_current_mark(null); 259 $this->check_current_output( 260 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 261 } 262 263 public function test_manual_graded_ignore_repeat_sumbission() { 264 // Create an essay question. 265 $essay = test_question_maker::make_an_essay_question(); 266 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 267 268 // Check the right model is being used. 269 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 270 $this->slot)->get_behaviour_name()); 271 272 // Check the initial state. 273 $this->check_current_state(question_state::$todo); 274 $this->check_current_mark(null); 275 276 // Simulate some data submitted by the student. 277 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 278 279 // Verify. 280 $this->check_current_state(question_state::$complete); 281 $this->check_current_mark(null); 282 283 // Finish the attempt. 284 $this->quba->finish_all_questions(); 285 286 // Verify. 287 $this->check_current_state(question_state::$needsgrading); 288 $this->check_current_mark(null); 289 $this->assertEquals('This is my wonderful essay!', 290 $this->quba->get_response_summary($this->slot)); 291 292 // Process a blank manual comment. Ensure it does not change the state. 293 $numsteps = $this->get_step_count(); 294 $this->manual_grade('', '', FORMAT_HTML); 295 $this->check_step_count($numsteps); 296 $this->check_current_state(question_state::$needsgrading); 297 $this->check_current_mark(null); 298 299 // Process a comment, but with the mark blank. Should be recorded, but 300 // not change the mark. 301 $this->manual_grade('I am not sure what grade to award.', '', FORMAT_HTML); 302 $this->check_step_count($numsteps + 1); 303 $this->check_current_state(question_state::$needsgrading); 304 $this->check_current_mark(null); 305 $this->check_current_output( 306 new question_pattern_expectation('/' . 307 preg_quote('I am not sure what grade to award.', '/') . '/')); 308 309 // Now grade it. 310 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 311 $this->check_step_count($numsteps + 2); 312 $this->check_current_state(question_state::$mangrpartial); 313 $this->check_current_mark(9); 314 $this->check_current_output( 315 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/')); 316 317 // Process the same data again, and make sure it does not add a step. 318 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 319 $this->check_step_count($numsteps + 2); 320 $this->check_current_state(question_state::$mangrpartial); 321 $this->check_current_mark(9); 322 323 // Now set the mark back to blank. 324 $this->manual_grade('Actually, I am not sure any more.', '', FORMAT_HTML); 325 $this->check_step_count($numsteps + 3); 326 $this->check_current_state(question_state::$needsgrading); 327 $this->check_current_mark(null); 328 $this->check_current_output( 329 new question_pattern_expectation('/' . 330 preg_quote('Actually, I am not sure any more.', '/') . '/')); 331 332 $qa = $this->quba->get_question_attempt($this->slot); 333 $this->assertEquals('Commented: Actually, I am not sure any more.', 334 $qa->summarise_action($qa->get_last_step())); 335 } 336 337 public function test_manual_graded_ignore_repeat_sumbission_commas() { 338 // Create an essay question. 339 $essay = test_question_maker::make_an_essay_question(); 340 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 341 342 // Check the right model is being used. 343 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 344 $this->slot)->get_behaviour_name()); 345 346 // Check the initial state. 347 $this->check_current_state(question_state::$todo); 348 $this->check_current_mark(null); 349 350 // Simulate some data submitted by the student. 351 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 352 353 // Verify. 354 $this->check_current_state(question_state::$complete); 355 $this->check_current_mark(null); 356 357 // Finish the attempt. 358 $this->quba->finish_all_questions(); 359 360 // Verify. 361 $this->check_current_state(question_state::$needsgrading); 362 $this->check_current_mark(null); 363 $this->assertEquals('This is my wonderful essay!', 364 $this->quba->get_response_summary($this->slot)); 365 366 // Now grade it with a mark with a comma. 367 $numsteps = $this->get_step_count(); 368 $this->manual_grade('Pretty good!', '9,00000', FORMAT_HTML); 369 $this->check_step_count($numsteps + 1); 370 $this->check_current_state(question_state::$mangrpartial); 371 $this->check_current_mark(9); 372 $qa = $this->get_question_attempt(); 373 $this->assertEquals('Manually graded 9 with comment: Pretty good!', 374 $qa->summarise_action($qa->get_last_step())); 375 $this->check_current_output( 376 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/')); 377 378 // Process the same mark with a dot. Verify it does not add a new step. 379 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 380 $this->check_step_count($numsteps + 1); 381 $this->check_current_state(question_state::$mangrpartial); 382 $this->check_current_mark(9); 383 } 384 385 public function test_manual_graded_essay_can_grade_0() { 386 global $PAGE; 387 388 // The current text editor depends on the users profile setting - so it needs a valid user. 389 $this->setAdminUser(); 390 // Required to init a text editor. 391 $PAGE->set_url('/'); 392 393 // Create an essay question. 394 $essay = test_question_maker::make_an_essay_question(); 395 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 396 397 // Check the right model is being used. 398 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 399 $this->slot)->get_behaviour_name()); 400 401 // Check the initial state. 402 $this->check_current_state(question_state::$todo); 403 $this->check_current_mark(null); 404 $this->check_current_output($this->get_contains_question_text_expectation($essay), 405 $this->get_does_not_contain_feedback_expectation()); 406 407 // Simulate some data submitted by the student. 408 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 409 410 // Verify. 411 $this->check_current_state(question_state::$complete); 412 $this->check_current_mark(null); 413 $this->check_current_output( 414 new question_contains_tag_with_attribute('textarea', 'name', 415 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 416 $this->get_does_not_contain_feedback_expectation()); 417 418 // Finish the attempt. 419 $this->quba->finish_all_questions(); 420 421 // Verify. 422 $this->check_current_state(question_state::$needsgrading); 423 $this->check_current_mark(null); 424 $this->assertEquals('This is my wonderful essay!', 425 $this->quba->get_response_summary($this->slot)); 426 427 // Process a blank comment and a grade of 0. 428 $this->manual_grade('', 0, FORMAT_HTML); 429 430 // Verify. 431 $this->check_current_state(question_state::$mangrwrong); 432 $this->check_current_mark(0); 433 } 434 435 public function test_manual_graded_change_comment_format() { 436 global $PAGE; 437 438 // The current text editor depends on the users profile setting - so it needs a valid user. 439 $this->setAdminUser(); 440 // Required to init a text editor. 441 $PAGE->set_url('/'); 442 443 // Create an essay question. 444 $essay = test_question_maker::make_an_essay_question(); 445 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 446 447 // Simulate some data submitted by the student. 448 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 449 450 // Finish the attempt. 451 $this->quba->finish_all_questions(); 452 453 // Process an example comment and a grade of 0. 454 $this->manual_grade('example', 0, FORMAT_HTML); 455 // Verify the format is FORMAT_HTML. 456 $this->check_comment('example', FORMAT_HTML); 457 458 // Process the same grade and comment with different format. 459 $this->manual_grade('example', 0, FORMAT_MARKDOWN); 460 // Verify the format is FORMAT_MARKDOWN. 461 $this->check_comment('example', FORMAT_MARKDOWN); 462 } 463 464 public function test_manual_graded_respects_display_options() { 465 // This test is for MDL-43874. Manual comments were not respecting the 466 // Display options for feedback. 467 global $PAGE; 468 469 // The current text editor depends on the users profile setting - so it needs a valid user. 470 $this->setAdminUser(); 471 // Required to init a text editor. 472 $PAGE->set_url('/'); 473 474 // Create an essay question. 475 $essay = test_question_maker::make_an_essay_question(); 476 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 477 478 // Check the right model is being used. 479 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 480 $this->slot)->get_behaviour_name()); 481 482 // Check the initial state. 483 $this->check_current_state(question_state::$todo); 484 $this->check_current_mark(null); 485 $this->check_current_output($this->get_contains_question_text_expectation($essay), 486 $this->get_does_not_contain_feedback_expectation()); 487 488 // Simulate some data submitted by the student. 489 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 490 491 // Verify. 492 $this->check_current_state(question_state::$complete); 493 $this->check_current_mark(null); 494 $this->check_current_output( 495 new question_contains_tag_with_attribute('textarea', 'name', 496 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 497 $this->get_does_not_contain_feedback_expectation()); 498 499 // Finish the attempt. 500 $this->quba->finish_all_questions(); 501 502 // Verify. 503 $this->check_current_state(question_state::$needsgrading); 504 $this->check_current_mark(null); 505 $this->assertEquals('This is my wonderful essay!', 506 $this->quba->get_response_summary($this->slot)); 507 508 // Process a comment and a grade. 509 $this->manual_grade('This should only appear if the displya options allow it', 5, FORMAT_HTML); 510 511 // Verify. 512 $this->check_current_state(question_state::$mangrpartial); 513 $this->check_current_mark(5); 514 515 $this->displayoptions->manualcomment = question_display_options::HIDDEN; 516 $this->check_output_does_not_contain('This should only appear if the displya options allow it'); 517 $this->displayoptions->manualcomment = question_display_options::VISIBLE; 518 $this->check_output_contains('This should only appear if the displya options allow it'); 519 } 520 521 public function test_manual_graded_invalid_value_throws_exception() { 522 global $PAGE; 523 524 // The current text editor depends on the users profile setting - so it needs a valid user. 525 $this->setAdminUser(); 526 // Required to init a text editor. 527 $PAGE->set_url('/'); 528 529 // Create an essay question. 530 $essay = test_question_maker::make_an_essay_question(); 531 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 532 533 // Check the right model is being used. 534 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 535 $this->slot)->get_behaviour_name()); 536 537 // Check the initial state. 538 $this->check_current_state(question_state::$todo); 539 $this->check_current_mark(null); 540 $this->check_current_output($this->get_contains_question_text_expectation($essay), 541 $this->get_does_not_contain_feedback_expectation()); 542 543 // Simulate some data submitted by the student. 544 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 545 546 // Verify. 547 $this->check_current_state(question_state::$complete); 548 $this->check_current_mark(null); 549 $this->check_current_output( 550 new question_contains_tag_with_attribute('textarea', 'name', 551 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 552 $this->get_does_not_contain_feedback_expectation()); 553 554 // Finish the attempt. 555 $this->quba->finish_all_questions(); 556 557 // Verify. 558 $this->check_current_state(question_state::$needsgrading); 559 $this->check_current_mark(null); 560 $this->assertEquals('This is my wonderful essay!', 561 $this->quba->get_response_summary($this->slot)); 562 563 // Try to process a an invalid grade. 564 $this->expectException('coding_exception'); 565 $this->manual_grade('Comment', 'frog', FORMAT_HTML); 566 } 567 568 public function test_manual_graded_out_of_range_throws_exception() { 569 global $PAGE; 570 571 // The current text editor depends on the users profile setting - so it needs a valid user. 572 $this->setAdminUser(); 573 // Required to init a text editor. 574 $PAGE->set_url('/'); 575 576 // Create an essay question. 577 $essay = test_question_maker::make_an_essay_question(); 578 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 579 580 // Check the right model is being used. 581 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 582 $this->slot)->get_behaviour_name()); 583 584 // Check the initial state. 585 $this->check_current_state(question_state::$todo); 586 $this->check_current_mark(null); 587 $this->check_current_output($this->get_contains_question_text_expectation($essay), 588 $this->get_does_not_contain_feedback_expectation()); 589 590 // Simulate some data submitted by the student. 591 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 592 593 // Verify. 594 $this->check_current_state(question_state::$complete); 595 $this->check_current_mark(null); 596 $this->check_current_output( 597 new question_contains_tag_with_attribute('textarea', 'name', 598 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 599 $this->get_does_not_contain_feedback_expectation()); 600 601 // Finish the attempt. 602 $this->quba->finish_all_questions(); 603 604 // Verify. 605 $this->check_current_state(question_state::$needsgrading); 606 $this->check_current_mark(null); 607 $this->assertEquals('This is my wonderful essay!', 608 $this->quba->get_response_summary($this->slot)); 609 610 // Try to process a an invalid grade. 611 $this->expectException('coding_exception'); 612 $this->manual_grade('Comment', '10.1', FORMAT_HTML); 613 } 614 615 public function test_manual_graded_displays_proper_comment_format () { 616 617 global $PAGE; 618 619 // The current text editor depends on the users profile setting - so it needs a valid user. 620 $this->setAdminUser(); 621 // Required to init a text editor. 622 $PAGE->set_url('/'); 623 624 // Create an essay question. 625 $essay = test_question_maker::make_an_essay_question(); 626 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 627 628 // Check the right model is being used. 629 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 630 $this->slot)->get_behaviour_name()); 631 632 // Simulate some data submitted by the student. 633 $this->process_submission( 634 array( 635 'answer' => "A submission!", 636 'answerformat' => FORMAT_PLAIN 637 ) 638 ); 639 640 // Finish the attempt. 641 $this->quba->finish_all_questions(); 642 643 // Write a manual comment in markdown. 644 $this->manual_grade("*one\n*two\n*three\n", 10, FORMAT_MARKDOWN); 645 646 // Check that feedback contains the original markdown format. 647 $preg = '/<textarea [^>]+name="[^"]+-comment"[^>]+>\*one\n\*two\n\*three\n/'; 648 $this->displayoptions->manualcomment = question_display_options::EDITABLE; 649 $this->check_current_output( 650 new question_pattern_expectation($preg) 651 ); 652 } 653 654 public function test_manual_grading_reshows_exactly_the_mark_input() { 655 global $PAGE; 656 657 // The current text editor depends on the users profile setting - so it needs a valid user. 658 $this->setAdminUser(); 659 // Required to init a text editor. 660 $PAGE->set_url('/'); 661 662 // Create an essay question graded out of 15 and attempt it. 663 $essay = test_question_maker::make_an_essay_question(); 664 $this->start_attempt_at_question($essay, 'deferredfeedback', 15); 665 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 666 $this->quba->finish_all_questions(); 667 668 // Verify. 669 $this->check_current_state(question_state::$needsgrading); 670 $this->check_current_mark(null); 671 $this->assertEquals('This is my wonderful essay!', 672 $this->quba->get_response_summary($this->slot)); 673 674 // Try to process a grade where the score will be stored rounded. 675 $this->manual_grade('Comment', '5.0', FORMAT_HTML); 676 677 // Verify. 678 $this->check_current_state(question_state::$mangrpartial); 679 $this->check_current_mark(5); 680 $this->displayoptions->manualcomment = question_display_options::EDITABLE; 681 $this->render(); 682 $this->check_output_contains_text_input('-mark', '5.0'); 683 684 // Rescale what the question is worth, and verify the display. 685 $this->get_question_attempt()->set_max_mark(1); 686 $this->render(); 687 $this->check_output_contains_text_input('-mark', '0.3333333'); 688 } 689 690 public function test_manual_grading_history_display() { 691 global $PAGE; 692 693 // The current text editor depends on the users profile setting - so it needs a valid user. 694 $this->setAdminUser(); 695 // Required to init a text editor. 696 $PAGE->set_url('/'); 697 698 // Create an essay question graded out of 15 and attempt it. 699 $essay = test_question_maker::make_an_essay_question(); 700 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 701 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 702 $this->quba->finish_all_questions(); 703 704 // Verify. 705 $this->check_current_state(question_state::$needsgrading); 706 707 // Process an initial grade and comment. 708 $this->manual_grade('First comment', '5.0', FORMAT_HTML); 709 710 // Process a second grade and comment. 711 $this->manual_grade('Second comment', '7.0', FORMAT_HTML); 712 713 // Verify. 714 $this->check_current_state(question_state::$mangrpartial); 715 $this->check_current_mark(7); 716 $this->displayoptions->history = question_display_options::VISIBLE; 717 $this->render(); 718 $this->check_output_contains('Manually graded 5 with comment: First comment'); 719 $this->check_output_contains('Manually graded 7 with comment: Second comment'); 720 } 721 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body