Skip to content

Commit

Permalink
MDL-72129 tool_brickfield: Ignore fa icons
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlkin committed Aug 14, 2024
1 parent a75365f commit d5feb55
Show file tree
Hide file tree
Showing 2 changed files with 25 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() {
foreach ($this->get_all_elements('i') as $element) {
// Ensure this is not a font awesome icon.
if ($element->hasAttribute('class') && strpos($element->getAttribute('class'), 'fa-') !== false) {
continue;
}
$this->add_report($element);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,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() {
$html = "<div><i class=\"fa fa-user\"></i><i>Hello there</i><i class=\"fa fa-address-book\"></i></div>";
$results = $this->get_checker_results($html);
$this->assertCount(1, $results);
}
}

0 comments on commit d5feb55

Please sign in to comment.