raakt 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/raakt.rb CHANGED
@@ -44,10 +44,11 @@ module Raakt
44
44
  :missing_input_alt => "Missing alt attribute for image button with id/name '%s'.",
45
45
  :missing_input_alt_text => "Missing alt text for image button with id/name '%s'.",
46
46
  :missing_area_alt => "Missing alt attribute for area with id/name '%s'.",
47
- :missing_area_alt_text => "Missing alt text for area with id/name '%s'."
47
+ :missing_area_alt_text => "Missing alt text for area with id/name '%s'.",
48
+ :difficult_word => "Vocabulary: %s"
48
49
  }
49
50
 
50
- VERSION = "0.5.2"
51
+ VERSION = "0.5.4"
51
52
 
52
53
  class ErrorMessage
53
54
 
@@ -78,19 +79,21 @@ module Raakt
78
79
 
79
80
  class Test
80
81
 
81
- attr_accessor :html, :headers, :user_agent, :ignore_bi
82
+ attr_accessor :html, :headers, :ignore_bi, :wordlist
82
83
 
83
- def initialize(html=nil, headers=nil)
84
+ def initialize(html=nil, headers=nil, wordlist=nil)
84
85
  @html = html
85
86
  @headers = headers
87
+ @wordlist = wordlist
86
88
  self.doc = @html if html
87
89
  self.headers = @headers if headers
90
+ self.wordlist = @wordlist if wordlist
88
91
  @ignore_bi = false
89
92
  end
90
93
 
91
94
  # Set the HTML used in the test.
92
95
  def doc=(html)
93
- Hpricot.buffer_size = 262144 #Allow for asp.net bastard-sized viewstate attributes...
96
+ Hpricot.buffer_size = 524288 #Allow for asp.net bastard-sized viewstate attributes...
94
97
  @doc = Hpricot(html)
95
98
  end
96
99
 
@@ -226,7 +229,7 @@ module Raakt
226
229
 
227
230
  # Verify that the document has at least one h1 element.
228
231
  def check_has_heading
229
- return [ErrorMessage.new(:missing_heading)] if (@doc/'h1').empty?
232
+ return [ErrorMessage.new(:missing_heading)] if (@doc/"h1").empty?
230
233
  []
231
234
  end
232
235
 
@@ -257,7 +260,7 @@ module Raakt
257
260
  end
258
261
 
259
262
 
260
- # Verify that the document does not have any nested tabled. This is indicative of a table-based layout.
263
+ # Verify that the document does not have any nested tables. This is indicative of a table-based layout.
261
264
  def check_for_nested_tables
262
265
 
263
266
  messages = []
@@ -283,6 +286,7 @@ module Raakt
283
286
  hasth = false
284
287
  hasth = true unless (table/">tr>th").empty?
285
288
  hasth = true unless (table/">thead>tr>th").empty?
289
+ hasth = true unless (table/">tbody>tr>th").empty?
286
290
 
287
291
  messages << ErrorMessage.new(:missing_th, currenttable.to_s) unless hasth
288
292
 
@@ -418,8 +422,45 @@ module Raakt
418
422
  end.map { ErrorMessage.new(:has_meta_refresh) }
419
423
  end
420
424
 
425
+
426
+ def check_difficult_words
427
+ messages = []
428
+ if @wordlist
429
+
430
+ # get document text (and all title and ait attributes but remove blockquote and q elements)
431
+
432
+ # remove q and blockquotes
433
+ @doc.search("blockquote").remove
434
+ @doc.search("q").remove
435
+
436
+ doctext = @doc.inner_text
437
+
438
+ #add alt texts
439
+ @doc.search("*[@alt]").each { |item|
440
+ doctext += " " + item['alt']
441
+ doctext += ", "
442
+ }
443
+
444
+ #add title texts
445
+ @doc.search("*[@title]").each { |item|
446
+ doctext += " " + item['title']
447
+ doctext += ", "
448
+ }
449
+
450
+ @wordlist.each { |key, value|
451
+ re = Regexp.new("\\b" + key.sub(/ /, "\\s+") + "\\b", true)
452
+ if doctext =~ re
453
+ # loop over all keys in wordlist
454
+ messages << ErrorMessage.new(:difficult_word, value)
455
+ end
456
+ }
457
+
458
+
459
+ end
460
+ return messages
461
+ end
421
462
 
422
- #Utility methods
463
+ # Utility methods
423
464
 
424
465
  def headings
425
466
  headings = []
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Difficult words. Reticent and taciturn should be found</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p>He was reticent. This is the text for the first news item. <a href="/news1">Read more </a></p>
9
+ <h2><a href="/news2" title="This is the word taciturn in a title attribute">New sitem 2</a></h2>
10
+ <p>This is the text for the second news item. <a href="/news2">
11
+ Read more</a></p>
12
+ <h2><a href="/news1">New sitem 3</a></h2>
13
+ <p>This is the text for the third news item. <a href="/news3">Read
14
+ more</a></p>
15
+ <h2><a href="/news1">New sitem 4</a></h2>
16
+ <p>This is the text for the fourth news item. <a href="/news4">Read&nbsp;more</a></p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Difficult words, on ein the alt attribute</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p>This is the text for the first news item. <a href="/news1">Read more </a></p>
9
+ <h2><img src="/news2" alt="This is the word taciturn in an alt attribute">New sitem 2</h2>
10
+ <p>This is the text for the second news item. <a href="/news2">
11
+ Read more</a></p>
12
+ <h2><a href="/news1">New sitem 3</a></h2>
13
+ <p>This is the text for the third news item. <a href="/news3">Read
14
+ more</a></p>
15
+ <h2><a href="/news1">New sitem 4</a></h2>
16
+ <p>This is the text for the fourth news item. <a href="/news4">Read&nbsp;more</a></p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Difficult words, on in the title attribute</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p>This is the text for the first news item. <a href="/news1">Read more </a></p>
9
+ <h2><img src="/news2" alt="This is the word taciturn in an alt attribute">New sitem 2</h2>
10
+ <p title="And here is reticent.">This is the text for the second news item. <a href="/news2">
11
+ Read more</a></p>
12
+ <h2><a href="/news1">New sitem 3</a></h2>
13
+ <p>This is the text for the third news item. <a href="/news3">Read
14
+ more</a></p>
15
+ <h2><a href="/news1">New sitem 4</a></h2>
16
+ <p>This is the text for the fourth news item. <a href="/news4">Read&nbsp;more</a></p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Difficult words, on in the title attribute</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p>This is the text for the first news item. <a href="/news1">Read more </a></p>
9
+ <h2><img src="/news2" alt="This is the word taciturn and reticent in an alt attribute">New sitem 2</h2>
10
+ <h2><a href="/news1">New sitem 3</a></h2>
11
+ <p>This is the text for the third news item. <a href="/news3">Read
12
+ more</a></p>
13
+ <h2><a href="/news1">New sitem 4</a></h2>
14
+ <p>This is the text for the fourth news item. <a href="/news4">Read&nbsp;more</a></p>
15
+ </body>
16
+ </html>
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Words that are not in the list</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p>This is the superreticent text for the first news item. <a href="/news1">Read more </a></p>
9
+ <h2><img src="/news2" alt="">New sitem 2</h2>
10
+ <h2><a href="/news1">New sitem 3</a></h2>
11
+ <p>This is the text for the third news item. <a href="/news3">Read
12
+ more</a></p>
13
+ <h2><a href="/news1">New sitem 4</a></h2>
14
+ <p>This is the text for the fourth news item. <a href="/news4">Read&nbsp;more</a></p>
15
+ </body>
16
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <h1>Checking for a phrase.</h1>
7
+ <h2><a href="/news1">New sitem 1</a></h2>
8
+ <p><q>Reticent</q> he said. <a href="/news1">Read more </a></p>
9
+ <h2><img src="/news2" alt="">New sitem 2</h2>
10
+ <h2><a href="/news1">New sitem 3</a></h2>
11
+ <p>Here are some accented chars: "anhängiggöra". <a href="/news3">Read
12
+ more</a></p>
13
+ <h2><a href="/news1">New sitem 4</a></h2>
14
+ <blockquote>
15
+ <p>This is the word reticent inside of a blockquote.</p>
16
+ </blockquote>
17
+ </body>
18
+ </html>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>This is a document with some difficult words</title>
4
+ </head>
5
+ <body>
6
+ <p>This is the ReTicent text for the first news item. <a href="/news1">Read more </a></p>
7
+ </body>
8
+ </html>
data/tests/raakt_test.rb CHANGED
@@ -205,6 +205,9 @@ class RaaktTest < Test::Unit::TestCase
205
205
  @raakt.doc = data_tabledoc2
206
206
  assert_equal 2, @raakt.check_tables.length
207
207
 
208
+ @raakt.doc = data_tabledoc7
209
+ assert_equal 0, @raakt.check_tables.length
210
+
208
211
  # More accurate count here due to hpricot
209
212
  @raakt.doc = data_full_berg
210
213
  assert_equal 21, @raakt.check_tables.length
@@ -412,5 +415,98 @@ class RaaktTest < Test::Unit::TestCase
412
415
  @raakt.doc = data_xhtmldoc1
413
416
  assert_equal 0, @raakt.check_refresh.length
414
417
  end
418
+
419
+
420
+
421
+
422
+ def test_difficult_words_combinations
423
+ #words tat are part of other words should not be flagged
424
+ @raakt.wordlist = {
425
+ "reticent" => "Use a 'did not want to say' instead.",
426
+ "taciturn" => "Use a different phrase.",
427
+ }
428
+
429
+ @raakt.doc = data_difficult_words5
430
+ assert_equal 0, @raakt.check_difficult_words.length
431
+ end
432
+
433
+
434
+ def test_difficult_words_ignore_case
435
+ #words tat are part of other words should not be flagged
436
+ @raakt.wordlist = {
437
+ "reticent" => "Use a 'did not want to say' instead.",
438
+ }
439
+
440
+ @raakt.doc = data_difficult_words7
441
+ assert_equal 1, @raakt.check_difficult_words.length
442
+ end
443
+
444
+
445
+ def test_difficult_words_exclude_blockquoted_text
446
+ #words that are part of a blockquote should not be flagged
447
+ @raakt.wordlist = {
448
+ "reticent" => "Use a 'did not want to say' instead.",
449
+ }
450
+ @raakt.doc = data_difficult_words6
451
+ assert_equal 0, @raakt.check_difficult_words.length
452
+ end
453
+
454
+
455
+ def test_difficult_words_exclude_text_in_q_elements
456
+ #words that are part of a q-element should not be flagged
457
+ @raakt.wordlist = {
458
+ "reticent" => "Use a 'did not want to say' instead.",
459
+ }
460
+ @raakt.doc = data_difficult_words6
461
+ assert_equal 0, @raakt.check_difficult_words.length
462
+ end
463
+
464
+
465
+
466
+ def test_difficult_words_accented_chars
467
+ #Phrases
468
+ @raakt.wordlist = {
469
+ "anhängiggöra" => "Använd 'väcka/inleda' istället",
470
+ }
471
+
472
+ @raakt.doc = data_difficult_words6
473
+ assert_equal 1, @raakt.check_difficult_words.length
474
+ end
475
+
476
+
477
+ def test_difficult_words_phrases
478
+ #Phrases
479
+ @raakt.wordlist = {
480
+ "a phrase" => "Use something else instead.",
481
+ }
482
+
483
+ @raakt.doc = data_difficult_words6
484
+ assert_equal 1, @raakt.check_difficult_words.length
485
+ end
415
486
 
