From c06b63113a9cbcb2a711663e2fcff3073587d3a5 Mon Sep 17 00:00:00 2001 From: hiendinh Date: Tue, 8 Dec 2020 14:54:19 +0700 Subject: [PATCH] MDL-69474 Accessibility: Profile image changes --- lib/outputrenderers.php | 21 +++++++++++---------- user/tests/behat/view_full_profile.feature | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 4b43557913c..15aaa8c72b5 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2526,14 +2526,11 @@ class core_renderer extends renderer_base { $user = $userpicture->user; $canviewfullnames = has_capability('moodle/site:viewfullnames', $this->page->context); + $alt = ''; if ($userpicture->alttext) { if (!empty($user->imagealt)) { $alt = $user->imagealt; - } else { - $alt = get_string('pictureof', '', fullname($user, $canviewfullnames)); } - } else { - $alt = ''; } if (empty($userpicture->size)) { @@ -2570,23 +2567,27 @@ class core_renderer extends renderer_base { $output .= fullname($userpicture->user, $canviewfullnames); } - // then wrap it in link if needed - if (!$userpicture->link) { - return $output; - } - if (empty($userpicture->courseid)) { $courseid = $this->page->course->id; } else { $courseid = $userpicture->courseid; } - if ($courseid == SITEID) { $url = new moodle_url('/user/profile.php', array('id' => $user->id)); } else { $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid)); } + // Then wrap it in link if needed. Also we don't wrap it in link if the link redirects to itself. + // It might not return page url in unit test. + if (PHPUNIT_TEST) { + if (!$userpicture->link ) { + return $output; + } + } else if (!$userpicture->link || $this->page->url == $url) { + return $output; + } + $attributes = array('href' => $url, 'class' => 'd-inline-block aabtn'); if (!$userpicture->visibletoscreenreaders) { $attributes['tabindex'] = '-1'; diff --git a/user/tests/behat/view_full_profile.feature b/user/tests/behat/view_full_profile.feature index e6cc8dfa837..59549fdea27 100644 --- a/user/tests/behat/view_full_profile.feature +++ b/user/tests/behat/view_full_profile.feature @@ -129,3 +129,19 @@ Feature: Access to full profiles of users And I log in as "student1" And I view the "Student 2" contact in the message area Then I should see "First access to site" + + @javascript + Scenario: Accessibility, users can not click on profile image when on user's profile page. + Given I log in as "admin" + And I am on "Course 1" course homepage + When I navigate to course participants + Then "//img[contains(@class, 'userpicture')]" "xpath_element" should exist + And "//a/child::img[contains(@class, 'userpicture')]" "xpath_element" should exist + When I follow "Teacher 1" + Then I should see "Teacher 1" + And "//img[contains(@class, 'userpicture')]" "xpath_element" should exist + And "//a/child::img[contains(@class, 'userpicture')]" "xpath_element" should not exist + When I follow "Full profile" + And I should see "Teacher 1" + Then "//img[contains(@class, 'userpicture')]" "xpath_element" should exist + And "//a/child::img[contains(@class, 'userpicture')]" "xpath_element" should not exist