MDL-80279 core: Set new attributes for user profile initials

When the user does not have a profile photo and initials are displayed,
there is no alt text for the initials which causes accessibility
issues, so with this change I added the user's full name to the title
and aria-label attributes and I set a role='img' when the element span
is rendered.
This commit is contained in:
Pedro Jordao
2024-03-15 07:39:23 -03:00
parent a30f476d18
commit eac4b571ee
2 changed files with 13 additions and 4 deletions
+6 -3
View File
@@ -917,7 +917,8 @@ class user_test extends \advanced_testcase {
// Display profile picture.
$context = \context_system::instance();
// No image, show initials.
$this->assertStringContainsString("<span class=\"userinitials size-35\">JD</span></a>",
$this->assertStringContainsString(
"<span class=\"userinitials size-35\" title=\"John Doe\" aria-label=\"John Doe\" role=\"img\">JD</span></a>",
$OUTPUT->render(\core_user::get_profile_picture($user1, $context)));
// With Image.
$expectedimagesrc = $CFG->wwwroot . '/pluginfile.php/' . \context_user::instance($user2->id)->id .
@@ -927,12 +928,14 @@ class user_test extends \advanced_testcase {
// Display profile picture with options.
$options = ['size' => 50, 'includefullname' => true];
$this->assertStringContainsString("<span class=\"userinitials size-50\">JD</span>John Doe</a>",
$this->assertStringContainsString(
"<span class=\"userinitials size-50\" title=\"John Doe\" aria-label=\"John Doe\" role=\"img\">JD</span>John Doe</a>",
$OUTPUT->render(\core_user::get_profile_picture($user1, $context, $options)));
// Display profile picture with options, no link.
$options = ['link' => false];
$this->assertEquals("<span class=\"userinitials size-35\">JD</span>",
$this->assertEquals(
"<span class=\"userinitials size-35\" title=\"John Doe\" aria-label=\"John Doe\" role=\"img\">JD</span>",
$OUTPUT->render(\core_user::get_profile_picture($user1, $context, $options)));
}