Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 267 lines (218 sloc) 6.267 kB
e39913f @abw *** empty log message ***
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/plugins.t
4 #
5 # Test the Template::Plugins module.
6 #
7 # Written by Andy Wardley <abw@kfs.org>
8 #
9 # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
10 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
11 #
12 # This is free software; you can redistribute it and/or modify it
13 # under the same terms as Perl itself.
14 #
15 # $Id$
16 #
17 #========================================================================
18
19 use strict;
af22f8c @abw Fixed bug (unbugged previous fix) in Template::Plugin::Filter that wa…
authored
20 use lib qw( t/lib ./lib ../lib ../blib/arch );
e39913f @abw *** empty log message ***
authored
21 use Template::Test;
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
22 use Template::Plugins;
4e99583 @abw * various minor updates to accomodate new DEBUG options
authored
23 use Template::Constants qw( :debug );
e39913f @abw *** empty log message ***
authored
24 use Cwd qw( abs_path );
25 $^W = 1;
26
4e99583 @abw * various minor updates to accomodate new DEBUG options
authored
27 my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);
28
e39913f @abw *** empty log message ***
authored
29 #$Template::Test::DEBUG = 0;
30 #$Template::Plugins::DEBUG = 0;
31
32 my $dir = abs_path( -d 't' ? 't/test/plugin' : 'test/plugin' );
af22f8c @abw Fixed bug (unbugged previous fix) in Template::Plugin::Filter that wa…
authored
33 my $src = abs_path( -d 't' ? 't/test/lib' : 'test/lib' );
e39913f @abw *** empty log message ***
authored
34 unshift(@INC, $dir);
35
36 my $tt1 = Template->new({
af22f8c @abw Fixed bug (unbugged previous fix) in Template::Plugin::Filter that wa…
authored
37 PLUGIN_BASE => ['MyPlugs','Template::Plugin'],
38 INCLUDE_PATH => $src,
39 DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
40 }) || die Template->error();
e39913f @abw *** empty log message ***
authored
41
42 require "MyPlugs/Bar.pm";
43 my $bar = MyPlugs::Bar->new(4);
44
45 my $tt2 = Template->new({
46 PLUGINS => {
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
47 bar => 'MyPlugs::Bar',
48 baz => 'MyPlugs::Foo',
49 cgi => 'MyPlugs::Bar',
e39913f @abw *** empty log message ***
authored
50 },
4e99583 @abw * various minor updates to accomodate new DEBUG options
authored
51 DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
52 }) || die Template->error();
e39913f @abw *** empty log message ***
authored
53
54 my $tt3 = Template->new({
55 LOAD_PERL => 1,
4e99583 @abw * various minor updates to accomodate new DEBUG options
authored
56 DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
57 }) || die Template->error();
58
59
60 # we need to delete one of the standard plugins from the $STD_PLUGINS hash
61 # for the purposes of testing
62 delete $Template::Plugins::STD_PLUGINS->{ date };
63
64 # for these we don't want the default Template::Plugin added to the
65 # PLUGIN_BASE search path
66 $Template::Plugins::PLUGIN_BASE = '';
67
68 my $tt4 = Template->new({
69 PLUGIN_BASE => 'MyPlugs',
70 DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
71 });
72
73 my $tt5 = Template->new({
74 DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
e39913f @abw *** empty log message ***
authored
75 });
76
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
77
e39913f @abw *** empty log message ***
authored
78 my $tt = [
79 def => Template->new(),
80 tt1 => $tt1,
81 tt2 => $tt2,
82 tt3 => $tt3,
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
83 tt4 => $tt4,
84 tt5 => $tt5,
e39913f @abw *** empty log message ***
authored
85 ];
86
87 test_expect(\*DATA, $tt, &callsign());
88
89 __END__
90 #------------------------------------------------------------------------
91 # basic plugin loads
92 #------------------------------------------------------------------------
93 -- test --
94 [% USE Table([2, 3, 5, 7, 11, 13], rows=2) -%]
95 [% Table.row(0).join(', ') %]
96 -- expect --
97 2, 5, 11
98
99 -- test --
100 [% USE table([17, 19, 23, 29, 31, 37], rows=2) -%]
101 [% table.row(0).join(', ') %]
102 -- expect --
103 17, 23, 31
104
105 -- test --
106 [% USE t = Table([41, 43, 47, 49, 53, 59], rows=2) -%]
107 [% t.row(0).join(', ') %]
108 -- expect --
109 41, 47, 53
110
111 -- test --
112 [% USE t = table([61, 67, 71, 73, 79, 83], rows=2) -%]
113 [% t.row(0).join(', ') %]
114 -- expect --
115 61, 71, 79
116
117 #------------------------------------------------------------------------
118 # load Foo plugin through custom PLUGIN_BASE
119 #------------------------------------------------------------------------
120 -- test --
121 -- use tt1 --
122 -- test --
123 [% USE t = table([89, 97, 101, 103, 107, 109], rows=2) -%]
124 [% t.row(0).join(', ') %]
125 -- expect --
126 89, 101, 107
127
128 -- test --
129 [% USE Foo(2) -%]
130 [% Foo.output %]
131 -- expect --
132 This is the Foo plugin, value is 2
133
134 -- test --
135 [% USE Bar(4) -%]
136 [% Bar.output %]
137 -- expect --
138 This is the Bar plugin, value is 4
139
140 #------------------------------------------------------------------------
141 # load Foo plugin through custom PLUGINS
142 #------------------------------------------------------------------------
143
144 -- test --
145 -- use tt2 --
146 [% USE t = table([113, 127, 131, 137, 139, 149], rows=2) -%]
147 [% t.row(0).join(', ') %]
148 -- expect --
149 113, 131, 139
150
151 -- test --
152 [% TRY -%]
153 [% USE Foo(8) -%]
154 [% Foo.output %]
155 [% CATCH -%]
156 ERROR: [% error.info %]
157 [% END %]
158 -- expect --
159 ERROR: Foo: plugin not found
160
161 -- test --
162 [% USE bar(16) -%]
163 [% bar.output %]
164 -- expect --
165 This is the Bar plugin, value is 16
166
167 -- test --
168 [% USE qux = baz(32) -%]
169 [% qux.output %]
170 -- expect --
171 This is the Foo plugin, value is 32
172
173 -- test --
174 [% USE wiz = cgi(64) -%]
175 [% wiz.output %]
176 -- expect --
177 This is the Bar plugin, value is 64
178
179 #------------------------------------------------------------------------
180 # LOAD_PERL
181 #------------------------------------------------------------------------
182
183 -- test --
184 -- use tt3 --
185 [% USE baz = MyPlugs.Baz(128) -%]
186 [% baz.output %]
187 -- expect --
188 This is the Baz module, value is 128
fefbc4c @abw * added test to ensure Perl modules loaded correctly strip the
authored
189
190 -- test --
191 [% USE boz = MyPlugs.Baz(256) -%]
192 [% boz.output %]
193 -- expect --
194 This is the Baz module, value is 256
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
195
196
197 #------------------------------------------------------------------------
198 # Test case insensitivity of plugin names. We first look for the plugin
199 # using the name specified in its original case. From v2.15 we also look
200 # for standard plugins using the lower case conversion of the plugin name
201 # specified.
202 #------------------------------------------------------------------------
203
204 -- test --
205 [% USE mycgi = url('/cgi-bin/bar.pl', debug=1); %][% mycgi %]
206 -- expect --
207 /cgi-bin/bar.pl?debug=1
208
209 -- test --
210 [% USE mycgi = URL('/cgi-bin/bar.pl', debug=1); %][% mycgi %]
211 -- expect --
212 /cgi-bin/bar.pl?debug=1
213
214 -- test --
215 [% USE mycgi = UrL('/cgi-bin/bar.pl', debug=1); %][% mycgi %]
216 -- expect --
217 /cgi-bin/bar.pl?debug=1
218
219
220
221
222 #------------------------------------------------------------------------
223 # ADD_DEFAULT_PLUGIN_BASE = 0.
224 # Template::Plugins::URL no longer works since Template::Plugins is not
225 # added to the default plugin base. Same with others. However, url will
226 # work since it is specified as a plugin in
227 # Template::Plugins::STD_PLUGINS.
228 #------------------------------------------------------------------------
229
230 # should find Foo as we've specified 'MyPlugs' in the PLUGIN_BASE
231 -- test --
232 -- use tt4 --
233 [% USE Foo(20) -%]
234 [% Foo.output %]
235 -- expect --
236 This is the Foo plugin, value is 20
237
238
239 -- test --
240 -- use tt4 --
241 [% TRY -%]
242 [% USE Date() -%]
243 [% CATCH -%]
244 ERROR: [% error.info %]
245 [% END %]
246 -- expect --
247 ERROR: Date: plugin not found
248
249 -- test --
250 [% USE mycgi = url('/cgi-bin/bar.pl', debug=1); %][% mycgi %]
251 -- expect --
252 /cgi-bin/bar.pl?debug=1
253
af22f8c @abw Fixed bug (unbugged previous fix) in Template::Plugin::Filter that wa…
authored
254 -- test --
255 -- use tt1 --
256 -- name Simple plugin filter --
257 [% USE Simple -%]
258 test 1: [% 'hello' | simple %]
259 [% INCLUDE simple2 %]
260 test 3: [% 'world' | simple %]
261 -- expect --
262 test 1: **hello**
263 test 2: **badger**
264 test 3: **world**
265
a3f1693 @abw * added tests for clearing $Template::Plugins::PLUGIN_BASE to prevent
authored
266
Something went wrong with that request. Please try again.