[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 22 * @subpackage manualgraded 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 (__DIR__ . '/../../../engine/lib.php'); 32 require_once (__DIR__ . '/../../../engine/tests/helpers.php'); 33 34 35 /** 36 * Unit tests for the manual graded behaviour. 37 * 38 * @copyright 2009 The Open University 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class qbehaviour_manualgraded_walkthrough_testcase extends qbehaviour_walkthrough_test_base { 42 public function test_manual_graded_essay() { 43 global $PAGE; 44 45 // The current text editor depends on the users profile setting - so it needs a valid user. 46 $this->setAdminUser(); 47 // Required to init a text editor. 48 $PAGE->set_url('/'); 49 50 // Create an essay question. 51 $essay = test_question_maker::make_an_essay_question(); 52 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 53 54 // Check the right model is being used. 55 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 56 $this->slot)->get_behaviour_name()); 57 58 // Check the initial state. 59 $this->check_current_state(question_state::$todo); 60 $this->check_current_mark(null); 61 $this->check_current_output($this->get_contains_question_text_expectation($essay), 62 $this->get_does_not_contain_feedback_expectation()); 63 64 // Simulate some data submitted by the student. 65 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 66 67 // Verify. 68 $this->check_current_state(question_state::$complete); 69 $this->check_current_mark(null); 70 $this->check_current_output( 71 new question_contains_tag_with_attribute('textarea', 'name', 72 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 73 $this->get_does_not_contain_feedback_expectation()); 74 75 // Process the same data again, check it does not create a new step. 76 $numsteps = $this->get_step_count(); 77 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 78 $this->check_step_count($numsteps); 79 80 // Process different data, check it creates a new step. 81 $this->process_submission(array('answer' => '', 'answerformat' => FORMAT_HTML)); 82 $this->check_step_count($numsteps + 1); 83 $this->check_current_state(question_state::$todo); 84 85 // Change back, check it creates a new step. 86 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 87 $this->check_step_count($numsteps + 2); 88 89 // Finish the attempt. 90 $this->quba->finish_all_questions(); 91 92 // Verify. 93 $this->check_current_state(question_state::$needsgrading); 94 $this->check_current_mark(null); 95 $this->assertEquals('This is my wonderful essay!', 96 $this->quba->get_response_summary($this->slot)); 97 98 // Process a manual comment. 99 $this->manual_grade('Not good enough!', 10, FORMAT_HTML); 100 101 // Verify. 102 $this->check_current_state(question_state::$mangrright); 103 $this->check_current_mark(10); 104 $this->check_current_output( 105 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 106 107 // Now change the max mark for the question and regrade. 108 $this->quba->regrade_question($this->slot, true, 1); 109 110 // Verify. 111 $this->check_current_state(question_state::$mangrright); 112 $this->check_current_mark(1); 113 } 114 115 public function test_manual_graded_essay_not_answered() { 116 global $PAGE; 117 118 // The current text editor depends on the users profile setting - so it needs a valid user. 119 $this->setAdminUser(); 120 // Required to init a text editor. 121 $PAGE->set_url('/'); 122 123 // Create an essay question. 124 $essay = test_question_maker::make_an_essay_question(); 125 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 126 127 // Check the right model is being used. 128 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 129 $this->slot)->get_behaviour_name()); 130 131 // Check the initial state. 132 $this->check_current_state(question_state::$todo); 133 $this->check_current_mark(null); 134 $this->check_current_output($this->get_contains_question_text_expectation($essay), 135 $this->get_does_not_contain_feedback_expectation()); 136 137 // Finish the attempt. 138 $this->quba->finish_all_questions(); 139 140 // Verify. 141 $this->check_current_state(question_state::$gaveup); 142 $this->check_current_mark(null); 143 $this->assertEquals('', 144 $this->quba->get_response_summary($this->slot)); 145 146 // Process a manual comment. 147 $this->manual_grade('Not good enough!', 1, FORMAT_HTML); 148 149 // Verify. 150 $this->check_current_state(question_state::$mangrpartial); 151 $this->check_current_mark(1); 152 $this->check_current_output( 153 new question_pattern_expectation('/' . preg_quote('Not good enough!') . '/')); 154 155 // Now change the max mark for the question and regrade. 156 $this->quba->regrade_question($this->slot, true, 1); 157 158 // Verify. 159 $this->check_current_state(question_state::$mangrpartial); 160 $this->check_current_mark(0.1); 161 } 162 163 public function test_manual_graded_truefalse() { 164 165 // Create a true-false question with correct answer true. 166 $tf = test_question_maker::make_question('truefalse', 'true'); 167 $this->start_attempt_at_question($tf, 'manualgraded', 2); 168 169 // Check the initial state. 170 $this->check_current_state(question_state::$todo); 171 $this->check_current_mark(null); 172 $this->check_current_output( 173 $this->get_contains_question_text_expectation($tf), 174 $this->get_does_not_contain_feedback_expectation()); 175 176 // Process a true answer and check the expected result. 177 $this->process_submission(array('answer' => 1)); 178 179 $this->check_current_state(question_state::$complete); 180 $this->check_current_mark(null); 181 $this->check_current_output( 182 $this->get_contains_tf_true_radio_expectation(true, true), 183 $this->get_does_not_contain_correctness_expectation(), 184 $this->get_does_not_contain_feedback_expectation()); 185 186 // Finish the attempt. 187 $this->quba->finish_all_questions(); 188 189 // Verify. 190 $this->check_current_state(question_state::$needsgrading); 191 $this->check_current_mark(null); 192 $this->check_current_output( 193 $this->get_does_not_contain_correctness_expectation(), 194 $this->get_does_not_contain_specific_feedback_expectation()); 195 196 // Process a manual comment. 197 $this->manual_grade('Not good enough!', 1, FORMAT_HTML); 198 199 $this->check_current_state(question_state::$mangrpartial); 200 $this->check_current_mark(1); 201 $this->check_current_output( 202 $this->get_does_not_contain_correctness_expectation(), 203 $this->get_does_not_contain_specific_feedback_expectation(), 204 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 205 } 206 207 public function test_manual_grade_ungraded_question() { 208 global $PAGE; 209 210 // The current text editor depends on the users profile setting - so it needs a valid user. 211 $this->setAdminUser(); 212 // Required to init a text editor. 213 $PAGE->set_url('/'); 214 215 // Create an essay question. 216 $essay = test_question_maker::make_an_essay_question(); 217 $this->start_attempt_at_question($essay, 'deferredfeedback', 0); 218 219 // Check the right model is being used. 220 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 221 $this->slot)->get_behaviour_name()); 222 223 // Check the initial state. 224 $this->check_current_state(question_state::$todo); 225 $this->check_current_mark(null); 226 $this->check_current_output($this->get_contains_question_text_expectation($essay), 227 $this->get_does_not_contain_feedback_expectation()); 228 229 // Simulate some data submitted by the student. 230 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 231 232 // Verify. 233 $this->check_current_state(question_state::$complete); 234 $this->check_current_mark(null); 235 $this->check_current_output( 236 new question_contains_tag_with_attribute('textarea', 'name', 237 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 238 $this->get_does_not_contain_feedback_expectation()); 239 240 // Finish the attempt. 241 $this->quba->finish_all_questions(); 242 243 // Verify. 244 $this->check_current_state(question_state::$needsgrading); 245 $this->check_current_mark(null); 246 $this->assertEquals('This is my wonderful essay!', 247 $this->quba->get_response_summary($this->slot)); 248 249 // Process a manual comment. Note: null mark is the whole point here. 250 $this->manual_grade('Not good enough!', null, FORMAT_HTML); 251 252 // Verify. 253 // I am pretty sure this next assertion is incorrect. We should change 254 // the question state to indicate that this quetion has now been commented 255 // on. However, that is tricky, because what if, after that, the mam mark 256 // for the qusetions is changed. So, for now, this assertion verifies 257 // the current behaviour. 258 $this->check_current_state(question_state::$needsgrading); 259 $this->check_current_mark(null); 260 $this->check_current_output( 261 new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); 262 } 263 264 public function test_manual_graded_ignore_repeat_sumbission() { 265 // Create an essay question. 266 $essay = test_question_maker::make_an_essay_question(); 267 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 268 269 // Check the right model is being used. 270 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 271 $this->slot)->get_behaviour_name()); 272 273 // Check the initial state. 274 $this->check_current_state(question_state::$todo); 275 $this->check_current_mark(null); 276 277 // Simulate some data submitted by the student. 278 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 279 280 // Verify. 281 $this->check_current_state(question_state::$complete); 282 $this->check_current_mark(null); 283 284 // Finish the attempt. 285 $this->quba->finish_all_questions(); 286 287 // Verify. 288 $this->check_current_state(question_state::$needsgrading); 289 $this->check_current_mark(null); 290 $this->assertEquals('This is my wonderful essay!', 291 $this->quba->get_response_summary($this->slot)); 292 293 // Process a blank manual comment. Ensure it does not change the state. 294 $numsteps = $this->get_step_count(); 295 $this->manual_grade('', '', FORMAT_HTML); 296 $this->check_step_count($numsteps); 297 $this->check_current_state(question_state::$needsgrading); 298 $this->check_current_mark(null); 299 300 // Process a comment, but with the mark blank. Should be recorded, but 301 // not change the mark. 302 $this->manual_grade('I am not sure what grade to award.', '', FORMAT_HTML); 303 $this->check_step_count($numsteps + 1); 304 $this->check_current_state(question_state::$needsgrading); 305 $this->check_current_mark(null); 306 $this->check_current_output( 307 new question_pattern_expectation('/' . 308 preg_quote('I am not sure what grade to award.', '/') . '/')); 309 310 // Now grade it. 311 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 312 $this->check_step_count($numsteps + 2); 313 $this->check_current_state(question_state::$mangrpartial); 314 $this->check_current_mark(9); 315 $this->check_current_output( 316 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/')); 317 318 // Process the same data again, and make sure it does not add a step. 319 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 320 $this->check_step_count($numsteps + 2); 321 $this->check_current_state(question_state::$mangrpartial); 322 $this->check_current_mark(9); 323 324 // Now set the mark back to blank. 325 $this->manual_grade('Actually, I am not sure any more.', '', FORMAT_HTML); 326 $this->check_step_count($numsteps + 3); 327 $this->check_current_state(question_state::$needsgrading); 328 $this->check_current_mark(null); 329 $this->check_current_output( 330 new question_pattern_expectation('/' . 331 preg_quote('Actually, I am not sure any more.', '/') . '/')); 332 333 $qa = $this->quba->get_question_attempt($this->slot); 334 $this->assertEquals('Commented: Actually, I am not sure any more.', 335 $qa->summarise_action($qa->get_last_step())); 336 } 337 338 public function test_manual_graded_ignore_repeat_sumbission_commas() { 339 // Create an essay question. 340 $essay = test_question_maker::make_an_essay_question(); 341 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 342 343 // Check the right model is being used. 344 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 345 $this->slot)->get_behaviour_name()); 346 347 // Check the initial state. 348 $this->check_current_state(question_state::$todo); 349 $this->check_current_mark(null); 350 351 // Simulate some data submitted by the student. 352 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 353 354 // Verify. 355 $this->check_current_state(question_state::$complete); 356 $this->check_current_mark(null); 357 358 // Finish the attempt. 359 $this->quba->finish_all_questions(); 360 361 // Verify. 362 $this->check_current_state(question_state::$needsgrading); 363 $this->check_current_mark(null); 364 $this->assertEquals('This is my wonderful essay!', 365 $this->quba->get_response_summary($this->slot)); 366 367 // Now grade it with a mark with a comma. 368 $numsteps = $this->get_step_count(); 369 $this->manual_grade('Pretty good!', '9,00000', FORMAT_HTML); 370 $this->check_step_count($numsteps + 1); 371 $this->check_current_state(question_state::$mangrpartial); 372 $this->check_current_mark(9); 373 $qa = $this->get_question_attempt(); 374 $this->assertEquals('Manually graded 9 with comment: Pretty good!', 375 $qa->summarise_action($qa->get_last_step())); 376 $this->check_current_output( 377 new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/')); 378 379 // Process the same mark with a dot. Verify it does not add a new step. 380 $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML); 381 $this->check_step_count($numsteps + 1); 382 $this->check_current_state(question_state::$mangrpartial); 383 $this->check_current_mark(9); 384 } 385 386 public function test_manual_graded_essay_can_grade_0() { 387 global $PAGE; 388 389 // The current text editor depends on the users profile setting - so it needs a valid user. 390 $this->setAdminUser(); 391 // Required to init a text editor. 392 $PAGE->set_url('/'); 393 394 // Create an essay question. 395 $essay = test_question_maker::make_an_essay_question(); 396 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 397 398 // Check the right model is being used. 399 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 400 $this->slot)->get_behaviour_name()); 401 402 // Check the initial state. 403 $this->check_current_state(question_state::$todo); 404 $this->check_current_mark(null); 405 $this->check_current_output($this->get_contains_question_text_expectation($essay), 406 $this->get_does_not_contain_feedback_expectation()); 407 408 // Simulate some data submitted by the student. 409 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 410 411 // Verify. 412 $this->check_current_state(question_state::$complete); 413 $this->check_current_mark(null); 414 $this->check_current_output( 415 new question_contains_tag_with_attribute('textarea', 'name', 416 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 417 $this->get_does_not_contain_feedback_expectation()); 418 419 // Finish the attempt. 420 $this->quba->finish_all_questions(); 421 422 // Verify. 423 $this->check_current_state(question_state::$needsgrading); 424 $this->check_current_mark(null); 425 $this->assertEquals('This is my wonderful essay!', 426 $this->quba->get_response_summary($this->slot)); 427 428 // Process a blank comment and a grade of 0. 429 $this->manual_grade('', 0, FORMAT_HTML); 430 431 // Verify. 432 $this->check_current_state(question_state::$mangrwrong); 433 $this->check_current_mark(0); 434 } 435 436 public function test_manual_graded_respects_display_options() { 437 // This test is for MDL-43874. Manual comments were not respecting the 438 // Display options for feedback. 439 global $PAGE; 440 441 // The current text editor depends on the users profile setting - so it needs a valid user. 442 $this->setAdminUser(); 443 // Required to init a text editor. 444 $PAGE->set_url('/'); 445 446 // Create an essay question. 447 $essay = test_question_maker::make_an_essay_question(); 448 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 449 450 // Check the right model is being used. 451 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 452 $this->slot)->get_behaviour_name()); 453 454 // Check the initial state. 455 $this->check_current_state(question_state::$todo); 456 $this->check_current_mark(null); 457 $this->check_current_output($this->get_contains_question_text_expectation($essay), 458 $this->get_does_not_contain_feedback_expectation()); 459 460 // Simulate some data submitted by the student. 461 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 462 463 // Verify. 464 $this->check_current_state(question_state::$complete); 465 $this->check_current_mark(null); 466 $this->check_current_output( 467 new question_contains_tag_with_attribute('textarea', 'name', 468 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 469 $this->get_does_not_contain_feedback_expectation()); 470 471 // Finish the attempt. 472 $this->quba->finish_all_questions(); 473 474 // Verify. 475 $this->check_current_state(question_state::$needsgrading); 476 $this->check_current_mark(null); 477 $this->assertEquals('This is my wonderful essay!', 478 $this->quba->get_response_summary($this->slot)); 479 480 // Process a comment and a grade. 481 $this->manual_grade('This should only appear if the displya options allow it', 5, FORMAT_HTML); 482 483 // Verify. 484 $this->check_current_state(question_state::$mangrpartial); 485 $this->check_current_mark(5); 486 487 $this->displayoptions->manualcomment = question_display_options::HIDDEN; 488 $this->check_output_does_not_contain('This should only appear if the displya options allow it'); 489 $this->displayoptions->manualcomment = question_display_options::VISIBLE; 490 $this->check_output_contains('This should only appear if the displya options allow it'); 491 } 492 493 public function test_manual_graded_invalid_value_throws_exception() { 494 global $PAGE; 495 496 // The current text editor depends on the users profile setting - so it needs a valid user. 497 $this->setAdminUser(); 498 // Required to init a text editor. 499 $PAGE->set_url('/'); 500 501 // Create an essay question. 502 $essay = test_question_maker::make_an_essay_question(); 503 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 504 505 // Check the right model is being used. 506 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 507 $this->slot)->get_behaviour_name()); 508 509 // Check the initial state. 510 $this->check_current_state(question_state::$todo); 511 $this->check_current_mark(null); 512 $this->check_current_output($this->get_contains_question_text_expectation($essay), 513 $this->get_does_not_contain_feedback_expectation()); 514 515 // Simulate some data submitted by the student. 516 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 517 518 // Verify. 519 $this->check_current_state(question_state::$complete); 520 $this->check_current_mark(null); 521 $this->check_current_output( 522 new question_contains_tag_with_attribute('textarea', 'name', 523 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 524 $this->get_does_not_contain_feedback_expectation()); 525 526 // Finish the attempt. 527 $this->quba->finish_all_questions(); 528 529 // Verify. 530 $this->check_current_state(question_state::$needsgrading); 531 $this->check_current_mark(null); 532 $this->assertEquals('This is my wonderful essay!', 533 $this->quba->get_response_summary($this->slot)); 534 535 // Try to process a an invalid grade. 536 $this->expectException('coding_exception'); 537 $this->manual_grade('Comment', 'frog', FORMAT_HTML); 538 } 539 540 public function test_manual_graded_out_of_range_throws_exception() { 541 global $PAGE; 542 543 // The current text editor depends on the users profile setting - so it needs a valid user. 544 $this->setAdminUser(); 545 // Required to init a text editor. 546 $PAGE->set_url('/'); 547 548 // Create an essay question. 549 $essay = test_question_maker::make_an_essay_question(); 550 $this->start_attempt_at_question($essay, 'deferredfeedback', 10); 551 552 // Check the right model is being used. 553 $this->assertEquals('manualgraded', $this->quba->get_question_attempt( 554 $this->slot)->get_behaviour_name()); 555 556 // Check the initial state. 557 $this->check_current_state(question_state::$todo); 558 $this->check_current_mark(null); 559 $this->check_current_output($this->get_contains_question_text_expectation($essay), 560 $this->get_does_not_contain_feedback_expectation()); 561 562 // Simulate some data submitted by the student. 563 $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML)); 564 565 // Verify. 566 $this->check_current_state(question_state::$complete); 567 $this->check_current_mark(null); 568 $this->check_current_output( 569 new question_contains_tag_with_attribute('textarea', 'name', 570 $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')), 571 $this->get_does_not_contain_feedback_expectation()); 572 573 // Finish the attempt. 574 $this->quba->finish_all_questions(); 575 576 // Verify. 577 $this->check_current_state(question_state::$needsgrading); 578 $this->check_current_mark(null); 579 $this->assertEquals('This is my wonderful essay!', 580 $this->quba->get_response_summary($this->slot)); 581 582 // Try to process a an invalid grade. 583 $this->expectException('coding_exception'); 584 $this->manual_grade('Comment', '10.1', FORMAT_HTML); 585 } 586 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |