File: 04-misc.t

package info (click to toggle)
libhtml-mason-perl 1%3A1.58-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,796 kB
  • sloc: perl: 8,618; sh: 49; makefile: 2
file content (317 lines) | stat: -rw-r--r-- 8,951 bytes parent folder | download | duplicates (6)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
use strict;
use warnings;

use File::Spec;
use HTML::Mason::Tests;

my $tests = make_tests();
$tests->run;

sub make_tests
{
    my $group = HTML::Mason::Tests->tests_class->new( name => 'misc',
                                                      description => 'autohandler and dhandler functionality' );


#------------------------------------------------------------

    $group->add_support( path => '/autohandler_test/autohandler',
                         component => <<'EOF',
<& header &>
Autohandler comp: <% $m->fetch_next->title %>
% my $buf;
% $m->call_next(b=>$a*2);
<& footer &>

<%args>
$a=>5
</%args>
EOF
                       );


#------------------------------------------------------------

    $group->add_support( path => '/autohandler_test/header',
                         component => <<'EOF',
<body bgcolor=<% $bgcolor %>>
<h2>The Site</h2>

<%args>
$bgcolor=>'white'
</%args>
EOF
                       );


#------------------------------------------------------------

    $group->add_support( path => '/autohandler_test/footer',
                         component => <<'EOF',
<hr>
Copyright 1999 Schmoopie Inc.

EOF
                       );


#------------------------------------------------------------

    $group->add_test( name => 'autohandler',
                      path => '/autohandler_test/hello',
                      call_path => '/autohandler_test/hello',
                      description => 'autohandler test',
                      component => <<'EOF',
Hello World!
The answer is <% $b %>.
<%args>
$b
</%args>



EOF
                      expect => <<'EOF',
<body bgcolor=white>
<h2>The Site</h2>


Autohandler comp: /misc/autohandler_test/hello
Hello World!
The answer is 10.



<hr>
Copyright 1999 Schmoopie Inc.



EOF
                    );



#------------------------------------------------------------

    $group->add_support( path => '/dhandler_test/dhandler',
                         component => <<'EOF',
dhandler = <% $m->current_comp->title %>
dhandler arg = <% $m->dhandler_arg %>
EOF
                       );


#------------------------------------------------------------

    $group->add_support( path => '/dhandler_test/subdir/dhandler',
                         component => <<'EOF',
% $m->decline if $m->dhandler_arg eq 'leaf3';
% $m->decline if $m->dhandler_arg eq 'slashes';
% $m->decline if $m->dhandler_arg eq 'buffers';
dhandler = <% $m->current_comp->title %>
dhandler arg = <% $m->dhandler_arg %>
EOF
                       );


#------------------------------------------------------------

    $group->add_support( path => '/dhandler_test/subdir/autohandler',
                         component => <<'EOF',
Header
<% $m->call_next %>
EOF
                       );


#------------------------------------------------------------

    $group->add_support( path => '/dhandler_test/bar/dhandler',
                         component => <<'EOF',
dhandler = <% $m->current_comp->title %>
dhandler arg = <% $m->dhandler_arg %>
EOF
                       );

#------------------------------------------------------------

    $group->add_support( path => '/dhandler_test/buff/dhandler',
                         component => <<'EOF',
Buffer stack size: <% scalar $m->buffer_stack %>
EOF
                       );


#------------------------------------------------------------

    $group->add_test( name => 'dhandler1',
                      description => 'tests dhandler against nonexistent comp',
                      call_path => '/dhandler_test/foo/bar',
                      skip_component => 1,
                      expect => <<'EOF',
dhandler = /misc/dhandler_test/dhandler
dhandler arg = foo/bar

EOF
                    );


#------------------------------------------------------------

    $group->add_test( name => 'dhandler2',
                      description => 'real comp to make sure the real comp is invoked, not the dhandler',
                      path => '/dhandler_test/subdir/leaf',
                      call_path => '/dhandler_test/subdir/leaf',
                      component => <<'EOF',
I'm leaf
EOF
                      expect => <<'EOF',
Header
I'm leaf

EOF
                    );


#------------------------------------------------------------

    $group->add_test( name => 'dhandler3',
                      description => 'real comp declines the request to make sure the dhandler is invoked',
                      path => '/dhandler_test/subdir/leaf2',
                      call_path => '/dhandler_test/subdir/leaf2',
                      component => <<'EOF',
% $m->decline;
I'm leaf2

EOF
                      expect => <<'EOF',
Header
dhandler = /misc/dhandler_test/subdir/dhandler
dhandler arg = leaf2

EOF
                    );


#------------------------------------------------------------

    $group->add_test( name => 'dhandler4',
                      description => 'declines twice to make sure higher level dhandler is called',
                      path => '/dhandler_test/subdir/leaf3',
                      call_path => '/dhandler_test/subdir/leaf3',
                      component => <<'EOF',
% $m->decline;
I'm leaf3
EOF
                      expect => <<'EOF',
dhandler = /misc/dhandler_test/dhandler
dhandler arg = subdir/leaf3

EOF
                    );

#------------------------------------------------------------

    $group->add_test( name => 'dhandler5',
                      description => 'decline with doubled slash (//) in URL path',
                      path => '/dhandler_test/subdir/slashes',
                      call_path => '//dhandler_test//subdir//slashes',
                      component => <<'EOF',
% $m->decline;
I have many slashes!
EOF
                      expect => <<'EOF',
dhandler = /misc/dhandler_test/dhandler
dhandler arg = subdir/slashes

EOF
                    );

#------------------------------------------------------------

    $group->add_test( name => 'dhandler6',
                      description => 'test that a dhandler more than one directory up is found',
                      call_path => '/dhandler_test/bar/baz/quux/not_here',
                      skip_component => 1,
                      expect => <<'EOF',
dhandler = /misc/dhandler_test/bar/dhandler
dhandler arg = baz/quux/not_here

EOF
                    );

#------------------------------------------------------------

    $group->add_test( name => 'accessor_validate',
                      description => 'test accessor parameter validation',
                      component => <<'EOF',
% $m->interp->ignore_warnings_expr([1]);
EOF
                      expect_error => qr/Parameter #1.*to .*? was an 'arrayref'/,
                    );

#------------------------------------------------------------

    $group->add_test( name => 'contained_accessor_validate',
                      description => 'test contained accessor parameter validation',
                      component => <<'EOF',
% $m->interp->autoflush([1]);
EOF
                      expect_error => qr/Parameter #1.*to .*? was an 'arrayref'/,
                    );

#------------------------------------------------------------

    # define /dhandler that sometimes declines. test framework should provide a
    # more supported way to define a top-level component!
    my $updir = File::Spec->updir;
    $group->add_support( path => "$updir/dhandler",
                         component => <<'EOF',
% if ($m->request_args->{decline_from_top}) {
%   $m->decline;
% } else {
top-level dhandler: path = <% $m->current_comp->path %>
% }
EOF
                       );

#------------------------------------------------------------

    $group->add_support( path => '/dhandler',
                         component => <<'EOF',
% $m->decline;
EOF
                       );

#------------------------------------------------------------

    $group->add_test( name => 'top_level_dhandler_handles',
                      description => 'make sure dhandler at /dhandler is called correctly after decline from lower-level dhandler',
                      path      => '/notused',
                      call_path => '/nonexistent',
                      component => <<'EOF',
not ever used
EOF
                      expect => <<'EOF',
top-level dhandler: path = /dhandler
EOF
                    );

#------------------------------------------------------------

    $group->add_test( name => 'top_level_dhandler_declines',
                      description => 'make sure /dhandler decline results in not-found error',
                      path      => '/notused2',
                      call_path => '/nonexistent',
                      call_args => { decline_from_top => 1 },
                      component => <<'EOF',
not ever used
EOF
                      expect_error => qr/could not find component for initial path/,
                    );

#------------------------------------------------------------

    return $group;
}