[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/question/behaviour/manualgraded/tests/ -> walkthrough_test.php (source)

   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(dirname(__FILE__) . '/../../../engine/lib.php');
  32  require_once(dirname(__FILE__) . '/../../../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_graded_ignore_repeat_sumbission() {
 208          // Create an essay question.
 209          $essay = test_question_maker::make_an_essay_question();
 210          $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
 211  
 212          // Check the right model is being used.
 213          $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
 214                  $this->slot)->get_behaviour_name());
 215  
 216          // Check the initial state.
 217          $this->check_current_state(question_state::$todo);
 218          $this->check_current_mark(null);
 219  
 220          // Simulate some data submitted by the student.
 221          $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
 222  
 223          // Verify.
 224          $this->check_current_state(question_state::$complete);
 225          $this->check_current_mark(null);
 226  
 227          // Finish the attempt.
 228          $this->quba->finish_all_questions();
 229  
 230          // Verify.
 231          $this->check_current_state(question_state::$needsgrading);
 232          $this->check_current_mark(null);
 233          $this->assertEquals('This is my wonderful essay!',
 234                  $this->quba->get_response_summary($this->slot));
 235  
 236          // Process a blank manual comment. Ensure it does not change the state.
 237          $numsteps = $this->get_step_count();
 238          $this->manual_grade('', '', FORMAT_HTML);
 239          $this->check_step_count($numsteps);
 240          $this->check_current_state(question_state::$needsgrading);
 241          $this->check_current_mark(null);
 242  
 243          // Process a comment, but with the mark blank. Should be recorded, but
 244          // not change the mark.
 245          $this->manual_grade('I am not sure what grade to award.', '', FORMAT_HTML);
 246          $this->check_step_count($numsteps + 1);
 247          $this->check_current_state(question_state::$needsgrading);
 248          $this->check_current_mark(null);
 249          $this->check_current_output(
 250                  new question_pattern_expectation('/' .
 251                          preg_quote('I am not sure what grade to award.', '/') . '/'));
 252  
 253          // Now grade it.
 254          $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML);
 255          $this->check_step_count($numsteps + 2);
 256          $this->check_current_state(question_state::$mangrpartial);
 257          $this->check_current_mark(9);
 258          $this->check_current_output(
 259                  new question_pattern_expectation('/' . preg_quote('Pretty good!', '/') . '/'));
 260  
 261          // Process the same data again, and make sure it does not add a step.
 262          $this->manual_grade('Pretty good!', '9.00000', FORMAT_HTML);
 263          $this->check_step_count($numsteps + 2);
 264          $this->check_current_state(question_state::$mangrpartial);
 265          $this->check_current_mark(9);
 266  
 267          // Now set the mark back to blank.
 268          $this->manual_grade('Actually, I am not sure any more.', '', FORMAT_HTML);
 269          $this->check_step_count($numsteps + 3);
 270          $this->check_current_state(question_state::$needsgrading);
 271          $this->check_current_mark(null);
 272          $this->check_current_output(
 273                  new question_pattern_expectation('/' .
 274                          preg_quote('Actually, I am not sure any more.', '/') . '/'));
 275  
 276          $qa = $this->quba->get_question_attempt($this->slot);
 277          $this->assertEquals('Commented: Actually, I am not sure any more.',
 278                  $qa->summarise_action($qa->get_last_step()));
 279      }
 280  
 281      public function test_manual_graded_essay_can_grade_0() {
 282          global $PAGE;
 283  
 284          // The current text editor depends on the users profile setting - so it needs a valid user.
 285          $this->setAdminUser();
 286          // Required to init a text editor.
 287          $PAGE->set_url('/');
 288  
 289          // Create an essay question.
 290          $essay = test_question_maker::make_an_essay_question();
 291          $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
 292  
 293          // Check the right model is being used.
 294          $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
 295                  $this->slot)->get_behaviour_name());
 296  
 297          // Check the initial state.
 298          $this->check_current_state(question_state::$todo);
 299          $this->check_current_mark(null);
 300          $this->check_current_output($this->get_contains_question_text_expectation($essay),
 301                  $this->get_does_not_contain_feedback_expectation());
 302  
 303          // Simulate some data submitted by the student.
 304          $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
 305  
 306          // Verify.
 307          $this->check_current_state(question_state::$complete);
 308          $this->check_current_mark(null);
 309          $this->check_current_output(
 310                  new question_contains_tag_with_attribute('textarea', 'name',
 311                  $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
 312                  $this->get_does_not_contain_feedback_expectation());
 313  
 314          // Finish the attempt.
 315          $this->quba->finish_all_questions();
 316  
 317          // Verify.
 318          $this->check_current_state(question_state::$needsgrading);
 319          $this->check_current_mark(null);
 320          $this->assertEquals('This is my wonderful essay!',
 321                  $this->quba->get_response_summary($this->slot));
 322  
 323          // Process a blank comment and a grade of 0.
 324          $this->manual_grade('', 0, FORMAT_HTML);
 325  
 326          // Verify.
 327          $this->check_current_state(question_state::$mangrwrong);
 328          $this->check_current_mark(0);
 329      }
 330  
 331      public function test_manual_graded_respects_display_options() {
 332          // This test is for MDL-43874. Manual comments were not respecting the
 333          // Display options for feedback.
 334          global $PAGE;
 335  
 336          // The current text editor depends on the users profile setting - so it needs a valid user.
 337          $this->setAdminUser();
 338          // Required to init a text editor.
 339          $PAGE->set_url('/');
 340  
 341          // Create an essay question.
 342          $essay = test_question_maker::make_an_essay_question();
 343          $this->start_attempt_at_question($essay, 'deferredfeedback', 10);
 344  
 345          // Check the right model is being used.
 346          $this->assertEquals('manualgraded', $this->quba->get_question_attempt(
 347                  $this->slot)->get_behaviour_name());
 348  
 349          // Check the initial state.
 350          $this->check_current_state(question_state::$todo);
 351          $this->check_current_mark(null);
 352          $this->check_current_output($this->get_contains_question_text_expectation($essay),
 353                  $this->get_does_not_contain_feedback_expectation());
 354  
 355          // Simulate some data submitted by the student.
 356          $this->process_submission(array('answer' => 'This is my wonderful essay!', 'answerformat' => FORMAT_HTML));
 357  
 358          // Verify.
 359          $this->check_current_state(question_state::$complete);
 360          $this->check_current_mark(null);
 361          $this->check_current_output(
 362                  new question_contains_tag_with_attribute('textarea', 'name',
 363                  $this->quba->get_question_attempt($this->slot)->get_qt_field_name('answer')),
 364                  $this->get_does_not_contain_feedback_expectation());
 365  
 366          // Finish the attempt.
 367          $this->quba->finish_all_questions();
 368  
 369          // Verify.
 370          $this->check_current_state(question_state::$needsgrading);
 371          $this->check_current_mark(null);
 372          $this->assertEquals('This is my wonderful essay!',
 373                  $this->quba->get_response_summary($this->slot));
 374  
 375          // Process a comment and a grade.
 376          $this->manual_grade('This should only appear if the displya options allow it', 5, FORMAT_HTML);
 377  
 378          // Verify.
 379          $this->check_current_state(question_state::$mangrpartial);
 380          $this->check_current_mark(5);
 381  
 382          $this->displayoptions->manualcomment = question_display_options::HIDDEN;
 383          $this->check_output_does_not_contain('This should only appear if the displya options allow it');
 384          $this->displayoptions->manualcomment = question_display_options::VISIBLE;
 385          $this->check_output_contains('This should only appear if the displya options allow it');
 386      }
 387  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1