# -*-perl-*-
use strict;
use Test::More 'no_plan';
use lib "$ENV{LJHOME}/cgi-bin";
use HTMLCleaner;
sub clean {
my $output = '';
my $cleaner = HTMLCleaner->new(
output => sub { $output .= $_[0] },
valid_stylesheet => sub { $_[0] eq 'http://www.example.com/valid.css' },
);
my $input = shift;
$cleaner->parse( $input );
$cleaner->eof;
return $output;
}
sub is_cleaned {
my $input = shift;
my $type = shift;
my $output = clean($input);
is( $output, '', $type );
}
sub not_cleaned {
my $input = shift;
my $type = shift;
my $output = clean($input);
is( $output, $input, $type );
}
not_cleaned(
'',
"html link rel=alternate"
);
not_cleaned(
'',
"html link with single valid rel attribute"
);
not_cleaned(
'',
"html link with two valid rel attributes"
);
not_cleaned(
'http://example.com/foo.html',
"rss style link"
);
not_cleaned(
'',
"html/atom link, rel is implied 'alternate' in this form"
);
is_cleaned(
'',
"html link with disallowed stylesheet href"
);
is_cleaned(
'',
"html link with one good and one bad rel value"
);
not_cleaned(
'',
"html link with good stylesheet"
);
is_cleaned(
'',
"html link with script rel, this is not allowed ever",
);