| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Accessibility.pm,v 1.3 2005/03/08 23:23:37 comdog Exp $ |
|
2
|
|
|
|
|
|
|
package Test::WWW::Accessibility; |
|
3
|
3
|
|
|
3
|
|
8147
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
136
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
18
|
use base qw( Exporter ); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
383
|
|
|
6
|
3
|
|
|
3
|
|
28
|
use vars qw( $VERSION @EXPORT_OK @EXPORT ); |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
297
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.11_01'; |
|
9
|
|
|
|
|
|
|
@EXPORT = qw( img_tags_have_alt_ok ); |
|
10
|
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
18
|
use Test::Builder; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
1134
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Test::WWW::Accessibility; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Test::More tests => 1; |
|
22
|
|
|
|
|
|
|
use Test::WWW::Accessibility; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $html = ...; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
img_tags_have_alt_ok( $html ); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# more functions to come |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module provides functions to check a web page for accessibility |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 Functions |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
All of these functions are exported by default. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item accessibility_ok( HTML ) |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This function will run several other of the tests and return a |
|
43
|
|
|
|
|
|
|
single answer. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub accessibility_ok |
|
50
|
0
|
|
|
0
|
1
|
0
|
{ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item img_tags_have_alt_ok( HTML [, NAME] ) |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
OK if all of the IMG tags in HTML have non-empty ALT values (so the |
|
57
|
|
|
|
|
|
|
empty string does not count!). |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
You can specify a name for the test as the optional, second argument. |
|
60
|
|
|
|
|
|
|
If you don't, the function supplies on for you. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub img_tags_have_alt_ok |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
3
|
|
100
|
3
|
1
|
5983
|
my $name = $_[1] || 'IMG tags have ALT attributes'; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# parse HTML to get all IMG tags |
|
69
|
3
|
|
|
|
|
9
|
my @imgs = &_get_img_tags; |
|
70
|
|
|
|
|
|
|
#$Test->diag( "Got " . @imgs . " image tags" ); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# count ALT tags |
|
73
|
3
|
100
|
|
|
|
11
|
my $alts = grep { exists $_->{alt} && $_->{alt} } @imgs; |
|
|
171
|
|
|
|
|
534
|
|
|
74
|
|
|
|
|
|
|
#$Test->diag( "Got " . $alts . " ALT tags" ); |
|
75
|
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
18
|
$Test->ok( @imgs == $alts, $name ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _get_img_tags |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
4
|
|
|
4
|
|
2099
|
my $html = shift; |
|
82
|
|
|
|
|
|
|
|
|
83
|
4
|
|
|
|
|
8
|
my @imgs = (); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $p = Test::WWW::Accessibility::ImgExtor->new( sub { |
|
86
|
228
|
|
|
228
|
|
257
|
my $tag = shift; |
|
87
|
228
|
50
|
|
|
|
476
|
return if $tag ne 'img'; |
|
88
|
228
|
|
|
|
|
2549
|
push @imgs, { @_ }; |
|
89
|
4
|
|
|
|
|
42
|
} ); |
|
90
|
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
68
|
$p->parse( $html ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
4
|
|
|
|
|
125
|
return @imgs; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item no_server_side_imagemaps_ok( HTML ) |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub no_server_side_imagemaps_ok |
|
103
|
0
|
|
|
0
|
1
|
0
|
{ |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item multimedia_has_caption_ok( HTML ) |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub multimedia_has_caption_ok |
|
113
|
0
|
|
|
0
|
1
|
0
|
{ |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item no_click_here_ok( HTML ) |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Link text is not "click here". |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub no_click_here_ok |
|
125
|
0
|
|
|
0
|
1
|
0
|
{ |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item unique_link_text_ok( HTML ) |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Link text for each URL is unique. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub unique_link_text_ok() |
|
137
|
0
|
|
|
0
|
1
|
0
|
{ |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item validates_ok( HTML ) |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
NOT YET IMPLEMENTED |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub validates_ok |
|
147
|
0
|
|
|
0
|
1
|
0
|
{ |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This source is part of a SourceForge project which always has the |
|
155
|
|
|
|
|
|
|
latest sources in CVS, as well as all of the previous releases. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
http://sourceforge.net/projects/brian-d-foy/ |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
If, for some reason, I disappear from the world, one of the other |
|
160
|
|
|
|
|
|
|
members of the project can shepherd this module appropriately. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
brian d foy, C<< >> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright 2004 brian d foy, All rights reserved. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
You can use this module under the same terms as |
|
171
|
|
|
|
|
|
|
Perl itself. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
package Test::WWW::Accessibility::ImgExtor; |
|
176
|
|
|
|
|
|
|
|
|
177
|
3
|
|
|
3
|
|
24
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
91
|
|
|
178
|
|
|
|
|
|
|
|
|
179
|
3
|
|
|
3
|
|
2690
|
use HTML::Tagset (); |
|
|
3
|
|
|
|
|
5114
|
|
|
|
3
|
|
|
|
|
77
|
|
|
180
|
3
|
|
|
3
|
|
18
|
use base qw( HTML::Parser ); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
2786
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
require HTML::Parser; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub new |
|
185
|
|
|
|
|
|
|
{ |
|
186
|
4
|
|
|
4
|
|
8
|
my($class, $cb, $base) = @_; |
|
187
|
4
|
|
|
|
|
78
|
my $self = $class->SUPER::new( |
|
188
|
|
|
|
|
|
|
start_h => ["_start_tag", "self,tagname,attr"], |
|
189
|
|
|
|
|
|
|
report_tags => [keys %HTML::Tagset::linkElements], |
|
190
|
|
|
|
|
|
|
); |
|
191
|
4
|
|
|
|
|
292
|
$self->{extractlink_cb} = $cb; |
|
192
|
4
|
50
|
|
|
|
13
|
if ($base) { |
|
193
|
0
|
|
|
|
|
0
|
require URI; |
|
194
|
0
|
|
|
|
|
0
|
$self->{extractlink_base} = URI->new($base); |
|
195
|
|
|
|
|
|
|
} |
|
196
|
4
|
|
|
|
|
9
|
$self; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub _start_tag |
|
200
|
|
|
|
|
|
|
{ |
|
201
|
568
|
|
|
568
|
|
858
|
my($self, $tag, $attr) = @_; |
|
202
|
|
|
|
|
|
|
|
|
203
|
568
|
|
|
|
|
764
|
my $base = $self->{extractlink_base}; |
|
204
|
568
|
|
|
|
|
1374
|
my $links = [ qw( src alt ) ]; |
|
205
|
568
|
50
|
|
|
|
1197
|
$links = [$links] unless ref $links; |
|
206
|
|
|
|
|
|
|
|
|
207
|
568
|
|
|
|
|
547
|
my @links; |
|
208
|
|
|
|
|
|
|
my $a; |
|
209
|
568
|
|
|
|
|
725
|
for $a (@$links) { |
|
210
|
1136
|
100
|
|
|
|
7462
|
next unless exists $attr->{$a}; |
|
211
|
399
|
50
|
|
|
|
1036
|
push(@links, $a, $base ? URI->new($attr->{$a}, $base)->abs($base) |
|
212
|
|
|
|
|
|
|
: $attr->{$a}); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
568
|
100
|
|
|
|
4155
|
return unless @links; |
|
215
|
228
|
|
|
|
|
463
|
$self->_found_link($tag, @links); |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub _found_link |
|
219
|
|
|
|
|
|
|
{ |
|
220
|
228
|
|
|
228
|
|
267
|
my $self = shift; |
|
221
|
228
|
|
|
|
|
287
|
my $cb = $self->{extractlink_cb}; |
|
222
|
228
|
50
|
|
|
|
539
|
if ($cb) { |
|
223
|
228
|
|
|
|
|
472
|
&$cb(@_); |
|
224
|
|
|
|
|
|
|
} else { |
|
225
|
0
|
|
|
|
|
|
push(@{$self->{'links'}}, [@_]); |
|
|
0
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
} |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# We override the parse_file() method so that we can clear the links |
|
230
|
|
|
|
|
|
|
# before we start a new file. |
|
231
|
|
|
|
|
|
|
sub parse_file |
|
232
|
|
|
|
|
|
|
{ |
|
233
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
234
|
0
|
|
|
|
|
|
delete $self->{'links'}; |
|
235
|
0
|
|
|
|
|
|
$self->SUPER::parse_file(@_); |
|
236
|
|
|
|
|
|
|
} |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |