File: 16-config.t

package info (click to toggle)
libhtml-template-perl 2.97-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 740 kB
  • sloc: perl: 2,572; makefile: 8
file content (178 lines) | stat: -rw-r--r-- 7,145 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
use strict;
use warnings;
use Test::More ('no_plan');
use_ok('HTML::Template');

my %config = HTML::Template->config();
is_deeply(
    \%config,
    {
        'associate'                   => [],
        'blind_cache'                 => 0,
        'cache'                       => 0,
        'cache_debug'                 => 0,
        'cache_lazy_loops'            => 0,
        'cache_lazy_vars'             => 0,
        'case_sensitive'              => 0,
        'debug'                       => 0,
        'die_on_bad_params'           => 1,
        'die_on_missing_include'      => 1,
        'double_cache'                => 0,
        'double_file_cache'           => 0,
        'file_cache'                  => 0,
        'file_cache_dir'              => '',
        'file_cache_dir_mode'         => 448,
        'filter'                      => [],
        'force_untaint'               => 0,
        'global_vars'                 => 0,
        'ipc_key'                     => 'TMPL',
        'ipc_max_size'                => 0,
        'ipc_mode'                    => 438,
        'ipc_segment_size'            => 65536,
        'loop_context_vars'           => 0,
        'max_includes'                => 10,
        'memory_debug'                => 0,
        'no_includes'                 => 0,
        'open_mode'                   => '',
        'path'                        => [],
        'search_path_on_include'      => 0,
        'shared_cache'                => 0,
        'shared_cache_debug'          => 0,
        'stack_debug'                 => 0,
        'strict'                      => 1,
        'timing'                      => 0,
        'utf8'                        => 0,
        'vanguard_compatibility_mode' => 0
    },
    'correct defaults'
);

# no path so we shouldn't be able to find it
my $tmpl = eval { HTML::Template->new(filename => 'utf8-test.tmpl') };
ok($@, 'exception thrown for not finding filename');
like($@, qr/file not found/, 'file not found');

# now try again after setting path via config
HTML::Template->config(path => 'templates');
$tmpl = eval { HTML::Template->new(filename => 'utf8-test.tmpl') };
ok(!$@, 'no exception thrown');
isa_ok($tmpl, 'HTML::Template');
my $output = $tmpl->output;
chomp($output);
is(sprintf('%vd', $output), "195.164", 'no utf8 config set, so just bytes');

# now try again after setting utf8 via config()
HTML::Template->config(utf8 => 1);
$tmpl = eval { HTML::Template->new(filename => 'utf8-test.tmpl') };
ok(!$@, 'no exception thrown');
isa_ok($tmpl, 'HTML::Template');
$output = $tmpl->output;
chomp($output);
is($output, chr(228), 'correct UTF8 encoded character');

# make sure options pass down into loops
HTML::Template->config(global_vars => 1, die_on_bad_params => 0);
$tmpl = HTML::Template->new_scalar_ref(\'<tmpl_var foo> <tmpl_loop bar><tmpl_var baz>:<tmpl_var foo> <tmpl_loop fiz><tmpl_var baz>:<tmpl_var foo>:<tmpl_var fuz></tmpl_loop> </tmpl_loop> ');
$tmpl->param(foo => 'A', bar => [{baz => 'B', fiz => [{fuz => 'Z'},{fuz => 'Y'}]},{baz => 'C', flop => 'D', fiz => [{fuz => 'X', flo => 'D'}]}]);

$output = $tmpl->output;
is($output, 'A B:A B:A:ZB:A:Y C:A C:A:X  ', 'options passed down into loops');
is($output, $tmpl->output, 'calling it twice results in the same thing');

# make sure the config hash has changed
%config = HTML::Template->config();
is_deeply(
    \%config,
    {
        'associate'                   => [],
        'blind_cache'                 => 0,
        'cache'                       => 0,
        'cache_debug'                 => 0,
        'cache_lazy_loops'            => 0,
        'cache_lazy_vars'             => 0,
        'case_sensitive'              => 0,
        'debug'                       => 0,
        'die_on_bad_params'           => 0,
        'die_on_missing_include'      => 1,
        'double_cache'                => 0,
        'double_file_cache'           => 0,
        'file_cache'                  => 0,
        'file_cache_dir'              => '',
        'file_cache_dir_mode'         => 448,
        'filter'                      => [],
        'force_untaint'               => 0,
        'global_vars'                 => 1,
        'ipc_key'                     => 'TMPL',
        'ipc_max_size'                => 0,
        'ipc_mode'                    => 438,
        'ipc_segment_size'            => 65536,
        'loop_context_vars'           => 0,
        'max_includes'                => 10,
        'memory_debug'                => 0,
        'no_includes'                 => 0,
        'open_mode'                   => '',
        'path'                        => ['templates'],
        'search_path_on_include'      => 0,
        'shared_cache'                => 0,
        'shared_cache_debug'          => 0,
        'stack_debug'                 => 0,
        'strict'                      => 1,
        'timing'                      => 0,
        'utf8'                        => 1,
        'vanguard_compatibility_mode' => 0
    },
    'correct changed defaults'
);

# make sure that options passed to new() don't effect the global configs
$tmpl = eval { HTML::Template->new(filename => 'utf8-test.tmpl', utf8 => 0) };
ok(!$@, 'no exception thrown');
isa_ok($tmpl, 'HTML::Template');
$output = $tmpl->output;
chomp($output);
is(sprintf('%vd', $output), "195.164", 'no utf8 config set, so just bytes');

# make sure the config hash hasn't changed
%config = HTML::Template->config();
is_deeply(
    \%config,
    {
        'associate'                   => [],
        'blind_cache'                 => 0,
        'cache'                       => 0,
        'cache_debug'                 => 0,
        'cache_lazy_loops'            => 0,
        'cache_lazy_vars'             => 0,
        'case_sensitive'              => 0,
        'debug'                       => 0,
        'die_on_bad_params'           => 0,
        'die_on_missing_include'      => 1,
        'double_cache'                => 0,
        'double_file_cache'           => 0,
        'file_cache'                  => 0,
        'file_cache_dir'              => '',
        'file_cache_dir_mode'         => 448,
        'filter'                      => [],
        'force_untaint'               => 0,
        'global_vars'                 => 1,
        'ipc_key'                     => 'TMPL',
        'ipc_max_size'                => 0,
        'ipc_mode'                    => 438,
        'ipc_segment_size'            => 65536,
        'loop_context_vars'           => 0,
        'max_includes'                => 10,
        'memory_debug'                => 0,
        'no_includes'                 => 0,
        'open_mode'                   => '',
        'path'                        => ['templates'],
        'search_path_on_include'      => 0,
        'shared_cache'                => 0,
        'shared_cache_debug'          => 0,
        'stack_debug'                 => 0,
        'strict'                      => 1,
        'timing'                      => 0,
        'utf8'                        => 1,
        'vanguard_compatibility_mode' => 0
    },
    'defaults unchanged'
);