From d9d4ae5535b19ed0eacd69a0f07569ec18b2e156 Mon Sep 17 00:00:00 2001 From: Adeel Khan Date: Mon, 1 Jan 2018 18:04:32 +0500 Subject: [PATCH] Fix invalid certificate page for a11y and translation. Invalid certificate page has hardcoded lang='en' for html, that would cause a11y issue for other languages user. Some of screen reader text is not under translation. This patch would fix both issues. LEARNER-3110 --- .../certificates/tests/test_webview_views.py | 59 ++++++++++++++++++- lms/djangoapps/certificates/views/webview.py | 3 +- .../certificates/_about-accomplishments.html | 1 + lms/templates/certificates/_about-edx.html | 1 + .../certificates/_accomplishment-banner.html | 24 ++++---- .../certificates/_accomplishment-footer.html | 3 +- .../certificates/_accomplishment-header.html | 1 + .../_accomplishment-introduction.html | 1 + .../_accomplishment-rendering.html | 9 +-- .../certificates/accomplishment-base.html | 5 +- lms/templates/certificates/invalid.html | 3 +- lms/templates/certificates/server-error.html | 3 +- lms/templates/certificates/valid.html | 3 +- 13 files changed, 90 insertions(+), 26 deletions(-) diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index dd4cae91d4..81a256c801 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -11,6 +11,7 @@ from django.conf import settings from django.core.urlresolvers import reverse from django.test.client import Client, RequestFactory from django.test.utils import override_settings +from django.utils import translation from mock import patch import ddt @@ -41,6 +42,7 @@ from nose.plugins.attrib import attr from openedx.core.djangoapps.certificates.config import waffle from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.lib.tests.assertions.events import assert_event_matches +from openedx.core.djangolib.js_utils import js_escaped_string from student.roles import CourseStaffRole from student.tests.factories import CourseEnrollmentFactory, UserFactory from track.tests import EventTrackingTestCase @@ -273,8 +275,8 @@ class CertificatesViewsTests(CommonCertificatesTestCase): ('pfCertificationUrl', self.request.build_absolute_uri(test_url),), ]) self.assertIn( - self.linkedin_url.format(params=urlencode(params)), - response.content + js_escaped_string(self.linkedin_url.format(params=urlencode(params))), + response.content.decode('utf-8') ) @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) @@ -296,7 +298,7 @@ class CertificatesViewsTests(CommonCertificatesTestCase): ('pfCertificationUrl', 'http://' + settings.MICROSITE_TEST_HOSTNAME + test_url,), ]) self.assertIn( - self.linkedin_url.format(params=urlencode(params)), + js_escaped_string(self.linkedin_url.format(params=urlencode(params))), response.content ) @@ -655,6 +657,29 @@ class CertificatesViewsTests(CommonCertificatesTestCase): self.assertIn("Cannot Find Certificate", response.content) self.assertIn("We cannot find a certificate with this URL or ID number.", response.content) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + def test_html_lang_attribute_is_dynamic_for_invalid_certificate_html_view(self): + """ + Tests that Certificate HTML Web View's lang attribute is based on user language. + """ + self._add_course_certificates(count=1, signatory_count=2) + test_url = get_certificate_url( + user_id=self.user.id, + course_id=unicode(self.course.id) + ) + + self.cert.invalidate() + + user_language = 'fr' + self.client.cookies[settings.LANGUAGE_COOKIE] = user_language + response = self.client.get(test_url) + self.assertIn('', response.content) + + user_language = 'ar' + self.client.cookies[settings.LANGUAGE_COOKIE] = user_language + response = self.client.get(test_url) + self.assertIn('', response.content) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) def test_html_view_for_non_viewable_certificate_and_for_student_user(self): """ @@ -782,6 +807,34 @@ class CertificatesViewsTests(CommonCertificatesTestCase): self.assertNotIn('Signatory_Name 0', response.content) self.assertNotIn('Signatory_Title 0', response.content) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + def test_render_html_view_is_html_escaped(self): + test_certificates = [ + { + 'id': 0, + 'name': 'Certificate Name', + 'description': '', + 'course_title': '', + 'org_logo_path': '/t4x/orgX/testX/asset/org-logo-1.png', + 'signatories': [], + 'version': 1, + 'is_active': True + } + ] + + self.course.certificates = {'certificates': test_certificates} + self.course.cert_html_view_enabled = True + self.course.save() + self.store.update_item(self.course, self.user.id) + + test_url = get_certificate_url( + user_id=self.user.id, + course_id=unicode(self.course.id) + ) + response = self.client.get(test_url) + self.assertNotIn('