mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
Merge branch 'MDL-83634-main' of https://github.com/junpataleta/moodle
This commit is contained in:
commit
db93e6943b
@ -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.
|
||||
*/
|
||||
@ -41,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);
|
||||
}
|
||||
|
@ -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.';
|
||||
|
@ -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');
|
||||
@ -64,21 +66,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 +98,18 @@ EOD;
|
||||
if ($expectedpass) {
|
||||
$this->assertEmpty($results);
|
||||
} else {
|
||||
$this->assertTrue($results[0]->element->tagName === 'img');
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user