[Templates] Testing plugins

Simon Wilcox essuu@ourshack.com
05 Nov 2002 12:01:10 +0000


Following on from the discussion about image plugins and so on I've
decided that I want to implement my munging as a filter, so that I can
seemlessly fix-up all the image tags on the site without having to break
html syntax in the templates and pages.

So I've used the Template::Plugin::Filter module as the base class and
written my code but when I try to test it I get the following error:

undef error - FilterImg: filter not found at t/1.t line 32.

That's coming from TT as it fails to load the filter but it is already
loaded. What am I doing wrong ?

Test script follows.

Simon.

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

use Test::More tests => 2;
BEGIN { use_ok('Template::Plugin::FilterImg') };

use Template;

#########################

# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

my $imgroot = `pwd`;
chomp $imgroot;

my $t = Template->new();

my $tmpl = <<END;
[% USE FilterImg("$imgroot") %]
[% FILTER FilterImg %]
<img src="/t/test1.gif" />
[% END %]
END

my $output = '';

$t->process( \$tmpl,{},\$output) or die $t->error();

is( $output, '<img src="/t/test1.gif" alt="*" width="470" height="60" />', 'test 1');