1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl HTML-Template-Pro.t'
3
4#########################
5
6# change 'tests => 1' to 'tests => last_test_to_print';
7
8use strict;
9use Test;
10BEGIN {
11    my $test_tmpl_std = 4;
12    my $test_tmpl = 2;
13    plan tests => 1+$test_tmpl_std*21+$test_tmpl*5;
14}
15use File::Spec;
16use HTML::Template::Pro;
17use lib "t";
18use HTML::Template::Pro::CommonTest;
19ok(1); # If we made it this far, we're ok.
20
21#########################
22
23my @varset1=(VAR1=>'VAR1',VAR2=>'VAR2',VAR3=>'VAR3',VAR10=>'VAR10');
24my @varset2=(STUFF1 => '&foo"bar\'</script>=-;+ \<>"; %FA'."hidden:\r\012end", STUFF2=>'Some"'."' Txt'");
25my @refset1=(
26HASHREF0=>[],
27HASHREF2=>[{},{}],
28HASHREF1=>[
29{LOOPVAR1=>'LOOP1-VAR1',LOOPVAR2=>'LOOP1-VAR2',LOOPVAR3=>'LOOP1-VAR3',LOOPVAR10=>'LOOP1-VAR10'},
30{LOOPVAR1=>'LOOP2-VAR1',LOOPVAR2=>'LOOP2-VAR2',LOOPVAR3=>'LOOP2-VAR3',LOOPVAR10=>'LOOP2-VAR10'},
31{LOOPVAR1=>'LOOP3-VAR1',LOOPVAR2=>'LOOP3-VAR2',LOOPVAR3=>'LOOP3-VAR3',LOOPVAR10=>'LOOP3-VAR10'},
32{LOOPVAR1=>'LOOP4-VAR1',LOOPVAR2=>'LOOP4-VAR2',LOOPVAR3=>'LOOP4-VAR3',LOOPVAR10=>'LOOP4-VAR10'},
33]);
34my @outer=({TEST=>'1'},{TEST=>'2'},{TEST=>'3'});
35my @inner=({TST=>'A'},{TST=>'B'});
36my @refset2=(INNER=>\@inner, OUTER=>\@outer);
37
38if ($ENV{HTP_TEST_BROKEN}) {
39    # manual test
40    test_tmpl_std('test_broken', @varset1, @refset1);
41}
42
43test_tmpl_std('test_esc1', @varset1, @varset2);
44test_tmpl_std('test_esc2', @varset1, @varset2);
45test_tmpl_std('test_esc3', @varset1, @varset2);
46test_tmpl_std('test_esc4', @varset1, @varset2);
47
48test_tmpl_std('test_var1', @varset1);
49test_tmpl_std('test_var2', @varset1);
50test_tmpl_std('test_var3', @varset1, @varset2);
51test_tmpl_std('test_if1',  @varset1);
52test_tmpl_std('test_if2',  @varset1);
53test_tmpl_std('test_if3',  @refset1);
54test_tmpl_std('test_if4',  @varset1);
55test_tmpl_std('test_if5',  @varset1);
56test_tmpl_std('test_if7',  @varset1);
57test_tmpl_std('test_include1', @varset1);
58test_tmpl('test_include2', [max_includes=>10], @varset1);
59test_tmpl_std('test_include3', @varset1);
60test_tmpl('test_include4', [path=>['include/1', 'include/2']]);
61test_tmpl('test_include5', [path=>['include/1', 'include/2'], search_path_on_include=>1]);
62test_tmpl_std('test_loop1', @varset1, @refset1);
63test_tmpl_std('test_loop2', @varset1, @refset1);
64test_tmpl_std('test_loop3', @varset1, @refset1);
65test_tmpl_std('test_loop4', @varset1, @refset1);
66test_tmpl_std('test_loop5', @varset1, @refset1);
67test_tmpl('test_loop6',[loop_context_vars=>1,global_vars=>1], @refset2);
68
69test_tmpl_std('include/2', 'LIST', [{TEST => 1}, {TEST=>2}]);
70
71# todo: use config.h and grep defines from here
72# if IMITATE==1 (-DCOMPAT_ALLOW_NAME_IN_CLOSING_TAG)
73#test_tmpl_std('test_if6',  @varset1);
74
75my $devnull=File::Spec->devnull();
76if (defined $devnull) {
77    close (STDERR);
78    #open(STDERR, '>>', $devnull); # is better, but seems not for perl 5.005
79    open (STDERR, '>/dev/null') || print STDERR "devnull: $!\n";
80}
81test_tmpl('test_broken1',[debug=>-1], @varset1, @refset1);
82# not a test -- to see warnings on broken tmpl
83# test_tmpl_std('test_broken', @varset1, @refset1);
84
85### Local Variables:
86### mode: perl
87### End:
88