1#============================================================= -*-perl-*- 2# 3# t/html.t 4# 5# Tests the 'HTML' plugin. 6# 7# Written by Andy Wardley <abw@kfs.org> 8# 9# Copyright (C) 2001 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 warnings; 20use lib qw( ./lib ../lib ); 21use Template; 22use Template::Test; 23use Template::Plugin::HTML; 24 25my $DEBUG = grep(/-d/, @ARGV); 26$Template::Test::DEBUG = $DEBUG; 27$Template::Test::PRESERVE = $DEBUG; 28 29#------------------------------------------------------------------------ 30# behaviour of html filter depends on these being available 31#------------------------------------------------------------------------ 32 33use constant HAS_HTML_Entities => eval { 34 require HTML::Entities; 35 1; 36}; 37use constant HAS_Apache_Util => eval { 38 require Apache::Util; 39 Apache::Utils::escape_html(''); 40 1; 41}; 42 43#print "Has HTML::Entities: ", HAS_HTML_Entities ? 'yes' : 'no', "\n"; 44#print "Has Apache::Util: ", HAS_Apache_Util ? 'yes' : 'no', "\n"; 45 46my $h = Template::Plugin::HTML->new('foo'); 47ok( $h, 'created HTML plugin' ); 48 49my $cfg = { }; 50my $vars = { 51 entities => HAS_HTML_Entities || HAS_Apache_Util || 0, 52}; 53 54test_expect(\*DATA, $cfg, $vars); 55 56__DATA__ 57-- test -- 58-- name html plugin -- 59[% USE HTML -%] 60OK 61-- expect -- 62OK 63 64-- test -- 65-- name html filter -- 66[% FILTER html -%] 67< & > 68[%- END %] 69-- expect -- 70< &amp; > 71 72-- test -- 73-- name html entity -- 74[% TRY; 75 text = "L�on Brocard" | html_entity; 76 77 IF text == "Léon Brocard"; 78 'passed'; 79 ELSIF text == "Léon Brocard"; 80 'passed'; 81 ELSE; 82 "failed: $text"; 83 END; 84 CATCH; 85 error; 86 END; 87%] 88-- expect -- 89-- process -- 90[% IF entities -%] 91passed 92[%- ELSE -%] 93html_entity error - cannot locate Apache::Util or HTML::Entities 94[%- END %] 95 96-- test -- 97[% USE html; html.url('my file.html') -%] 98-- expect -- 99my%20file.html 100 101-- test -- 102-- name escape -- 103[% USE HTML -%] 104[% HTML.escape("if (a < b && c > d) ...") %] 105-- expect -- 106if (a < b && c > d) ... 107 108-- test -- 109-- name sorted -- 110[% USE HTML(sorted=1) -%] 111[% HTML.element(table => { border => 1, cellpadding => 2 }) %] 112-- expect -- 113<table border="1" cellpadding="2"> 114 115-- test -- 116-- name attributes -- 117[% USE HTML -%] 118[% HTML.attributes(border => 1, cellpadding => 2).split.sort.join %] 119-- expect -- 120border="1" cellpadding="2" 121 122