Skip to content

Commit 3813cba

Browse files
lamtranblamtranb
andauthored
Questionnaire\Accessibility\Rate: The form controls within the table are not accessible (#505)
Co-authored-by: lamtranb <[email protected]>
1 parent cb07cc2 commit 3813cba

File tree

6 files changed

+82
-33
lines changed

6 files changed

+82
-33
lines changed

classes/question/rate.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class rate extends question {
2929
/** @var array $nameddegrees */
3030
public $nameddegrees = [];
3131

32+
/** @var int Row start position of the rate table. */
33+
public const ROW_START = 2;
34+
35+
/** @var int Column start position of the rate table. */
36+
public const COL_START = 2;
37+
3238
/**
3339
* The class constructor
3440
* @param int $id
@@ -319,22 +325,24 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
319325
$notcomplete = true;
320326
}
321327

322-
$row = 0;
328+
$rowstart = self::ROW_START;
323329
$choicetags->qelements['rows'] = [];
324330
foreach ($this->choices as $cid => $choice) {
325331
$cols = [];
326332
if (isset($choice->content)) {
327-
$row++;
328333
$str = 'q'."{$this->id}_$cid";
329334
$content = $choice->content;
335+
$rendercontent = format_text($choice->content, FORMAT_PLAIN);
330336
if ($this->osgood_rate_scale()) {
331337
list($content, $contentright) = array_merge(preg_split('/[|]/', $content), array(' '));
332338
}
333339
$cols[] = ['colstyle' => 'text-align: '.$textalign.';',
334340
'coltext' => format_text($content, FORMAT_HTML, ['noclean' => true]).'&nbsp;'];
335341

336342
$bg = 'c0 raterow';
343+
$hasnotansweredchoice = false;
337344
if (($nbchoices > 1) && !$this->no_duplicate_choices() && !$blankquestionnaire) {
345+
$hasnotansweredchoice = true;
338346
$checked = ' checked="checked"';
339347
$completeclass = 'notanswered';
340348
$title = '';
@@ -351,12 +359,15 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
351359
if (!empty($order)) {
352360
$colinput['onclick'] = $order;
353361
}
362+
$colinput['label'] = $this->set_label($rowstart, $rendercontent, self::COL_START,
363+
get_string('unanswered', 'questionnaire'));
354364
$cols[] = ['colstyle' => 'width:1%;', 'colclass' => $completeclass, 'coltitle' => $title,
355365
'colinput' => $colinput];
356366
}
357367
if ($nameddegrees > 0) {
358368
reset($this->nameddegrees);
359369
}
370+
$colstart = $hasnotansweredchoice ? self::COL_START + 1 : self::COL_START;
360371
for ($j = 1; $j <= $this->length + $this->has_na_column(); $j++) {
361372
if (!isset($collabel[$j])) {
362373
// If not using this value, continue.
@@ -389,18 +400,20 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
389400
if (!empty($order)) {
390401
$col['colinput']['onclick'] = $order;
391402
}
392-
$col['colinput']['label'] = 'Choice '.$collabel[$j].' for row '.format_text($content, FORMAT_PLAIN);
403+
$col['colinput']['label'] = $this->set_label($rowstart, $rendercontent, $colstart, $collabel[$j]);
393404
if ($bg == 'c0 raterow') {
394405
$bg = 'c1 raterow';
395406
} else {
396407
$bg = 'c0 raterow';
397408
}
409+
$colstart++;
398410
$cols[] = $col;
399411
}
400412
if ($this->osgood_rate_scale()) {
401413
$cols[] = ['coltext' => '&nbsp;'.format_text($contentright, FORMAT_HTML, ['noclean' => true])];
402414
}
403415
$choicetags->qelements['rows'][] = ['cols' => $cols];
416+
$rowstart++;
404417
}
405418
}
406419

@@ -1089,4 +1102,23 @@ public static function move_all_nameddegree_choices(int $surveyid = null) {
10891102
}
10901103
$ratequests->close();
10911104
}
1105+
1106+
/**
1107+
* Set label for per column inside rate table.
1108+
*
1109+
* @param int $rowposition
1110+
* @param string $choicetitle
1111+
* @param int $colposition
1112+
* @param string $choiceanswer
1113+
* @return string
1114+
*/
1115+
private function set_label(int $rowposition, string $choicetitle, int $colposition, string $choiceanswer): string {
1116+
$a = (object) [
1117+
'rowposition' => $rowposition,
1118+
'choicetitle' => $choicetitle,
1119+
'colposition' => $colposition,
1120+
'choiceanswer' => $choiceanswer,
1121+
];
1122+
return get_string('accessibility:rate:choice', 'questionnaire', $a);
1123+
}
10921124
}

lang/en/questionnaire.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26+
$string['accessibility:rate:choice'] = 'Row {$a->rowposition}, {$a->choicetitle}: Column {$a->colposition}, {$a->choiceanswer}.';
2627
$string['action'] = 'Action';
2728
$string['activityoverview'] = 'You have questionnaires that are due';
2829
$string['additionalinfo'] = 'Additional Info';
@@ -682,3 +683,4 @@
682683
$string['yourresponses'] = 'View your response(s)';
683684
$string['crontask'] = 'Questionnaire cleanup job';
684685
$string['nopermissions'] = 'Sorry, but you do not currently have permissions to view this page or perform this action.';
686+
$string['unanswered'] = 'Unanswered';

tests/behat/add_feedback.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ Feature: In questionnaire, personality tests can be constructed using feedback o
7979
Then I should see "Select one dropdown"
8080
And I set the field "Select one dropdown" to "Three"
8181
And I click on "Three" "radio"
82-
And I click on "Choice Three for row Cheese" "radio"
83-
And I click on "Choice Three for row Bread" "radio"
84-
And I click on "Choice Three for row Meat" "radio"
85-
And I click on "Choice Three for row Fruit" "radio"
82+
And I click on "Row 2, Cheese: Column 5, Three." "radio"
83+
And I click on "Row 3, Bread: Column 5, Three." "radio"
84+
And I click on "Row 4, Meat: Column 5, Three." "radio"
85+
And I click on "Row 5, Fruit: Column 5, Three." "radio"
8686
And I click on "Yes" "radio"
8787
And I press "Submit questionnaire"
8888
Then I should see "Thank you for completing this Questionnaire."
@@ -102,10 +102,10 @@ Feature: In questionnaire, personality tests can be constructed using feedback o
102102
Then I should see "Select one dropdown"
103103
And I set the field "Select one dropdown" to "One"
104104
And I click on "One" "radio"
105-
And I click on "Choice Two for row Cheese" "radio"
106-
And I click on "Choice Two for row Bread" "radio"
107-
And I click on "Choice Two for row Meat" "radio"
108-
And I click on "Choice Two for row Fruit" "radio"
105+
And I click on "Row 2, Cheese: Column 4, Two." "radio"
106+
And I click on "Row 3, Bread: Column 4, Two." "radio"
107+
And I click on "Row 4, Meat: Column 4, Two." "radio"
108+
And I click on "Row 5, Fruit: Column 4, Two." "radio"
109109
And I click on "Yes" "radio"
110110
And I press "Submit questionnaire"
111111
Then I should see "Thank you for completing this Questionnaire."

tests/behat/add_multi_feedback_with_sections.feature

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ Feature: In questionnaire, personality tests can be constructed using feedback o
117117
And I set the field "dropQ1" to "Three"
118118
Then I should not see "<span lang=\"en\" class=\"multilang\">Three</span>" in the "//select[@id='dropQ1']//option[4]" "xpath_element"
119119
And I click on "Three" "radio"
120-
And I click on "Choice Three for row Cheese" "radio"
121-
And I click on "Choice Three for row Bread" "radio"
122-
And I click on "Choice Three for row Meat" "radio"
123-
And I click on "Choice Three for row Fruit" "radio"
120+
And I click on "Row 2, Cheese: Column 5, Three." "radio"
121+
And I click on "Row 3, Bread: Column 5, Three." "radio"
122+
And I click on "Row 4, Meat: Column 5, Three." "radio"
123+
And I click on "Row 5, Fruit: Column 5, Three." "radio"
124124
And I click on "Yes" "radio"
125-
And I click on "Choice Two for row Clubs" "radio"
126-
And I click on "Choice Four for row Diamonds" "radio"
127-
And I click on "Choice Zero for row Hearts" "radio"
128-
And I click on "Choice Sixteen for row Spades" "radio"
125+
And I click on "Row 2, Clubs: Column 4, Two." "radio"
126+
And I click on "Row 3, Diamonds: Column 5, Four." "radio"
127+
And I click on "Row 4, Hearts: Column 3, Zero." "radio"
128+
And I click on "Row 5, Spades: Column 7, Sixteen." "radio"
129129
And I press "Submit questionnaire"
130130
Then I should see "Thank you for completing this Questionnaire."
131131
And I press "Continue"
@@ -147,15 +147,15 @@ Feature: In questionnaire, personality tests can be constructed using feedback o
147147
Then I should see "Select one dropdown"
148148
And I set the field "dropQ1" to "One"
149149
And I click on "One" "radio"
150-
And I click on "Choice Two for row Cheese" "radio"
151-
And I click on "Choice Two for row Bread" "radio"
152-
And I click on "Choice Two for row Meat" "radio"
153-
And I click on "Choice Two for row Fruit" "radio"
150+
And I click on "Row 2, Cheese: Column 4, Two." "radio"
151+
And I click on "Row 3, Bread: Column 4, Two." "radio"
152+
And I click on "Row 4, Meat: Column 4, Two." "radio"
153+
And I click on "Row 5, Fruit: Column 4, Two." "radio"
154154
And I click on "Yes" "radio"
155-
And I click on "Choice Zero for row Clubs" "radio"
156-
And I click on "Choice Two for row Diamonds" "radio"
157-
And I click on "Choice Four for row Hearts" "radio"
158-
And I click on "Choice Eight for row Spades" "radio"
155+
And I click on "Row 2, Clubs: Column 3, Zero." "radio"
156+
And I click on "Row 3, Diamonds: Column 4, Two." "radio"
157+
And I click on "Row 4, Hearts: Column 5, Four." "radio"
158+
And I click on "Row 5, Spades: Column 6, Eight." "radio"
159159
And I press "Submit questionnaire"
160160
Then I should see "Thank you for completing this Questionnaire."
161161
And I press "Continue"

tests/behat/rate_question_named.feature

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,22 @@ Feature: Rate scale questions can use names for degrees
4646
And I should see "I did not like"
4747
And I should see "Ehhh"
4848
And I should see "I liked"
49-
And I click on "Choice I liked for row Star Wars" "radio"
50-
And I click on "Choice I liked for row Casablanca" "radio"
51-
And I click on "Choice I liked for row Airplane" "radio"
49+
# Check Row 2 with correct labels.
50+
And "Row 2, Star Wars: Column 2, Unanswered." "radio" should exist
51+
And "Row 2, Star Wars: Column 3, I did not like." "radio" should exist
52+
And "Row 2, Star Wars: Column 4, Ehhh." "radio" should exist
53+
And "Row 2, Star Wars: Column 5, I liked." "radio" should exist
54+
# Check Row 3 with correct labels.
55+
And "Row 3, Casablanca: Column 2, Unanswered." "radio" should exist
56+
And "Row 3, Casablanca: Column 3, I did not like." "radio" should exist
57+
And "Row 3, Casablanca: Column 4, Ehhh." "radio" should exist
58+
And "Row 3, Casablanca: Column 5, I liked." "radio" should exist
59+
# Check Row 4 with correct labels.
60+
And "Row 4, Airplane: Column 2, Unanswered." "radio" should exist
61+
And "Row 4, Airplane: Column 3, I did not like." "radio" should exist
62+
And "Row 4, Airplane: Column 4, Ehhh." "radio" should exist
63+
And "Row 4, Airplane: Column 5, I liked." "radio" should exist
64+
And I click on "Row 2, Star Wars: Column 5, I liked." "radio"
65+
And I click on "Row 3, Casablanca: Column 5, I liked." "radio"
66+
And I click on "Row 4, Airplane: Column 5, I liked." "radio"
5267
And I press "Submit questionnaire"

tests/behat/rate_question_ranking.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Feature: Rate scale questions can be used to uniquely rank options
4242
And I navigate to "Answer the questions..." in current page administration
4343
Then I should see "Test questionnaire"
4444
And I should see "What are your top three movies?"
45-
And I click on "Choice 1 for row Star Wars" "radio"
46-
And I click on "Choice 2 for row Airplane" "radio"
47-
And I click on "Choice 3 for row Casablanca" "radio"
45+
And I click on "Row 2, Star Wars: Column 2, 1." "radio"
46+
And I click on "Row 4, Airplane: Column 3, 2." "radio"
47+
And I click on "Row 3, Casablanca: Column 4, 3." "radio"
4848
And I press "Submit questionnaire"

0 commit comments

Comments
 (0)