Skip to content

Commit

Permalink
fix: html-lang-valid should consider xml:lang (dequelabs#1152)
Browse files Browse the repository at this point in the history
This PR enhances `html-lang-valid` rule to allow `xml:lang` attribute.

Closes issue:
- dequelabs#1140

## Reviewer checks

**Required fields, to be filled out by PR reviewer(s)**
- [x] Follows the commit message policy, appropriate for next version
- [x] Has documentation updated, a DU ticket, or requires no documentation change
- [x] Includes new tests, or was unnecessary
- [x] Code is reviewed for security by: @WilcoFiers
  • Loading branch information
jeeyyy authored and Daniel Aasen committed Nov 1, 2018
1 parent 04854cf commit 988d7bf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rules/html-lang-valid.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "html-lang-valid",
"selector": "html[lang]",
"selector": "html[lang], html[xml\\:lang]",
"tags": [
"cat.language",
"wcag2a",
Expand Down
2 changes: 2 additions & 0 deletions test/integration/full/html-lang-valid/frames/level1.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<body>
<iframe id="frame2" src="level2.html"></iframe>
<iframe id="frame3" src="level2-a.html"></iframe>
<iframe id="frame4" src="level2-b.html"></iframe>
<iframe id="frame5" src="level2-c.html"></iframe>
</body>
</html>
11 changes: 11 additions & 0 deletions test/integration/full/html-lang-valid/frames/level2-b.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html id="pass2b" xml:lang="en">
<head>
<title>No lang test</title>
<meta charset="utf8">
<script src="/axe.js"></script>
</head>
<body>
Hi
</body>
</html>
11 changes: 11 additions & 0 deletions test/integration/full/html-lang-valid/frames/level2-c.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html id="violation2c" xml:lang="unknownLang">
<head>
<title>No lang test</title>
<meta charset="utf8">
<script src="/axe.js"></script>
</head>
<body>
Hi
</body>
</html>
3 changes: 3 additions & 0 deletions test/integration/full/html-lang-valid/html-lang-valid.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html id="ignored1">

<head>
<title>html-lang-valid test</title>
<meta charset="utf8">
Expand All @@ -16,10 +17,12 @@
var assert = chai.assert;
</script>
</head>

<body>
<iframe id="frame1" src="frames/level1.html"></iframe>
<div id="mocha"></div>
<script src="html-lang-valid.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>

</html>
28 changes: 24 additions & 4 deletions test/integration/full/html-lang-valid/html-lang-valid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe('html-lang-valid test', function() {
'use strict';

var results;

before(function(done) {
axe.testUtils.awaitNestedLoad(function() {
axe.run(
Expand All @@ -15,27 +17,37 @@ describe('html-lang-valid test', function() {
});

describe('violations', function() {
it('should find 2', function() {
assert.lengthOf(results.violations[0].nodes, 2);
it('should find 3', function() {
assert.lengthOf(results.violations[0].nodes, 3);
});

it('should find first level iframe', function() {
assert.deepEqual(results.violations[0].nodes[0].target, [
'#frame1',
'#violation1'
]);
});

it('should find second level iframe', function() {
assert.deepEqual(results.violations[0].nodes[1].target, [
'#frame1',
'#frame2',
'#violation2'
]);
});

it('should find #violation2c', function() {
assert.deepEqual(results.violations[0].nodes[2].target, [
'#frame1',
'#frame5',
'#violation2c'
]);
});
});

describe('passes', function() {
it('should find 1', function() {
assert.lengthOf(results.passes[0].nodes, 1);
it('should find 2', function() {
assert.lengthOf(results.passes[0].nodes, 2);
});

it('should find #pass1', function() {
Expand All @@ -45,5 +57,13 @@ describe('html-lang-valid test', function() {
'#pass1'
]);
});

it('should find #pass2b', function() {
assert.deepEqual(results.passes[0].nodes[1].target, [
'#frame1',
'#frame4',
'#pass2b'
]);
});
});
});

0 comments on commit 988d7bf

Please sign in to comment.