From 8968b682be557f9c0129b62d047a11ac22022139 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 16 Apr 2025 12:32:31 +0100 Subject: [PATCH] MDL-85208 core: switch to ARIA attribute to label table headings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since ad14d58d visually hidden text within tables was displayed as block elements, which introduced artificial line breaks in headings for column names and sorting icons. Co-authored-by: Mikel Martín --- lib/table/classes/flexible_table.php | 10 ++++- .../tests/behat/multiple_grade_items.feature | 16 ++++---- .../overview/tests/behat/regrading.feature | 37 +++++++++---------- .../responses/tests/behat/basic.feature | 9 ++--- .../tests/behat/columnsortingeditor.feature | 2 +- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/lib/table/classes/flexible_table.php b/lib/table/classes/flexible_table.php index 8b2a955e835..4d17513ec3b 100644 --- a/lib/table/classes/flexible_table.php +++ b/lib/table/classes/flexible_table.php @@ -1693,15 +1693,21 @@ class flexible_table { $this->request[TABLE_VAR_DIR] => $sortorder, ]; + if ($order != SORT_ASC) { + $sortlabel = get_string('sortbyxreverse', 'moodle', $text); + } else { + $sortlabel = get_string('sortbyx', 'moodle', $text); + } + return html_writer::link( $this->baseurl->out(false, $params), - $text . get_accesshide(get_string('sortby') . ' ' . - $text . ' ' . $this->sort_order_name($isprimary, $order)), + $text, [ 'data-sortable' => $this->is_sortable($column), 'data-sortby' => $column, 'data-sortorder' => $sortorder, 'role' => 'button', + 'aria-label' => $sortlabel, ] ) . ' ' . $this->sort_icon($isprimary, $order); } diff --git a/mod/quiz/report/overview/tests/behat/multiple_grade_items.feature b/mod/quiz/report/overview/tests/behat/multiple_grade_items.feature index f9495995201..00bfcea48a2 100644 --- a/mod/quiz/report/overview/tests/behat/multiple_grade_items.feature +++ b/mod/quiz/report/overview/tests/behat/multiple_grade_items.feature @@ -41,14 +41,12 @@ Feature: Grades report for a quiz with multiple grade items | slot | response | | 1 | True | | 2 | False | - When I am on the "Test quiz" "mod_quiz > Grades report" page logged in as teacher - - Then "Lorna LottReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "50.00" - And "Lorna LottReview attempt" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "0.00" - And "Lorna LottReview attempt" row "Q. 2/50.00Sort by Q. 2/50.00 Ascending" column of "attempts" table should contain "0.00" - And "Lorna LottReview attempt" row "Reading/1.00Sort by Reading/1.00 Ascending" column of "attempts" table should contain "1.00" - And "Lorna LottReview attempt" row "Listening/1.00Sort by Listening/1.00 Ascending" column of "attempts" table should contain "0.00" - And I follow "Reading/1.00Sort by Reading/1.00 Ascending" + Then "Lorna LottReview attempt" row "Grade/100.00" column of "attempts" table should contain "50.00" + And "Lorna LottReview attempt" row "Q. 1/50.00" column of "attempts" table should contain "0.00" + And "Lorna LottReview attempt" row "Q. 2/50.00" column of "attempts" table should contain "0.00" + And "Lorna LottReview attempt" row "Reading/1.00" column of "attempts" table should contain "1.00" + And "Lorna LottReview attempt" row "Listening/1.00" column of "attempts" table should contain "0.00" # Main thing to check here is that sorting does not give a fatal error - And "Lorna LottReview attempt" row "Listening/1.00Sort by Listening/1.00 Ascending" column of "attempts" table should contain "0.00" + And I click on "//a[@aria-label='Sort by Reading/1.00 ascending']" "xpath_element" in the "attempts" "table" + And "Lorna LottReview attempt" row "Listening/1.00" column of "attempts" table should contain "0.00" diff --git a/mod/quiz/report/overview/tests/behat/regrading.feature b/mod/quiz/report/overview/tests/behat/regrading.feature index 4b6b1bfa0a7..0bdcd4e0fa1 100644 --- a/mod/quiz/report/overview/tests/behat/regrading.feature +++ b/mod/quiz/report/overview/tests/behat/regrading.feature @@ -92,10 +92,10 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Finished regrading (2/2)" And I should see "Regrade completed" And I press "Continue" - And "Student OneReview attempt" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "50.00/0.00" - And "Student TwoReview attempt" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "50.00/0.00" - And "Student OneReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "100.00/50.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/40.00" + And "Student OneReview attempt" row "Q. 1/50.00" column of "attempts" table should contain "50.00/0.00" + And "Student TwoReview attempt" row "Q. 1/50.00" column of "attempts" table should contain "50.00/0.00" + And "Student OneReview attempt" row "Grade/100.00" column of "attempts" table should contain "100.00/50.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/40.00" Scenario: Regrade selected attempts and selected questions. Given I am on the "Quiz for testing regrading" "mod_quiz > edit" page logged in as teacher @@ -123,8 +123,8 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Finished regrading (1/1)" And I should see "Regrade completed" And I press "Continue" - And "Student TwoReview attempt" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "50.00/0.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/40.00" + And "Student TwoReview attempt" row "Q. 1/50.00" column of "attempts" table should contain "50.00/0.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/40.00" Scenario: Dry-run all attempts, then regrade all attempts. Given I am on the "Quiz for testing regrading" "mod_quiz > edit" page logged in as teacher @@ -141,13 +141,12 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Finished regrading (2/2)" And I should see "Regrade completed" And I press "Continue" - And "Student One" row "Regrade" column of "attempts" table should not contain "Needed" And "Student TwoReview attempt" row "Regrade" column of "attempts" table should contain "Needed" # In the following, the first number is strike-through, and the second is not, but Behat can't see that. # At this point, it is showing what would change. - And "Student TwoReview attempt" row "Q. 2/50.00Sort by Q. 2/50.00 Ascending" column of "attempts" table should contain "40.00/25.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/75.00" + And "Student TwoReview attempt" row "Q. 2/50.00" column of "attempts" table should contain "40.00/25.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/75.00" And I press "Regrade attempts..." And I click on "Regrade now" "button" in the "Regrade" "dialogue" And I should see "Quiz for testing regrading" @@ -158,8 +157,8 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Quiz for testing regrading" And I should see "Overall number of students achieving grade ranges" # Now, both old-score strike-through and new score plain, are still shown, but now it indicates what did change. - And "Student TwoReview attempt" row "Q. 2/50.00Sort by Q. 2/50.00 Ascending" column of "attempts" table should contain "40.00/25.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/75.00" + And "Student TwoReview attempt" row "Q. 2/50.00" column of "attempts" table should contain "40.00/25.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/75.00" Scenario: Dry-run a full regrade, then regrade the commit regrade. Given I am on the "Quiz for testing regrading" "mod_quiz > edit" page logged in as teacher @@ -180,8 +179,8 @@ Feature: Regrading quiz attempts using the Grades report And "Student TwoReview attempt" row "Regrade" column of "attempts" table should contain "Needed" # In the following, the first number is strike-through, and the second is not, but Behat can't see that. # At this point, it is showing what would change. - And "Student TwoReview attempt" row "Q. 2/50.00Sort by Q. 2/50.00 Ascending" column of "attempts" table should contain "40.00/25.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/75.00" + And "Student TwoReview attempt" row "Q. 2/50.00" column of "attempts" table should contain "40.00/25.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/75.00" Then I should see "The last dry run of a regrade found that the regrade would change the marks for 1 questions in 1 attempts." And I press "Commit regrade" And I should see "Quiz for testing regrading" @@ -193,8 +192,8 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Quiz for testing regrading" And I should see "Overall number of students achieving grade ranges" # Now, both old-score strike-through and new score plain, are still shown, but now it indicates what did change. - And "Student TwoReview attempt" row "Q. 2/50.00Sort by Q. 2/50.00 Ascending" column of "attempts" table should contain "40.00/25.00" - And "Student TwoReview attempt" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "attempts" table should contain "90.00/75.00" + And "Student TwoReview attempt" row "Q. 2/50.00" column of "attempts" table should contain "40.00/25.00" + And "Student TwoReview attempt" row "Grade/100.00" column of "attempts" table should contain "90.00/75.00" And I should not see "The last dry run of a regrade found that the regrade would change the marks for 1 questions in 1 attempts." Scenario: Regrade all attempts works against quiz selected question version @@ -227,7 +226,7 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Regrade completed" And I press "Continue" Then "student1@example.com" row "Regrade" column of "attempts" table should contain "Done" - And "Student OneReview attempt" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "50.00/0.00" + And "Student OneReview attempt" row "Q. 1/50.00" column of "attempts" table should contain "50.00/0.00" And "Incorrect" "icon" should appear before "50.00/0.00" "text" Scenario: Regrade all attempts works against quiz selected latest question version @@ -267,7 +266,7 @@ Feature: Regrading quiz attempts using the Grades report And I should see "Finished regrading (1/1)" And I should see "Regrade completed" And I press "Continue" - Then "student3@example.com" row "Q. 1/50.00Sort by Q. 1/50.00 Ascending" column of "attempts" table should contain "50.00/0.00" + Then "student3@example.com" row "Q. 1/50.00" column of "attempts" table should contain "50.00/0.00" And "Incorrect" "icon" should appear before "50.00/0.00" "text" Scenario: Regrade attempts should always regrade against latest random question version @@ -300,12 +299,12 @@ Feature: Regrading quiz attempts using the Grades report And I set the field "Correct answer" to "False" And I press "id_submitbutton" And I navigate to "Results" in current page administration - And "student3@example.com" row "Q. 1/100.00Sort by Q. 1/100.00 Ascending" column of "attempts" table should contain "100.00" + And "student3@example.com" row "Q. 1/100.00" column of "attempts" table should contain "100.00" And "Correct" "icon" should be visible And I press "Regrade attempts..." And I click on "Regrade now" "button" in the "Regrade" "dialogue" And I should see "Finished regrading (1/1)" And I should see "Regrade completed" And I press "Continue" - Then "student3@example.com" row "Q. 1/100.00Sort by Q. 1/100.00 Ascending" column of "attempts" table should contain "100.00/0.00" + Then "student3@example.com" row "Q. 1/100.00" column of "attempts" table should contain "100.00/0.00" And "Incorrect" "icon" should be visible diff --git a/mod/quiz/report/responses/tests/behat/basic.feature b/mod/quiz/report/responses/tests/behat/basic.feature index 50b822b3430..d4aff3efa29 100644 --- a/mod/quiz/report/responses/tests/behat/basic.feature +++ b/mod/quiz/report/responses/tests/behat/basic.feature @@ -51,7 +51,6 @@ Feature: Basic use of the Responses report | slot | response | | 1 | 3.14 | And user "student1" has finished an attempt at quiz "Quiz 1" - When I am on the "Quiz 1" "mod_quiz > Responses report" page logged in as teacher Then I should see "Attempts: 1" And I should see "Student One" @@ -60,12 +59,12 @@ Feature: Basic use of the Responses report And I set the field "Which tries" to "All tries" And I should see "Response 1a" And I press "Show report" - And "Student OneReview attempt" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "1.0" + And "Student OneReview attempt" row "Response 1a" column of "responses" table should contain "1.0" And "Student OneReview attempt" row "Status" column of "responses" table should contain "" - And "Finished" row "Grade/100.00Sort by Grade/100.00 Ascending" column of "responses" table should contain "33.33" - And "Finished" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "3.14" + And "Finished" row "Grade/100.00" column of "responses" table should contain "33.33" + And "Finished" row "Response 1a" column of "responses" table should contain "3.14" And "Student Two" row "Status" column of "responses" table should contain "-" - And "Student Two" row "Response 1aSort by Response 1a Ascending" column of "responses" table should contain "-" + And "Student Two" row "Response 1a" column of "responses" table should contain "-" @javascript Scenario: Report does not allow strange combinations of options diff --git a/reportbuilder/tests/behat/columnsortingeditor.feature b/reportbuilder/tests/behat/columnsortingeditor.feature index e07eedcdd8f..87d4be3acf1 100644 --- a/reportbuilder/tests/behat/columnsortingeditor.feature +++ b/reportbuilder/tests/behat/columnsortingeditor.feature @@ -78,7 +78,7 @@ Feature: Manage custom report columns sorting And I click on "Switch to preview mode" "button" And "user02" "table_row" should appear before "user01" "table_row" # Custom sorting for the user. - And I click on "Sort by First name Ascending" "link" + And I click on "//a[@aria-label='Sort by First name ascending']" "xpath_element" in the "Users" "table" And "user01" "table_row" should appear before "user02" "table_row" # Switching back to edit mode should observe report config. And I click on "Switch to edit mode" "button"