1use strict; 2use vars qw( @tokens ); 3 4BEGIN { 5 @tokens = ( 6 "\n", "\n", 7 "\nVous Etes Perdu ?\n", "\n", 8 "\n", "\n", 9 "Perdu sur l'Internet ?", "\n", 10 "Pas de panique, on va vous aider", "\n", 11 " * ", "<-", 12 "---- vous ", "tes ici", 13 "\n", "\n", 14 "\n\n" 15 ); 16} 17 18use Test::More tests => 2 + scalar @tokens; 19use HTTP::Proxy::BodyFilter::htmltext; 20 21# the tests are in the HTTP::Proxy::BodyFilter::htmltext callback 22my $sub = sub { is( $_, shift (@tokens), "Correct text token matched" ); }; 23my $data = 24qq{<HTML>\n<HEAD>\n<TITLE>\nVous Etes Perdu ?\n</TITLE>\n</HEAD>\n<BODY>\n<H1>Perdu sur l'Internet ?</H1>\n<H2>Pas de panique, on va vous aider</H2>\n<STRONG><PRE> * <----- vous êtes ici</PRE></STRONG>\n</BODY>\n</HTML>\n\n}; 25my $result = $data; 26 27# test the filter's parser 28my $filter = HTTP::Proxy::BodyFilter::htmltext->new($sub); 29$filter->filter( \$data, undef, undef, undef ); 30is( $data, $result, "Text data not modified" ); 31 32# test the result data when modified 33$result = $data = "<h1>This is a test.</h1>\n<p>Yes, a <b>test</b></p>\n"; 34$result =~ s/test/foobar/g; 35$filter = HTTP::Proxy::BodyFilter::htmltext->new( sub { s/test/foobar/g } ); 36$filter->filter( \$data, undef, undef, undef ); 37 38is( $data, $result, "Text data correctly transformed" ); 39 40