MDL-20636 truefalse qtype was showing the false feedback even when no response was given. #386

This commit is contained in:
Tim Hunt 2011-05-27 14:41:48 +01:00
parent 9199e7a569
commit 188e174457
3 changed files with 163 additions and 1 deletions

View file

@ -128,7 +128,7 @@ class qtype_truefalse_renderer extends qtype_renderer {
if ($response) { if ($response) {
return $question->format_text($question->truefeedback, $question->truefeedbackformat, return $question->format_text($question->truefeedback, $question->truefeedbackformat,
$qa, 'question', 'answerfeedback', $question->trueanswerid); $qa, 'question', 'answerfeedback', $question->trueanswerid);
} else { } else if ($response !== '') {
return $question->format_text($question->falsefeedback, $question->falsefeedbackformat, return $question->format_text($question->falsefeedback, $question->falsefeedbackformat,
$qa, 'question', 'answerfeedback', $question->falseanswerid); $qa, 'question', 'answerfeedback', $question->falseanswerid);
} }

View file

@ -0,0 +1,90 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Test helpers for the truefalse question type.
*
* @package qtype
* @subpackage truefalse
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Test helper class for the truefalse question type.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_truefalse_test_helper extends question_test_helper {
public function get_test_questions() {
return array('true', 'false');
}
/**
* Makes a truefalse question with correct answer true.
* @return qtype_truefalse_question
*/
public function make_truefalse_question_true() {
question_bank::load_question_definition_classes('truefalse');
$tf = new qtype_truefalse_question();
test_question_maker::initialise_a_question($tf);
$tf->name = 'True/false question';
$tf->questiontext = 'The answer is true.';
$tf->generalfeedback = 'You should have selected true.';
$tf->penalty = 1;
$tf->qtype = question_bank::get_qtype('truefalse');
$tf->rightanswer = true;
$tf->truefeedback = 'This is the right answer.';
$tf->falsefeedback = 'This is the wrong answer.';
$tf->truefeedbackformat = FORMAT_HTML;
$tf->falsefeedbackformat = FORMAT_HTML;
$tf->trueanswerid = 13;
$tf->falseanswerid = 14;
return $tf;
}
/**
* Makes a truefalse question with correct answer false.
* @return qtype_truefalse_question
*/
public function make_truefalse_question_false() {
question_bank::load_question_definition_classes('truefalse');
$tf = new qtype_truefalse_question();
test_question_maker::initialise_a_question($tf);
$tf->name = 'True/false question';
$tf->questiontext = 'The answer is false.';
$tf->generalfeedback = 'You should have selected false.';
$tf->penalty = 1;
$tf->qtype = question_bank::get_qtype('truefalse');
$tf->rightanswer = false;
$tf->truefeedback = 'This is the wrong answer.';
$tf->falsefeedback = 'This is the right answer.';
$tf->truefeedbackformat = FORMAT_HTML;
$tf->falsefeedbackformat = FORMAT_HTML;
$tf->trueanswerid = 13;
$tf->falseanswerid = 14;
return $tf;
}
}

View file

@ -0,0 +1,72 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains tests that walks a truefalse question through various
* behaviours.
*
* @package qtype
* @subpackage truefalse
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
/**
* Walkthrough tests for the truefalse question type.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base {
public function test_false_right_does_not_show_feedback_when_not_answered() {
// Create a true-false question with correct answer false.
$tf = test_question_maker::make_question('truefalse', 'false');
$this->start_attempt_at_question($tf, 'deferredfeedback', 1);
// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_question_text_expectation($tf),
$this->get_does_not_contain_feedback_expectation());
$this->assertEqual(get_string('false', 'qtype_truefalse'),
$this->quba->get_right_answer_summary($this->slot));
$this->assertPattern('/' . preg_quote($tf->questiontext) . '/',
$this->quba->get_question_summary($this->slot));
$this->assertNull($this->quba->get_response_summary($this->slot));
// Finish the attempt without answering.
$this->quba->finish_all_questions();
// Verify.
$this->check_current_state(question_state::$gaveup);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_tf_true_radio_expectation(false, false),
$this->get_contains_tf_false_radio_expectation(false, false),
// In particular, check that the false feedback is not displayed.
new NoPatternExpectation('/' . preg_quote($tf->falsefeedback) . '/'));
}
}