1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!perl
use strict;
use warnings;
use HTML::Restrict ();
use Test::More;
my @texts = (
{
label => '<img ... />',
html => q{<img alt="foo bar" src="http://example.com/foo.jpg" />},
},
{
label => '<img ... ></img>',
html => q{<img alt="foo bar" src="http://example.com/foo.jpg"></img>},
},
);
my @cases = (
{
label => 'default args',
args => {},
expect => undef,
},
{
label => 'replace_img => 0',
args => { replace_img => 0 },
expect => undef,
},
{
label => 'replace_img => 1',
args => { replace_img => 1 },
expect => '[IMAGE: foo bar]',
},
{
label => 'replace_img => CODE',
args => { replace_img => \&replacer },
expect => '[IMAGE REMOVED: foo bar]',
},
);
sub replacer {
my ( $tag, $attr, $text ) = @_;
return "[IMAGE REMOVED: $attr->{alt}]";
}
for my $c (@cases) {
ok(
my $hr = HTML::Restrict->new( debug => 0, %{ $c->{args} } ),
"$c->{label}: HTML::Restrict->new(...)"
);
for my $t (@texts) {
is(
$hr->process( $t->{html} ), $c->{expect},
"$c->{label}: $t->{label}"
);
}
}
done_testing();
|