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 qtype_truefalse;
  18  
  19  use question_state;
  20  
  21  defined('MOODLE_INTERNAL') || die();
  22  
  23  global $CFG;
  24  require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
  25  
  26  
  27  /**
  28   * Walkthrough tests for the truefalse question type.
  29   *
  30   * @package    qtype_truefalse
  31   * @copyright  2011 The Open University
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class walkthrough_test extends \qbehaviour_walkthrough_test_base {
  35      public function test_false_right_does_not_show_feedback_when_not_answered() {
  36  
  37          // Create a true-false question with correct answer false.
  38          $tf = \test_question_maker::make_question('truefalse', 'false');
  39          $this->start_attempt_at_question($tf, 'deferredfeedback', 1);
  40  
  41          // Check the initial state.
  42          $this->check_current_state(question_state::$todo);
  43          $this->check_current_mark(null);
  44          $this->check_current_output(
  45                  $this->get_contains_question_text_expectation($tf),
  46                  $this->get_does_not_contain_feedback_expectation(),
  47                  new \question_contains_tag_with_contents('h4',
  48                          get_string('questiontext', 'question')));
  49          $this->assertEquals(get_string('false', 'qtype_truefalse'),
  50                  $this->quba->get_right_answer_summary($this->slot));
  51          $this->assertMatchesRegularExpression('/' . preg_quote($tf->questiontext, '/') . '/',
  52                  $this->quba->get_question_summary($this->slot));
  53          $this->assertNull($this->quba->get_response_summary($this->slot));
  54  
  55          // Finish the attempt without answering.
  56          $this->quba->finish_all_questions();
  57  
  58          // Verify.
  59          $this->check_current_state(question_state::$gaveup);
  60          $this->check_current_mark(null);
  61          $this->check_current_output(
  62                  $this->get_contains_tf_true_radio_expectation(false, false),
  63                  $this->get_contains_tf_false_radio_expectation(false, false),
  64  
  65                  // In particular, check that the false feedback is not displayed.
  66                  new \question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/'));
  67  
  68      }
  69  }