Skip to content

Commit

Permalink
MDL-82812 tool_brickfield: Ignore fa icons
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlkin committed Oct 8, 2024
1 parent 67f5ee3 commit e5a5007
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace tool_brickfield\local\htmlchecker\common\checks;

use tool_brickfield\local\htmlchecker\common\brickfield_accessibility_tag_test;
use tool_brickfield\local\htmlchecker\common\brickfield_accessibility_test;

/**
* Brickfield accessibility HTML checker library.
Expand All @@ -28,11 +28,25 @@
* @copyright 2020 onward: Brickfield Education Labs, www.brickfield.ie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class i_is_not_used extends brickfield_accessibility_tag_test {
class i_is_not_used extends brickfield_accessibility_test {

/** @var int The default severity code for this test. */
public $defaultseverity = \tool_brickfield\local\htmlchecker\brickfield_accessibility::BA_TEST_SEVERE;

/** @var string The tag this test will fire on. */
public $tag = 'i';

/**
* Check for any i elements and flag them as errors
* while allowing font awesome icons to be used.
*/
public function check(): void {
foreach ($this->get_all_elements('i') as $element) {
// Ensure this is not a font awesome icon with aria-hidden.
if (str_contains($element->getAttribute('class'), 'fa-') && $element->getAttribute('aria-hidden') === 'true') {
continue;
}
$this->add_report($element);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

/**
* Class i_is_not_used_testcase
*
* @covers \tool_brickfield\local\htmlchecker\common\checks\i_is_not_used
*/
class i_is_not_used_test extends all_checks {
/** @var string Check type */
Expand Down Expand Up @@ -71,4 +73,13 @@ public function test_check(): void {
$results = $this->get_checker_results($this->htmlpass);
$this->assertEmpty($results);
}

/**
* Test for font awesome icon.
*/
public function test_fa_icon(): void {
$html = '<div><i class="fa fa-user"></i><i>Hello there</i><i class="fa fa-address-book" aria-hidden="true"></i></div>';
$results = $this->get_checker_results($html);
$this->assertCount(2, $results);
}
}

0 comments on commit e5a5007

Please sign in to comment.