1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 18:04:43 +02:00

MDL-82429 tool_brickfield: Process calculated fontsizes

This commit is contained in:
david adamson 2024-07-10 14:41:29 +10:00
parent 67f5ee3cec
commit 29bdc66fc2
2 changed files with 32 additions and 4 deletions
admin/tool/brickfield
classes/local/htmlchecker/common
tests/local/htmlchecker/common/checks

@ -410,13 +410,13 @@ class brickfield_accessibility_color_test extends brickfield_accessibility_test
$pos3 = stripos($fontsize, 'px');
if ($pos1 !== false) {
$rem = substr($fontsize, 0, -3);
$newfontsize = $newfontsize * $rem;
$newfontsize = is_numeric($rem) ? $newfontsize * $rem : $newfontsize;
} else if ($pos2 !== false) {
$em = substr($fontsize, 0, -2);
$newfontsize = $newfontsize * $em;
$newfontsize = is_numeric($em) ? $newfontsize * $em : $newfontsize;
} else if ($pos3 !== false) {
$px = substr($fontsize, 0, -2);
$newfontsize = 0.75 * $px;
$newfontsize = is_numeric($px) ? 0.75 * $px : $newfontsize;
} else if (in_array($fontsize, array_keys($this->fontsizenames))) {
$newfontsize = $this->fontsizenames[$fontsize];
} else {

@ -32,7 +32,7 @@ require_once('all_checks.php');
* Class test_css_text_has_contrast_test
* @covers \tool_brickfield\local\htmlchecker\brickfield_accessibility
*/
class css_text_has_contrast_test extends all_checks {
final class css_text_has_contrast_test extends all_checks {
/** @var string The check type. */
protected $checktype = 'css_text_has_contrast';
@ -227,6 +227,18 @@ EOD;
This is contrasty enough.</p></body>
EOD;
/** @var string HTML with calculated size colour values. */
private $calculatedfail = <<<EOD
<body><p style="color:#EF0000; background-color:white; font-size: calc(0.90375rem + 0.045vw)">
This is not contrasty enough.</p></body>
EOD;
/** @var string HTML with calculated size colour values. */
private $calculatedpass = <<<EOD
<body><p style="color:#E60000; background-color:white; font-size: calc(0.90375rem + 0.045vw);">
This is contrasty enough.</p></body>
EOD;
/**
* Test for the area assign intro
*/
@ -458,4 +470,20 @@ EOD;
$results = $this->get_checker_results($html);
$this->assertEmpty($results);
}
/**
* Test for calculated (12pt) text with insufficient contrast of 4.49.
*/
public function test_check_for_calculated_fail(): void {
$results = $this->get_checker_results($this->calculatedfail);
$this->assertTrue($results[0]->element->tagName == 'p');
}
/**
* Test for calculated (12pt) text with sufficient contrast of 4.81.
*/
public function test_check_for_calculated_pass(): void {
$results = $this->get_checker_results($this->calculatedpass);
$this->assertEmpty($results);
}
}