From 206b3c3bba96fc3a62637350fb9bfbae9a1703a9 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 5 Nov 2024 12:45:58 +0800 Subject: [PATCH 1/3] MDL-83634 tool_brickfield: Downgrade image alt text check's severity Given that * There is no formally defined limit for alt text length, * Current versions of screen readers can read alt texts longer than 125 characters, * Accessibility checkers like axe DevTools, WAVE, etc., do not raise errors or warnings about long image alt texts. This patch: - Downgrades the default severity for the `img_alt_is_too_long` check from `BA_TEST_SEVERE` to `BA_TEST_SUGGESTION`. - Updates the `checkdesc:imgaltistoolong` lang string to be more of a reminder/suggestion rather than an error. --- .../local/htmlchecker/common/checks/img_alt_is_too_long.php | 4 ---- admin/tool/brickfield/lang/en/tool_brickfield.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php index 7963e14947b..2e0f1ad172b 100644 --- a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php +++ b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php @@ -30,10 +30,6 @@ use tool_brickfield\local\htmlchecker\common\brickfield_accessibility_test; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class img_alt_is_too_long extends brickfield_accessibility_test { - - /** @var int The default severity code for this test. */ - public $defaultseverity = \tool_brickfield\local\htmlchecker\brickfield_accessibility::BA_TEST_SEVERE; - /** * The main check function. This is called by the parent class to actually check content. */ diff --git a/admin/tool/brickfield/lang/en/tool_brickfield.php b/admin/tool/brickfield/lang/en/tool_brickfield.php index ed0e4f27410..972427377b0 100644 --- a/admin/tool/brickfield/lang/en/tool_brickfield.php +++ b/admin/tool/brickfield/lang/en/tool_brickfield.php @@ -179,7 +179,7 @@ $string['checkdesc:headerh3'] = 'Headers following after H3 headers (the editor $string['checkdesc:headershavetext'] = 'A header needs to contain text to be perceivable.'; $string['checkdesc:iisnotused'] = 'Italic (i) elements should not be used; "em" should be used instead.'; $string['checkdesc:imgaltisdifferent'] = 'Image alt (alternative) text should not be the image filename.'; -$string['checkdesc:imgaltistoolong'] = 'Image alt (alternative) text should not be more than the maximum allowed (125) characters.'; +$string['checkdesc:imgaltistoolong'] = 'Ensure that the image alt (alternative) text is concise enough to describe the image.'; $string['checkdesc:imgaltnotemptyinanchor'] = 'Image alt (alternative) text should not be empty, especially when the image has a link going elsewhere.'; $string['checkdesc:imgaltnotplaceholder'] = 'Image alt (alternative) text should not be a simple placeholder text, such as "image".'; $string['checkdesc:imghasalt'] = 'Image alt (alternative) text should not be missing for image elements, unless purely decorative with no meaning.'; From 33a8062efdc7c425dc87539b3d2d9ff710834dd8 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 5 Nov 2024 15:17:17 +0800 Subject: [PATCH 2/3] MDL-83634 tool_brickfield: Increase the alt text limit to 750 characters This is consistent with the alt-text length limit of 750 characters in Moodle's editor. --- .../common/checks/img_alt_is_too_long.php | 2 +- .../common/checks/img_alt_is_too_long_test.php | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php index 2e0f1ad172b..21e2c2ce4b5 100644 --- a/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php +++ b/admin/tool/brickfield/classes/local/htmlchecker/common/checks/img_alt_is_too_long.php @@ -37,7 +37,7 @@ class img_alt_is_too_long extends brickfield_accessibility_test { global $alttextlengthlimit; foreach ($this->get_all_elements('img') as $img) { - $alttextlengthlimit = 125; + $alttextlengthlimit = 750; if ($img->hasAttribute('alt') && core_text::strlen($img->getAttribute('alt')) > $alttextlengthlimit) { $this->add_report($img); } diff --git a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php index c2472cb37f9..d780a2b76ad 100644 --- a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php +++ b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php @@ -64,21 +64,21 @@ EOD; */ public static function img_alt_text_provider(): array { return [ - 'Alt text <= 125 characters' => [ + 'Alt text <= 750 characters' => [ true, - str_repeat("Hello world!", 10), + str_repeat("Hello world!", 60), ], - 'Alt text > 125 characters' => [ + 'Alt text > 750 characters' => [ false, - str_repeat("Hello world!", 25), + str_repeat("Hello world!", 65), ], - 'Multi-byte alt text <= 125 characters' => [ + 'Multi-byte alt text <= 750 characters' => [ true, - str_repeat('こんにちは、世界!', 13), + str_repeat('こんにちは、世界!', 83), ], - 'Multi-byte alt text > 125 characters' => [ + 'Multi-byte alt text > 750 characters' => [ false, - str_repeat('こんにちは、世界!', 30), + str_repeat('こんにちは、世界!', 90), ], ]; } @@ -96,7 +96,7 @@ EOD; if ($expectedpass) { $this->assertEmpty($results); } else { - $this->assertTrue($results[0]->element->tagName === 'img'); + $this->assertEquals('img', $results[0]->element->tagName); } } } From aa7e06c0b8c3c9836e5bba0716386ded81c45a78 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Wed, 5 Mar 2025 14:19:38 +0800 Subject: [PATCH 3/3] MDL-83634 tool_brickfield: Test the image alt text check's severity --- .../common/checks/img_alt_is_too_long_test.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php index d780a2b76ad..74e17d46681 100644 --- a/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php +++ b/admin/tool/brickfield/tests/local/htmlchecker/common/checks/img_alt_is_too_long_test.php @@ -24,6 +24,8 @@ namespace tool_brickfield\local\htmlchecker\common\checks; +use tool_brickfield\local\htmlchecker\brickfield_accessibility; + defined('MOODLE_INTERNAL') || die(); require_once('all_checks.php'); @@ -99,4 +101,15 @@ EOD; $this->assertEquals('img', $results[0]->element->tagName); } } + + /** + * Test the severity of the {@see img_alt_is_too_long} check. + * + * @return void + */ + public function test_severity(): void { + $html = $this->get_test_html('Some alt text'); + $checker = new brickfield_accessibility($html, 'brickfield', 'string'); + $this->assertEquals(brickfield_accessibility::BA_TEST_SUGGESTION, $checker->get_test_severity(img_alt_is_too_long::class)); + } }