Skip to content

Commit

Permalink
MDL-29571 questions: improve class=accesshide screen-reader hints.
Browse files Browse the repository at this point in the history
This changes the hint that comes before the question text. There are
unit tests to verify the new behaviour.

(amended to fix comments)
  • Loading branch information
timhunt authored and stronk7 committed Oct 4, 2011
1 parent 9d1658a commit 7042a25
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
8 changes: 4 additions & 4 deletions question/engine/renderer.php
Expand Up @@ -77,16 +77,16 @@ public function question(question_attempt $qa, qbehaviour_renderer $behaviourout
$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),
Expand Down
1 change: 1 addition & 0 deletions question/type/description/lang/en/qtype_description.php
Expand Up @@ -30,3 +30,4 @@
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 changes: 4 additions & 0 deletions question/type/description/renderer.php
Expand Up @@ -40,4 +40,8 @@ public function formulation_and_controls(question_attempt $qa,
return html_writer::tag('div', $qa->get_question()->format_questiontext($qa),
array('class' => 'qtext'));
}

public function formulation_heading() {
return get_string('informationtext', 'qtype_description');
}
}
52 changes: 52 additions & 0 deletions question/type/description/simpletest/testwalkthrough.php
@@ -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 changes: 10 additions & 0 deletions question/type/rendererbase.php
Expand Up @@ -49,6 +49,16 @@ public function formulation_and_controls(question_attempt $qa,
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.
*
Expand Down
4 changes: 3 additions & 1 deletion question/type/truefalse/simpletest/testwalkthrough.php
Expand Up @@ -48,7 +48,9 @@ public function test_false_right_does_not_show_feedback_when_not_answered() {
$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) . '/',
Expand Down

0 comments on commit 7042a25

Please sign in to comment.