Merge branch 'MDL-82812_master_toolbrickfieldfaicons' of https://github.com/brickfield/moodle

This commit is contained in:
Jun Pataleta 2024-10-10 10:13:37 +08:00
commit 57880e1b40
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 27 additions and 2 deletions

View File

@ -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.
@ -28,11 +28,25 @@ use tool_brickfield\local\htmlchecker\common\brickfield_accessibility_tag_test;
* @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);
}
}
}

View File

@ -30,6 +30,8 @@ require_once('all_checks.php');
/**
* 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 */
@ -71,4 +73,13 @@ EOD;
$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);
}
}