Skip to content

Commit

Permalink
MDL-82429 tool_brickfield: Process calculated fontsizes
Browse files Browse the repository at this point in the history
  • Loading branch information
x-iy committed Aug 7, 2024
1 parent 8a6e856 commit b7cf766
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ public function get_fontsize(string $fontsize): int {
$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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

/**
* 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';

Expand Down Expand Up @@ -226,6 +227,18 @@ class css_text_has_contrast_test extends all_checks {
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
*/
Expand Down Expand Up @@ -347,4 +360,20 @@ public function test_check_for_largerbold_pass(): void {
$results = $this->get_checker_results($this->largerboldpass);
$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);
}
}

0 comments on commit b7cf766

Please sign in to comment.