Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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 qbehaviour_informationitem;
  18  
  19  use question_state;
  20  
  21  defined('MOODLE_INTERNAL') || die();
  22  
  23  global $CFG;
  24  require_once (__DIR__ . '/../../../engine/lib.php');
  25  require_once (__DIR__ . '/../../../engine/tests/helpers.php');
  26  
  27  
  28  /**
  29   * Unit tests for the information item behaviour.
  30   *
  31   * @package   qbehaviour_informationitem
  32   * @category  test
  33   * @copyright 2009 The Open University
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class walkthrough_test extends \qbehaviour_walkthrough_test_base {
  37      public function test_informationitem_feedback_description() {
  38  
  39          // Create a true-false question with correct answer true.
  40          $description = \test_question_maker::make_question('description');
  41          $this->start_attempt_at_question($description, 'deferredfeedback');
  42  
  43          // Check the initial state.
  44          $this->check_current_state(question_state::$todo);
  45          $this->check_current_mark(null);
  46          $this->check_current_output($this->get_contains_question_text_expectation($description),
  47                  $this->get_contains_hidden_expectation(
  48                          $this->quba->get_field_prefix($this->slot) . '-seen', 1),
  49                  $this->get_does_not_contain_feedback_expectation());
  50  
  51          // Check no hidden input when read-only.
  52          $this->displayoptions->readonly = true;
  53          $this->check_current_output($this->get_contains_question_text_expectation($description),
  54                  $this->get_does_not_contain_hidden_expectation(
  55                          $this->quba->get_field_prefix($this->slot) . '-seen', 1));
  56          $this->displayoptions->readonly = false;
  57  
  58          // Process a submission indicating this question has been seen.
  59          $this->process_submission(array('-seen' => 1));
  60  
  61          $this->check_current_state(question_state::$complete);
  62          $this->check_current_mark(null);
  63          $this->check_current_output($this->get_does_not_contain_correctness_expectation(),
  64                  new \question_no_pattern_expectation(
  65                  '/type=\"hidden\"[^>]*name=\"[^"]*seen\"|name=\"[^"]*seen\"[^>]*type=\"hidden\"/'),
  66                  $this->get_does_not_contain_feedback_expectation());
  67  
  68          // Finish the attempt.
  69          $this->quba->finish_all_questions();
  70  
  71          // Verify.
  72          $this->check_current_state(question_state::$finished);
  73          $this->check_current_mark(null);
  74          $this->check_current_output(
  75                  $this->get_contains_question_text_expectation($description),
  76                  $this->get_contains_general_feedback_expectation($description));
  77  
  78          // Process a manual comment.
  79          $this->manual_grade('Not good enough!', null, FORMAT_HTML);
  80  
  81          $this->check_current_state(question_state::$manfinished);
  82          $this->check_current_mark(null);
  83          $this->check_current_output(
  84                  new \question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/'));
  85  
  86          // Check that trying to process a manual comment with a grade causes an exception.
  87          $this->expectException('moodle_exception');
  88          $this->manual_grade('Not good enough!', 1, FORMAT_HTML);
  89      }
  90  }