[Templates-cvs] cvs commit: TT3/t plugins.t

cvs@template-toolkit.org cvs@template-toolkit.org
Mon, 29 Mar 2004 17:26:52 +0100


cvs         04/03/29 16:26:52

  Modified:    t        plugins.t
  Log:
  more tests
  
  Revision  Changes    Path
  1.3       +73 -2     TT3/t/plugins.t
  
  Index: plugins.t
  ===================================================================
  RCS file: /template-toolkit/TT3/t/plugins.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- plugins.t	2004/03/26 13:27:17	1.2
  +++ plugins.t	2004/03/29 16:26:52	1.3
  @@ -9,7 +9,7 @@
   # This is free software; you can redistribute it and/or modify it
   # under the same terms as Perl itself.
   #
  -# $Id: plugins.t,v 1.2 2004/03/26 13:27:17 abw Exp $
  +# $Id: plugins.t,v 1.3 2004/03/29 16:26:52 abw Exp $
   #
   #========================================================================
   
  @@ -17,8 +17,9 @@
   use warnings;
   
   use lib qw( ./lib ../lib );
  +use Template::Component;
   use Template::Plugins;
  -use Test::More tests => 48;
  +use Test::More tests => 54;
   
   my $DEBUG = 
   $Template::Plugins::DEBUG = 
  @@ -183,8 +184,78 @@
   
   
   
  +#------------------------------------------------------------------------
  +# now try it in the context of a component
  +#------------------------------------------------------------------------
  +
  +# first time through using Template::Plugins class name
  +my $component = Template::Component->new({
  +    plugins => 'Template::Plugins',
  +});
  +
  +$plugin = $component->plugin('hello')
  +    || die $component->error();
  +ok( $plugin, 'got plugin from component using class plugins' );
  +is( $plugin->hello(), 'Hello World!', 'got english plugin from component' );
  +
  +is ( $component->plugin('hello', { language => 'german' })->hello(),
  +    'Hallo Welt!', 'got german plugin from component' );
  +
  +# once again using Template:Plugins object
  +$component = Template::Component->new({
  +    plugins => Template::Plugins->new(),
  +});
  +
  +$plugin = $component->plugin('hello')
  +    || die $component->error();
  +ok( $plugin, 'got plugin from component using class plugins' );
  +is( $plugin->hello(), 'Hello World!', 'got english plugin from component' );
  +
  +is ( $component->plugin('hello', { language => 'german' })->hello(),
  +    'Hallo Welt!', 'got german plugin from component' );
  +
  +
  +#------------------------------------------------------------------------
  +# now let's try it from a real template
  +#------------------------------------------------------------------------
  +
  +use Template::Compilers;
  +use Template::Templates;
  +
  +my $template =<<END_OF_TEMPLATE;
  +This is the first line
  +using plugin: [% USE Hello %]
  +saying hello: [% Hello.hello %]
  +saying hello in english: [% Hello.hello(language => 'english') %]
  +saying hello in german: [% Hello.hello(language => 'german') %]
  +END_OF_TEMPLATE
  +
  +$component = Template::Component->new({
  +    templates => {
  +        hello => $template,
  +    },
  +    plugins   => 'Template::Plugins',
  +    compilers => 'Template::Compilers',
  +    resources => {
  +        templates => Template::Templates->new(),
  +    }
  +});
  +
  +__END__
  +
  +my $result = $component->process('hello')
  +    || die $component->error();
  +
  +#print "result: $result\n";
   
  +my $hello = $component->template('hello');
  +my $source = $hello->source();
   
  +if ($DEBUG) {
  +    my $bar = '-' x 72;
  +    print "$bar\ntext: ", $source->text(), "\n$bar\n";
  +    print "$bar\ncode: ", $source->code(), "\n$bar\n";
  +}
   
   __END__