487
+
488
+ def test_difficult_words
489
+ @raakt.wordlist = {
490
+ "reticent" => "Use a 'did not want to say' instead.",
491
+ "taciturn" => "Use a different phrase.",
492
+ }
493
+
494
+ @raakt.doc = data_xhtmldoc1
495
+ assert_equal 0, @raakt.check_difficult_words.length
496
+
497
+ @raakt.doc = data_difficult_words1
498
+ assert_equal 2, @raakt.check_difficult_words.length
499
+
500
+ #Make sure text in alt attribute is found
501
+ @raakt.doc = data_difficult_words2
502
+ assert_equal 1, @raakt.check_difficult_words.length
503
+
504
+ #Make sure text in title attribute is found
505
+ @raakt.doc = data_difficult_words3
506
+ assert_equal 2, @raakt.check_difficult_words.length
507
+
508
+ @raakt.doc = data_difficult_words4
509
+ assert_equal 2, @raakt.check_difficult_words.length
510
+ end
511
+
416
512
  end
@@ -0,0 +1 @@
1
+ <table><tbody><tr><th>Fondkapital</th><td>227,5&nbsp;mdkr</td></tr></tbody></table>
metadata CHANGED
@@ -1,33 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: raakt
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
7
- date: 2007-03-31 00:00:00 +02:00
8
- summary: A toolkit to find accessibility issues in HTML documents.
9
- require_paths:
10
- - lib
11
- email: peter.krantzNODAMNSPAM@gmail.com
12
- homepage: http://raakt.rubyforge.org
13
- rubyforge_project: raakt
14
- description:
15
- autorequire: raakt
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 0.5.4
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Peter Krantz
8
+ autorequire: raakt
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-19 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.5"
24
+ version:
25
+ description:
26
+ email: peter.krantzNODAMNSPAM@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
31
33
  files:
32
34
  - lib/iso_language_codes.rb
33
35
  - lib/raakt.rb
@@ -37,6 +39,13 @@ files:
37
39
  - tests/bdoc.htm
38
40
  - tests/charset_nocharset_specified.htm
39
41
  - tests/charset_utf8.htm
42
+ - tests/difficult_words1.htm
43
+ - tests/difficult_words2.htm
44
+ - tests/difficult_words3.htm
45
+ - tests/difficult_words4.htm
46
+ - tests/difficult_words5.htm
47
+ - tests/difficult_words6.htm
48
+ - tests/difficult_words7.htm
40
49
  - tests/embeddoc1.htm
41
50
  - tests/empty.htm
42
51
  - tests/emptytitledoc.htm
@@ -90,28 +99,35 @@ files:
90
99
  - tests/tabledoc4.htm
91
100
  - tests/tabledoc5.htm
92
101
  - tests/tabledoc6.htm
102
+ - tests/tabledoc7.htm
93
103
  - tests/tablelayoutdoc.htm
94
104
  - tests/test_helper.rb
95
105
  - tests/xhtmldoc1.htm
96
- test_files:
97
- - tests/raakt_test.rb
106
+ has_rdoc: true
107
+ homepage: http://raakt.rubyforge.org
108
+ post_install_message:
98
109
  rdoc_options: []
99
110
 
100
- extra_rdoc_files: []
101
-
102
- executables: []
103
-
104
- extensions: []
105
-
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.2
118
+ version:
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ version:
106
125
  requirements: []
107
126
 
108
- dependencies:
109
- - !ruby/object:Gem::Dependency
110
- name: hpricot
111
- version_requirement:
112
- version_requirements: !ruby/object:Gem::Version::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: "0.5"
117
- version:
127
+ rubyforge_project: raakt
128
+ rubygems_version: 1.3.1
129
+ signing_key:
130
+ specification_version: 2
131
+ summary: A toolkit to find accessibility issues in HTML documents.
132
+ test_files:
133
+ - tests/raakt_test.rb