1#============================================================= -*-perl-*- 2# 3# t/image.t 4# 5# Tests the Image plugin. 6# 7# Written by Andy Wardley <abw@wardley.org> 8# 9# Copyright (C) 2002 Andy Wardley. All Rights Reserved. 10# 11# This is free software; you can redistribute it and/or modify it 12# under the same terms as Perl itself. 13# 14# $Id$ 15# 16#======================================================================== 17 18use strict; 19use lib qw( ./lib ../lib ); 20use Template::Test; 21use Cwd; 22use File::Spec; 23$^W = 1; 24 25eval "use Image::Info"; 26if ($@) { 27 eval "use Image::Size"; 28 skip_all('Neither Image::Info nor Image::Size installed') if $@; 29} 30 31my $dir = -d 't' ? 'images' : File::Spec->catfile(File::Spec->updir(), 'images'); 32my $vars = { 33 dir => $dir, 34 file => { 35 logo => File::Spec->catfile($dir, 'ttdotorg.gif'), 36 power => File::Spec->catfile($dir, 'tt2power.gif'), 37 lname => 'ttdotorg.gif', 38 }, 39}; 40 41 42test_expect(\*DATA, undef, $vars); 43 44__DATA__ 45-- test -- 46[% USE Image(file.logo) -%] 47file: [% Image.file %] 48size: [% Image.size.join(', ') %] 49width: [% Image.width %] 50height: [% Image.height %] 51-- expect -- 52-- process -- 53file: [% file.logo %] 54size: 110, 60 55width: 110 56height: 60 57 58-- test -- 59[% USE image( name = file.power) -%] 60name: [% image.name %] 61file: [% image.file %] 62width: [% image.width %] 63height: [% image.height %] 64size: [% image.size.join(', ') %] 65-- expect -- 66-- process -- 67name: [% file.power %] 68file: [% file.power %] 69width: 78 70height: 47 71size: 78, 47 72 73-- test -- 74[% USE image file.logo -%] 75attr: [% image.attr %] 76-- expect -- 77attr: width="110" height="60" 78 79-- test -- 80[% USE image file.logo -%] 81tag: [% image.tag %] 82tag: [% image.tag(class="myimage", alt="image") %] 83-- expect -- 84-- process -- 85tag: <img src="[% file.logo %]" width="110" height="60" alt="" /> 86tag: <img src="[% file.logo %]" width="110" height="60" alt="image" class="myimage" /> 87 88 89# test "root" 90-- test -- 91[% USE image( root=dir name=file.lname ) -%] 92[% image.tag %] 93-- expect -- 94-- process -- 95<img src="[% file.lname %]" width="110" height="60" alt="" /> 96 97# test separate file and name 98-- test -- 99[% USE image( file= file.logo name = "other.jpg" alt="myfile") -%] 100[% image.tag %] 101-- expect -- 102<img src="other.jpg" width="110" height="60" alt="myfile" /> 103