Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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 truefalse question through various
  19   * behaviours.
  20   *
  21   * @package    qtype
  22   * @subpackage truefalse
  23   * @copyright  2011 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($CFG->dirroot . '/question/engine/tests/helpers.php');
  32  
  33  
  34  /**
  35   * Walkthrough tests for the truefalse question type.
  36   *
  37   * @copyright  2011 The Open University
  38   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base {
  41      public function test_false_right_does_not_show_feedback_when_not_answered() {
  42  
  43          // Create a true-false question with correct answer false.
  44          $tf = test_question_maker::make_question('truefalse', 'false');
  45          $this->start_attempt_at_question($tf, 'deferredfeedback', 1);
  46  
  47          // Check the initial state.
  48          $this->check_current_state(question_state::$todo);
  49          $this->check_current_mark(null);
  50          $this->check_current_output(
  51                  $this->get_contains_question_text_expectation($tf),
  52                  $this->get_does_not_contain_feedback_expectation(),
  53                  new question_contains_tag_with_contents('h4',
  54                          get_string('questiontext', 'question')));
  55          $this->assertEquals(get_string('false', 'qtype_truefalse'),
  56                  $this->quba->get_right_answer_summary($this->slot));
  57          $this->assertRegExp('/' . preg_quote($tf->questiontext, '/') . '/',
  58                  $this->quba->get_question_summary($this->slot));
  59          $this->assertNull($this->quba->get_response_summary($this->slot));
  60  
  61          // Finish the attempt without answering.
  62          $this->quba->finish_all_questions();
  63  
  64          // Verify.
  65          $this->check_current_state(question_state::$gaveup);
  66          $this->check_current_mark(null);
  67          $this->check_current_output(
  68                  $this->get_contains_tf_true_radio_expectation(false, false),
  69                  $this->get_contains_tf_false_radio_expectation(false, false),
  70  
  71                  // In particular, check that the false feedback is not displayed.
  72                  new question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/'));
  73  
  74      }
  75  }