MDL-29571 questions: improve class=accesshide screen-reader hints.

This changes the hint that comes before the question text. There are
unit tests to verify the new behaviour.

(amended to fix comments)
This commit is contained in:
Tim Hunt
2011-10-04 11:53:07 +02:00
committed by Eloy Lafuente (stronk7)
parent 5e69fe4971
commit 74969d8866
6 changed files with 74 additions and 5 deletions
+4 -4
View File
@@ -77,16 +77,16 @@ class core_question_renderer extends plugin_renderer_base {
$output .= html_writer::start_tag('div', array('class' => 'content'));
$output .= html_writer::tag('div',
$this->add_part_heading(get_string('questiontext', 'question'),
$this->formulation($qa, $behaviouroutput, $qtoutput, $options)),
$this->add_part_heading($qtoutput->formulation_heading(),
$this->formulation($qa, $behaviouroutput, $qtoutput, $options)),
array('class' => 'formulation'));
$output .= html_writer::nonempty_tag('div',
$this->add_part_heading(get_string('feedback', 'question'),
$this->outcome($qa, $behaviouroutput, $qtoutput, $options)),
$this->outcome($qa, $behaviouroutput, $qtoutput, $options)),
array('class' => 'outcome'));
$output .= html_writer::nonempty_tag('div',
$this->add_part_heading(get_string('comments', 'question'),
$this->manual_comment($qa, $behaviouroutput, $qtoutput, $options)),
$this->manual_comment($qa, $behaviouroutput, $qtoutput, $options)),
array('class' => 'comment'));
$output .= html_writer::nonempty_tag('div',
$this->response_history($qa, $behaviouroutput, $qtoutput, $options),
@@ -30,3 +30,4 @@ $string['description_help'] = 'A description is not really a question type. It s
The question text is displayed both during the attempt and on the review page. Any general feedback is displayed on the review page only.';
$string['descriptionsummary'] = 'This is not actually a question. Instead it is a way to add some instructions, rubric or other content to the activity. This is similar to the way that labels can be used to add content to the course page.';
$string['editingdescription'] = 'Editing a Description';
$string['informationtext'] = 'Information text';
+4
View File
@@ -40,4 +40,8 @@ class qtype_description_renderer extends qtype_renderer {
return html_writer::tag('div', $qa->get_question()->format_questiontext($qa),
array('class' => 'qtext'));
}
public function formulation_heading() {
return get_string('informationtext', 'qtype_description');
}
}
@@ -0,0 +1,52 @@
<?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 description question through its interaction model.
*
* @package qtype
* @subpackage description
* @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->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
class qtype_description_walkthrough_test extends qbehaviour_walkthrough_test_base {
public function test_informationitem_feedback_description() {
// Create a description question.
$description = test_question_maker::make_question('description');
$this->start_attempt_at_question($description, 'deferredfeedback');
// Check the initial state.
$this->assertEqual('informationitem',
$this->quba->get_question_attempt($this->slot)->get_behaviour_name());
$this->check_current_output(
new ContainsTagWithContents('h3', get_string('informationtext', 'qtype_description'))
);
// Further tests of the description qtype are in
// question/behaviour/informationitem/simpletest/testwalkthrough.php.
}
}
+10
View File
@@ -49,6 +49,16 @@ abstract class qtype_renderer extends plugin_renderer_base {
return $qa->get_question()->format_questiontext($qa);
}
/**
* In the question output there are some class="accesshide" headers to help
* screen-readers. This method returns the text to use for the heading above
* the formulation_and_controls section.
* @return string to use as the heading.
*/
public function formulation_heading() {
return get_string('questiontext', 'question');
}
/**
* Output hidden form fields to clear any wrong parts of the student's response.
*
@@ -48,7 +48,9 @@ class qtype_truefalse_walkthrough_test extends qbehaviour_walkthrough_test_base
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_question_text_expectation($tf),
$this->get_does_not_contain_feedback_expectation());
$this->get_does_not_contain_feedback_expectation(),
new ContainsTagWithContents('h3',
get_string('questiontext', 'question')));
$this->assertEqual(get_string('false', 'qtype_truefalse'),
$this->quba->get_right_answer_summary($this->slot));
$this->assertPattern('/' . preg_quote($tf->questiontext) . '/',